Commit 87b8530fe24408b0ef41c9b80f38c395ccafad2c
Committed by
Tom Rini
1 parent
ba07984068
Exists in
v2017.01-smarct4x
and in
25 other branches
disk: part: implement generic function part_get_info_by_name()
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>
Showing 8 changed files with 53 additions and 33 deletions Side-by-side Diff
common/fb_mmc.c
... | ... | @@ -27,7 +27,7 @@ |
27 | 27 | { |
28 | 28 | int ret; |
29 | 29 | |
30 | - ret = part_get_info_efi_by_name(dev_desc, name, info); | |
30 | + ret = part_get_info_by_name(dev_desc, name, info); | |
31 | 31 | if (ret) { |
32 | 32 | /* strlen("fastboot_partition_alias_") + 32(part_name) + 1 */ |
33 | 33 | char env_alias_name[25 + 32 + 1]; |
... | ... | @@ -38,7 +38,7 @@ |
38 | 38 | strncat(env_alias_name, name, 32); |
39 | 39 | aliased_part_name = getenv(env_alias_name); |
40 | 40 | if (aliased_part_name != NULL) |
41 | - ret = part_get_info_efi_by_name(dev_desc, | |
41 | + ret = part_get_info_by_name(dev_desc, | |
42 | 42 | aliased_part_name, info); |
43 | 43 | } |
44 | 44 | return ret; |
disk/part.c
... | ... | @@ -615,4 +615,30 @@ |
615 | 615 | free(dup_str); |
616 | 616 | return ret; |
617 | 617 | } |
618 | + | |
619 | +int part_get_info_by_name(struct blk_desc *dev_desc, const char *name, | |
620 | + disk_partition_t *info) | |
621 | +{ | |
622 | + struct part_driver *first_drv = | |
623 | + ll_entry_start(struct part_driver, part_driver); | |
624 | + const int n_drvs = ll_entry_count(struct part_driver, part_driver); | |
625 | + struct part_driver *part_drv; | |
626 | + | |
627 | + for (part_drv = first_drv; part_drv != first_drv + n_drvs; part_drv++) { | |
628 | + int ret; | |
629 | + int i; | |
630 | + for (i = 1; i < part_drv->max_entries; i++) { | |
631 | + ret = part_drv->get_info(dev_desc, i, info); | |
632 | + if (ret != 0) { | |
633 | + /* no more entries in table */ | |
634 | + break; | |
635 | + } | |
636 | + if (strcmp(name, (const char *)info->name) == 0) { | |
637 | + /* matched */ | |
638 | + return 0; | |
639 | + } | |
640 | + } | |
641 | + } | |
642 | + return -1; | |
643 | +} |
disk/part_amiga.c
disk/part_dos.c
disk/part_efi.c
... | ... | @@ -296,25 +296,6 @@ |
296 | 296 | return 0; |
297 | 297 | } |
298 | 298 | |
299 | -int part_get_info_efi_by_name(struct blk_desc *dev_desc, | |
300 | - const char *name, disk_partition_t *info) | |
301 | -{ | |
302 | - int ret; | |
303 | - int i; | |
304 | - for (i = 1; i < GPT_ENTRY_NUMBERS; i++) { | |
305 | - ret = part_get_info_efi(dev_desc, i, info); | |
306 | - if (ret != 0) { | |
307 | - /* no more entries in table */ | |
308 | - return -1; | |
309 | - } | |
310 | - if (strcmp(name, (const char *)info->name) == 0) { | |
311 | - /* matched */ | |
312 | - return 0; | |
313 | - } | |
314 | - } | |
315 | - return -2; | |
316 | -} | |
317 | - | |
318 | 299 | static int part_test_efi(struct blk_desc *dev_desc) |
319 | 300 | { |
320 | 301 | ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz); |
... | ... | @@ -958,6 +939,7 @@ |
958 | 939 | U_BOOT_PART_TYPE(a_efi) = { |
959 | 940 | .name = "EFI", |
960 | 941 | .part_type = PART_TYPE_EFI, |
942 | + .max_entries = GPT_ENTRY_NUMBERS, | |
961 | 943 | .get_info = part_get_info_ptr(part_get_info_efi), |
962 | 944 | .print = part_print_ptr(part_print_efi), |
963 | 945 | .test = part_test_efi, |
disk/part_iso.c
disk/part_mac.c
include/part.h
... | ... | @@ -28,6 +28,11 @@ |
28 | 28 | #define PART_TYPE_AMIGA 0x04 |
29 | 29 | #define PART_TYPE_EFI 0x05 |
30 | 30 | |
31 | +/* maximum number of partition entries supported by search */ | |
32 | +#define DOS_ENTRY_NUMBERS 8 | |
33 | +#define ISO_ENTRY_NUMBERS 64 | |
34 | +#define MAC_ENTRY_NUMBERS 64 | |
35 | +#define AMIGA_ENTRY_NUMBERS 8 | |
31 | 36 | /* |
32 | 37 | * Type string for U-Boot bootable partitions |
33 | 38 | */ |
... | ... | @@ -146,6 +151,20 @@ |
146 | 151 | int blk_get_device_part_str(const char *ifname, const char *dev_part_str, |
147 | 152 | struct blk_desc **dev_desc, |
148 | 153 | disk_partition_t *info, int allow_whole_dev); |
154 | + | |
155 | +/** | |
156 | + * part_get_info_by_name() - Search for a partition by name | |
157 | + * among all available registered partitions | |
158 | + * | |
159 | + * @param dev_desc - block device descriptor | |
160 | + * @param gpt_name - the specified table entry name | |
161 | + * @param info - returns the disk partition info | |
162 | + * | |
163 | + * @return - '0' on match, '-1' on no match, otherwise error | |
164 | + */ | |
165 | +int part_get_info_by_name(struct blk_desc *dev_desc, | |
166 | + const char *name, disk_partition_t *info); | |
167 | + | |
149 | 168 | extern const struct block_drvr block_drvr[]; |
150 | 169 | #else |
151 | 170 | static inline struct blk_desc *blk_get_dev(const char *ifname, int dev) |
... | ... | @@ -189,6 +208,7 @@ |
189 | 208 | struct part_driver { |
190 | 209 | const char *name; |
191 | 210 | int part_type; |
211 | + const int max_entries; /* maximum number of entries to search */ | |
192 | 212 | |
193 | 213 | /** |
194 | 214 | * get_info() - Get information about a partition |
... | ... | @@ -224,18 +244,6 @@ |
224 | 244 | #ifdef CONFIG_EFI_PARTITION |
225 | 245 | #include <part_efi.h> |
226 | 246 | /* disk/part_efi.c */ |
227 | -/** | |
228 | - * part_get_info_efi_by_name() - Find the specified GPT partition table entry | |
229 | - * | |
230 | - * @param dev_desc - block device descriptor | |
231 | - * @param gpt_name - the specified table entry name | |
232 | - * @param info - returns the disk partition info | |
233 | - * | |
234 | - * @return - '0' on match, '-1' on no match, otherwise error | |
235 | - */ | |
236 | -int part_get_info_efi_by_name(struct blk_desc *dev_desc, | |
237 | - const char *name, disk_partition_t *info); | |
238 | - | |
239 | 247 | /** |
240 | 248 | * write_gpt_table() - Write the GUID Partition Table to disk |
241 | 249 | * |