* [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
* Re: [PATCH] libblkid: support for GUID Partition Table (GPT), please?
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
0 siblings, 1 reply; 5+ messages in thread
From: Ivan Shmakov @ 2010-05-15 3:06 UTC (permalink / raw)
To: linux-ext4; +Cc: Ivan Shmakov
[-- 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 --]
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] libblkid: support for GUID Partition Table (GPT), please?
2010-05-15 3:06 ` Ivan Shmakov
@ 2010-05-17 9:47 ` Karel Zak
2010-05-17 13:45 ` Ivan Shmakov
0 siblings, 1 reply; 5+ messages in thread
From: Karel Zak @ 2010-05-17 9:47 UTC (permalink / raw)
To: Ivan Shmakov; +Cc: linux-ext4
On Sat, May 15, 2010 at 10:06:23AM +0700, Ivan Shmakov wrote:
> >>>>> "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.
The devel version of libblkid from util-linux-ng supports partition tables
parsing, and the partition name (GPT nad Mac) and partition UUID (only GPT)
are exported to udev. For example:
# blkid -p -o udev /dev/sdb1
ID_PART_ENTRY_SCHEME=gpt
ID_PART_ENTRY_NAME=ThisIsName
ID_PART_ENTRY_UUID=bc10cf1d-7e63-524c-8203-087ae10a820b
ID_PART_ENTRY_TYPE=a2a0d0eb-e5b9-3344-87c0-68b6b72699c7
ID_PART_ENTRY_NUMBER=1
In my TODO list is to support partition identifiers for standard
operations like mount/fsck, something like:
# mount PARTUUID=bc10cf1d-7e63-524c-8203-087ae10a820b /mnt
or
# mount PARTLABEL=ThisIsName /mnt
Comments?
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libblkid: support for GUID Partition Table (GPT), please?
2010-05-17 9:47 ` Karel Zak
@ 2010-05-17 13:45 ` Ivan Shmakov
2010-05-17 17:54 ` tytso
0 siblings, 1 reply; 5+ messages in thread
From: Ivan Shmakov @ 2010-05-17 13:45 UTC (permalink / raw)
To: linux-ext4
[-- Attachment #1: Type: text/plain, Size: 2742 bytes --]
>>>>> Karel Zak <kzak@redhat.com> writes:
>>>>> Ivan Shmakov <ivan@main.uusia.org> writes:
>>> GPT contains a supposed to be unique “Disk GUID” field, which allows
>>> for the media bearing such a partition table to be identified.
> The devel version of libblkid from util-linux-ng supports partition
> tables parsing, and the partition name (GPT nad Mac) and partition
> UUID (only GPT) are exported to udev.
I don't quite understand how udev is tied here, but please note
that the UUID I was talking above is the one associated with the
partition table as a whole, not with a particular partition.
(Huh? util-linux-ng has its own libblkid? And, BTW, any chance
of having the changes accepted into e2fsprogs?)
Such a UUID allows for removable media to be identified, which,
in turn, allows for automated backups for such media.
(Consider, e. g., that one has a bunch of bootable USB flash
drives. From time to time, the OS'es are upgraded; and there
may be problems with newer versions. The possibility of
restoring the bootable image to the state it had at a certain
time could then become extremly handy.)
(Actually, I've just finished with the design of such a backup
scheme, and it relies on the media — or partition table —
UUID's, Sleuthkit and, to preserve disk space, Jigdo. Hopefully
I'd be able to describe it at my “hacks collection” [1] soon.)
[1] http://lhc.am-1.org/lhc/users/ivan_shmakov/
> For example:
> # blkid -p -o udev /dev/sdb1
> ID_PART_ENTRY_SCHEME=gpt
> ID_PART_ENTRY_NAME=ThisIsName
> ID_PART_ENTRY_UUID=bc10cf1d-7e63-524c-8203-087ae10a820b
> ID_PART_ENTRY_TYPE=a2a0d0eb-e5b9-3344-87c0-68b6b72699c7
> ID_PART_ENTRY_NUMBER=1
> In my TODO list is to support partition identifiers for standard
> operations like mount/fsck, something like:
> # mount PARTUUID=bc10cf1d-7e63-524c-8203-087ae10a820b /mnt
> or
> # mount PARTLABEL=ThisIsName /mnt
> Comments?
Well, to my mind, allowing UUID's that are stored in the
partition table could be useful in two cases:
• the filesystem contained on a partition doesn't allow for a
UUID;
• the filesystem is ought to be re-initialized (either to the
same filesystem type or any other one) from time to time.
Although I consider both of the above somewhat unlikely in my
current practice, I don't see any harm of having such a feature
“just for a case”.
The labels are a bit useless, to my mind, since when one does
mount(8) or fsck(8) by hand, it's usually when one does it with
the medium attached to a host other than it was usually attached
to. There, a name clash is quite likely.
--
FSF associate member #7257
[-- Attachment #2: Type: application/pgp-signature, Size: 196 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] libblkid: support for GUID Partition Table (GPT), please?
2010-05-17 13:45 ` Ivan Shmakov
@ 2010-05-17 17:54 ` tytso
0 siblings, 0 replies; 5+ messages in thread
From: tytso @ 2010-05-17 17:54 UTC (permalink / raw)
To: Ivan Shmakov; +Cc: linux-ext4
On Mon, May 17, 2010 at 08:45:10PM +0700, Ivan Shmakov wrote:
>
> (Huh? util-linux-ng has its own libblkid? And, BTW, any chance
> of having the changes accepted into e2fsprogs?)
The blkid library has been transitioned to util-linux-ng. I'll put in
critical bug fixes, but at this point, there is significant new
functionality in the version of blkid in util-linux-ng, and the major
distributions are using the one from util-linux-ng.
- Ted
^ permalink raw reply [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).