exfat: convert to new timestamp accessors

Convert to using the new inode timestamp accessor functions.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/20231004185347.80880-31-jlayton@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
This commit is contained in:
Jeff Layton 2023-11-02 23:54:56 +09:00 • committed by Namjae Jeon
commit 59b349e724
6 changed files with 107 additions and 0 deletions

View file

@ -598,6 +598,9 @@ void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...)
void exfat_get_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
u8 tz, __le16 time, __le16 date, u8 time_cs);
void exfat_truncate_atime(struct timespec64 *ts);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
void exfat_truncate_inode_atime(struct inode *inode);
#endif
void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
u8 *tz, __le16 *time, __le16 *date, u8 *time_cs);
#else

12
file.c
View file

@ -31,7 +31,11 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
#else
inode->i_mtime = inode_set_ctime_current(inode);
#endif
#else
inode->i_ctime = inode->i_mtime = current_time(inode);
#endif
@ -368,7 +372,11 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
if (attr->ia_valid & ATTR_SIZE)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
#else
inode->i_mtime = inode_set_ctime_current(inode);
#endif
#else
inode->i_mtime = inode->i_ctime = current_time(inode);
#endif
@ -376,6 +384,9 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
exfat_truncate_inode_atime(inode);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
setattr_copy(&nop_mnt_idmap, inode, attr);
@ -386,6 +397,7 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
setattr_copy(inode, attr);
#endif
exfat_truncate_atime(&inode->i_atime);
#endif
if (attr->ia_valid & ATTR_SIZE) {
error = exfat_block_truncate_page(inode, attr->ia_size);

34
inode.c
View file

@ -28,6 +28,9 @@ int __exfat_write_inode(struct inode *inode, int sync)
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_inode_info *ei = EXFAT_I(inode);
bool is_dir = (ei->type == TYPE_DIR) ? true : false;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
struct timespec64 ts;
#endif
if (inode->i_ino == EXFAT_ROOT_INO)
return 0;
@ -57,6 +60,20 @@ int __exfat_write_inode(struct inode *inode, int sync)
&ep->dentry.file.create_time,
&ep->dentry.file.create_date,
&ep->dentry.file.create_time_cs);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
exfat_set_entry_time(sbi, &ts,
&ep->dentry.file.modify_tz,
&ep->dentry.file.modify_time,
&ep->dentry.file.modify_date,
&ep->dentry.file.modify_time_cs);
inode_set_mtime_to_ts(inode, ts);
exfat_set_entry_time(sbi, &ts,
&ep->dentry.file.access_tz,
&ep->dentry.file.access_time,
&ep->dentry.file.access_date,
NULL);
inode_set_atime_to_ts(inode, ts);
#else
exfat_set_entry_time(sbi, &inode->i_mtime,
&ep->dentry.file.modify_tz,
&ep->dentry.file.modify_time,
@ -67,6 +84,7 @@ int __exfat_write_inode(struct inode *inode, int sync)
&ep->dentry.file.access_time,
&ep->dentry.file.access_date,
NULL);
#endif
/* File size should be zero if there is no cluster allocated */
on_disk_size = i_size_read(inode);
@ -381,7 +399,11 @@ static void exfat_write_failed(struct address_space *mapping, loff_t to)
truncate_pagecache(inode, i_size_read(inode));
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
#else
inode->i_mtime = inode_set_ctime_current(inode);
#endif
#else
inode->i_mtime = inode->i_ctime = current_time(inode);
#endif
@ -443,7 +465,11 @@ static int exfat_write_end(struct file *file, struct address_space *mapping,
if (!(err < 0) && !(ei->attr & EXFAT_ATTR_ARCHIVE)) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
#else
inode->i_mtime = inode_set_ctime_current(inode);
#endif
#else
inode->i_mtime = inode->i_ctime = current_time(inode);
#endif
@ -666,14 +692,22 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
exfat_save_attr(inode, info->attr);
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >> 9;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_mtime_to_ts(inode, info->mtime);
#else
inode->i_mtime = info->mtime;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
inode_set_ctime_to_ts(inode, info->mtime);
#else
inode->i_ctime = info->mtime;
#endif
ei->i_crtime = info->crtime;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_atime_to_ts(inode, info->atime);
#else
inode->i_atime = info->atime;
#endif
return 0;
}

10
misc.c
View file

