From 0c86fccdc9950436c0b76a64051ea4942f4621c6 Mon Sep 17 00:00:00 2001 From: aia21 Date: Tue, 10 Oct 2006 10:29:11 +0000 Subject: [PATCH] Fix GUID to string conversion to follow documentation (details: it is not little endian at all, it is a binary sequence)... See remarks section at: http://windowssdk.msdn.microsoft.com/en-us/library/96ff78dc.aspx --- include/ntfs/layout.h | 24 ++++++++++++++++-------- libntfs/security.c | 17 ++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/ntfs/layout.h b/include/ntfs/layout.h index 9db8066c..330743dc 100644 --- a/include/ntfs/layout.h +++ b/include/ntfs/layout.h @@ -1142,16 +1142,24 @@ typedef struct { * implementation of the distributed computing environment (DCE) universally * unique identifier (UUID). * - * Example of a GUID: + * Example of a GUID in string format: * 1F010768-5A73-BC91-0010-A52216A7227B + * And the same in binary: + * 1F0107685A73BC910010A52216A7227B */ -typedef struct { - u32 data1; /* The first eight hexadecimal digits of the GUID. */ - u16 data2; /* The first group of four hexadecimal digits. */ - u16 data3; /* The second group of four hexadecimal digits. */ - u8 data4[8]; /* The first two bytes are the third group of four - hexadecimal digits. The remaining six bytes are the - final 12 hexadecimal digits. */ +typedef union { + struct { + u32 data1; /* The first eight hexadecimal digits of the + GUID. */ + u16 data2; /* The first group of four hexadecimal + digits. */ + u16 data3; /* The second group of four hexadecimal + digits. */ + u8 data4[8]; /* The first two bytes are the third group of + four hexadecimal digits. The remaining six + bytes are the final 12 hexadecimal digits. */ + }; + u8 raw[16]; /* Raw binary for ease of access. */ } __attribute__((__packed__)) GUID; /** diff --git a/libntfs/security.c b/libntfs/security.c index 62f9bedd..3af48726 100644 --- a/libntfs/security.c +++ b/libntfs/security.c @@ -43,8 +43,7 @@ /* * The zero GUID. */ -static const GUID __zero_guid = { const_cpu_to_le32(0), const_cpu_to_le16(0), - const_cpu_to_le16(0), { 0, 0, 0, 0, 0, 0, 0, 0 } }; +static const GUID __zero_guid = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }; const GUID *const zero_guid = &__zero_guid; /** @@ -90,13 +89,13 @@ char *ntfs_guid_to_mbs(const GUID *guid, char *guid_str) if (!_guid_str) return _guid_str; } - res = snprintf(_guid_str, 37, - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - (unsigned int)le32_to_cpu(guid->data1), - le16_to_cpu(guid->data2), le16_to_cpu(guid->data3), - guid->data4[0], guid->data4[1], - guid->data4[2], guid->data4[3], guid->data4[4], - guid->data4[5], guid->data4[6], guid->data4[7]); + res = snprintf(_guid_str, 37, "%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x-%02x%02x%02x%02x%02x%02x", guid->raw[0], + guid->raw[1], guid->raw[2], guid->raw[3], guid->raw[4], + guid->raw[5], guid->raw[6], guid->raw[7], guid->raw[8], + guid->raw[9], guid->raw[10], guid->raw[11], + guid->raw[12], guid->raw[13], guid->raw[14], + guid->raw[15], guid->raw[16]); if (res == 36) return _guid_str; if (!guid_str)