uboot:disk add get_partition_bynameorindex()

This function will get partition through name or index.This reference
by Digi U-Boot.
This commit is contained in:
SteveChen
2018-04-30 10:28:23 +08:00
parent c0fce23730
commit a39b446324

View File

@ -741,3 +741,33 @@ cleanup:
free(dup_str); free(dup_str);
return ret; return ret;
} }
int get_partition_bynameorindex(const char *ifname, const char *dev_str,
char *part_nameorindex, disk_partition_t *info)
{
int dev;
unsigned long part;
block_dev_desc_t *dev_desc;
dev = get_device(ifname, dev_str, &dev_desc);
if (dev < 0)
return -1;
/* Check if partition to update is given as a number */
if (!strict_strtoul(part_nameorindex, 16, &part)) {
/* Look up partition by number */
if (!get_partition_info(dev_desc, part, info))
return (int)part;
} else {
/* Look up partition by name */
part = 1;
while (!get_partition_info(dev_desc, part, info)) {
/* Check if partition name matches */
if (!strcmp((char *)info->name, part_nameorindex))
return (int)part;
part++;
}
}
return -1;
}