Skip to contentSkip to conversation

disk: update partition type reporting

PATCH Superseded [email protected] 2 participants 2 messages Aug 18 – Aug 23

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 disk: update partition type reporting

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").

---
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(-)
disk/part.c +3 -10
index 4923dc44593c..0661394d2e5d 100644
@@ -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);
 
disk/part_dos.c +2 -3
index 4e1d01b2f21e..2336321dc77e 100644
@@ -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;
 	}
disk/part_efi.c +4 -1
index d8b17ec2e91a..de7048639a6d 100644
@@ -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,
disk/part_iso.c +1 -1
index 6e05b2feffba..7b4e61f2099e 100644
@@ -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) */
include/part.h +10 -0
index 15daacd7faaa..6fee58b290c9 100644
@@ -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
test/dm/scsi.c +1 -1
index fbc36a742446..fbf4d1000a10 100644
@@ -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;
Signature · 1 line
2.54.0
#1 lore raw
Quoted 84 lines · On 8/18/26 21:04, [email protected] wrote:

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").

---
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(-)
disk/part.c +3 -10
index 4923dc44593c..0661394d2e5d 100644
@@ -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);
 
disk/part_dos.c +0 -0
index 4e1d01b2f21e..2336321dc77e 100644

disk/part_dos.c static int part_get_info_extended(struct blk_desc *desc, · line 276

Quoted 6 lines
disk/part_dos.c +1 -2
@@ -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);

For GPT partitions the output of the gpt read command looks good with this patch.

Like GPT partitions, MBR partitions have different types.

For type ef, info->type could be 'EFI System Partition'. For type 83, info->type could be 'Linux'.

If you don't want a conversion function, write the hex number to info->type:

sprintf(info->type, "%02x", pt->sys_ind);

Quoted 53 lines
disk/part_dos.c +1 -1
  				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;
  	}
disk/part_efi.c +4 -1
index d8b17ec2e91a..de7048639a6d 100644
@@ -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,
disk/part_iso.c +1 -1
index 6e05b2feffba..7b4e61f2099e 100644
@@ -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) */
include/part.h +0 -0
index 15daacd7faaa..6fee58b290c9 100644

include/part.h struct block_drvr { · line 35

Quoted 5 lines
include/part.h +2 -0
@@ -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"

This is not a valid MAC partition type name.

struct mac_partition has a field uchar type[32]. This is what you should copy in part_get_info_mac().

include/part.h struct block_drvr { · line 36

Quoted 1 line
include/part.h +1 -0
+#define PART_TYPE_NAME_DOS	"dos"

Neither the constant name and nor the value make sense to me. There is nothing called 'dos' in an MBR partition table.

include/part.h struct block_drvr { · line 38

Quoted 2 lines
include/part.h +2 -0
+#define PART_TYPE_NAME_ISO	"iso"
+#define PART_TYPE_NAME_AMIGA	"amiga"

I sent a patch to drop the Amiga driver.

include/part.h struct block_drvr { · line 39

Quoted 1 line
include/part.h +1 -0
+#define PART_TYPE_NAME_EFI	"efi"

The table type is GPT not efi.

Best regards

Heinrich

Quoted 20 lines
include/part.h +4 -0
+#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
test/dm/scsi.c +1 -1
index fbc36a742446..fbf4d1000a10 100644
@@ -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;