summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
Diffstat (limited to 'disk')
-rw-r--r--disk/part.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/disk/part.c b/disk/part.c
index e9e18a0910..44ef14dc54 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -26,23 +26,35 @@
DECLARE_GLOBAL_DATA_PTR;
-#ifdef CONFIG_HAVE_BLOCK_DEVICE
-static struct part_driver *part_driver_lookup_type(int part_type)
+static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
{
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;
+ if (dev_desc->part_type == PART_TYPE_UNKNOWN) {
+ for (entry = drv; entry != drv + n_ents; entry++) {
+ int ret;
+
+ ret = entry->test(dev_desc);
+ if (!ret) {
+ dev_desc->part_type = entry->part_type;
+ return entry;
+ }
+ }
+ } else {
+ for (entry = drv; entry != drv + n_ents; entry++) {
+ if (dev_desc->part_type == entry->part_type)
+ return entry;
+ }
}
/* Not found */
return NULL;
}
+#ifdef CONFIG_HAVE_BLOCK_DEVICE
static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
{
struct blk_desc *dev_desc;
@@ -285,7 +297,7 @@ void part_print(struct blk_desc *dev_desc)
{
struct part_driver *drv;
- drv = part_driver_lookup_type(dev_desc->part_type);
+ drv = part_driver_lookup_type(dev_desc);
if (!drv) {
printf("## Unknown partition table type %x\n",
dev_desc->part_type);
@@ -314,7 +326,7 @@ int part_get_info(struct blk_desc *dev_desc, int part,
info->type_guid[0] = 0;
#endif
- drv = part_driver_lookup_type(dev_desc->part_type);
+ drv = part_driver_lookup_type(dev_desc);
if (!drv) {
debug("## Unknown partition table type %x\n",
dev_desc->part_type);
@@ -632,28 +644,25 @@ cleanup:
int part_get_info_by_name_type(struct blk_desc *dev_desc, const char *name,
disk_partition_t *info, int part_type)
{
- struct part_driver *first_drv =
- ll_entry_start(struct part_driver, part_driver);
- const int n_drvs = ll_entry_count(struct part_driver, part_driver);
struct part_driver *part_drv;
-
- for (part_drv = first_drv; part_drv != first_drv + n_drvs; part_drv++) {
- int ret;
- int i;
- for (i = 1; i < part_drv->max_entries; i++) {
- if (part_type >= 0 && part_type != part_drv->part_type)
- break;
- ret = part_drv->get_info(dev_desc, i, info);
- if (ret != 0) {
- /* no more entries in table */
- break;
- }
- if (strcmp(name, (const char *)info->name) == 0) {
- /* matched */
- return i;
- }
+ int ret;
+ int i;
+
+ part_drv = part_driver_lookup_type(dev_desc);
+ if (!part_drv)
+ return -1;
+ for (i = 1; i < part_drv->max_entries; i++) {
+ ret = part_drv->get_info(dev_desc, i, info);
+ if (ret != 0) {
+ /* no more entries in table */
+ break;
+ }
+ if (strcmp(name, (const char *)info->name) == 0) {
+ /* matched */
+ return i;
}
}
+
return -1;
}