mirror of
https://xff.cz/git/u-boot/
synced 2025-10-28 17:13:38 +01:00
disk: part: Add API to get partitions with specific driver
Adds part_driver_get_type() API which can be used to force a specific driver to be used when getting partition information instead of relying on auto detection. Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
34
disk/part.c
34
disk/part.c
@@ -26,6 +26,22 @@
|
|||||||
/* Check all partition types */
|
/* Check all partition types */
|
||||||
#define PART_TYPE_ALL -1
|
#define PART_TYPE_ALL -1
|
||||||
|
|
||||||
|
static struct part_driver *part_driver_get_type(int part_type)
|
||||||
|
{
|
||||||
|
struct part_driver *drv =
|
||||||
|
ll_entry_start(struct part_driver, part_driver);
|
||||||
|
const int n_ents = ll_entry_count(struct part_driver, part_driver);
|
||||||
|
struct part_driver *entry;
|
||||||
|
|
||||||
|
for (entry = drv; entry != drv + n_ents; entry++) {
|
||||||
|
if (part_type == entry->part_type)
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not found */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
|
static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
|
||||||
{
|
{
|
||||||
struct part_driver *drv =
|
struct part_driver *drv =
|
||||||
@@ -44,10 +60,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (entry = drv; entry != drv + n_ents; entry++) {
|
return part_driver_get_type(dev_desc->part_type);
|
||||||
if (dev_desc->part_type == entry->part_type)
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not found */
|
/* Not found */
|
||||||
@@ -322,7 +335,7 @@ void part_print(struct blk_desc *dev_desc)
|
|||||||
drv->print(dev_desc);
|
drv->print(dev_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
int part_get_info(struct blk_desc *dev_desc, int part,
|
int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
|
||||||
struct disk_partition *info)
|
struct disk_partition *info)
|
||||||
{
|
{
|
||||||
struct part_driver *drv;
|
struct part_driver *drv;
|
||||||
@@ -336,7 +349,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
|
|||||||
info->type_guid[0] = 0;
|
info->type_guid[0] = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (part_type == PART_TYPE_UNKNOWN) {
|
||||||
drv = part_driver_lookup_type(dev_desc);
|
drv = part_driver_lookup_type(dev_desc);
|
||||||
|
} else {
|
||||||
|
drv = part_driver_get_type(part_type);
|
||||||
|
}
|
||||||
|
|
||||||
if (!drv) {
|
if (!drv) {
|
||||||
debug("## Unknown partition table type %x\n",
|
debug("## Unknown partition table type %x\n",
|
||||||
dev_desc->part_type);
|
dev_desc->part_type);
|
||||||
@@ -356,6 +374,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int part_get_info(struct blk_desc *dev_desc, int part,
|
||||||
|
struct disk_partition *info)
|
||||||
|
{
|
||||||
|
return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info);
|
||||||
|
}
|
||||||
|
|
||||||
int part_get_info_whole_disk(struct blk_desc *dev_desc,
|
int part_get_info_whole_disk(struct blk_desc *dev_desc,
|
||||||
struct disk_partition *info)
|
struct disk_partition *info)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -105,7 +105,24 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev);
|
|||||||
|
|
||||||
struct blk_desc *mg_disk_get_dev(int dev);
|
struct blk_desc *mg_disk_get_dev(int dev);
|
||||||
|
|
||||||
/* disk/part.c */
|
/**
|
||||||
|
* part_get_info_by_type() - Get partitions from a block device using a specific
|
||||||
|
* partition driver
|
||||||
|
*
|
||||||
|
* Each interface allocates its own devices and typically struct blk_desc is
|
||||||
|
* contained with the interface's data structure. There is no global
|
||||||
|
* numbering for block devices, so the interface name must be provided.
|
||||||
|
*
|
||||||
|
* @dev_desc: Block device descriptor
|
||||||
|
* @part: Partition number to read
|
||||||
|
* @part_type: Partition driver to use, or PART_TYPE_UNKNOWN to automatically
|
||||||
|
* choose a driver
|
||||||
|
* @info: Returned partition information
|
||||||
|
*
|
||||||
|
* Return: 0 on success, negative errno on failure
|
||||||
|
*/
|
||||||
|
int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
|
||||||
|
struct disk_partition *info);
|
||||||
int part_get_info(struct blk_desc *dev_desc, int part,
|
int part_get_info(struct blk_desc *dev_desc, int part,
|
||||||
struct disk_partition *info);
|
struct disk_partition *info);
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user