partitions: UUID was missing from partitions by name
PATCH 1/2 partitions: UUID was missing from partitions by name
The partition code registers one or two cdevs for each partition. The 2nd one is used if the partition has a name. The block of code for each cdev is duplicated twice, and the 2nd copy is missing the bit that copies the partition uuid and the dos partition type to the cdev.
Refactor the register cdev out to a new function that is called twice. This way each cdev is done correctly.
--- common/partitions.c | 70 +++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 32 deletions(-)
common/partitions.c +38 -32
@@ -36,57 +36,63 @@static LIST_HEAD (partition_parser_list);/** -* Register one partition on the given block device +* Register a cdev for given partition. One partition +* can have multiple (1-2) cdev's associated with it. * @param blk Block device to register to * @param part Partition description -* @param no Partition number -* @return 0 on success +* @param partition_name Name for cdev (NULL is checked for) +* @param start Offset of partition start (bytes) +* @param size Partition size (bytes) */ -static int register_one_partition (struct block_device *blk, -struct partition *part,int no) +static int register_partition_cdev (struct block_device *blk, +const struct partition *part, +const char *partition_name, +uint64_t start,uint64_t size) { -char *partition_name; -int ret; -uint64_t start = part->first_sec *SECTOR_SIZE ; -uint64_t size = part->size *SECTOR_SIZE ;struct cdev *cdev; - partition_name =asprintf ("%s.%d" , blk->cdev.name, no);if (!partition_name)return -ENOMEM ;dev_dbg (blk->dev,"Registering partition %s on drive %s\n" , partition_name, blk->cdev.name); cdev =devfs_add_partition (blk->cdev.name, - start, size,0 , partition_name); -if (IS_ERR (cdev)) { - ret =PTR_ERR (cdev); - goto out; - } + start, size,0 , partition_name); +if (IS_ERR (cdev)) +return PTR_ERR (cdev); cdev->dos_partition_type = part->dos_partition_type;strcpy (cdev->partuuid, part->partuuid); -free (partition_name); - -if (!part->name[0 ]) -return 0 ; +return 0 ; +} - partition_name =asprintf ("%s.%s" , blk->cdev.name, part->name); -if (!partition_name) -return -ENOMEM ; +/** +* Register one partition on the given block device +* @param blk Block device to register to +* @param part Partition description +* @param no Partition number +* @return 0 on success +*/ +static int register_one_partition (struct block_device *blk, +struct partition *part,int no) +{ +char *partition_name; +int ret; +uint64_t start = part->first_sec *SECTOR_SIZE ; +uint64_t size = part->size *SECTOR_SIZE ; -dev_dbg (blk->dev,"Registering partition %s on drive %s\n" , - partition_name, blk->cdev.name); - cdev =devfs_add_partition (blk->cdev.name, - start, size,0 , partition_name); +/* Make device with partition number */ + partition_name =asprintf ("%s.%d" , blk->cdev.name, no); + ret =register_partition_cdev (blk, part, partition_name, start, size); +free (partition_name); -if (IS_ERR (cdev)) -dev_warn (blk->dev,"Registering partition %s on drive %s failed\n" , - partition_name, blk->cdev.name); +/* If that worked, try to register with the part name too */ +if (!ret && part->name[0 ]) { + partition_name =asprintf ("%s.%s" , blk->cdev.name, part->name); + ret =register_partition_cdev (blk, part, partition_name, start, size); +free (partition_name); + } - ret =0 ; -out: -free (partition_name);return ret; }
Signature · 7 lines
1.8.3.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/2 partitions/efi: Add partuuid to partition description
In commit bc31d85c6e23d724664e76bcfc3b2eda778012a3 the partition UUID was added to the partition struct and thence to the cdev(s) for the partition. But just for DOS partitions. Do this for GPT aka EFI partitions too.
--- common/partitions/Kconfig | 1 + common/partitions/efi.c | 1 + 2 files changed, 2 insertions(+)
common/partitions/Kconfig +1 -0
@@ -16,6 +16,7 @@ config PARTITION_DISK_DOS config PARTITION_DISK_EFI depends on PARTITION_DISK select CRC32 + select PRINTF_UUID bool "EFI: GPT partition support" help Add support to handle partitions in GUID Partition Table style.
common/partitions/efi.c +1 -0
@@ -457,6 +457,7 @@ static void efi_partition(void *buf, struct block_device *blk, pentry->size =le64_to_cpu (ptes[i].ending_lba) - pentry->first_sec; pentry->size++;part_set_efi_name (&ptes[i], pentry->name); +snprintf (pentry->partuuid,sizeof (pentry->partuuid),"%pU" , &ptes[i].unique_partition_guid); pd->used_entries++; }
Signature · 7 lines
1.8.3.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/2 v2] partitions/efi: Add partuuid to partition description
In commit bc31d85c6e23d724664e76bcfc3b2eda778012a3 the partition UUID was added to the partition struct and thence to the cdev(s) for the partition. But just for DOS partitions. Do this for GPT aka EFI partitions too.
---
Changes from v1:
Turns out the default is to print the UUID in big-endian format but the kernel and everyone else uses little-endian for GPT UUIDs.
common/partitions/Kconfig | 1 + common/partitions/efi.c | 1 + 2 files changed, 2 insertions(+)
common/partitions/Kconfig +1 -0
@@ -16,6 +16,7 @@ config PARTITION_DISK_DOS config PARTITION_DISK_EFI depends on PARTITION_DISK select CRC32 + select PRINTF_UUID bool "EFI: GPT partition support" help Add support to handle partitions in GUID Partition Table style.
common/partitions/efi.c +1 -0
@@ -457,6 +457,7 @@ static void efi_partition(void *buf, struct block_device *blk, pentry->size =le64_to_cpu (ptes[i].ending_lba) - pentry->first_sec; pentry->size++;part_set_efi_name (&ptes[i], pentry->name); +snprintf (pentry->partuuid,sizeof (pentry->partuuid),"%pUl" , &ptes[i].unique_partition_guid); pd->used_entries++; }
Signature · 7 lines
1.8.3.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 7 lines · Trent Piepho
The partition code registers one or two cdevs for each partition. The 2nd one is used if the partition has a name. The block of code for each cdev is duplicated twice, and the 2nd copy is missing the bit that copies the partition uuid and the dos partition type to the cdev.
Refactor the register cdev out to a new function that is called twice. This way each cdev is done correctly.
Nice. Besides of fixing a bug this makes intention of the code is much clearer. Thanks, applied.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox