From: Daniel Golle Date: Thu, 23 Nov 2023 02:06:08 +0000 (+0000) Subject: libfstools: query drivers by priority X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=97bacb70138a56a8f843faaf63af16c5fb2e0d42;p=project%2Ffstools.git libfstools: query drivers by priority 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 --- diff --git a/libfstools/mtd.c b/libfstools/mtd.c index 3696828..fe38145 100644 --- a/libfstools/mtd.c +++ b/libfstools/mtd.c @@ -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, diff --git a/libfstools/rootdisk.c b/libfstools/rootdisk.c index 9f2317f..ba7d8c3 100644 --- a/libfstools/rootdisk.c +++ b/libfstools/rootdisk.c @@ -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; diff --git a/libfstools/ubi.c b/libfstools/ubi.c index be2c12b..9bd7b05 100644 --- a/libfstools/ubi.c +++ b/libfstools/ubi.c @@ -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, diff --git a/libfstools/volume.c b/libfstools/volume.c index 0d293d5..b26d1a0 100644 --- a/libfstools/volume.c +++ b/libfstools/volume.c @@ -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) diff --git a/libfstools/volume.h b/libfstools/volume.h index 912b711..d6a5870 100644 --- a/libfstools/volume.h +++ b/libfstools/volume.h @@ -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;