mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-27 16:01:27 +00:00
part: Support string block devices in part_get_info_by_dev_and_name
This adds support for things like "#partname" and "0.1#partname". The block device parsing is done like in blk_get_device_part_str. Signed-off-by: Sean Anderson <sean.anderson@seco.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
9f7bb2825b
commit
81c1aa89e1
1 changed files with 22 additions and 19 deletions
41
disk/part.c
41
disk/part.c
|
@ -693,12 +693,13 @@ int part_get_info_by_name(struct blk_desc *dev_desc, const char *name,
|
||||||
* Get partition info from device number and partition name.
|
* Get partition info from device number and partition name.
|
||||||
*
|
*
|
||||||
* Parse a device number and partition name string in the form of
|
* Parse a device number and partition name string in the form of
|
||||||
* "device_num#partition_name", for example "0#misc". If the partition
|
* "devicenum.hwpartnum#partition_name", for example "0.1#misc". devicenum and
|
||||||
* is found, sets dev_desc and part_info accordingly with the information
|
* hwpartnum are both optional, defaulting to 0. If the partition is found,
|
||||||
* of the partition with the given partition_name.
|
* sets dev_desc and part_info accordingly with the information of the
|
||||||
|
* partition with the given partition_name.
|
||||||
*
|
*
|
||||||
* @param[in] dev_iface Device interface
|
* @param[in] dev_iface Device interface
|
||||||
* @param[in] dev_part_str Input string argument, like "0#misc"
|
* @param[in] dev_part_str Input string argument, like "0.1#misc"
|
||||||
* @param[out] dev_desc Place to store the device description pointer
|
* @param[out] dev_desc Place to store the device description pointer
|
||||||
* @param[out] part_info Place to store the partition information
|
* @param[out] part_info Place to store the partition information
|
||||||
* @return 0 on success, or a negative on error
|
* @return 0 on success, or a negative on error
|
||||||
|
@ -708,29 +709,31 @@ static int part_get_info_by_dev_and_name(const char *dev_iface,
|
||||||
struct blk_desc **dev_desc,
|
struct blk_desc **dev_desc,
|
||||||
struct disk_partition *part_info)
|
struct disk_partition *part_info)
|
||||||
{
|
{
|
||||||
char *ep;
|
char *dup_str = NULL;
|
||||||
const char *part_str;
|
const char *dev_str, *part_str;
|
||||||
int dev_num, ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Separate device and partition name specification */
|
||||||
part_str = strchr(dev_part_str, '#');
|
part_str = strchr(dev_part_str, '#');
|
||||||
if (!part_str || part_str == dev_part_str)
|
if (part_str) {
|
||||||
return -EINVAL;
|
dup_str = strdup(dev_part_str);
|
||||||
|
dup_str[part_str - dev_part_str] = 0;
|
||||||
dev_num = simple_strtoul(dev_part_str, &ep, 16);
|
dev_str = dup_str;
|
||||||
if (ep != part_str) {
|
part_str++;
|
||||||
/* Not all the first part before the # was parsed. */
|
} else {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
part_str++;
|
|
||||||
|
|
||||||
*dev_desc = blk_get_dev(dev_iface, dev_num);
|
ret = blk_get_device_by_str(dev_iface, dev_str, dev_desc);
|
||||||
if (!*dev_desc) {
|
if (ret)
|
||||||
printf("Could not find %s %d\n", dev_iface, dev_num);
|
goto cleanup;
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
ret = part_get_info_by_name(*dev_desc, part_str, part_info);
|
ret = part_get_info_by_name(*dev_desc, part_str, part_info);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
printf("Could not find \"%s\" partition\n", part_str);
|
printf("Could not find \"%s\" partition\n", part_str);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
free(dup_str);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue