Linux-EROFS Archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] erofs-utils: mkfs: rename ctime to mtime
@ 2022-03-11  4:17 David Anderson via Linux-erofs
  2022-03-11  4:17 ` [PATCH 2/2] erofs-utils: mkfs: use mtime instead of ctime David Anderson via Linux-erofs
  0 siblings, 1 reply; 2+ messages in thread
From: David Anderson via Linux-erofs @ 2022-03-11  4:17 UTC (permalink / raw
  To: linux-erofs

Currently mkfs.erofs picks up whatever the system time happened to be
when the input file structure was created. Since there's no (easy) way for
userspace to control ctime, there's no way to control the per-file ctime
that mkfs.erofs uses.

In preparation for switching to mtime, rename the "ctime" members of the
inode structure.

Signed-off-by: David Anderson <dvander@google.com>
---
 dump/main.c              |  4 ++--
 fsck/main.c              | 12 ++++++------
 fuse/main.c              |  2 +-
 include/erofs/internal.h |  4 ++--
 include/erofs_fs.h       |  4 ++--
 lib/inode.c              | 14 +++++++-------
 lib/namei.c              |  8 ++++----
 7 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/dump/main.c b/dump/main.c
index bb1bd7f..6565d35 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -488,7 +488,7 @@ static void erofsdump_show_fileinfo(bool show_extent)
 	}
 
 	strftime(timebuf, sizeof(timebuf),
-		 "%Y-%m-%d %H:%M:%S", localtime((time_t *)&inode.i_ctime));
+		 "%Y-%m-%d %H:%M:%S", localtime((time_t *)&inode.i_mtime));
 	access_mode = inode.i_mode & 0777;
 	for (i = 8; i >= 0; i--)
 		if (((access_mode >> i) & 1) == 0)
@@ -507,7 +507,7 @@ static void erofsdump_show_fileinfo(bool show_extent)
 	fprintf(stdout,	"Xattr size: %u\n", inode.xattr_isize);
 	fprintf(stdout, "Uid: %u   Gid: %u  ", inode.i_uid, inode.i_gid);
 	fprintf(stdout, "Access: %04o/%s\n", access_mode, access_mode_str);
-	fprintf(stdout, "Timestamp: %s.%09d\n", timebuf, inode.i_ctime_nsec);
+	fprintf(stdout, "Timestamp: %s.%09d\n", timebuf, inode.i_mtime_nsec);
 
 	if (!dumpcfg.show_extent)
 		return;
diff --git a/fsck/main.c b/fsck/main.c
index e669b44..0af15b4 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -229,14 +229,14 @@ static void erofsfsck_set_attributes(struct erofs_inode *inode, char *path)
 
 #ifdef HAVE_UTIMENSAT
 	if (utimensat(AT_FDCWD, path, (struct timespec []) {
-				[0] = { .tv_sec = inode->i_ctime,
-					.tv_nsec = inode->i_ctime_nsec },
-				[1] = { .tv_sec = inode->i_ctime,
-					.tv_nsec = inode->i_ctime_nsec },
+				[0] = { .tv_sec = inode->i_mtime,
+					.tv_nsec = inode->i_mtime_nsec },
+				[1] = { .tv_sec = inode->i_mtime,
+					.tv_nsec = inode->i_mtime_nsec },
 			}, AT_SYMLINK_NOFOLLOW) < 0)
 #else
-	if (utime(path, &((struct utimbuf){.actime = inode->i_ctime,
-					   .modtime = inode->i_ctime})) < 0)
+	if (utime(path, &((struct utimbuf){.actime = inode->i_mtime,
+					   .modtime = inode->i_mtime})) < 0)
 #endif
 		erofs_warn("failed to set times: %s", path);
 
diff --git a/fuse/main.c b/fuse/main.c
index 2549d8a..ae377ae 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -98,7 +98,7 @@ static int erofsfuse_getattr(const char *path, struct stat *stbuf)
 	stbuf->st_gid = vi.i_gid;
 	if (S_ISBLK(vi.i_mode) || S_ISCHR(vi.i_mode))
 		stbuf->st_rdev = vi.u.i_rdev;
-	stbuf->st_ctime = vi.i_ctime;
+	stbuf->st_ctime = vi.i_mtime;
 	stbuf->st_mtime = stbuf->st_ctime;
 	stbuf->st_atime = stbuf->st_ctime;
 	return 0;
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 947304f..56627e9 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -154,8 +154,8 @@ struct erofs_inode {
 	u64 i_ino[2];
 	u32 i_uid;
 	u32 i_gid;
-	u64 i_ctime;
-	u32 i_ctime_nsec;
+	u64 i_mtime;
+	u32 i_mtime_nsec;
 	u32 i_nlink;
 
 	union {
diff --git a/include/erofs_fs.h b/include/erofs_fs.h
index 9a91877..e01f5c7 100644
--- a/include/erofs_fs.h
+++ b/include/erofs_fs.h
@@ -183,8 +183,8 @@ struct erofs_inode_extended {
 
 	__le32 i_uid;
 	__le32 i_gid;
-	__le64 i_ctime;
-	__le32 i_ctime_nsec;
+	__le64 i_mtime;
+	__le32 i_mtime_nsec;
 	__le32 i_nlink;
 	__u8   i_reserved2[16];
 };
diff --git a/lib/inode.c b/lib/inode.c
index 461c797..24f2567 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -477,8 +477,8 @@ static bool erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
 		u.die.i_uid = cpu_to_le32(inode->i_uid);
 		u.die.i_gid = cpu_to_le32(inode->i_gid);
 
-		u.die.i_ctime = cpu_to_le64(inode->i_ctime);
-		u.die.i_ctime_nsec = cpu_to_le32(inode->i_ctime_nsec);
+		u.die.i_mtime = cpu_to_le64(inode->i_mtime);
+		u.die.i_mtime_nsec = cpu_to_le32(inode->i_mtime_nsec);
 
 		switch (inode->i_mode & S_IFMT) {
 		case S_IFCHR:
@@ -806,16 +806,16 @@ static int erofs_fill_inode(struct erofs_inode *inode,
 	inode->i_mode = st->st_mode;
 	inode->i_uid = cfg.c_uid == -1 ? st->st_uid : cfg.c_uid;
 	inode->i_gid = cfg.c_gid == -1 ? st->st_gid : cfg.c_gid;
-	inode->i_ctime = st->st_ctime;
-	inode->i_ctime_nsec = ST_CTIM_NSEC(st);
+	inode->i_mtime = st->st_ctime;
+	inode->i_mtime_nsec = ST_CTIM_NSEC(st);
 
 	switch (cfg.c_timeinherit) {
 	case TIMESTAMP_CLAMPING:
-		if (st->st_ctime < sbi.build_time)
+		if (inode->i_mtime < sbi.build_time)
 			break;
 	case TIMESTAMP_FIXED:
-		inode->i_ctime = sbi.build_time;
-		inode->i_ctime_nsec = sbi.build_time_nsec;
+		inode->i_mtime = sbi.build_time;
+		inode->i_mtime_nsec = sbi.build_time_nsec;
 	default:
 		break;
 	}
diff --git a/lib/namei.c b/lib/namei.c
index 7377e74..2c8891a 100644
--- a/lib/namei.c
+++ b/lib/namei.c
@@ -79,8 +79,8 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
 		vi->i_gid = le32_to_cpu(die->i_gid);
 		vi->i_nlink = le32_to_cpu(die->i_nlink);
 
-		vi->i_ctime = le64_to_cpu(die->i_ctime);
-		vi->i_ctime_nsec = le64_to_cpu(die->i_ctime_nsec);
+		vi->i_mtime = le64_to_cpu(die->i_mtime);
+		vi->i_mtime_nsec = le64_to_cpu(die->i_mtime_nsec);
 		vi->i_size = le64_to_cpu(die->i_size);
 		if (vi->datalayout == EROFS_INODE_CHUNK_BASED)
 			/* fill chunked inode summary info */
@@ -114,8 +114,8 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
 		vi->i_gid = le16_to_cpu(dic->i_gid);
 		vi->i_nlink = le16_to_cpu(dic->i_nlink);
 
-		vi->i_ctime = sbi.build_time;
-		vi->i_ctime_nsec = sbi.build_time_nsec;
+		vi->i_mtime = sbi.build_time;
+		vi->i_mtime_nsec = sbi.build_time_nsec;
 
 		vi->i_size = le32_to_cpu(dic->i_size);
 		if (vi->datalayout == EROFS_INODE_CHUNK_BASED)
-- 
2.35.1.723.g4982287a31-goog


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

* [PATCH 2/2] erofs-utils: mkfs: use mtime instead of ctime
  2022-03-11  4:17 [PATCH 1/2] erofs-utils: mkfs: rename ctime to mtime David Anderson via Linux-erofs
@ 2022-03-11  4:17 ` David Anderson via Linux-erofs
  0 siblings, 0 replies; 2+ messages in thread
