diff options
| author | Varadarajan Narayanan <[email protected]> | 2025-05-13 14:47:06 +0530 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2025-05-29 18:35:43 -0600 |
| commit | 43fd4bcefd4ea5e586e201a0908018d1e8395c82 (patch) | |
| tree | cbab621399f961aec7eacb801315fb1e3bcebafe /disk | |
| parent | 48db49b0977cc1c9c9abf82c0fb704238fcef4fd (diff) | |
disk: part: implement generic function part_get_info_by_uuid()
Add function to search for a partition by UUID as partition
names may not be unique.
Signed-off-by: Varadarajan Narayanan <[email protected]>
Acked-by: Casey Connolly <[email protected]>
Diffstat (limited to 'disk')
| -rw-r--r-- | disk/part.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/disk/part.c b/disk/part.c index 303178161c0..8eefda39d7b 100644 --- a/disk/part.c +++ b/disk/part.c @@ -698,6 +698,45 @@ int part_get_info_by_name(struct blk_desc *desc, const char *name, return -ENOENT; } +int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid, + struct disk_partition *info) +{ + struct part_driver *part_drv; + int ret; + int i; + + if (!CONFIG_IS_ENABLED(PARTITION_UUIDS)) + return -ENOENT; + + part_drv = part_driver_lookup_type(desc); + if (!part_drv) + return -1; + + if (!part_drv->get_info) { + log_debug("## Driver %s does not have the get_info() method\n", + part_drv->name); + return -ENOSYS; + } + + for (i = 1; i < part_drv->max_entries; i++) { + ret = part_drv->get_info(desc, i, info); + if (ret != 0) { + /* + * Partition with this index can't be obtained, but + * further partitions might be, so keep checking. + */ + continue; + } + + if (!strncasecmp(uuid, disk_partition_uuid(info), UUID_STR_LEN)) { + /* matched */ + return i; + } + } + + return -ENOENT; +} + /** * Get partition info from device number and partition name. * |
