Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exfat test #58

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions exfat_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
return err;

#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
#else
inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
#endif
Expand Down Expand Up @@ -269,7 +277,11 @@ int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry,

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
#else
generic_fillattr(&nop_mnt_idmap, inode, stat);
#endif
#else
generic_fillattr(&init_user_ns, inode, stat);
#endif
Expand Down Expand Up @@ -359,11 +371,23 @@ 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
#else
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
setattr_copy(&nop_mnt_idmap, inode, attr);
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);
Expand All @@ -374,6 +398,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);
Expand Down
46 changes: 46 additions & 0 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
ts = inode_get_mtime(inode);
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);
ts = inode_get_atime(inode);
exfat_set_entry_time(sbi, &ts,
&ep->dentry.file.access_tz,
&ep->dentry.file.access_time,
&ep->dentry.file.access_date,
NULL);
#else
exfat_set_entry_time(sbi, &inode->i_mtime,
&ep->dentry.file.modify_tz,
&ep->dentry.file.modify_time,
Expand All @@ -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);
Expand Down Expand Up @@ -380,7 +398,15 @@ static void exfat_write_failed(struct address_space *mapping, loff_t to)
if (to > i_size_read(inode)) {
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
#else
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
#endif
Expand Down Expand Up @@ -438,7 +464,15 @@ 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
#else
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
#endif
Expand Down Expand Up @@ -658,10 +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;
}
Expand Down
10 changes: 10 additions & 0 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
86 changes: 85 additions & 1 deletion namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,15 @@ static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
dir->i_version++;
#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
#else
dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
#endif
Expand All @@ -646,14 +654,23 @@ 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);
#else
inode->i_mtime = inode->i_atime = inode->i_ctime =
EXFAT_I(inode)->i_crtime = current_time(inode);
#endif
#else
inode->i_mtime = inode->i_atime = inode->i_ctime =
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);
Expand Down Expand Up @@ -902,24 +919,43 @@ 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);
#else
dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir);
#endif
#else
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);
#else
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
#endif
#else
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));
Expand Down Expand Up @@ -964,7 +1000,15 @@ static int exfat_mkdir(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
#else
dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
#endif
Expand All @@ -985,14 +1029,23 @@ 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);
#else
inode->i_mtime = inode->i_atime = inode->i_ctime =
EXFAT_I(inode)->i_crtime = current_time(inode);
#endif
#else
inode->i_mtime = inode->i_atime = inode->i_ctime =
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);
Expand Down Expand Up @@ -1110,25 +1163,43 @@ 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);
#else
dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir);
#endif
#else
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
mark_inode_dirty(dir);
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);
#else
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
#endif
#else
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));
Expand Down Expand Up @@ -1481,13 +1552,22 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
new_dir->i_version++;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry);
EXFAT_I(new_dir)->i_crtime = current_time(new_dir);
#else
new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime =
EXFAT_I(new_dir)->i_crtime = current_time(new_dir);
#endif
#else
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
Expand All @@ -1513,7 +1593,7 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
#else
old_dir->i_version++;
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) && LINUX_VERSION_CODE <= KERNEL_VERSION(6, 6, 0)
old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
#else
old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
Expand All @@ -1536,8 +1616,12 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
WARN_ON(new_inode->i_nlink == 0);
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
EXFAT_I(new_inode)->i_crtime = current_time(new_inode);
#else
new_inode->i_ctime = EXFAT_I(new_inode)->i_crtime =
current_time(new_inode);
#endif
#else
new_inode->i_ctime = EXFAT_I(new_inode)->i_crtime =
CURRENT_TIME_SEC;
Expand Down
Loading