From: David Anderson via Linux-erofs @ 2022-03-11  4:17 UTC (permalink / raw
  To: linux-erofs

Change the default timestamp behavior to use modification time rather
than creation time. This will allow more control over the output
timestamps when not using TIMESTAMP_FIXED.

EROFS_FEATURE_COMPAT_MTIME has been added so tooling can detect the
change in timestamp behavior.

Signed-off-by: David Anderson <dvander@google.com>
---
 dump/main.c        | 1 +
 include/erofs_fs.h | 1 +
 lib/inode.c        | 4 ++--
 mkfs/main.c        | 8 +++++---
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/dump/main.c b/dump/main.c
index 6565d35..72761bd 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -84,6 +84,7 @@ struct erofsdump_feature {
 
 static struct erofsdump_feature feature_lists[] = {
 	{ true, EROFS_FEATURE_COMPAT_SB_CHKSUM, "sb_csum" },
+	{ true, EROFS_FEATURE_COMPAT_MTIME, "mtime" },
 	{ false, EROFS_FEATURE_INCOMPAT_LZ4_0PADDING, "0padding" },
 	{ false, EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER, "big_pcluster" },
 	{ false, EROFS_FEATURE_INCOMPAT_CHUNKED_FILE, "chunked_file" },
diff --git a/include/erofs_fs.h b/include/erofs_fs.h
index e01f5c7..7956a62 100644
--- a/include/erofs_fs.h
+++ b/include/erofs_fs.h
@@ -13,6 +13,7 @@
 #define EROFS_SUPER_OFFSET      1024
 
 #define EROFS_FEATURE_COMPAT_SB_CHKSUM		0x00000001
+#define EROFS_FEATURE_COMPAT_MTIME		0x00000002
 
 /*
  * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
diff --git a/lib/inode.c b/lib/inode.c
index 24f2567..c9fdda1 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -806,8 +806,8 @@ static int erofs_fill_inode(struct erofs_inode *inode,
 	inode->i_mode = st->st_mode;
 	inode->i_uid = cfg.c_uid == -1 ? st->st_uid : cfg.c_uid;
 	inode->i_gid = cfg.c_gid == -1 ? st->st_gid : cfg.c_gid;
-	inode->i_mtime = st->st_ctime;
-	inode->i_mtime_nsec = ST_CTIM_NSEC(st);
+	inode->i_mtime = st->st_mtime;
+	inode->i_mtime_nsec = ST_MTIM_NSEC(st);
 
 	switch (cfg.c_timeinherit) {
 	case TIMESTAMP_CLAMPING:
diff --git a/mkfs/main.c b/mkfs/main.c
index 3f34450..b1ed187 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -421,6 +421,8 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
 				  erofs_nid_t root_nid,
 				  erofs_blk_t *blocks)
 {
+	int compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
+		EROFS_FEATURE_COMPAT_MTIME;
 	struct erofs_super_block sb = {
 		.magic     = cpu_to_le32(EROFS_SUPER_MAGIC_V1),
 		.blkszbits = LOG_BLOCK_SIZE,
@@ -431,8 +433,7 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,
 		.meta_blkaddr  = sbi.meta_blkaddr,
 		.xattr_blkaddr = sbi.xattr_blkaddr,
 		.feature_incompat = cpu_to_le32(sbi.feature_incompat),
-		.feature_compat = cpu_to_le32(sbi.feature_compat &
-					      ~EROFS_FEATURE_COMPAT_SB_CHKSUM),
+		.feature_compat = cpu_to_le32(sbi.feature_compat & ~compat),
 		.extra_devices = cpu_to_le16(sbi.extra_devices),
 		.devt_slotoff = cpu_to_le16(sbi.devt_slotoff),
 	};
@@ -511,7 +512,8 @@ static void erofs_mkfs_default_options(void)
 {
 	cfg.c_legacy_compress = false;
 	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
-	sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM;
+	sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
+			     EROFS_FEATURE_COMPAT_MTIME;
 
 	/* generate a default uuid first */
 #ifdef HAVE_LIBUUID
-- 
2.35.1.723.g4982287a31-goog


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

end of thread, other threads:[~2022-03-11  4:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-11  4:17 [PATCH 1/2] erofs-utils: mkfs: rename ctime to mtime David Anderson via Linux-erofs
2022-03-11  4:17 ` [PATCH 2/2] erofs-utils: mkfs: use mtime instead of ctime David Anderson via Linux-erofs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).