fat: split fat_truncate_time() into separate functions
Subsystems (2)
PATCH v2 1/3 fat: split fat_truncate_time() into separate functions
Separate fat_truncate_time() to each timestamps for later creation time work.
This patch does not introduce any functional changes, it's merely refactoring change.
--- fs/fat/fat.h | 6 +++++ fs/fat/misc.c | 72 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 26 deletions(-)
fs/fat/fat.h +6 -0
@@ -446,6 +446,12 @@ extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec64 *ts, __le16 __time, __le16 __date, u8 time_cs);extern void fat_time_unix2fat (struct msdos_sb_info *sbi,struct timespec64 *ts,__le16 *time,__le16 *date,u8 *time_cs); +extern void fat_truncate_atime (struct msdos_sb_info *sbi,struct timespec64 *ts, +struct timespec64 *atime); +extern void fat_truncate_crtime (struct msdos_sb_info *sbi,struct timespec64 *ts, +struct timespec64 *crtime); +extern void fat_truncate_mtime (struct msdos_sb_info *sbi,struct timespec64 *ts, +struct timespec64 *mtime);extern int fat_truncate_time (struct inode *inode,struct timespec64 *now,int flags); extern int fat_update_time(struct inode *inode, struct timespec64 *now,
fs/fat/misc.c +46 -26
87 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 2/3 fat: make ctime and mtime identical explicitly
FAT supports creation time but not change time, and there was no corresponding timestamp for creation time in previous VFS. The original implementation took the compromise of saving the in-memory change time into the on-disk creation time field, but this would lead to compatibility issues with non-linux systems.
In address this issue, this patch changes the behavior of ctime. ctime will no longer be loaded and stored from the creation time on disk. Instead of that, it'll be consistent with the in-memory mtime and share the same on-disk field.
--- fs/fat/dir.c | 2 +- fs/fat/file.c | 4 ++++ fs/fat/inode.c | 11 ++++------- fs/fat/misc.c | 11 ++++++++--- fs/fat/namei_msdos.c | 6 +++--- fs/fat/namei_vfat.c | 6 +++--- 6 files changed, 23 insertions(+), 17 deletions(-)
fs/fat/dir.c +1 -1
@@ -1068,7 +1068,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 ,S_ATIME |S_CTIME |S_MTIME );if (IS_DIRSYNC (dir)) (void )fat_sync_inode (dir);else
fs/fat/file.c +4 -0
@@ -544,6 +544,10 @@ int fat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,/* * setattr_copy can't truncate these appropriately, so we'll * copy them ourselves +* +* fat_truncate_time() keeps ctime and mtime the same. if both +* ctime and mtime are need to update here, mtime will overwrite +* ctime */ if (attr->ia_valid &ATTR_ATIME )fat_truncate_time (inode, &attr->ia_atime,S_ATIME );
fs/fat/inode.c +4 -7
@@ -567,12 +567,11 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) & ~((loff_t)sbi->cluster_size - 1)) >> 9;fat_time_fat2unix (sbi, &inode->i_mtime, de->time, de->date,0 ); -if (sbi->options.isvfat) { -fat_time_fat2unix (sbi, &inode->i_ctime, de->ctime, - de->cdate, de->ctime_cs); + inode->i_ctime = inode->i_mtime; +if (sbi->options.isvfat)fat_time_fat2unix (sbi, &inode->i_atime,0 , de->adate,0 ); - }else -fat_truncate_time (inode, &inode->i_mtime,S_ATIME |S_CTIME ); +else +fat_truncate_atime (sbi, &inode->i_mtime, &inode->i_atime);return 0 ; }
@@ -888,8 +887,6 @@ static int __fat_write_inode(struct inode *inode, int wait) &raw_entry->date, NULL);if (sbi->options.isvfat) {__le16 atime; -fat_time_unix2fat (sbi, &inode->i_ctime, &raw_entry->ctime, - &raw_entry->cdate, &raw_entry->ctime_cs);fat_time_unix2fat (sbi, &inode->i_atime, &atime, &raw_entry->adate,NULL ); }
fs/fat/misc.c +8 -3
@@ -341,10 +341,15 @@ int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags)if (flags &S_ATIME )fat_truncate_atime (sbi, now, &inode->i_atime); -if (flags &S_CTIME ) -fat_truncate_crtime (sbi, now, &inode->i_ctime); -if (flags &S_MTIME ) + +/* +* ctime and mtime share the same on-disk field, and should be +* identical in memory. +*/ +if (flags & (S_CTIME |S_MTIME )) {fat_truncate_mtime (sbi, now, &inode->i_mtime); + inode->i_ctime = inode->i_mtime; + }return 0 ; }
fs/fat/namei_msdos.c +3 -3
@@ -328,7 +328,7 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry)drop_nlink (dir);clear_nlink (inode); -fat_truncate_time (inode,NULL ,S_CTIME ); +fat_truncate_time (inode,NULL ,S_CTIME |S_MTIME );fat_detach (inode); out:mutex_unlock (&MSDOS_SB (sb)->s_lock);
@@ -415,7 +415,7 @@ 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_truncate_time (inode,NULL ,S_CTIME |S_MTIME );fat_detach (inode); out:mutex_unlock (&MSDOS_SB (sb)->s_lock);
@@ -550,7 +550,7 @@ 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 ); +fat_truncate_time (new_inode, &ts,S_CTIME |S_MTIME ); } out:brelse (sinfo.bh);
fs/fat/namei_vfat.c +3 -3
@@ -811,7 +811,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 ,S_ATIME |S_CTIME |S_MTIME );fat_detach (inode);vfat_d_version_set (dentry,inode_query_iversion (dir)); out:
@@ -837,7 +837,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 ,S_ATIME |S_CTIME |S_MTIME );fat_detach (inode);vfat_d_version_set (dentry,inode_query_iversion (dir)); out:
@@ -981,7 +981,7 @@ static int vfat_rename(struct user_namespace *mnt_userns, struct inode *old_dir,drop_nlink (new_inode);if (is_dir)drop_nlink (new_inode); -fat_truncate_time (new_inode, &ts,S_CTIME ); +fat_truncate_time (new_inode, &ts,S_CTIME |S_MTIME ); } out:brelse (sinfo.bh);
Signature · 1 line
2.34.1
OGAWA Hirofumi
maintainerRe: [PATCH v2 2/3] fat: make ctime and mtime identical explicitly
Quoted 10 lines · Chung-Chiang Cheng
FAT supports creation time but not change time, and there was no corresponding timestamp for creation time in previous VFS. The original implementation took the compromise of saving the in-memory change time into the on-disk creation time field, but this would lead to compatibility issues with non-linux systems.
In address this issue, this patch changes the behavior of ctime. ctime will no longer be loaded and stored from the creation time on disk. Instead of that, it'll be consistent with the in-memory mtime and share the same on-disk field.
Hm, this changes mtime includes ctime update. So, the question is, this behavior is compatible with Windows's fatfs behavior? E.g. Windows updates mtime on rename?
If not same behavior with Windows, new behavior is new incompatible behavior, and looks break fundamental purpose of this.
I was thinking, we ignores ctime update (because fatfs doesn't have) and always same with mtime. What behavior was actually compatible with Windows?
Thanks.
Quoted 153 lines
Signed-off-by Chung-Chiang Cheng <[email protected]>--- fs/fat/dir.c | 2 +- fs/fat/file.c | 4 ++++ fs/fat/inode.c | 11 ++++------- fs/fat/misc.c | 11 ++++++++--- fs/fat/namei_msdos.c | 6 +++--- fs/fat/namei_vfat.c | 6 +++--- 6 files changed, 23 insertions(+), 17 deletions(-)fs/fat/dir.c +1
-1@@ -1068,7 +1068,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 ,S_ATIME |S_CTIME |S_MTIME );if (IS_DIRSYNC (dir)) (void )fat_sync_inode (dir);else fs/fat/file.c +4
-0@@ -544,6 +544,10 @@ int fat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,/* * setattr_copy can't truncate these appropriately, so we'll * copy them ourselves +* +* fat_truncate_time() keeps ctime and mtime the same. if both +* ctime and mtime are need to update here, mtime will overwrite +* ctime */ if (attr->ia_valid &ATTR_ATIME )fat_truncate_time (inode, &attr->ia_atime,S_ATIME );fs/fat/inode.c +4
-7@@ -567,12 +567,11 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) & ~((loff_t)sbi->cluster_size - 1)) >> 9;fat_time_fat2unix (sbi, &inode->i_mtime, de->time, de->date,0 ); -if (sbi->options.isvfat) { -fat_time_fat2unix (sbi, &inode->i_ctime, de->ctime, - de->cdate, de->ctime_cs); + inode->i_ctime = inode->i_mtime; +if (sbi->options.isvfat)fat_time_fat2unix (sbi, &inode->i_atime,0 , de->adate,0 ); - }else -fat_truncate_time (inode, &inode->i_mtime,S_ATIME |S_CTIME ); +else +fat_truncate_atime (sbi, &inode->i_mtime, &inode->i_atime);return 0 ; }@@ -888,8 +887,6 @@ static int __fat_write_inode(struct inode *inode, int wait) &raw_entry->date, NULL);if (sbi->options.isvfat) {__le16 atime; -fat_time_unix2fat (sbi, &inode->i_ctime, &raw_entry->ctime, - &raw_entry->cdate, &raw_entry->ctime_cs);fat_time_unix2fat (sbi, &inode->i_atime, &atime, &raw_entry->adate,NULL ); }fs/fat/misc.c +8
-3@@ -341,10 +341,15 @@ int fat_truncate_time(struct inode *inode, struct timespec64 *now, int flags)if (flags &S_ATIME )fat_truncate_atime (sbi, now, &inode->i_atime); -if (flags &S_CTIME ) -fat_truncate_crtime (sbi, now, &inode->i_ctime); -if (flags &S_MTIME ) + +/* +* ctime and mtime share the same on-disk field, and should be +* identical in memory. +*/ +if (flags & (S_CTIME |S_MTIME )) {fat_truncate_mtime (sbi, now, &inode->i_mtime); + inode->i_ctime = inode->i_mtime; + }return 0 ; }fs/fat/namei_msdos.c +3
-3@@ -328,7 +328,7 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry)drop_nlink (dir);clear_nlink (inode); -fat_truncate_time (inode,NULL ,S_CTIME ); +fat_truncate_time (inode,NULL ,S_CTIME |S_MTIME );fat_detach (inode); out:mutex_unlock (&MSDOS_SB (sb)->s_lock);@@ -415,7 +415,7 @@ 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_truncate_time (inode,NULL ,S_CTIME |S_MTIME );fat_detach (inode); out:mutex_unlock (&MSDOS_SB (sb)->s_lock);@@ -550,7 +550,7 @@ 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 ); +fat_truncate_time (new_inode, &ts,S_CTIME |S_MTIME ); } out:brelse (sinfo.bh);fs/fat/namei_vfat.c +3
-3@@ -811,7 +811,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 ,S_ATIME |S_CTIME |S_MTIME );fat_detach (inode);vfat_d_version_set (dentry,inode_query_iversion (dir)); out:@@ -837,7 +837,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 ,S_ATIME |S_CTIME |S_MTIME );fat_detach (inode);vfat_d_version_set (dentry,inode_query_iversion (dir)); out:@@ -981,7 +981,7 @@ static int vfat_rename(struct user_namespace *mnt_userns, struct inode *old_dir,drop_nlink (new_inode);if (is_dir)drop_nlink (new_inode); -fat_truncate_time (new_inode, &ts,S_CTIME ); +fat_truncate_time (new_inode, &ts,S_CTIME |S_MTIME ); } out:brelse (sinfo.bh);
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Re: [PATCH v2 2/3] fat: make ctime and mtime identical explicitly
Quoted 5 lines · OGAWA Hirofumi
Hm, this changes mtime includes ctime update. So, the question is, this behavior is compatible with Windows's fatfs behavior? E.g. Windows updates mtime on rename?
Quoted 7 lines
If not same behavior with Windows, new behavior is new incompatible behavior, and looks break fundamental purpose of this.
I was thinking, we ignores ctime update (because fatfs doesn't have) and always same with mtime. What behavior was actually compatible with Windows?
If possible, to ignore ctime update may be a better choice that doesn't affect mtime. But we need an initial value for ctime when the inode is loaded.
One possible option is to use mtime. Although ctime won't be updated anymore, when mtime is changed, ctime needs to take effect. Otherwise the next time the inode is loaded, ctime will be inconsistent. That is, ctime is still updated indirectly by mtime. It seems impossible to avoid updating ctime, or do we just show ctime a non-sense value?
Thanks.
OGAWA Hirofumi
maintainerRe: [PATCH v2 2/3] fat: make ctime and mtime identical explicitly
Quoted 19 lines · Chung-Chiang Cheng
Quoted 5 lines · OGAWA Hirofumi
Hm, this changes mtime includes ctime update. So, the question is, this behavior is compatible with Windows's fatfs behavior? E.g. Windows updates mtime on rename?
Quoted 7 lines
If not same behavior with Windows, new behavior is new incompatible behavior, and looks break fundamental purpose of this.
I was thinking, we ignores ctime update (because fatfs doesn't have) and always same with mtime. What behavior was actually compatible with Windows?
If possible, to ignore ctime update may be a better choice that doesn't affect mtime. But we need an initial value for ctime when the inode is loaded.
Quoted 5 lines
One possible option is to use mtime. Although ctime won't be updated anymore, when mtime is changed, ctime needs to take effect. Otherwise the next time the inode is loaded, ctime will be inconsistent. That is, ctime is still updated indirectly by mtime. It seems impossible to avoid updating ctime, or do we just show ctime a non-sense value?
I mean I also think the behavior what you said sounds like reasonable. mtime change affect to ctime, but ctime change doesn't affect to mtime.
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
PATCH v2 3/3 fat: report creation time in statx
In reply to Chung-Chiang Chengcreation time is no longer mixed with change time. Add a in-memory field for it, and report it in statx.
--- fs/fat/fat.h | 1 + fs/fat/file.c | 6 ++++++ fs/fat/inode.c | 12 ++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-)
fs/fat/fat.h +1 -0
@@ -126,6 +126,7 @@ struct msdos_inode_info {struct hlist_node i_fat_hash;/* hash by i_location */ struct hlist_node i_dir_hash;/* hash by i_logstart */ struct rw_semaphore truncate_lock;/* protect bmap against truncate */ +struct timespec64 i_crtime;/* File creation (birth) time */ struct inode vfs_inode; };
fs/fat/file.c +6 -0
@@ -406,6 +406,12 @@ int fat_getattr(struct user_namespace *mnt_userns, const struct path *path,/* Use i_pos for ino. This is used as fileid of nfs. */ stat->ino =fat_i_pos_read (MSDOS_SB (inode->i_sb), inode); } + +if (request_mask &STATX_BTIME ) { + stat->result_mask |=STATX_BTIME ; + stat->btime =MSDOS_I (inode)->i_crtime; + } +return 0 ; }EXPORT_SYMBOL_GPL (fat_getattr);
fs/fat/inode.c +10 -2
@@ -568,10 +568,14 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)fat_time_fat2unix (sbi, &inode->i_mtime, de->time, de->date,0 ); inode->i_ctime = inode->i_mtime; -if (sbi->options.isvfat) +if (sbi->options.isvfat) {fat_time_fat2unix (sbi, &inode->i_atime,0 , de->adate,0 ); -else +fat_time_fat2unix (sbi, &MSDOS_I (inode)->i_crtime, de->ctime, + de->cdate, de->ctime_cs); + }else {fat_truncate_atime (sbi, &inode->i_mtime, &inode->i_atime); +fat_truncate_crtime (sbi, &inode->i_mtime, &MSDOS_I (inode)->i_crtime); + }return 0 ; }
@@ -756,6 +760,8 @@ static struct inode *fat_alloc_inode(struct super_block *sb) ei->i_logstart =0 ; ei->i_attrs =0 ; ei->i_pos =0 ; + ei->i_crtime.tv_sec =0 ; + ei->i_crtime.tv_nsec =0 ;return &ei->vfs_inode; }
@@ -887,6 +893,8 @@ static int __fat_write_inode(struct inode *inode, int wait) &raw_entry->date, NULL);if (sbi->options.isvfat) {__le16 atime; +fat_time_unix2fat (sbi, &MSDOS_I (inode)->i_crtime, &raw_entry->ctime, + &raw_entry->cdate, &raw_entry->ctime_cs);fat_time_unix2fat (sbi, &inode->i_atime, &atime, &raw_entry->adate,NULL ); }
Signature · 1 line
2.34.1
OGAWA Hirofumi
maintainerRe: [PATCH v2 3/3] fat: report creation time in statx
Quoted 3 lines · Chung-Chiang Cheng
creation time is no longer mixed with change time. Add a in-memory field for it, and report it in statx.
[...]
Quoted 6 lines
fs/fat/file.c +6
-0+ +if (request_mask &STATX_BTIME ) { + stat->result_mask |=STATX_BTIME ; + stat->btime =MSDOS_I (inode)->i_crtime; + } +
[...]
fs/fat/inode.c int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) · line 578
Quoted 10 lines
fs/fat/inode.c +6
-2-if (sbi->options.isvfat) +if (sbi->options.isvfat) {fat_time_fat2unix (sbi, &inode->i_atime,0 , de->adate,0 ); -else +fat_time_fat2unix (sbi, &MSDOS_I (inode)->i_crtime, de->ctime, + de->cdate, de->ctime_cs); + }else {fat_truncate_atime (sbi, &inode->i_mtime, &inode->i_atime); +fat_truncate_crtime (sbi, &inode->i_mtime, &MSDOS_I (inode)->i_crtime); + }
This looks strange. MSDOS doesn't have crtime, but set the fake time from mtime and returns to userspace. Why don't we disable STATX_BTIME for MSDOS?
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Re: [PATCH v2 3/3] fat: report creation time in statx
Quoted 20 lines
Quoted 6 lines
fs/fat/file.c +6
-0+ +if (request_mask &STATX_BTIME ) { + stat->result_mask |=STATX_BTIME ; + stat->btime =MSDOS_I (inode)->i_crtime; + } +[...]
fs/fat/inode.c int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de) · line 578
Quoted 10 lines
fs/fat/inode.c +6
-2-if (sbi->options.isvfat) +if (sbi->options.isvfat) {fat_time_fat2unix (sbi, &inode->i_atime,0 , de->adate,0 ); -else +fat_time_fat2unix (sbi, &MSDOS_I (inode)->i_crtime, de->ctime, + de->cdate, de->ctime_cs); + }else {fat_truncate_atime (sbi, &inode->i_mtime, &inode->i_atime); +fat_truncate_crtime (sbi, &inode->i_mtime, &MSDOS_I (inode)->i_crtime); + }
Quoted 3 lines
This looks strange. MSDOS doesn't have crtime, but set the fake time from mtime and returns to userspace. Why don't we disable
STATX_BTIMEfor MSDOS?
Agree. It's not necessary to report in statx.
Thanks.