erofs-utils: enable mapfile for `--tar=f`
authorGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 18 Jun 2024 08:24:14 +0000 (16:24 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 20 Jun 2024 08:46:30 +0000 (16:46 +0800)
The data offsets in the tar streams can always be looked up now:
    mkfs.erofs --tar=f,MAPFILE IMAGE TARBALL

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240618082414.47876-9-hsiangkao@linux.alibaba.com
lib/tar.c
mkfs/main.c

index 8d2caa5ed4eb04e4125ddfceef2337f2a568ce93..532e5669782fa3f25e2fdbb8f03577f4de34d08e 100644 (file)
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -858,7 +858,8 @@ restart:
                        eh.link = strndup(th->linkname, sizeof(th->linkname));
        }
 
-       if (tar->index_mode && !tar->mapfile &&
+       /* EROFS metadata index referring to the original tar data */
+       if (tar->index_mode && sbi->extra_devices &&
            erofs_blkoff(sbi, data_offset)) {
                erofs_err("invalid tar data alignment @ %llu", tar_offset);
                ret = -EIO;
index 971f109c5e2c981de4a8d098781b9959aacbe6f7..c1fe551f2e8a1236cdf8d262b97f7e43887e567e 100644 (file)
@@ -423,6 +423,27 @@ static int mkfs_apply_zfeature_bits(uintmax_t bits)
        return 0;
 }
 
+static void mkfs_parse_tar_cfg(char *cfg)
+{
+       char *p;
+
+       tar_mode = true;
+       if (!cfg)
+               return;
+       p = strchr(cfg, ',');
+       if (p) {
+               *p = '\0';
+               if ((*++p) != '\0')
+                       erofstar.mapfile = strdup(p);
+       }
+       if (!strcmp(cfg, "headerball"))
+               erofstar.headeronly_mode = true;
+
+       if (erofstar.headeronly_mode || !strcmp(optarg, "i") ||
+           !strcmp(optarg, "0"))
+               erofstar.index_mode = true;
+}
+
 static int mkfs_parse_one_compress_alg(char *alg,
                                       struct erofs_compr_opts *copts)
 {
@@ -729,15 +750,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                        cfg.c_extra_ea_name_prefixes = true;
                        break;
                case 20:
-                       if (optarg && (!strcmp(optarg, "i") || (!strcmp(optarg, "headerball") ||
-                               !strcmp(optarg, "0") || !memcmp(optarg, "0,", 2)))) {
-                               erofstar.index_mode = true;
-                               if (!memcmp(optarg, "0,", 2))
-                                       erofstar.mapfile = strdup(optarg + 2);
-                               if (!strcmp(optarg, "headerball"))
-                                       erofstar.headeronly_mode = true;
-                       }
-                       tar_mode = true;
+                       mkfs_parse_tar_cfg(optarg);
                        break;
                case 21:
                        erofstar.aufs = true;