All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Shmakov <ivan@main.uusia.org>
To: linux-ext4@vger.kernel.org
Cc: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: [PATCH] libblkid: support for GUID Partition Table (GPT), please?
Date: Sat, 15 May 2010 10:06:23 +0700	[thread overview]
Message-ID: <87vdapkgnk.fsf@violet.siamics.net> (raw)
In-Reply-To: 87632ql0pg.fsf@violet.siamics.net


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

>>>>> "IS" == Ivan Shmakov <ivan@main.uusia.org> writes:

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

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

	Ahem.  Wrong copy-paste late at night.  Should be better this
	time.

	For a test:

$ blkid -t TYPE=gpt /dev/sd? 
/dev/sdb: UUID="CE050C6F-E7BE-AD46-8FEE-F02476EC767E" TYPE="gpt" 
/dev/sdd: UUID="2A1210B5-535F-4A4A-84D0-34ABC6E57FFB" TYPE="gpt" 
/dev/sde: UUID="7B0FA8C6-26DD-1840-BBF5-46AD26CA551C" TYPE="gpt" 
/dev/sdf: UUID="04DF9DE5-CFDA-514D-99B7-CC61061FCE3C" TYPE="gpt" 
$ 

	Please note that the CRC-32 value contained in the GPT is not
	checked.

	The UUID could be printed in lower case instead.

-- 
FSF associate member #7257

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

diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c
index 6b75732..8500320 100644
--- a/lib/blkid/probe.c
+++ b/lib/blkid/probe.c
@@ -1383,6 +1383,33 @@ 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 */
+
+	{
+		const __u8 *u = gh->disk_guid;
+		char uuid_str[33];
+
+		sprintf (uuid_str,
+			 ("%02X%02X%02X%02X"
+			  "-%02X%02X-%02X%02X-%02X%02X"
+			  "-%02X%02X%02X%02X%02X%02X"),
+			 u[0], u[1], u[2], u[3],
+			 u[4], u[5], u[6], u[7], u[8], u[9],
+			 u[10], u[11], u[12], u[13], u[14], u[15]);
+		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 +1509,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 --]

  reply	other threads:[~2010-05-15  3:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-14 19:53 [PATCH] libblkid: support for GUID Partition Table (GPT), please? Ivan Shmakov
2010-05-15  3:06 ` Ivan Shmakov [this message]
2010-05-17  9:47   ` Karel Zak
2010-05-17 13:45     ` Ivan Shmakov
2010-05-17 17:54       ` tytso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vdapkgnk.fsf@violet.siamics.net \
    --to=ivan@main.uusia.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=oneingray@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.