]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
disk: part: implement generic function part_get_info_by_name()
authorPetr Kulhavy <brain@jikos.cz>
Fri, 9 Sep 2016 08:27:15 +0000 (10:27 +0200)
committerTom Rini <trini@konsulko.com>
Sun, 2 Oct 2016 00:04:45 +0000 (20:04 -0400)
So far partition search by name has been supported only on the EFI partition
table. This patch extends the search to all partition tables.

Rename part_get_info_efi_by_name() to part_get_info_by_name(), move it from
part_efi.c into part.c and make it a generic function which traverses all part
drivers and searches all partitions (in the order given by the linked list).

For this a new variable struct part_driver.max_entries is added, which limits
the number of partitions searched. For EFI this was GPT_ENTRY_NUMBERS.
Similarly the limit is defined for DOS, ISO, MAC and AMIGA partition tables.

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Steve Rae <steve.rae@raedomain.com>
common/fb_mmc.c
disk/part.c
disk/part_amiga.c
disk/part_dos.c
disk/part_efi.c
disk/part_iso.c
disk/part_mac.c
include/part.h

index 8d0524da78f39c5b829bc71813c7549007482ccb..a0a4a83143a7e88292131e4c3e8b16e1eb76ebab 100644 (file)
@@ -27,7 +27,7 @@ static int part_get_info_efi_by_name_or_alias(struct blk_desc *dev_desc,
 {
        int ret;
 
-       ret = part_get_info_efi_by_name(dev_desc, name, info);
+       ret = part_get_info_by_name(dev_desc, name, info);
        if (ret) {
                /* strlen("fastboot_partition_alias_") + 32(part_name) + 1 */
                char env_alias_name[25 + 32 + 1];
@@ -38,7 +38,7 @@ static int part_get_info_efi_by_name_or_alias(struct blk_desc *dev_desc,
                strncat(env_alias_name, name, 32);
                aliased_part_name = getenv(env_alias_name);
                if (aliased_part_name != NULL)
-                       ret = part_get_info_efi_by_name(dev_desc,
+                       ret = part_get_info_by_name(dev_desc,
                                        aliased_part_name, info);
        }
        return ret;
index 6a1c02d9fada7410c953cd144c2ea6968fb3a200..8317e80db5e508396203046ab07ed5eff2ede3d6 100644 (file)
@@ -615,3 +615,29 @@ cleanup:
        free(dup_str);
        return ret;
 }
+
+int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
+       disk_partition_t *info)
+{
+       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++) {
+                       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 0;
+                       }
+               }
+       }
+       return -1;
+}
index d4316b858c1ab45bd6a8077e1ac0b9d818ee8408..25fe56ce4242a8e6e48f42ce3b4e1839253d7bbb 100644 (file)
@@ -381,6 +381,7 @@ static void part_print_amiga(struct blk_desc *dev_desc)
 U_BOOT_PART_TYPE(amiga) = {
        .name           = "AMIGA",
        .part_type      = PART_TYPE_AMIGA,
+       .max_entries    = AMIGA_ENTRY_NUMBERS,
        .get_info       = part_get_info_amiga,
        .print          = part_print_amiga,
        .test           = part_test_amiga,
index 511917a44491e039a396f606da6806d2f4cbe7ac..82266012efd001d4b92abea5f270fbf7f92978e0 100644 (file)
@@ -300,6 +300,7 @@ int part_get_info_dos(struct blk_desc *dev_desc, int part,
 U_BOOT_PART_TYPE(dos) = {
        .name           = "DOS",
        .part_type      = PART_TYPE_DOS,
+       .max_entries    = DOS_ENTRY_NUMBERS,
        .get_info       = part_get_info_ptr(part_get_info_dos),
        .print          = part_print_ptr(part_print_dos),
        .test           = part_test_dos,
index 8d67c09a43a22669af9e702114dc90f4a0d51fad..19243380da75a201beba837918dbacb6fc51ec1e 100644 (file)
@@ -296,25 +296,6 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
        return 0;
 }
 
-int part_get_info_efi_by_name(struct blk_desc *dev_desc,
-       const char *name, disk_partition_t *info)
-{
-       int ret;
-       int i;
-       for (i = 1; i < GPT_ENTRY_NUMBERS; i++) {
-               ret = part_get_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;
-}
-
 static int part_test_efi(struct blk_desc *dev_desc)
 {
        ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz);
@@ -958,6 +939,7 @@ static int is_pte_valid(gpt_entry * pte)
 U_BOOT_PART_TYPE(a_efi) = {
        .name           = "EFI",
        .part_type      = PART_TYPE_EFI,
+       .max_entries    = GPT_ENTRY_NUMBERS,
        .get_info       = part_get_info_ptr(part_get_info_efi),
        .print          = part_print_ptr(part_print_efi),
        .test           = part_test_efi,
index f9a741d2973ba896932753142c3354b27db8f553..78fc97e4f139177f45001137da87c02c31a54a06 100644 (file)
@@ -257,6 +257,7 @@ static int part_test_iso(struct blk_desc *dev_desc)
 U_BOOT_PART_TYPE(iso) = {
        .name           = "ISO",
        .part_type      = PART_TYPE_ISO,
+       .max_entries    = ISO_ENTRY_NUMBERS,
        .get_info       = part_get_info_iso,
        .print          = part_print_iso,
        .test           = part_test_iso,
index 3952b8d37932cb9d894e475590ed20e097151a75..b6c082e7e16d71eb33038d9b185f0e78eead7280 100644 (file)
@@ -239,6 +239,7 @@ static int part_get_info_mac(struct blk_desc *dev_desc, int part,
 U_BOOT_PART_TYPE(mac) = {
        .name           = "MAC",
        .part_type      = PART_TYPE_MAC,
+       .max_entries    = MAC_ENTRY_NUMBERS,
        .get_info       = part_get_info_mac,
        .print          = part_print_mac,
        .test           = part_test_mac,
index 226b5be9df26384818e0299fde0d5f0e9d782646..bd8fd4958c4dcc255d90cf4a6f96b74f9d77510d 100644 (file)
@@ -28,6 +28,11 @@ struct block_drvr {
 #define PART_TYPE_AMIGA                0x04
 #define PART_TYPE_EFI          0x05
 
+/* maximum number of partition entries supported by search */
+#define DOS_ENTRY_NUMBERS      8
+#define ISO_ENTRY_NUMBERS      64
+#define MAC_ENTRY_NUMBERS      64
+#define AMIGA_ENTRY_NUMBERS    8
 /*
  * Type string for U-Boot bootable partitions
  */
@@ -146,6 +151,20 @@ int blk_get_device_by_str(const char *ifname, const char *dev_str,
 int blk_get_device_part_str(const char *ifname, const char *dev_part_str,
                            struct blk_desc **dev_desc,
                            disk_partition_t *info, int allow_whole_dev);
+
+/**
+ * part_get_info_by_name() - Search for a partition by name
+ *                           among all available registered partitions
+ *
+ * @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 part_get_info_by_name(struct blk_desc *dev_desc,
+                             const char *name, disk_partition_t *info);
+
 extern const struct block_drvr block_drvr[];
 #else
 static inline struct blk_desc *blk_get_dev(const char *ifname, int dev)
@@ -189,6 +208,7 @@ static inline int blk_get_device_part_str(const char *ifname,
 struct part_driver {
        const char *name;
        int part_type;
+       const int max_entries;  /* maximum number of entries to search */
 
        /**
         * get_info() - Get information about a partition
@@ -224,18 +244,6 @@ struct part_driver {
 #ifdef CONFIG_EFI_PARTITION
 #include <part_efi.h>
 /* disk/part_efi.c */
-/**
- * part_get_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 part_get_info_efi_by_name(struct blk_desc *dev_desc,
-                             const char *name, disk_partition_t *info);
-
 /**
  * write_gpt_table() - Write the GUID Partition Table to disk
  *