@ -163,6 +163,16 @@ void exfat_truncate_atime(struct timespec *ts)
ts->tv_nsec = 0;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
void exfat_truncate_inode_atime(struct inode *inode)
{
struct timespec64 atime = inode_get_atime(inode);
exfat_truncate_atime(&atime);
inode_set_atime_to_ts(inode, atime);
}
#endif
u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type)
{
int i;

43
namei.c
View file

@ -626,7 +626,11 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
#else
dir->i_mtime = inode_set_ctime_current(dir);
#endif
#else
dir->i_ctime = dir->i_mtime = current_time(dir);
#endif
@ -650,6 +654,10 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
inode->i_version++;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
EXFAT_I(inode)->i_crtime = simple_inode_init_ts(inode);
exfat_truncate_inode_atime(inode);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
inode->i_mtime = inode->i_atime = EXFAT_I(inode)->i_crtime = inode_set_ctime_current(inode);
@ -662,6 +670,7 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
EXFAT_I(inode)->i_crtime = CURRENT_TIME_SEC;
#endif
exfat_truncate_atime(&inode->i_atime);
#endif
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
d_instantiate(dentry, inode);
@ -910,6 +919,11 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
#else
dir->i_version++;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(dir);
exfat_truncate_inode_atime(dir);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
dir->i_mtime = dir->i_atime = inode_set_ctime_current(dir);
@ -920,12 +934,17 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
dir->i_mtime = dir->i_atime = dir->i_ctime = CURRENT_TIME_SEC;
#endif
exfat_truncate_atime(&dir->i_atime);
#endif
if (IS_DIRSYNC(dir))
exfat_sync_inode(dir);
else
mark_inode_dirty(dir);
clear_nlink(inode);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(inode);
exfat_truncate_inode_atime(inode);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode);
@ -936,6 +955,7 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
inode->i_mtime = inode->i_atime = dir->i_ctime = CURRENT_TIME_SEC;
#endif
exfat_truncate_atime(&inode->i_atime);
#endif
exfat_unhash_inode(inode);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
exfat_d_version_set(dentry, inode_query_iversion(dir));
@ -981,7 +1001,11 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
#else
dir->i_mtime = inode_set_ctime_current(dir);
#endif
#else
dir->i_ctime = dir->i_mtime = current_time(dir);
#endif
@ -1005,6 +1029,10 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
#else
inode->i_version++;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
EXFAT_I(inode)->i_crtime = simple_inode_init_ts(inode);
exfat_truncate_inode_atime(inode);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
inode->i_mtime = inode->i_atime = EXFAT_I(inode)->i_crtime = inode_set_ctime_current(inode);
@ -1017,6 +1045,7 @@ static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
EXFAT_I(inode)->i_crtime = CURRENT_TIME_SEC;
#endif
exfat_truncate_atime(&inode->i_atime);
#endif
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
d_instantiate(dentry, inode);
@ -1134,6 +1163,10 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
#else
dir->i_version++;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(dir);
exfat_truncate_inode_atime(dir);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
dir->i_mtime = dir->i_atime = inode_set_ctime_current(dir);
@ -1144,6 +1177,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
dir->i_mtime = dir->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
#endif
exfat_truncate_atime(&dir->i_atime);
#endif
if (IS_DIRSYNC(dir))
exfat_sync_inode(dir);
else
@ -1151,6 +1185,10 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
drop_nlink(dir);
clear_nlink(inode);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
simple_inode_init_ts(inode);
exfat_truncate_inode_atime(inode);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
inode->i_mtime = inode->i_atime = inode_set_ctime_current(inode);
@ -1161,6 +1199,7 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
#endif
exfat_truncate_atime(&inode->i_atime);
#endif
exfat_unhash_inode(inode);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
exfat_d_version_set(dentry, inode_query_iversion(dir));
@ -1524,7 +1563,11 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
EXFAT_I(new_dir)->i_crtime = CURRENT_TIME_SEC;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
exfat_truncate_inode_atime(new_dir);
#else
exfat_truncate_atime(&new_dir->i_atime);
#endif
if (IS_DIRSYNC(new_dir))
exfat_sync_inode(new_dir);
else

View file

@ -650,6 +650,10 @@ static int exfat_read_root(struct inode *inode)
ei->i_size_ondisk = i_size_read(inode);
exfat_save_attr(inode, EXFAT_ATTR_SUBDIR);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
ei->i_crtime = simple_inode_init_ts(inode);
exfat_truncate_inode_atime(inode);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
inode->i_mtime = inode->i_atime = ei->i_crtime = inode_set_ctime_current(inode);
@ -662,6 +666,7 @@ static int exfat_read_root(struct inode *inode)
CURRENT_TIME_SEC;
#endif
exfat_truncate_atime(&inode->i_atime);
#endif
return 0;
}