cmd/part.c: implement "part name" subcommand
PATCH 1/1 cmd/part.c: implement "part name" subcommand
This is a natural buddy to the existing "part number", allowing one to get the partition name for a given partition number.
--- cmd/part.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
cmd/part.c +15 -1
@@ -25,7 +25,8 @@enum cmd_part_info {CMD_PART_INFO_START =0 ,CMD_PART_INFO_SIZE , -CMD_PART_INFO_NUMBER +CMD_PART_INFO_NUMBER , +CMD_PART_INFO_NAME , };static int do_part_uuid (int argc,char *const argv[])
@@ -154,6 +155,9 @@ static int do_part_info(int argc, char *const argv[], enum cmd_part_info param)case CMD_PART_INFO_NUMBER :snprintf (buf,sizeof (buf),"0x%x" , part);break ; +case CMD_PART_INFO_NAME : +snprintf (buf,sizeof (buf),"%s" , info.name); +break ;default :printf ("** Unknown cmd_part_info value: %d\n" , param);return 1 ;
@@ -182,6 +186,11 @@ static int do_part_number(int argc, char *const argv[])return do_part_info (argc, argv,CMD_PART_INFO_NUMBER ); } +static int do_part_name (int argc,char *const argv[]) +{ +return do_part_info (argc, argv,CMD_PART_INFO_NAME ); +} +static int do_part_set (int argc,char *const argv[]) {const char *devname, *partstr, *typestr;
@@ -273,6 +282,8 @@ static int do_part(struct cmd_tbl *cmdtp, int flag, int argc,return do_part_size (argc -2 , argv +2 ); else if (!strcmp(argv[1], "number")) return do_part_number(argc - 2, argv + 2); + else if (!strcmp(argv[1], "name")) + return do_part_name(argc - 2, argv + 2); else if (!strcmp(argv[1], "types")) return do_part_types(argc - 2, argv + 2); else if (!strcmp(argv[1], "set"))
@@ -305,6 +316,9 @@ U_BOOT_CMD("part number <interface> <dev> <part> <varname>\n" " - set environment variable to the partition number using the partition name\n" " part must be specified as partition name\n" +"part name <interface> <dev> <part> <varname>\n" +" - set environment variable to the partition name using the partition number\n" +" part must be specified as partition number\n" #ifdef CONFIG_PARTITION_TYPE_GUID"part type <interface> <dev>:<part>\n" " - print partition type\n"
Signature · 1 line
2.51.0
Hi Rasmus,
Quoted 3 lines · Rasmus Villemoes
This is a natural buddy to the existing "part number", allowing one to get the partition name for a given partition number.
Can you update the documentation in doc/usage/cmd/part.rst as well?
Quoted 20 lines
Signed-off-by Rasmus Villemoes <[email protected]>--- cmd/part.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)cmd/part.c +2
-1@@ -25,7 +25,8 @@enum cmd_part_info {CMD_PART_INFO_START =0 ,CMD_PART_INFO_SIZE , -CMD_PART_INFO_NUMBER +CMD_PART_INFO_NUMBER , +CMD_PART_INFO_NAME , };static int do_part_uuid (int argc,char *const argv[])
cmd/part.c static int do_part_info(int argc, char *const argv[], enum cmd_part_info param) · line 159
Quoted 5 lines
cmd/part.c +2
-0@@ -154,6 +155,9 @@ static int do_part_info(int argc, char *const argv[], enum cmd_part_info param)case CMD_PART_INFO_NUMBER :snprintf (buf,sizeof (buf),"0x%x" , part);break ; +case CMD_PART_INFO_NAME : +snprintf (buf,sizeof (buf),"%s" , info.name);
Is it possible info.name is never set by the fs/blk driver? Should we initialize this field?
Cheers,
Quentin
Quoted 8 lines · Quentin Schulz
Hi Rasmus,
Quoted 3 lines · Rasmus Villemoes
This is a natural buddy to the existing "part number", allowing one to get the partition name for a given partition number.
Can you update the documentation in
doc/usage/cmd/part.rstas well?
Will do, thanks.
Quoted 16 lines
Quoted 16 lines
cmd/part.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)cmd/part.c +2
-1@@ -25,7 +25,8 @@enum cmd_part_info {CMD_PART_INFO_START =0 ,CMD_PART_INFO_SIZE , -CMD_PART_INFO_NUMBER +CMD_PART_INFO_NUMBER , +CMD_PART_INFO_NAME , };static int do_part_uuid (int argc,char *const argv[])@@ -154,6 +155,9 @@ static int do_part_info(int argc, char *const argv[], enum cmd_part_info param)
Quoted 9 lines
cmd/part.c static int do_part_info(int argc, char *const argv[], enum cmd_part_info param) · line 159
Quoted 5 lines
cmd/part.c +2
-0case CMD_PART_INFO_NUMBER :snprintf (buf,sizeof (buf),"0x%x" , part);break ; +case CMD_PART_INFO_NAME : +snprintf (buf,sizeof (buf),"%s" , info.name);Is it possible info.name is never set by the fs/blk driver? Should we initialize this field?
So I took a look, and it seems that all but part_amiga.c do initialize it.
- iso and dos uses part_set_generic_name()
- mac and efi have real data from the partition table to put in
- mtd also initializes name, either from a name defined in mtdparts or a size@offset generated one
- ubi uses the volume name
I suppose we should make sure info.name is zero-initialized (or, at least, that info.name[0] is 0 so there's a valid C string). But I think that shouldn't have to be the responsibility of every caller of part_get_info(). IOW, I think we should just add
info->name[0] = '\0'; info->type[0] = '\0';
into part_get_info_by_type(), and then that's a separate patch. WDYT?
Rasmus
Hi Rasmus,
Quoted 5 lines · Rasmus Villemoes
Quoted 3 lines · Quentin Schulz
Hi Rasmus,
On 10/16/25 2:52 PM, Rasmus Villemoes wrote:
[...]
Quoted 43 lines
Quoted 16 lines
Quoted 16 lines
cmd/part.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)cmd/part.c +2
-1@@ -25,7 +25,8 @@enum cmd_part_info {CMD_PART_INFO_START =0 ,CMD_PART_INFO_SIZE , -CMD_PART_INFO_NUMBER +CMD_PART_INFO_NUMBER , +CMD_PART_INFO_NAME , };static int do_part_uuid (int argc,char *const argv[])@@ -154,6 +155,9 @@ static int do_part_info(int argc, char *const argv[], enum cmd_part_info param)Quoted 9 lines
cmd/part.c static int do_part_info(int argc, char *const argv[], enum cmd_part_info param) · line 159
Quoted 5 lines
cmd/part.c +2
-0case CMD_PART_INFO_NUMBER :snprintf (buf,sizeof (buf),"0x%x" , part);break ; +case CMD_PART_INFO_NAME : +snprintf (buf,sizeof (buf),"%s" , info.name);Is it possible info.name is never set by the fs/blk driver? Should we initialize this field?
So I took a look, and it seems that all but
part_amiga.cdo initialize it.- iso and dos uses
part_set_generic_name()- mac and efi have real data from the partition table to put in
- mtd also initializes name, either from a name defined in mtdparts or a size@offset generated one
- ubi uses the volume name
I suppose we should make sure info.name is zero-initialized (or, at least, that info.name[0] is 0 so there's a valid C string). But I think that shouldn't have to be the responsibility of every caller of
part_get_info(). IOW, I think we should just add
Quoted 5 lines
info->name[0] = '\0'; info->type[0] = '\0';into
part_get_info_by_type(), and then that's a separate patch. WDYT?
Yeah, something like disk_partition_clr_name and disk_partition_clr_type for example and call it around the other disk_partition_clr_uuid() calls in part_get_info_by_type.
I think this should also be done by *any* caller of drv->get_info? So likely in part_get_info_by_uuid as well as part_get_info_by_name. I'm also wondering if we shouldn't clear every member when iterating with the same disk_partition, e.g. in part_get_info_by_name, part_get_info_by_uuid, part_get_bootable so that we don't have leftovers from previous failed loops? Essentially what part_get_info_whole_disk() does (though it's missing an init for sys_ind and type_flags). Mmmm but that would mean also patching the loop in cmd/part.c:do_part_list() for example. Or... maybe the whole thing should be a responsibility of the get_info implementer (the part_driver) so that calling get_info is always "safe"?
That would be a separate patch yes, but likely before this one? Or have at least info.name[0] = '\0'; before calling part_get_info*() in do_part_info()?
Pfew.. seems like a lot to do here :/
Quentin