[PATCH 17/18] common: partitions: efi: record type UUID in cdev

Marco Felsch m.felsch at pengutronix.de
Wed Jun 7 01:55:54 PDT 2023


On 23-06-06, Ahmad Fatoum wrote:
> On 31.05.23 21:31, Marco Felsch wrote:
> > Hi Ahmad,
> > 
> > On 23-05-31, Ahmad Fatoum wrote:
> >> We already record DOS partition type in cdev, so let's do the same for
> >> GPT Type UUID. This will be used in a later commit to identify
> >> barebox-state partitions.
> >>
> >> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> >> ---
> >>  common/partitions.c        | 2 +-
> >>  common/partitions/efi.c    | 1 +
> >>  common/partitions/parser.h | 5 ++++-
> >>  fs/fs.c                    | 2 ++
> >>  include/driver.h           | 6 +++++-
> >>  5 files changed, 13 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/common/partitions.c b/common/partitions.c
> >> index b579559672a0..e3e8a9f3044d 100644
> >> --- a/common/partitions.c
> >> +++ b/common/partitions.c
> >> @@ -50,7 +50,7 @@ static int register_one_partition(struct block_device *blk,
> >>  
> >>  	cdev->flags |= DEVFS_PARTITION_FROM_TABLE;
> >>  
> >> -	cdev->dos_partition_type = part->dos_partition_type;
> >> +	cdev->typeuuid = part->typeuuid;
> > 
> > Even though it's an union I would prefer to make it easier for the
> > reader (without checking the header and noticing that it is an union).
> > So the above code would be:
> > 
> > 	if (blkdev_is_gpt_partitioned(blk))
> > 		cdev->typeuuid = part->typeuuid;
> > 	else if (blkdev_is_mbr_partitioned(blk))
> > 		cdev->dos_partition_type = part->dos_partition_type;
> 
> I don't think this is implementable without a runtime cost. I'd leave
> it as is.

I agree if this code path is called often. Anyway, I have no strong
opinion on this but at least to me it is more clear.

Regards,
  Marco


> 
> > 
> > with 
> > 
> > static inline blkdev_is_gpt_partitioned(struct block_device *blkdev)
> > {
> > 	return cdev_is_gpt_partitioned(&blkdev->cdev);
> > }
> > 
> > Regards,
> >   Marco
> > 
> >>  	strcpy(cdev->partuuid, part->partuuid);
> >>  
> >>  	free(partition_name);
> >> diff --git a/common/partitions/efi.c b/common/partitions/efi.c
> >> index df63b82afe24..2756337ab284 100644
> >> --- a/common/partitions/efi.c
> >> +++ b/common/partitions/efi.c
> >> @@ -471,6 +471,7 @@ static void efi_partition(void *buf, struct block_device *blk,
> >>  		pentry->size++;
> >>  		part_set_efi_name(&ptes[i], pentry->name);
> >>  		snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid);
> >> +		pentry->typeuuid = ptes[i].partition_type_guid;
> >>  		pd->used_entries++;
> >>  	}
> >>  }
> >> diff --git a/common/partitions/parser.h b/common/partitions/parser.h
> >> index f2f692f7903b..9cc41a7573fe 100644
> >> --- a/common/partitions/parser.h
> >> +++ b/common/partitions/parser.h
> >> @@ -17,10 +17,13 @@
> >>  
> >>  struct partition {
> >>  	char name[MAX_PARTITION_NAME];
> >> -	u8 dos_partition_type;
> >>  	char partuuid[MAX_UUID_STR];
> >>  	uint64_t first_sec;
> >>  	uint64_t size;
> >> +	union {
> >> +		u8 dos_partition_type;
> >> +		guid_t typeuuid;
> >> +	};
> >>  };
> >>  
> >>  struct partition_desc {
> >> diff --git a/fs/fs.c b/fs/fs.c
> >> index 9a92e6e251e5..16cc072adfaf 100644
> >> --- a/fs/fs.c
> >> +++ b/fs/fs.c
> >> @@ -110,6 +110,8 @@ void cdev_print(const struct cdev *cdev)
> >>  		nbytes += printf("Filetype: %s\t", file_type_to_string(cdev->filetype));
> >>  	if (cdev_is_mbr_partitioned(cdev->master))
> >>  		nbytes += printf("DOS parttype: 0x%02x\t", cdev->dos_partition_type);
> >> +	else if (cdev_is_gpt_partitioned(cdev->master))
> >> +		nbytes += printf("GPT typeuuid: %pUl\t", &cdev->typeuuid);
> >>  	if (*cdev->partuuid || *cdev->diskuuid)
> >>  		nbytes += printf("%sUUID: %s", cdev_is_partition(cdev) ? "PART" : "DISK",
> >>  				 cdev_is_partition(cdev) ? cdev->partuuid : cdev->diskuuid);
> >> diff --git a/include/driver.h b/include/driver.h
> >> index 5f2eae65466f..6407f7d6ba36 100644
> >> --- a/include/driver.h
> >> +++ b/include/driver.h
> >> @@ -8,6 +8,7 @@
> >>  
> >>  #include <linux/list.h>
> >>  #include <linux/ioport.h>
> >> +#include <linux/uuid.h>
> >>  #include <of.h>
> >>  #include <filetype.h>
> >>  
> >> @@ -536,12 +537,15 @@ struct cdev {
> >>  	unsigned int flags;
> >>  	int open;
> >>  	struct mtd_info *mtd;
> >> -	u8 dos_partition_type;
> >>  	struct cdev *link;
> >>  	struct list_head link_entry, links;
> >>  	struct list_head partition_entry, partitions;
> >>  	struct cdev *master;
> >>  	enum filetype filetype;
> >> +	union {
> >> +		u8 dos_partition_type;
> >> +		guid_t typeuuid;
> >> +	};
> >>  };
> >>  
> >>  int devfs_create(struct cdev *);
> >> -- 
> >> 2.39.2
> >>
> >>
> >>
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> 



More information about the barebox mailing list