erofs-utils: mkfs: add `--mkfs-time` option
authorGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 8 Aug 2024 09:45:22 +0000 (17:45 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 8 Aug 2024 10:01:30 +0000 (18:01 +0800)
Some users need a fixed build time in the superblock for reproducible
builds rather than a fixed timestamp everywhere.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240808094522.2161075-1-hsiangkao@linux.alibaba.com
include/erofs/config.h
man/mkfs.erofs.1
mkfs/main.c

index 56650e3b37c5ab65e8e2de148f87a72d75bcb368..ae366c150232d7be796cd3460f283f74ce12e8d5 100644 (file)
@@ -27,6 +27,7 @@ enum {
 };
 
 enum {
+       TIMESTAMP_UNSPECIFIED,
        TIMESTAMP_NONE,
        TIMESTAMP_FIXED,
        TIMESTAMP_CLAMPING,
index 3bff41d3b4774b9b46cba31be2759c992b358270..d599fac3d30acc0add8d0182a99a39d60daee6c8 100644 (file)
@@ -100,8 +100,10 @@ Set the volume label for the filesystem to
 The maximum length of the volume label is 16 bytes.
 .TP
 .BI "\-T " #
-Set all files to the given UNIX timestamp. Reproducible builds require setting
-all to a specific one. By default, the source file's modification time is used.
+Specify a UNIX timestamp for image creation time for reproducible builds.
+If \fI--mkfs-time\fR is not specified, it will behave as \fI--all-time\fR:
+setting all files to the specified UNIX timestamp instead of using the
+modification times of the source files.
 .TP
 .BI "\-U " UUID
 Set the universally unique identifier (UUID) of the filesystem to
@@ -112,6 +114,10 @@ like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16".
 .B \-\-all-root
 Make all files owned by root.
 .TP
+.B \-\-all-time
+(used together with \fB-T\fR) set all files to the fixed timestamp. This is the
+default.
+.TP
 .BI "\-\-blobdev " file
 Specify an extra blob device to store chunk-based data.
 .TP
@@ -177,6 +183,10 @@ can reduce total metadata size. Implied by
 .BI "\-\-max-extent-bytes " #
 Specify maximum decompressed extent size in bytes.
 .TP
+.B \-\-mkfs-time
+(used together with \fB-T\fR) the given timestamp is only applied to the build
+time.
+.TP
 .B "\-\-preserve-mtime"
 Use extended inodes instead of compact inodes if the file modification time
 would overflow compact inodes. This is the default. Overrides
index aba5ce4b868675475538c8b0597eb61d48acebbe..b7129eb7c6e05489af9f950b3ee590dc920bc352 100644 (file)
@@ -82,6 +82,8 @@ static struct option long_options[] = {
        {"clean", optional_argument, NULL, 522},
        {"incremental", optional_argument, NULL, 523},
        {"root-xattr-isize", required_argument, NULL, 524},
+       {"mkfs-time", no_argument, NULL, 525},
+       {"all-time", no_argument, NULL, 526},
        {0, 0, 0, 0},
 };
 
@@ -150,7 +152,9 @@ static void usage(int argc, char **argv)
                " -C#                   specify the size of compress physical cluster in bytes\n"
                " -EX[,...]             X=extended options\n"
                " -L volume-label       set the volume label (maximum 16)\n"
-               " -T#                   set a fixed UNIX timestamp # to all files\n"
+               " -T#                   specify a fixed UNIX timestamp # as build time\n"
+               "    --all-time         the timestamp is also applied to all files (default)\n"
+               "    --mkfs-time        the timestamp is applied as build time only\n"
                " -UX                   use a given filesystem UUID\n"
                " --all-root            make all files owned by root\n"
                " --blobdev=X           specify an extra device X to store chunked data\n"
@@ -548,6 +552,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
        int opt, i, err;
        bool quiet = false;
        int tarerofs_decoder = 0;
+       bool has_timestamp = false;
 
        while ((opt = getopt_long(argc, argv, "C:E:L:T:U:b:d:x:z:Vh",
                                  long_options, NULL)) != -1) {
@@ -607,7 +612,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                                erofs_err("invalid UNIX timestamp %s", optarg);
                                return -EINVAL;
                        }
-                       cfg.c_timeinherit = TIMESTAMP_FIXED;
+                       has_timestamp = true;
                        break;
                case 'U':
                        if (erofs_uuid_parse(optarg, fixeduuid)) {
@@ -829,6 +834,12 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                                return -EINVAL;
                        }
                        break;
+               case 525:
+                       cfg.c_timeinherit = TIMESTAMP_NONE;
+                       break;
+               case 526:
+                       cfg.c_timeinherit = TIMESTAMP_FIXED;
+                       break;
                case 'V':
                        version();
                        exit(0);
@@ -984,6 +995,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                }
                cfg.c_mkfs_pclustersize_packed = pclustersize_packed;
        }
+
+       if (has_timestamp && cfg.c_timeinherit == TIMESTAMP_UNSPECIFIED)
+               cfg.c_timeinherit = TIMESTAMP_FIXED;
        return 0;
 }