Linux-EROFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v4][ 1/2] erofs-utils: introduce fixed UNIX timestamp
@ 2019-10-11 17:09 Li Guifu
  2019-10-11 17:09 ` [PATCH v4][ 2/2] erofs-utils: fix error handler notes when parameter miss Li Guifu
  2019-10-12  0:18 ` [PATCH v4][ 1/2] erofs-utils: introduce fixed UNIX timestamp Gao Xiang via Linux-erofs
  0 siblings, 2 replies; 4+ messages in thread
From: Li Guifu @ 2019-10-11 17:09 UTC (permalink / raw)
  To: linux-erofs

Introduce option "-T" for UNIX timestamp.

Signed-off-by: Li Guifu <blucerlee@gmail.com>
---
 include/erofs/config.h |  1 +
 lib/config.c           |  1 +
 mkfs/main.c            | 11 +++++++++--
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/erofs/config.h b/include/erofs/config.h
index fde936c..8df05a1 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -30,6 +30,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_unix_timestamp;
 };
 
 extern struct erofs_configure cfg;
diff --git a/lib/config.c b/lib/config.c
index dc10754..cee835c 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -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_unix_timestamp = -1;
 }
 
 void erofs_show_config(void)
diff --git a/mkfs/main.c b/mkfs/main.c
index 978c5b4..77a4b78 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -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 UNIX timestamp # to all files\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,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			if (opt)
 				return opt;
 			break;
+		case 'T':
+			cfg.c_unix_timestamp = atoll(optarg);
+			break;
 
 		default: /* '?' */
 			return -EINVAL;
@@ -224,7 +228,10 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	if (!gettimeofday(&t, NULL)) {
+	if (cfg.c_unix_timestamp != -1) {
+		sbi.build_time      = cfg.c_unix_timestamp;
+		sbi.build_time_nsec = 0;
+	} else if (!gettimeofday(&t, NULL)) {
 		sbi.build_time      = t.tv_sec;
 		sbi.build_time_nsec = t.tv_usec;
 	}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4][ 2/2] erofs-utils: fix error handler notes when parameter miss
  2019-10-11 17:09 [PATCH v4][ 1/2] erofs-utils: introduce fixed UNIX timestamp Li Guifu
@ 2019-10-11 17:09 ` Li Guifu
  2019-10-12  0:19   ` Gao Xiang via Linux-erofs
  2019-10-12  0:18 ` [PATCH v4][ 1/2] erofs-utils: introduce fixed UNIX timestamp Gao Xiang via Linux-erofs
  1 sibling, 1 reply; 4+ messages in thread
From: Li Guifu @ 2019-10-11 17:09 UTC (permalink / raw)
  To: linux-erofs

If a parameter isnot input, mkfs's error handler cannot give
a correct notes, fix it.

Signed-off-by: Li Guifu <blucerlee@gmail.com>
---
 mkfs/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mkfs/main.c b/mkfs/main.c
index 77a4b78..adfc79c 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -143,7 +143,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 	if (!cfg.c_img_path)
 		return -ENOMEM;
 
-	if (optind > argc) {
+	if (optind >= argc) {
 		erofs_err("Source directory is missing");
 		return -EINVAL;
 	}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4][ 1/2] erofs-utils: introduce fixed UNIX timestamp
  2019-10-11 17:09 [PATCH v4][ 1/2] erofs-utils: introduce fixed UNIX timestamp Li Guifu
  2019-10-11 17:09 ` [PATCH v4][ 2/2] erofs-utils: fix error handler notes when parameter miss Li Guifu
