libblkid: support for GUID Partition Table (GPT), please?
PATCH 1/1 libblkid: support for GUID Partition Table (GPT), please?
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.
Signature · 1 line
FSF associate member #7257
lib/blkid/probe.c +23 -0
@@ -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 } };
lib/blkid/probe.h +22 -0
@@ -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 */
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"IS" == Ivan Shmakov <[email protected]> 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.
Signature · 1 line
FSF associate member #7257
lib/blkid/probe.c +28 -0
@@ -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 } };
lib/blkid/probe.h +22 -0
@@ -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 */
Quoted 5 lines · Ivan Shmakov
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"IS" == Ivan Shmakov <[email protected]> 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
Signature · 6 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Karel Zak <[email protected]> writes:
Ivan Shmakov <[email protected]> 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/
Quoted 9 lines
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
Quoted 8 lines
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 /mntComments?
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.
Signature · 1 line
FSF associate member #7257
Quoted 3 lines · Ivan Shmakov
(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