Skip to contentSkip to conversation

disk: part: scan the disk if the part_type is unknown

PATCH New Kever Yang 2 participants 4 messages Feb 10, 2018 – Mar 14, 2018

lore
Share & tools
lore

Kever Yang

author
#0 lore raw

PATCH v2 1/2 disk: part: scan the disk if the part_type is unknown

If a DUT do not have partition table, and we write one with 'gpt write' cmd, we should able to list the partition with 'part list' cmd. It's reasonable to scan the disk again if the initial part_type is unknown in case we just write a new one into disk.

---

Changes in v2:
- update commit message to make it more clear why we need this patch

 disk/part.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
disk/part.c +18 -6
index 66b8101..df0d50d 100644
@@ -27,16 +27,28 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 #ifdef HAVE_BLOCK_DEVICE
-static struct part_driver *part_driver_lookup_type(int part_type)
+static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
 	struct part_driver *drv =
 		ll_entry_start(struct part_driver, part_driver);
 	const int n_ents = ll_entry_count(struct part_driver, part_driver);
 	struct part_driver *entry;
 
-	for (entry = drv; entry != drv + n_ents; entry++) {
-		if (part_type == entry->part_type)
-			return entry;
+	if (dev_desc->part_type == PART_TYPE_UNKNOWN) {
+		for (entry = drv; entry != drv + n_ents; entry++) {
+			int ret;
+
+			ret = entry->test(dev_desc);
+			if (!ret) {
+				dev_desc->part_type = entry->part_type;
+				return entry;
+			}
+		}
+	} else {
+		for (entry = drv; entry != drv + n_ents; entry++) {
+			if (dev_desc->part_type == entry->part_type)
+				return entry;
+		}
 	}
 
 	/* Not found */
@@ -285,7 +297,7 @@ void part_print(struct blk_desc *dev_desc)
 {
 	struct part_driver *drv;
 
-	drv = part_driver_lookup_type(dev_desc->part_type);
+	drv = part_driver_lookup_type(dev_desc);
 	if (!drv) {
 		printf("## Unknown partition table type %x\n",
 		       dev_desc->part_type);
@@ -314,7 +326,7 @@ int part_get_info(struct blk_desc *dev_desc, int part,
 	info->type_guid[0] = 0;
 #endif
 
-	drv = part_driver_lookup_type(dev_desc->part_type);
+	drv = part_driver_lookup_type(dev_desc);
 	if (!drv) {
 		debug("## Unknown partition table type %x\n",
 		      dev_desc->part_type);
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v2 2/2 disk: part: use common api to lookup part driver

Do not need to scan disk every time when we get part info by name.

---

Changes in v2:
- rebase to latest version
- add error handle for partition tbale not exist

 disk/part.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)
disk/part.c +16 -19
index df0d50d..b80a4b1 100644
@@ -644,28 +644,25 @@ cleanup:
 int part_get_info_by_name_type(struct blk_desc *dev_desc, const char *name,
 			       disk_partition_t *info, int part_type)
 {
-	struct part_driver *first_drv =
-		ll_entry_start(struct part_driver, part_driver);
-	const int n_drvs = ll_entry_count(struct part_driver, part_driver);
 	struct part_driver *part_drv;
-
-	for (part_drv = first_drv; part_drv != first_drv + n_drvs; part_drv++) {
-		int ret;
-		int i;
-		for (i = 1; i < part_drv->max_entries; i++) {
-			if (part_type >= 0 && part_type != part_drv->part_type)
-				break;
-			ret = part_drv->get_info(dev_desc, i, info);
-			if (ret != 0) {
-				/* no more entries in table */
-				break;
-			}
-			if (strcmp(name, (const char *)info->name) == 0) {
-				/* matched */
-				return i;
-			}
+	int ret;
+	int i;
+
+	part_drv = part_driver_lookup_type(dev_desc);
+	if (!part_drv)
+		return -1;
+	for (i = 1; i < part_drv->max_entries; i++) {
+		ret = part_drv->get_info(dev_desc, i, info);
+		if (ret != 0) {
+			/* no more entries in table */
+			break;
+		}
+		if (strcmp(name, (const char *)info->name) == 0) {
+			/* matched */
+			return i;
 		}
 	}
+
 	return -1;
 }
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH v2 2/2 disk: part: use common api to lookup part driver

Quoted 4 lines · Kever Yang

Do not need to scan disk every time when we get part info by name.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180314/06ea5222/attachment.sig>
#3 lore raw

PATCH v2 1/2 disk: part: scan the disk if the part_type is unknown

In reply to Kever Yang
Quoted 6 lines · Kever Yang

If a DUT do not have partition table, and we write one with 'gpt write' cmd, we should able to list the partition with 'part list' cmd. It's reasonable to scan the disk again if the initial part_type is unknown in case we just write a new one into disk.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180314/bdc73701/attachment.sig>