[PATCH v2] disk: update partition type reporting

[email protected]
Newsgroups gmane.comp.boot-loaders.u-boot
Message-ID <20260818190426.3567429-3-dmukhin__41966.7171941668$1787080013$gmane$org@ford.com>
From: Denis Mukhin <[email protected]> 

Partition drivers currently report "U-Boot" as the human-readable
partition type. This does not describe the actual partition and can be
misleading to the users of this information.

Update the human-readable partition type from "U-Boot" to
partition-specific type.

For GUID partitions, when CONFIG_PARTITION_TYPE_GUID is enabled, use
gpt_pte.partition_type_guid.b directly for type reporting.

Update the relevant tests and drop "U-Boot" check in
blk_get_device_part_str() since it can match against
gpt_pte.partition_type_guid.b (e.g. "linux").

Signed-off-by: Denis Mukhin <[email protected]>
---
Changes since v1:
- use gpt_pte.partition_type_guid.b for CONFIG_PARTITION_TYPE_GUID=y
- add per-type partition string names
- updated commit message text

v1: https://lore.kernel.org/u-boot/[email protected]/
CI: https://github.com/u-boot/u-boot/pull/1036
---
 disk/part.c     | 13 +++----------
 disk/part_dos.c |  5 ++---
 disk/part_efi.c |  5 ++++-
 disk/part_iso.c |  2 +-
 include/part.h  | 10 ++++++++++
 test/dm/scsi.c  |  2 +-
 6 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 4923dc44593c..0661394d2e5d 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -383,7 +383,7 @@ int part_get_info_whole_disk(struct blk_desc *desc,
 	info->size = desc->lba;
 	info->blksz = desc->blksz;
 	info->bootable = 0;
-	strcpy((char *)info->type, BOOT_PART_TYPE);
+	strcpy((char *)info->type, PART_TYPE_NAME_UNKNOWN);
 	strcpy((char *)info->name, "Whole Disk");
 	disk_partition_clr_uuid(info);
 	disk_partition_clr_type_guid(info);
@@ -475,7 +475,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 	 * host's own filesystem.
 	 */
 	if (!strcmp(ifname, "hostfs")) {
-		strcpy((char *)info->type, BOOT_PART_TYPE);
+		strcpy((char *)info->type, PART_TYPE_NAME_HOSTFS);
 		strcpy((char *)info->name, "Host filesystem");
 
 		return 0;
@@ -493,7 +493,7 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 			return -EINVAL;
 		}
 
-		strcpy((char *)info->type, BOOT_PART_TYPE);
+		strcpy((char *)info->type, PART_TYPE_NAME_UBI);
 		strcpy((char *)info->name, "UBI");
 		return 0;
 	}
@@ -645,13 +645,6 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
 			goto cleanup;
 		}
 	}
-	if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 0) {
-		printf("** Invalid partition type \"%.32s\""
-			" (expect \"" BOOT_PART_TYPE "\")\n",
-			info->type);
-		ret  = -EINVAL;
-		goto cleanup;
-	}
 
 	(*desc)->log2blksz = LOG2((*desc)->blksz);
 
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 4e1d01b2f21e..2336321dc77e 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -273,8 +273,7 @@ static int part_get_info_extended(struct blk_desc *desc,
 				info->size  = (lbaint_t)get_unaligned_le32(&pt->nr_sects);
 				part_set_generic_name(desc, part_num,
 						      (char *)info->name);
-				/* sprintf(info->type, "%d, pt->sys_ind); */
-				strcpy((char *)info->type, "U-Boot");
+				strcpy((char *)info->type, PART_TYPE_NAME_DOS);
 				info->bootable = get_bootable(pt);
 				if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
 					char str[12];
@@ -321,7 +320,7 @@ static int part_get_info_extended(struct blk_desc *desc,
 		else
 			info->blksz = DOS_PART_DEFAULT_SECTOR;
 		info->bootable = 0;
-		strcpy((char *)info->type, "U-Boot");
+		strcpy((char *)info->type, PART_TYPE_NAME_DOS);
 		disk_partition_clr_uuid(info);
 		return 0;
 	}
diff --git a/disk/part_efi.c b/disk/part_efi.c
index d8b17ec2e91a..de7048639a6d 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -304,7 +304,6 @@ static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part,
 
 	snprintf((char *)info->name, sizeof(info->name), "%s",
 		 print_efiname(&gpt_pte));
-	strcpy((char *)info->type, "U-Boot");
 	info->bootable = get_bootable(&gpt_pte);
 	info->type_flags = gpt_pte.attributes.fields.type_guid_specific;
 	if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
@@ -316,6 +315,10 @@ static int __maybe_unused part_get_info_efi(struct blk_desc *desc, int part,
 		uuid_bin_to_str(gpt_pte.partition_type_guid.b,
 				(char *)disk_partition_type_guid(info),
 				UUID_STR_FORMAT_GUID);
+		snprintf((char *)info->type, sizeof(info->type), "%pUs",
+			 gpt_pte.partition_type_guid.b);
+	} else {
+		strcpy((char *)info->type, PART_TYPE_NAME_EFI);
 	}
 
 	log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start,
diff --git a/disk/part_iso.c b/disk/part_iso.c
index 6e05b2feffba..7b4e61f2099e 100644
--- a/disk/part_iso.c
+++ b/disk/part_iso.c
@@ -135,7 +135,7 @@ int part_get_info_iso_verb(struct blk_desc *desc, int part_num,
 	/* the validation entry seems to be ok, now search the "partition" */
 	entry_num=1;
 	offset=0x20;
-	strcpy((char *)info->type, "U-Boot");
+	strcpy((char *)info->type, PART_TYPE_NAME_ISO);
 	part_set_generic_name(desc, part_num, (char *)info->name);
 	/* the bootcatalog (including validation Entry) is limited to 2048Bytes
 	 * (63 boot entries + validation entry) */
diff --git a/include/part.h b/include/part.h
index 15daacd7faaa..6fee58b290c9 100644
--- a/include/part.h
+++ b/include/part.h
@@ -31,6 +31,16 @@ struct block_drvr {
 #define PART_TYPE_MTD		0x06
 #define PART_TYPE_UBI		0x07
 
+#define PART_TYPE_NAME_UNKNOWN	"unknown"
+#define PART_TYPE_NAME_MAC	"mac"
+#define PART_TYPE_NAME_DOS	"dos"
+#define PART_TYPE_NAME_ISO	"iso"
+#define PART_TYPE_NAME_AMIGA	"amiga"
+#define PART_TYPE_NAME_EFI	"efi"
+#define PART_TYPE_NAME_MTD	"mtd"
+#define PART_TYPE_NAME_UBI	"ubi"
+#define PART_TYPE_NAME_HOSTFS	"hostfs"
+
 /* maximum number of partition entries supported by search */
 #define DOS_ENTRY_NUMBERS	8
 #define ISO_ENTRY_NUMBERS	64
diff --git a/test/dm/scsi.c b/test/dm/scsi.c
index fbc36a742446..fbf4d1000a10 100644
--- a/test/dm/scsi.c
+++ b/test/dm/scsi.c
@@ -30,7 +30,7 @@ static int dm_test_scsi_base(struct unit_test_state *uts)
 
 	info = &part->gpt_part_info;
 	ut_asserteq_str("sda1", info->name);
-	ut_asserteq_str("U-Boot", info->type);
+	ut_asserteq_str(PART_TYPE_NAME_DOS, info->type);
 	ut_asserteq(0x83 /* linux */, info->sys_ind);
 
 	return 0;
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.