erofs-utils: lib: use filesystem UUID if the device name is not specified
authorGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 12 Jun 2024 16:18:23 +0000 (00:18 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 13 Jun 2024 02:44:24 +0000 (10:44 +0800)
The device name is not always valid.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240612161826.711279-2-hsiangkao@linux.alibaba.com
lib/rebuild.c

index 618067a50d42e02afb64b0472f2fd307ab78ff69..c25d22295cd35c93e65bbb92a295643ec31c3ec4 100644 (file)
@@ -15,6 +15,7 @@
 #include "erofs/xattr.h"
 #include "erofs/blobchunk.h"
 #include "erofs/internal.h"
+#include "liberofs_uuid.h"
 
 #ifdef HAVE_LINUX_AUFS_TYPE_H
 #include <linux/aufs_type.h>
@@ -375,16 +376,17 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi)
 {
        struct erofs_inode inode = {};
        struct erofs_rebuild_dir_context ctx;
+       char uuid_str[37];
+       char *fsid = sbi->devname;
        int ret;
 
-       if (!sbi->devname) {
-               erofs_err("failed to find a device for rebuilding");
-               return -EINVAL;
+       if (!fsid) {
+               erofs_uuid_unparse_lower(sbi->uuid, uuid_str);
+               fsid = uuid_str;
        }
-
        ret = erofs_read_superblock(sbi);
        if (ret) {
-               erofs_err("failed to read superblock of %s", sbi->devname);
+               erofs_err("failed to read superblock of %s", fsid);
                return ret;
        }
 
@@ -392,7 +394,7 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi)
        inode.sbi = sbi;
        ret = erofs_read_inode_from_disk(&inode);
        if (ret) {
-               erofs_err("failed to read root inode of %s", sbi->devname);
+               erofs_err("failed to read root inode of %s", fsid);
                return ret;
        }
        inode.i_srcpath = strdup("/");