Unverified Commit 1cbc8228 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Christian Brauner
Browse files

fat: cleanup the flags for fat_truncate_time



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: default avatarChristoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260108141934.2052404-5-hch@lst.de


Acked-by: default avatarOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent b8b3002f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+4 −4
Original line number Diff line number Diff line
@@ -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);

+6 −8
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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);
	}
+23 −24
Original line number Diff line number Diff line
@@ -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;
Loading