Skip to contentSkip to conversation

[] erofs-utils:introduce fixed timestamp using "-T"

PATCH In review Li Guifu 2 participants 2 messages Oct 9, 2019 Library code

lore
Share & tools
lore

Li Guifu

author
#0 lore raw

PATCH 1/1 [] erofs-utils:introduce fixed timestamp using "-T"

Introduce option "-T" for timestamp.

---
 include/erofs/config.h |  3 +++
 lib/config.c           |  1 +
 mkfs/main.c            | 14 ++++++++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)
include/erofs/config.h +3 -0
index fde936c..61f5c71 100644
@@ -11,6 +11,8 @@
 
 #include "defs.h"
 
+#define EROFS_FIXED_TIMESTAMP 1569859200 // 2019/10/1 00:00:00
+
 enum {
 	FORCE_INODE_COMPACT = 1,
 	FORCE_INODE_EXTENDED,
@@ -30,6 +32,7 @@ struct erofs_configure {
 	int c_force_inodeversion;
 	/* < 0, xattr disabled and INT_MAX, always use inline xattrs */
 	int c_inline_xattr_tolerance;
+	long long c_timestamp;
 };
 
 extern struct erofs_configure cfg;
lib/config.c +1 -0
index dc10754..6141497 100644
@@ -24,6 +24,7 @@ void erofs_init_configure(void)
 	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
 	cfg.c_force_inodeversion = 0;
 	cfg.c_inline_xattr_tolerance = 2;
+	cfg.c_timestamp = -1;
 }
 
 void erofs_show_config(void)
mkfs/main.c +12 -2
index 978c5b4..85b8f34 100644
@@ -30,6 +30,7 @@ static void usage(void)
 	fprintf(stderr, " -zX[,Y]   X=compressor (Y=compression level, optional)\n");
 	fprintf(stderr, " -d#       set output message level to # (maximum 9)\n");
 	fprintf(stderr, " -EX[,...] X=extended options\n");
+	fprintf(stderr, " -T#       set a fixed timestamp to files and dirs\n");
 }
 
 static int parse_extended_opts(const char *opts)
@@ -93,7 +94,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 {
 	int opt, i;
 
-	while ((opt = getopt(argc, argv, "d:z:E:")) != -1) {
+	while ((opt = getopt(argc, argv, "d:z:E:T::")) != -1) {
 		switch (opt) {
 		case 'z':
 			if (!optarg) {
@@ -126,6 +127,12 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			if (opt)
 				return opt;
 			break;
+		case 'T':
+			if (optarg)
+				cfg.c_timestamp = strtoll(optarg, NULL, 10);
+			else
+				cfg.c_timestamp = EROFS_FIXED_TIMESTAMP;
+			break;
 
 		default: /* '?' */
 			return -EINVAL;
@@ -224,7 +231,10 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	if (!gettimeofday(&t, NULL)) {
+	if (cfg.c_timestamp != -1) {
+		sbi.build_time      = cfg.c_timestamp;
+		sbi.build_time_nsec = 0;
+	} else if (!gettimeofday(&t, NULL)) {
 		sbi.build_time      = t.tv_sec;
 		sbi.build_time_nsec = t.tv_usec;
 	}
Signature · 1 line
2.17.1
#1 lore raw

Hi Guifu,

Quoted 3 lines · Li Guifu

Introduce option "-T" for timestamp.

A few suggestions here...

It should be better marked the version such as "PATCH", "PATCH v2", "PATCH vN" in the subject line
"[PATCH preview][] erofs-utils:introduce fixed timestamp using", e.g.
[PATCH v2] erofs-utils: introduce fixed timestamp using

And the subject prefix is odd and no whitespace after semicolon
...
You could take care of it if you then do any sorts of kernel development when you send out patches...

Quoted 11 lines
---
 include/erofs/config.h |  3 +++
 lib/config.c           |  1 +
 mkfs/main.c            | 14 ++++++++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)
include/erofs/config.h +0 -0
index fde936c..61f5c71 100644

include/erofs/config.h line 15

Quoted 5 lines
include/erofs/config.h +2 -0
@@ -11,6 +11,8 @@
 
 #include "defs.h"
 
+#define EROFS_FIXED_TIMESTAMP 1569859200 // 2019/10/1 00:00:00
+

It seems not very useful.. Could we just remove it?

Quoted 28 lines
include/erofs/config.h +1 -0
 enum {
 	FORCE_INODE_COMPACT = 1,
 	FORCE_INODE_EXTENDED,
@@ -30,6 +32,7 @@ struct erofs_configure {
 	int c_force_inodeversion;
 	/* < 0, xattr disabled and INT_MAX, always use inline xattrs */
 	int c_inline_xattr_tolerance;
+	long long c_timestamp;
 };
 
 extern struct erofs_configure cfg;
lib/config.c +1 -0
index dc10754..6141497 100644
@@ -24,6 +24,7 @@ void erofs_init_configure(void)
 	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
 	cfg.c_force_inodeversion = 0;
 	cfg.c_inline_xattr_tolerance = 2;
+	cfg.c_timestamp = -1;
 }
 
 void erofs_show_config(void)
mkfs/main.c +0 -0
index 978c5b4..85b8f34 100644

mkfs/main.c static void usage(void) · line 33

Quoted 4 lines
mkfs/main.c +1 -0
@@ -30,6 +30,7 @@ static void usage(void)
 	fprintf(stderr, " -zX[,Y]   X=compressor (Y=compression level, optional)\n");
 	fprintf(stderr, " -d#       set output message level to # (maximum 9)\n");
 	fprintf(stderr, " -EX[,...] X=extended options\n");
+	fprintf(stderr, " -T#       set a fixed timestamp to files and dirs\n");

fprintf(stderr, " -T# set a fixed UNIX timestamp # to all files\n");

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 97

Quoted 9 lines
mkfs/main.c +1 -1
 }
 
 static int parse_extended_opts(const char *opts)
@@ -93,7 +94,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 {
 	int opt, i;
 
-	while ((opt = getopt(argc, argv, "d:z:E:")) != -1) {
+	while ((opt = getopt(argc, argv, "d:z:E:T::")) != -1) {

Can we avoid two colons since this is a GNU extension? It seems we don't need an optional arg here.

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 134

Quoted 12 lines
mkfs/main.c +5 -0
 		switch (opt) {
 		case 'z':
 			if (!optarg) {
@@ -126,6 +127,12 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			if (opt)
 				return opt;
 			break;
+		case 'T':
+			if (optarg)
+				cfg.c_timestamp = strtoll(optarg, NULL, 10);
+			else
+				cfg.c_timestamp = EROFS_FIXED_TIMESTAMP;

no EROFS_FIXED_TIMESTAMP here, useless.

Thanks,
Gao Xiang

Quoted 19 lines
mkfs/main.c +5 -1
+			break;
 
 		default: /* '?' */
 			return -EINVAL;
@@ -224,7 +231,10 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	if (!gettimeofday(&t, NULL)) {
+	if (cfg.c_timestamp != -1) {
+		sbi.build_time      = cfg.c_timestamp;
+		sbi.build_time_nsec = 0;
+	} else if (!gettimeofday(&t, NULL)) {
 		sbi.build_time      = t.tv_sec;
 		sbi.build_time_nsec = t.tv_usec;
 	}
Signature · 1 line
2.17.1