From: Omar Sandoval <osan...@fb.com>

The ext4 inode format includes btime (under the name crtime) if the
inode is large enough (256 bytes).

Signed-off-by: Omar Sandoval <osan...@fb.com>
---
 fs/ext4/inode.c | 15 +++++++++++++--
 fs/ext4/super.c |  2 +-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 34d7e0703cc6..7f4f83ef539d 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5489,6 +5489,13 @@ static void ext4_wait_for_tail_page_commit(struct inode 
*inode)
        }
 }
 
+static bool ext4_inode_has_crtime(struct inode *inode)
+{
+       struct ext4_inode *raw_inode;
+
+       return EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), i_crtime);
+}
+
 /*
  * ext4_setattr()
  *
@@ -5520,6 +5527,9 @@ int ext4_setattr(struct dentry *dentry, struct iattr 
*attr)
        int orphan = 0;
        const unsigned int ia_valid = attr->ia_valid;
 
+       if ((ia_valid & ATTR_BTIME) && !ext4_inode_has_crtime(inode))
+               return -EOPNOTSUPP;
+
        if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
                return -EIO;
 
@@ -5671,6 +5681,8 @@ int ext4_setattr(struct dentry *dentry, struct iattr 
*attr)
 
        if (!error) {
                setattr_copy(inode, attr);
+               if (ia_valid & ATTR_BTIME)
+                       EXT4_I(inode)->i_crtime = attr->ia_btime;
                mark_inode_dirty(inode);
        }
 
@@ -5695,11 +5707,10 @@ int ext4_getattr(const struct path *path, struct kstat 
*stat,
                 u32 request_mask, unsigned int query_flags)
 {
        struct inode *inode = d_inode(path->dentry);
-       struct ext4_inode *raw_inode;
        struct ext4_inode_info *ei = EXT4_I(inode);
        unsigned int flags;
 
-       if (EXT4_FITS_IN_INODE(raw_inode, ei, i_crtime)) {
+       if (ext4_inode_has_crtime(inode)) {
                stat->result_mask |= STATX_BTIME;
                stat->btime.tv_sec = ei->i_crtime.tv_sec;
                stat->btime.tv_nsec = ei->i_crtime.tv_nsec;
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index fb12d3c17c1b..cdd3975de130 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5976,7 +5976,7 @@ static struct file_system_type ext4_fs_type = {
        .name           = "ext4",
        .mount          = ext4_mount,
        .kill_sb        = kill_block_super,
-       .fs_flags       = FS_REQUIRES_DEV,
+       .fs_flags       = FS_REQUIRES_DEV | FS_HAS_BTIME,
 };
 MODULE_ALIAS_FS("ext4");
 
-- 
2.20.1

Reply via email to