diff mbox

[3/3] disk: part_efi: add get_partition_info_efi_by_name()

Message ID 1401130344-15450-4-git-send-email-srae@broadcom.com
State Accepted
Commit 60bf94169366acaf7dafeb30d7439af366f2c585
Headers show

Commit Message

Steve Rae May 26, 2014, 6:52 p.m. UTC
Add function to find a GPT table entry by name.

Tested on little endian ARMv7 and ARMv8 configurations

Signed-off-by: Steve Rae <srae@broadcom.com>
---

 disk/part_efi.c | 21 ++++++++++++++++++++-
 include/part.h  | 11 +++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

Comments

Tom Rini June 5, 2014, 10:47 p.m. UTC | #1
On Mon, May 26, 2014 at 11:52:24AM -0700, Steve Rae wrote:

> Add function to find a GPT table entry by name.
> 
> Tested on little endian ARMv7 and ARMv8 configurations
> 
> Signed-off-by: Steve Rae <srae@broadcom.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 78a3782..612f092 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -181,7 +181,7 @@  int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 			UUID_STR_FORMAT_GUID);
 #endif
 
-	debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s", __func__,
+	debug("%s: start 0x" LBAF ", size 0x" LBAF ", name %s\n", __func__,
 	      info->start, info->size, info->name);
 
 	/* Remember to free pte */
@@ -189,6 +189,25 @@  int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 	return 0;
 }
 
+int get_partition_info_efi_by_name(block_dev_desc_t *dev_desc,
+	const char *name, disk_partition_t *info)
+{
+	int ret;
+	int i;
+	for (i = 1; i < GPT_ENTRY_NUMBERS; i++) {
+		ret = get_partition_info_efi(dev_desc, i, info);
+		if (ret != 0) {
+			/* no more entries in table */
+			return -1;
+		}
+		if (strcmp(name, (const char *)info->name) == 0) {
+			/* matched */
+			return 0;
+		}
+	}
+	return -2;
+}
+
 int test_part_efi(block_dev_desc_t * dev_desc)
 {
 	ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
diff --git a/include/part.h b/include/part.h
index f2c8c64..a496a4a 100644
--- a/include/part.h
+++ b/include/part.h
@@ -180,6 +180,17 @@  int   test_part_amiga (block_dev_desc_t *dev_desc);
 #include <part_efi.h>
 /* disk/part_efi.c */
 int get_partition_info_efi (block_dev_desc_t * dev_desc, int part, disk_partition_t *info);
+/**
+ * get_partition_info_efi_by_name() - Find the specified GPT partition table entry
+ *
+ * @param dev_desc - block device descriptor
+ * @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
+ */
+int get_partition_info_efi_by_name(block_dev_desc_t *dev_desc,
+	const char *name, disk_partition_t *info);
 void print_part_efi (block_dev_desc_t *dev_desc);
 int   test_part_efi (block_dev_desc_t *dev_desc);