From: Christoph Hellwig <hch@lst.de>
To: Christian Brauner <brauner@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
David Sterba <dsterba@suse.com>, Jan Kara <jack@suse.cz>,
Mike Marshall <hubcap@omnibond.com>,
Martin Brandenburg <martin@omnibond.com>,
Carlos Maiolino <cem@kernel.org>, Stefan Roesch <shr@fb.com>,
Jeff Layton <jlayton@kernel.org>,
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>,
linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org, gfs2@lists.linux.dev,
io-uring@vger.kernel.org, devel@lists.orangefs.org,
linux-unionfs@vger.kernel.org, linux-mtd@lists.infradead.org,
linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org
Subject: [PATCH 04/11] fat: cleanup the flags for fat_truncate_time
Date: Thu, 8 Jan 2026 15:19:04 +0100 [thread overview]
Message-ID: <20260108141934.2052404-5-hch@lst.de> (raw)
In-Reply-To: <20260108141934.2052404-1-hch@lst.de>
Fat only has a single on-disk timestamp covering ctime and mtime. Add
fat-specific flags that indicate which timestamp fat_truncate_time should
update to make this more clear. This allows removing no-op
fat_truncate_time calls with the S_CTIME flag and prepares for removing
the S_* flags.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/fat/dir.c | 2 +-
fs/fat/fat.h | 8 ++++----
fs/fat/file.c | 14 ++++++-------
fs/fat/inode.c | 2 +-
fs/fat/misc.c | 47 ++++++++++++++++++++++----------------------
fs/fat/namei_msdos.c | 13 +++++-------
fs/fat/namei_vfat.c | 9 ++++-----
7 files changed, 44 insertions(+), 51 deletions(-)
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 92b091783966..3d03bff40944 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -1080,7 +1080,7 @@ int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo)
}
}
- fat_truncate_time(dir, NULL, S_ATIME|S_MTIME);
+ fat_truncate_time(dir, NULL, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME);
if (IS_DIRSYNC(dir))
(void)fat_sync_inode(dir);
else
diff --git a/fs/fat/fat.h b/fs/fat/fat.h
index d3e426de5f01..767b566b1cab 100644
--- a/fs/fat/fat.h
+++ b/fs/fat/fat.h
@@ -468,10 +468,10 @@ extern void fat_time_unix2fat(struct msdos_sb_info *sbi, struct timespec64 *ts,
__le16 *time, __le16 *date, u8 *time_cs);
extern struct timespec64 fat_truncate_atime(const struct msdos_sb_info *sbi,
const struct timespec64 *ts);
-extern struct timespec64 fat_truncate_mtime(const struct msdos_sb_info *sbi,
- const struct timespec64 *ts);
-extern int fat_truncate_time(struct inode *inode, struct timespec64 *now,
- int flags);
+#define FAT_UPDATE_ATIME (1u << 0)
+#define FAT_UPDATE_CMTIME (1u << 1)
+void fat_truncate_time(struct inode *inode, struct timespec64 *now,
+ unsigned int flags);
extern int fat_update_time(struct inode *inode, int flags);
extern int fat_sync_bhs(struct buffer_head **bhs, int nr_bhs);
diff --git a/fs/fat/file.c b/fs/fat/file.c
index 4fc49a614fb8..f9bc93411aa2 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -224,7 +224,7 @@ static int fat_cont_expand(struct inode *inode, loff_t size)
if (err)
goto out;
- fat_truncate_time(inode, NULL, S_CTIME|S_MTIME);
+ fat_truncate_time(inode, NULL, FAT_UPDATE_CMTIME);
mark_inode_dirty(inode);
if (IS_SYNC(inode)) {
int err2;
@@ -327,7 +327,7 @@ static int fat_free(struct inode *inode, int skip)
MSDOS_I(inode)->i_logstart = 0;
}
MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
- fat_truncate_time(inode, NULL, S_CTIME|S_MTIME);
+ fat_truncate_time(inode, NULL, FAT_UPDATE_CMTIME);
if (wait) {
err = fat_sync_inode(inode);
if (err) {
@@ -553,15 +553,13 @@ int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
}
/*
- * setattr_copy can't truncate these appropriately, so we'll
- * copy them ourselves
+ * setattr_copy can't truncate these appropriately, so we'll copy them
+ * ourselves. See fat_truncate_time for the c/mtime logic on fat.
*/
if (attr->ia_valid & ATTR_ATIME)
- fat_truncate_time(inode, &attr->ia_atime, S_ATIME);
- if (attr->ia_valid & ATTR_CTIME)
- fat_truncate_time(inode, &attr->ia_ctime, S_CTIME);
+ fat_truncate_time(inode, &attr->ia_atime, FAT_UPDATE_ATIME);
if (attr->ia_valid & ATTR_MTIME)
- fat_truncate_time(inode, &attr->ia_mtime, S_MTIME);
+ fat_truncate_time(inode, &attr->ia_mtime, FAT_UPDATE_CMTIME);
attr->ia_valid &= ~(ATTR_ATIME|ATTR_CTIME|ATTR_MTIME);
setattr_copy(idmap, inode, attr);
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 0b6009cd1844..59fa90617b5b 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -246,7 +246,7 @@ static int fat_write_end(const struct kiocb *iocb,
if (err < len)
fat_write_failed(mapping, pos + len);
if (!(err < 0) && !(MSDOS_I(inode)->i_attrs & ATTR_ARCH)) {
- fat_truncate_time(inode, NULL, S_CTIME|S_MTIME);
+ fat_truncate_time(inode, NULL, FAT_UPDATE_CMTIME);
MSDOS_I(inode)->i_attrs |= ATTR_ARCH;
mark_inode_dirty(inode);
}
diff --git a/fs/fat/misc.c b/fs/fat/misc.c
index 950da09f0961..78c620e9b3fd 100644
--- a/fs/fat/misc.c
+++ b/fs/fat/misc.c
@@ -299,54 +299,53 @@ struct timespec64 fat_truncate_atime(const struct msdos_sb_info *sbi,
}
/*
- * truncate mtime to 2 second granularity
- */
-struct timespec64 fat_truncate_mtime(const struct msdos_sb_info *sbi,
- const struct timespec64 *ts)
-{
- return fat_timespec64_trunc_2secs(*ts);
-}
-
-/*
- * truncate the various times with appropriate granularity:
- * all times in root node are always 0
+ * Update the in-inode atime and/or mtime after truncating the timestamp to the
+ * granularity. All timestamps in root inode are always 0.
+ *
+ * ctime and mtime share the same on-disk field, and should be identical in
+ * memory. All mtime updates will be applied to ctime, but ctime updates are
+ * ignored.
*/
-int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags)
+void fat_truncate_time(struct inode *inode, struct timespec64 *now,
+ unsigned int flags)
{
struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
struct timespec64 ts;
if (inode->i_ino == MSDOS_ROOT_INO)
- return 0;
+ return;
if (now == NULL) {
now = &ts;
ts = current_time(inode);
}
- if (flags & S_ATIME)
+ if (flags & FAT_UPDATE_ATIME)
inode_set_atime_to_ts(inode, fat_truncate_atime(sbi, now));
- /*
- * ctime and mtime share the same on-disk field, and should be
- * identical in memory. all mtime updates will be applied to ctime,
- * but ctime updates are ignored.
- */
- if (flags & S_MTIME)
- inode_set_mtime_to_ts(inode,
- inode_set_ctime_to_ts(inode, fat_truncate_mtime(sbi, now)));
+ if (flags & FAT_UPDATE_CMTIME) {
+ /* truncate mtime to 2 second granularity */
+ struct timespec64 mtime = fat_timespec64_trunc_2secs(*now);
- return 0;
+ inode_set_mtime_to_ts(inode, mtime);
+ inode_set_ctime_to_ts(inode, mtime);
+ }
}
EXPORT_SYMBOL_GPL(fat_truncate_time);
int fat_update_time(struct inode *inode, int flags)
{
+ unsigned int fat_flags = 0;
int dirty_flags = 0;
if (inode->i_ino == MSDOS_ROOT_INO)
return 0;
- if (flags & (S_ATIME | S_CTIME | S_MTIME)) {
+ if (flags & S_ATIME)
+ fat_flags |= FAT_UPDATE_ATIME;
+ if (flags & (S_CTIME | S_MTIME))
+ fat_flags |= FAT_UPDATE_CMTIME;
+
+ if (fat_flags) {
fat_truncate_time(inode, NULL, flags);
if (inode->i_sb->s_flags & SB_LAZYTIME)
dirty_flags |= I_DIRTY_TIME;
diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
index 0b920ee40a7f..ba0152ed0810 100644
--- a/fs/fat/namei_msdos.c
+++ b/fs/fat/namei_msdos.c
@@ -251,7 +251,7 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name,
if (err)
return err;
- fat_truncate_time(dir, ts, S_CTIME|S_MTIME);
+ fat_truncate_time(dir, ts, FAT_UPDATE_CMTIME);
if (IS_DIRSYNC(dir))
(void)fat_sync_inode(dir);
else
@@ -295,7 +295,7 @@ static int msdos_create(struct mnt_idmap *idmap, struct inode *dir,
err = PTR_ERR(inode);
goto out;
}
- fat_truncate_time(inode, &ts, S_ATIME|S_CTIME|S_MTIME);
+ fat_truncate_time(inode, &ts, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
d_instantiate(dentry, inode);
@@ -328,7 +328,6 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
drop_nlink(dir);
clear_nlink(inode);
- fat_truncate_time(inode, NULL, S_CTIME);
fat_detach(inode);
out:
mutex_unlock(&MSDOS_SB(sb)->s_lock);
@@ -382,7 +381,7 @@ static struct dentry *msdos_mkdir(struct mnt_idmap *idmap, struct inode *dir,
goto out;
}
set_nlink(inode, 2);
- fat_truncate_time(inode, &ts, S_ATIME|S_CTIME|S_MTIME);
+ fat_truncate_time(inode, &ts, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
d_instantiate(dentry, inode);
@@ -415,7 +414,6 @@ static int msdos_unlink(struct inode *dir, struct dentry *dentry)
if (err)
goto out;
clear_nlink(inode);
- fat_truncate_time(inode, NULL, S_CTIME);
fat_detach(inode);
out:
mutex_unlock(&MSDOS_SB(sb)->s_lock);
@@ -480,7 +478,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
mark_inode_dirty(old_inode);
inode_inc_iversion(old_dir);
- fat_truncate_time(old_dir, NULL, S_CTIME|S_MTIME);
+ fat_truncate_time(old_dir, NULL, FAT_UPDATE_CMTIME);
if (IS_DIRSYNC(old_dir))
(void)fat_sync_inode(old_dir);
else
@@ -540,7 +538,7 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
if (err)
goto error_dotdot;
inode_inc_iversion(old_dir);
- fat_truncate_time(old_dir, &ts, S_CTIME|S_MTIME);
+ fat_truncate_time(old_dir, &ts, FAT_UPDATE_CMTIME);
if (IS_DIRSYNC(old_dir))
(void)fat_sync_inode(old_dir);
else
@@ -550,7 +548,6 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
drop_nlink(new_inode);
if (is_dir)
drop_nlink(new_inode);
- fat_truncate_time(new_inode, &ts, S_CTIME);
}
out:
brelse(sinfo.bh);
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index 5dbc4cbb8fce..e46f34cade1a 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -676,7 +676,7 @@ static int vfat_add_entry(struct inode *dir, const struct qstr *qname,
goto cleanup;
/* update timestamp */
- fat_truncate_time(dir, ts, S_CTIME|S_MTIME);
+ fat_truncate_time(dir, ts, FAT_UPDATE_CMTIME);
if (IS_DIRSYNC(dir))
(void)fat_sync_inode(dir);
else
@@ -806,7 +806,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
drop_nlink(dir);
clear_nlink(inode);
- fat_truncate_time(inode, NULL, S_ATIME|S_MTIME);
+ fat_truncate_time(inode, NULL, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME);
fat_detach(inode);
vfat_d_version_set(dentry, inode_query_iversion(dir));
out:
@@ -832,7 +832,7 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry)
if (err)
goto out;
clear_nlink(inode);
- fat_truncate_time(inode, NULL, S_ATIME|S_MTIME);
+ fat_truncate_time(inode, NULL, FAT_UPDATE_ATIME | FAT_UPDATE_CMTIME);
fat_detach(inode);
vfat_d_version_set(dentry, inode_query_iversion(dir));
out:
@@ -918,7 +918,7 @@ static int vfat_update_dotdot_de(struct inode *dir, struct inode *inode,
static void vfat_update_dir_metadata(struct inode *dir, struct timespec64 *ts)
{
inode_inc_iversion(dir);
- fat_truncate_time(dir, ts, S_CTIME | S_MTIME);
+ fat_truncate_time(dir, ts, FAT_UPDATE_CMTIME);
if (IS_DIRSYNC(dir))
(void)fat_sync_inode(dir);
else
@@ -996,7 +996,6 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
drop_nlink(new_inode);
if (is_dir)
drop_nlink(new_inode);
- fat_truncate_time(new_inode, &ts, S_CTIME);
}
out:
brelse(sinfo.bh);
--
2.47.3
next prev parent reply other threads:[~2026-01-08 14:20 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 14:19 re-enable IOCB_NOWAIT writes to files v6 Christoph Hellwig
2026-01-08 14:19 ` [PATCH 01/11] fs: remove inode_update_time Christoph Hellwig
2026-01-08 14:19 ` [PATCH 02/11] fs: allow error returns from generic_update_time Christoph Hellwig
2026-01-08 14:19 ` [PATCH 03/11] nfs: split nfs_update_timestamps Christoph Hellwig
2026-01-08 14:19 ` Christoph Hellwig [this message]
2026-01-08 14:19 ` [PATCH 05/11] fs: refactor ->update_time handling Christoph Hellwig
2026-01-08 15:20 ` Jan Kara
2026-01-08 14:19 ` [PATCH 06/11] fs: factor out a sync_lazytime helper Christoph Hellwig
2026-01-08 14:19 ` [PATCH 07/11] fs: add a ->sync_lazytime method Christoph Hellwig
2026-01-08 15:24 ` Jan Kara
2026-01-08 14:19 ` [PATCH 08/11] fs: add support for non-blocking timestamp updates Christoph Hellwig
2026-01-08 14:19 ` [PATCH 09/11] fs: refactor file_update_time_flags Christoph Hellwig
2026-01-08 14:19 ` [PATCH 10/11] xfs: implement ->sync_lazytime Christoph Hellwig
2026-01-08 14:19 ` [PATCH 11/11] xfs: enable non-blocking timestamp updates Christoph Hellwig
2026-01-12 13:02 ` re-enable IOCB_NOWAIT writes to files v6 Christian Brauner
-- strict thread matches above, loose matches on Subject: below --
2026-01-06 7:49 re-enable IOCB_NOWAIT writes to files v5 Christoph Hellwig
2026-01-06 7:49 ` [PATCH 04/11] fat: cleanup the flags for fat_truncate_time Christoph Hellwig
2026-01-06 10:45 ` OGAWA Hirofumi
2026-01-06 17:55 ` OGAWA Hirofumi
2026-01-07 7:43 ` Christoph Hellwig
2026-01-06 7:44 re-enable IOCB_NOWAIT writes to files v5 Christoph Hellwig
2026-01-06 7:44 ` [PATCH 04/11] fat: cleanup the flags for fat_truncate_time Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260108141934.2052404-5-hch@lst.de \
--to=hch@lst.de \
--cc=anna@kernel.org \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=devel@lists.orangefs.org \
--cc=dsterba@suse.com \
--cc=gfs2@lists.linux.dev \
--cc=hirofumi@mail.parknet.co.jp \
--cc=hubcap@omnibond.com \
--cc=io-uring@vger.kernel.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=martin@omnibond.com \
--cc=shr@fb.com \
--cc=trondmy@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox