--- parted-1.4.23/libparted/disk_gpt.c.orig	Mon Jan 21 09:59:56 2002
+++ parted-1.4.23/libparted/disk_gpt.c	Mon Jan 21 10:17:58 2002
@@ -158,6 +158,38 @@ gpt_cpu_to_le_part_attributes(GuidPartit
 	*b = PED_CPU_TO_LE64(*b);
 }
 
+/**
+ * swap_uuid_and_efi_guid() - converts between uuid formats
+ * @uuid - uuid_t in either format (converts it to the other)
+ *
+ * There are two different representations for Globally Unique Identifiers
+ * (GUIDs or UUIDs).
+ * 
+ * The RFC specifies a UUID as a string of 16 bytes, essentially
+ * a big-endian array of char.
+ * Intel, in their EFI Specification, references the same RFC, but
+ * then defines a GUID as a structure of little-endian fields.
+ * Coincidentally, both structures have the same format when unparsed.
+ *
+ * When read from disk, EFI GUIDs are in struct of little endian format,
+ * and need to be converted to be treated as uuid_t in memory.
+ *
+ * When writing to disk, uuid_ts need to be converted into EFI GUIDs.
+ *
+ * Blame Intel.
+ */
+static void
+swap_uuid_and_efi_guid(uuid_t uuid)
+{
+	int i;
+	efi_guid_t *guid = (efi_guid_t *)uuid;
+
+	PED_ASSERT(uuid != NULL, return);
+	guid->time_low            = PED_SWAP32(guid->time_low);
+	guid->time_mid            = PED_SWAP16(guid->time_mid);
+	guid->time_hi_and_version = PED_SWAP16(guid->time_hi_and_version);
+}
+
 
 /************************************************************
  * efi_crc32()
@@ -347,9 +379,11 @@ gpt_print_part_entry(GuidPartitionEntry_
 	}
 	printf("GUID Partition Entry %d:\n", i);
 	memcpy(uuid, &pte->PartitionTypeGuid, sizeof(uuid_t));
+	swap_uuid_and_efi_guid(uuid);
 	uuid_unparse(uuid, uuid_buffer);
 	printf("\tPartitionTypeGuid : %s\n", uuid_buffer);
 	memcpy(uuid, &pte->UniquePartitionGuid, sizeof(uuid_t));
+	swap_uuid_and_efi_guid(uuid);
 	uuid_unparse(uuid, uuid_buffer);
 	printf("\tUniquePartitionGuid : %s\n", uuid_buffer);
 	printf("\tStartingLBA : " PRIx64 "\n", pte->StartingLBA);
@@ -380,6 +414,7 @@ gpt_print_header(GuidPartitionTableHeade
 	printf("FirstUsableLBA : 0x" PRIx64 "\n", gpt->FirstUsableLBA);
 	printf("LastUsableLBA  : 0x" PRIx64 "\n", gpt->LastUsableLBA);
 	memcpy(uuid, &gpt->DiskGUID, sizeof(uuid_t));
+	swap_uuid_and_efi_guid(uuid);
 	uuid_unparse(uuid, uuid_buffer);
 	printf("DiskGUID : %s\n", uuid_buffer);
 	printf("PartitionEntryLBA : " PRIx64 "\n", gpt->PartitionEntryLBA);
@@ -661,6 +695,7 @@ gpt_write_new(PedDevice *dev)
 		(GPT_DEFAULT_RESERVED_PARTITION_ENTRY_ARRAY_SIZE /
 		 dev->sector_size) - 1;
 	uuid_generate(uuid);
+	swap_uuid_and_efi_guid(uuid);
 	memcpy(&(gpt.DiskGUID), uuid, sizeof(uuid));
 	gpt.PartitionEntryLBA = 2;
 	gpt.NumberOfPartitionEntries = GPT_DEFAULT_RESERVED_PARTITION_ENTRIES;
@@ -1423,6 +1458,7 @@ gpt_partition_new(const PedDisk *disk,
 	gpt_disk_data->ptes[i].StartingLBA = part->geom.start;
 	gpt_disk_data->ptes[i].EndingLBA = part->geom.end;
 	uuid_generate(uuid);
+	swap_uuid_and_efi_guid(uuid);
 	memcpy(&(gpt_disk_data->ptes[i].UniquePartitionGuid), uuid, sizeof(uuid));
 
 	gpt_disk_data->ptes[i].PartitionTypeGuid = PARTITION_BASIC_DATA_GUID;
