fat: report creation time in statx
authorChung-Chiang Cheng <cccheng@synology.com>
Tue, 3 May 2022 15:25:35 +0000 (23:25 +0800)
committerakpm <akpm@linux-foundation.org>
Thu, 19 May 2022 21:10:31 +0000 (14:10 -0700)
creation time is no longer mixed with change time.  Add an in-memory field
for it, and report it in statx if supported.

Link: https://lkml.kernel.org/r/20220503152536.2503003-3-cccheng@synology.com
Signed-off-by: Chung-Chiang Cheng <cccheng@synology.com>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/fat/fat.h
fs/fat/file.c
fs/fat/inode.c

index b7f60b366030cfa268e15f94dfee4f515fe81fdd..6ed05ac0e694de819a050a775cd1024fcfb7928d 100644 (file)
@@ -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;
 };
 
index a5a309fcc7faf6dbdffa07243208e3d53e6c9462..8f5218450a3a48175a5d512856ed5f83f102dc98 100644 (file)
@@ -399,13 +399,21 @@ int fat_getattr(struct user_namespace *mnt_userns, const struct path *path,
                struct kstat *stat, u32 request_mask, unsigned int flags)
 {
        struct inode *inode = d_inode(path->dentry);
+       struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);
+
        generic_fillattr(mnt_userns, inode, stat);
-       stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size;
+       stat->blksize = sbi->cluster_size;
 
-       if (MSDOS_SB(inode->i_sb)->options.nfs == FAT_NFS_NOSTALE_RO) {
+       if (sbi->options.nfs == FAT_NFS_NOSTALE_RO) {
                /* Use i_pos for ino. This is used as fileid of nfs. */
-               stat->ino = fat_i_pos_read(MSDOS_SB(inode->i_sb), inode);
+               stat->ino = fat_i_pos_read(sbi, inode);
        }
+
+       if (sbi->options.isvfat && request_mask & STATX_BTIME) {
+               stat->result_mask |= STATX_BTIME;
+               stat->btime = MSDOS_I(inode)->i_crtime;
+       }
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(fat_getattr);
index d0371913f496d5727bde3dc37c7576ae1da7610e..32e721b88a49de772a385ac99ef1e75407137ac9 100644 (file)
@@ -568,9 +568,11 @@ 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
                inode->i_atime = fat_truncate_atime(sbi, &inode->i_mtime);
 
        return 0;
@@ -756,6 +758,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;
 }
@@ -889,6 +893,8 @@ retry:
                __le16 atime;
                fat_time_unix2fat(sbi, &inode->i_atime, &atime,
                                  &raw_entry->adate, NULL);
+               fat_time_unix2fat(sbi, &MSDOS_I(inode)->i_crtime, &raw_entry->ctime,
+                                 &raw_entry->cdate, &raw_entry->ctime_cs);
        }
        spin_unlock(&sbi->inode_hash_lock);
        mark_buffer_dirty(bh);