[U-Boot] [PATCH 4/6] disk: Return the partition number in part_get_info_by_name()

Alex Deymo deymo at google.com
Sun Apr 2 08:49:50 UTC 2017


Similar to what blk_get_device_part_str() does, this patch makes
part_get_info_by_name() return the partition number in case of a match.
This is useful when the partition number is needed and not just the
descriptor.

Signed-off-by: Alex Deymo <deymo at google.com>
---
 common/fb_mmc.c | 6 +++---
 disk/part.c     | 2 +-
 include/part.h  | 3 ++-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index 6cc113d825..866982e41c 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -37,7 +37,7 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
 	int ret;
 
 	ret = part_get_info_by_name(dev_desc, name, info);
-	if (ret) {
+	if (ret < 0) {
 		/* strlen("fastboot_partition_alias_") + 32(part_name) + 1 */
 		char env_alias_name[25 + 32 + 1];
 		char *aliased_part_name;
@@ -153,7 +153,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 	}
 #endif
 
-	if (part_get_info_by_name_or_alias(dev_desc, cmd, &info)) {
+	if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) {
 		error("cannot find partition: '%s'\n", cmd);
 		fastboot_fail("cannot find partition");
 		return;
@@ -205,7 +205,7 @@ void fb_mmc_erase(const char *cmd)
 	}
 
 	ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info);
-	if (ret) {
+	if (ret < 0) {
 		error("cannot find partition: '%s'", cmd);
 		fastboot_fail("cannot find partition");
 		return;
diff --git a/disk/part.c b/disk/part.c
index cd447024c0..491b02dc9c 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -635,7 +635,7 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
 			}
 			if (strcmp(name, (const char *)info->name) == 0) {
 				/* matched */
-				return 0;
+				return i;
 			}
 		}
 	}
diff --git a/include/part.h b/include/part.h
index b6d1b33167..83bce05a43 100644
--- a/include/part.h
+++ b/include/part.h
@@ -163,7 +163,8 @@ int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
  * @param gpt_name - the specified table entry name
  * @param info - returns the disk partition info
  *
- * @return - '0' on match, '-1' on no match, otherwise error
+ * @return - the partition number on match (starting on 1), -1 on no match,
+ * otherwise error
  */
 int part_get_info_by_name(struct blk_desc *dev_desc,
 			      const char *name, disk_partition_t *info);
-- 
2.12.2.564.g063fe858b8-goog



More information about the U-Boot mailing list