@ 2019-10-12  0:18 ` Gao Xiang via Linux-erofs
  1 sibling, 0 replies; 4+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-10-12  0:18 UTC (permalink / raw)
  To: Li Guifu; +Cc: linux-erofs

Hi Guifu,

On Sat, Oct 12, 2019 at 01:09:52AM +0800, Li Guifu wrote:
> Introduce option "-T" for UNIX timestamp.
> 
> Signed-off-by: Li Guifu <blucerlee@gmail.com>
> ---

Applied with the following minor changes.
Let me know if you have some other thoughts...

From 0da0c97cc5ca7e02192ee99dde0a82cb531823a6 Mon Sep 17 00:00:00 2001
From: Li Guifu <blucerlee@gmail.com>
Date: Sat, 12 Oct 2019 01:09:52 +0800
Subject: [PATCH] erofs-utils: introduce fixed UNIX timestamp

Introduce option "-T" for UNIX timestamp.

Signed-off-by: Li Guifu <blucerlee@gmail.com>
[ Gao Xiang: use u64 for timestamp rather than long long. ]
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
 include/erofs/config.h |  1 +
 lib/config.c           |  1 +
 mkfs/main.c            | 16 ++++++++++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/erofs/config.h b/include/erofs/config.h
index 8b09430..9711638 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -28,6 +28,7 @@ struct erofs_configure {
 	char *c_compr_alg_master;
 	int c_compr_level_master;
 	int c_force_inodeversion;
+	u64 c_unix_timestamp;
 };
 
 extern struct erofs_configure cfg;
diff --git a/lib/config.c b/lib/config.c
index 110c8b6..4cddc25 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -23,6 +23,7 @@ void erofs_init_configure(void)
 	cfg.c_compr_level_master = -1;
 	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
 	cfg.c_force_inodeversion = 0;
+	cfg.c_unix_timestamp = -1;
 }
 
 void erofs_show_config(void)
diff --git a/mkfs/main.c b/mkfs/main.c
index 4b279c0..6ecc905 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -29,6 +29,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 UNIX timestamp # to all files\n");
 }
 
 static int parse_extended_opts(const char *opts)
@@ -90,9 +91,10 @@ static int parse_extended_opts(const char *opts)
 
 static int mkfs_parse_options_cfg(int argc, char *argv[])
 {
+	char *endptr;
 	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) {
@@ -125,6 +127,13 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			if (opt)
 				return opt;
 			break;
+		case 'T':
+			cfg.c_unix_timestamp = strtoull(optarg, &endptr, 0);
+			if (cfg.c_unix_timestamp == -1 || *endptr != '\0') {
+				erofs_err("invalid UNIX timestamp %s", optarg);
+				return -EINVAL;
+			}
+			break;
 
 		default: /* '?' */
 			return -EINVAL;
@@ -223,7 +232,10 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	if (!gettimeofday(&t, NULL)) {
+	if (cfg.c_unix_timestamp != -1) {
+		sbi.build_time      = cfg.c_unix_timestamp;
+		sbi.build_time_nsec = 0;
+	} else if (!gettimeofday(&t, NULL)) {
 		sbi.build_time      = t.tv_sec;
 		sbi.build_time_nsec = t.tv_usec;
 	}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v4][ 2/2] erofs-utils: fix error handler notes when parameter miss
  2019-10-11 17:09 ` [PATCH v4][ 2/2] erofs-utils: fix error handler notes when parameter miss Li Guifu
@ 2019-10-12  0:19   ` Gao Xiang via Linux-erofs
  0 siblings, 0 replies; 4+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-10-12  0:19 UTC (permalink / raw)
  To: Li Guifu; +Cc: linux-erofs

On Sat, Oct 12, 2019 at 01:09:53AM +0800, Li Guifu wrote:
> If a parameter isnot input, mkfs's error handler cannot give
> a correct notes, fix it.
> 
> Signed-off-by: Li Guifu <blucerlee@gmail.com>
> ---
>  mkfs/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 77a4b78..adfc79c 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -143,7 +143,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
>  	if (!cfg.c_img_path)
>  		return -ENOMEM;
>  
> -	if (optind > argc) {
> +	if (optind >= argc) {
>  		erofs_err("Source directory is missing");
>  		return -EINVAL;
>  	}
> -- 
> 2.17.1
>

Already applied.

Thanks,
Gao Xiang


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 17:09 [PATCH v4][ 1/2] erofs-utils: introduce fixed UNIX timestamp Li Guifu
2019-10-11 17:09 ` [PATCH v4][ 2/2] erofs-utils: fix error handler notes when parameter miss Li Guifu
2019-10-12  0:19   ` Gao Xiang via Linux-erofs
2019-10-12  0:18 ` [PATCH v4][ 1/2] erofs-utils: introduce fixed UNIX timestamp Gao Xiang via Linux-erofs

Linux-EROFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-erofs/0 linux-erofs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-erofs linux-erofs/ https://lore.kernel.org/linux-erofs \
		linux-erofs@lists.ozlabs.org linux-erofs@ozlabs.org
	public-inbox-index linux-erofs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.ozlabs.lists.linux-erofs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git