libfstools: query drivers by priority
authorDaniel Golle <daniel@makrotopia.org>
Thu, 23 Nov 2023 02:06:08 +0000 (02:06 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Fri, 1 Dec 2023 22:59:24 +0000 (22:59 +0000)
Instead of individual hacks meant to prioritize the storage backend
drivers, register them with an optional priotity. If set, the higher
priority driver should be considered be considered first.

Prioritize UBI and MTD over the bulk of block device drivers
(partname, rootdisk) which allows removing previous hacks having the
same effect.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
libfstools/mtd.c
libfstools/rootdisk.c
libfstools/ubi.c
libfstools/volume.c
libfstools/volume.h

index 3696828902c14b27c871d9a4b3bee0f4a0f180eb..fe381450940e522833028cb26cfb0f720bd04365 100644 (file)
@@ -336,6 +336,7 @@ static int mtd_volume_write(struct volume *v, void *buf, int offset, int length)
 
 static struct driver mtd_driver = {
        .name = "mtd",
+       .priority = 10,
        .find = mtd_volume_find,
        .init = mtd_volume_init,
        .erase = mtd_volume_erase,
index 9f2317f14e8d8f12c71b30944138d7a6c877b406..ba7d8c3727ba6c67123d544344dcfa215070becb 100644 (file)
@@ -108,10 +108,6 @@ static struct volume *rootdisk_volume_find(char *name)
        if (!rootdev)
                return NULL;
 
-       if (strstr(rootdev, "mtdblock") ||
-           strstr(rootdev, "ubiblock"))
-               return NULL;
-
        if (get_squashfs(&sb))
                return NULL;
 
index be2c12beafa85bbd38a7efab131292de29ca1c7a..9bd7b050f4784bd59b7ed3d6be3ee6e64ae26c1a 100644 (file)
@@ -171,6 +171,7 @@ static int ubi_volume_identify(struct volume *v)
 
 static struct driver ubi_driver = {
        .name = "ubi",
+       .priority = 20,
        .find = ubi_volume_find,
        .init = ubi_volume_init,
        .identify = ubi_volume_identify,
index 0d293d54ea738acc9f308eaddcfe297ca94b3d7f..b26d1a0f74eba0c2fe510bf8656f501abaee18b7 100644 (file)
@@ -23,7 +23,16 @@ static LIST_HEAD(drivers);
 void
 volume_register_driver(struct driver *d)
 {
-       list_add(&d->list, &drivers);
+       struct driver *cur, *tmp;
+
+       list_for_each_entry_safe(cur, tmp, &drivers, list) {
+               if (d->priority <= cur->priority)
+                       continue;
+
+               _list_add(&d->list, cur->list.prev, &cur->list);
+               return;
+       }
+       list_add_tail(&d->list, &drivers);
 }
 
 struct volume* volume_find(char *name)
index 912b711d4b9347346ff52bbff538d0266b0b16d0..d6a5870541dad4c6ce85e9e8598f26ed2fa2ff76 100644 (file)
@@ -30,6 +30,7 @@ typedef int (*volume_erase_all_t)(struct volume *v);
 
 struct driver {
        struct list_head        list;
+       unsigned int            priority;
        char                    *name;
        volume_probe_t          probe;
        volume_init_t           init;