linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libblkid: support for GUID Partition Table (GPT), please?
@ 2010-05-14 19:53 Ivan Shmakov
  2010-05-15  3:06 ` Ivan Shmakov
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Shmakov @ 2010-05-14 19:53 UTC (permalink / raw)
  To: linux-ext4; +Cc: Ivan Shmakov


[-- Attachment #1.1: Type: text/plain, Size: 268 bytes --]

	GPT contains a supposed to be unique “Disk GUID” field, which
	allows for the media bearing such a partition table to be
	identified.

	May I suggest adding support for GPT to libblkid?  An
	alpha-quality patch is MIME'd.

-- 
FSF associate member #7257

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: Type: text/x-diff, Size: 2100 bytes --]

diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c
index 6b75732..0e6c70d 100644
--- a/lib/blkid/probe.c
+++ b/lib/blkid/probe.c
@@ -1383,6 +1383,28 @@ static int probe_btrfs(struct blkid_probe *probe,
 	set_uuid(probe->dev, bs->fsid, 0);
 	return 0;
 }
+
+static int probe_gpt (struct blkid_probe *probe,
+                      struct blkid_magic *id,
+                      unsigned char *buf)
+{
+	struct gpt_header *gh
+		= (struct gpt_header *)(buf + 0x200);
+
+	/* FIXME: check gh->header_crc32 */
+
+	{
+		__u64 uuid;
+		char uuid_str[17];
+
+		uuid = blkid_le64 (*((__u64 *)gh->disk_guid));
+		sprintf (uuid_str, "%016llX", uuid);
+		blkid_set_tag (probe->dev, "UUID", uuid_str, 0);
+	}
+
+	return 0;
+}
+
 /*
  * Various filesystem magics that we can check for.  Note that kboff and
  * sboff are in kilobytes and bytes respectively.  All magics are in
@@ -1482,6 +1504,7 @@ static struct blkid_magic type_array[] = {
   { "lvm2pv",	 1,  0x018,  8, "LVM2 001",		probe_lvm2 },
   { "lvm2pv",	 1,  0x218,  8, "LVM2 001",		probe_lvm2 },
   { "btrfs",	 64,  0x40,  8, "_BHRfS_M",		probe_btrfs },
+  { "gpt",       0,  0x200,  8, "EFI PART",             probe_gpt },
   {   NULL,	 0,	 0,  0, NULL,			NULL }
 };
 
diff --git a/lib/blkid/probe.h b/lib/blkid/probe.h
index 37fc9c0..4d39b84 100644
--- a/lib/blkid/probe.h
+++ b/lib/blkid/probe.h
@@ -725,6 +725,28 @@ struct btrfs_super_block {
 	__u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
 } __attribute__ ((__packed__));
 
+struct gpt_header {
+	/* references:
+	 *   * linux/include/linux/efi.h;
+	 *   * Wikipedia entry.
+	 */
+	__u64 signature;
+	__u32 revision;
+	__u32 header_size;
+	__u32 header_crc32;
+	__u32 reserved1;
+	__u64 my_lba;
+	__u64 alternate_lba;
+	__u64 first_usable_lba;
+	__u64 last_usable_lba;
+	__u8 disk_guid[16];
+	__u64 partition_entry_lba;
+	__u32 num_partition_entries;
+	__u32 sizeof_partition_entry;
+	__u32 partition_entry_array_crc32;
+	__u8 reserved2[512 - 92];
+} __attribute__ ((__packed__));
+
 /*
  * Byte swap functions
  */

[-- Attachment #2: Type: application/pgp-signature, Size: 196 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-05-17 17:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-14 19:53 [PATCH] libblkid: support for GUID Partition Table (GPT), please? Ivan Shmakov
2010-05-15  3:06 ` Ivan Shmakov
2010-05-17  9:47   ` Karel Zak
2010-05-17 13:45     ` Ivan Shmakov
2010-05-17 17:54       ` tytso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).