block: always use st_dev (device ID) of / when looking for root
authorRafał Miłecki <rafal@milecki.pl>
Sat, 2 May 2020 12:05:11 +0000 (14:05 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Tue, 5 May 2020 06:49:36 +0000 (08:49 +0200)
Use this method even if UBIFS extroot support is enabled. This is needed
on x86 systems (using F2FS for overlay) as they may still come with F2FS
enabled.

Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2231
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
block.c

diff --git a/block.c b/block.c
index fd35d6b..c4ae88a 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1316,8 +1316,7 @@ static int find_block_ubi_RO(libubi_t libubi, char *name, char *part, int plen)
 
        return err;
 }
-
-#else
+#endif
 
 static int find_root_dev(char *buf, int len)
 {
@@ -1348,8 +1347,6 @@ static int find_root_dev(char *buf, int len)
        return -1;
 }
 
-#endif
-
 static int test_fs_support(const char *name)
 {
        char line[128], *p;
@@ -1392,26 +1389,25 @@ static int check_extroot(char *path)
        char devpath[32];
        char tag[64];
        FILE *fp;
+       int err;
 
+       err = find_block_mtd("\"rootfs\"", devpath, sizeof(devpath));
 #ifdef UBIFS_EXTROOT
-       if (find_block_mtd("\"rootfs\"", devpath, sizeof(devpath))) {
-               int err = -1;
+       if (err) {
                libubi_t libubi;
 
                libubi = libubi_open();
                err = find_block_ubi_RO(libubi, "rootfs", devpath, sizeof(devpath));
                libubi_close(libubi);
-               if (err)
-                       return -1;
-       }
-#else
-       if (find_block_mtd("\"rootfs\"", devpath, sizeof(devpath))) {
-               if (find_root_dev(devpath, sizeof(devpath))) {
-                       ULOG_ERR("extroot: unable to determine root device\n");
-                       return -1;
-               }
        }
 #endif
+       if (err) {
+               err = find_root_dev(devpath, sizeof(devpath));
+       }
+       if (err) {
+               ULOG_ERR("extroot: unable to determine root device\n");
+               return -1;
+       }
 
        /* Find root device probe_info so we know its UUID */
        list_for_each_entry(tmp, &devices, list) {