erofs-utils: mkfs: fix -U option
authorGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 12 Jul 2024 09:38:08 +0000 (17:38 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Sat, 13 Jul 2024 17:05:58 +0000 (01:05 +0800)
`-U <UUID>` option cannot work properly now.

Fixes: 7550a30c332c ("erofs-utils: enable incremental builds")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240712093808.2986196-2-hsiangkao@linux.alibaba.com
mkfs/main.c

index 117f8e3e09c1675f6a4454e59667e47298ba5b33..20f12fc7e82648833b09b9c4b8a12845f66194b9 100644 (file)
@@ -231,6 +231,8 @@ enum {
 
 static unsigned int rebuild_src_count;
 static LIST_HEAD(rebuild_src_list);
+static u8 fixeduuid[16];
+static bool valid_fixeduuid;
 
 static int erofs_mkfs_feat_set_legacy_compress(bool en, const char *val,
                                               unsigned int vallen)
@@ -606,10 +608,11 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                        cfg.c_timeinherit = TIMESTAMP_FIXED;
                        break;
                case 'U':
-                       if (erofs_uuid_parse(optarg, g_sbi.uuid)) {
+                       if (erofs_uuid_parse(optarg, fixeduuid)) {
                                erofs_err("invalid UUID %s", optarg);
                                return -EINVAL;
                        }
+                       valid_fixeduuid = true;
                        break;
                case 2:
                        opt = erofs_parse_exclude_path(optarg, false);
@@ -1255,8 +1258,6 @@ int main(int argc, char **argv)
                        err = PTR_ERR(sb_bh);
                        goto exit;
                }
-               /* generate new UUIDs for clean builds */
-               erofs_uuid_generate(g_sbi.uuid);
        } else {
                union {
                        struct stat st;
@@ -1283,6 +1284,12 @@ int main(int argc, char **argv)
                sb_bh = NULL;
        }
 
+       /* Use the user-defined UUID or generate one for clean builds */
+       if (valid_fixeduuid)
+               memcpy(g_sbi.uuid, fixeduuid, sizeof(g_sbi.uuid));
+       else if (!incremental_mode)
+               erofs_uuid_generate(g_sbi.uuid);
+
        if (tar_mode && !erofstar.index_mode) {
                err = erofs_diskbuf_init(1);
                if (err) {