]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/ntfs3: add fileattr support
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Fri, 22 May 2026 12:36:13 +0000 (14:36 +0200)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Tue, 2 Jun 2026 15:02:30 +0000 (17:02 +0200)
Implement fileattr_get() and fileattr_set() to fix a problem found
during the internal testing.

This allows ntfs3 to expose and modify inode flags through the generic
file attribute interface used by FS_IOC_GETFLAGS and FS_IOC_SETFLAGS.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/file.c
fs/ntfs3/inode.c
fs/ntfs3/namei.c
fs/ntfs3/ntfs_fs.h

index b041639ab406f73096d9b79e0ae49bf2027b3426..f421a36b1ed63fbec336c3fadcef00be801e4cf9 100644 (file)
@@ -89,6 +89,80 @@ static int ntfs_ioctl_fitrim(struct ntfs_sb_info *sbi, unsigned long arg)
        return 0;
 }
 
+/*
+ * ntfs_fileattr_get - inode_operations::fileattr_get
+ */
+int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
+{
+       struct inode *inode = d_inode(dentry);
+       struct ntfs_inode *ni = ntfs_i(inode);
+       u32 flags = 0;
+
+       /* Avoid any operation if inode is bad. */
+       if (unlikely(is_bad_ni(ni)))
+               return -EINVAL;
+
+       if (inode->i_flags & S_IMMUTABLE)
+               flags |= FS_IMMUTABLE_FL;
+
+       if (inode->i_flags & S_APPEND)
+               flags |= FS_APPEND_FL;
+
+       if (is_compressed(ni))
+               flags |= FS_COMPR_FL;
+
+       if (is_encrypted(ni))
+               flags |= FS_ENCRYPT_FL;
+
+       if (ni->nodump)
+               flags |= FS_NODUMP_FL;
+
+       fileattr_fill_flags(fa, flags);
+
+       return 0;
+}
+
+/*
+ * ntfs_fileattr_set - inode_operations::fileattr_set
+ */
+int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
+                     struct file_kattr *fa)
+{
+       struct inode *inode = d_inode(dentry);
+       struct ntfs_inode *ni = ntfs_i(inode);
+       u32 flags = fa->flags;
+       unsigned int new_fl = 0;
+
+       /* Avoid any operation if inode is bad. */
+       if (unlikely(is_bad_ni(ni)))
+               return -EINVAL;
+
+       if (fileattr_has_fsx(fa))
+               return -EOPNOTSUPP;
+
+       if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL))
+               return -EOPNOTSUPP;
+
+       if (flags & FS_IMMUTABLE_FL)
+               new_fl |= S_IMMUTABLE;
+
+       if (flags & FS_APPEND_FL)
+               new_fl |= S_APPEND;
+
+       inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND);
+
+       /* Save nodump flag to return in ntfs_getattr. */
+       if (flags & FS_NODUMP_FL)
+               ni->nodump = 1;
+       else
+               ni->nodump = 0;
+
+       inode_set_ctime_current(inode);
+       mark_inode_dirty(inode);
+
+       return 0;
+}
+
 static int ntfs_ioctl_get_volume_label(struct ntfs_sb_info *sbi, u8 __user *buf)
 {
        if (copy_to_user(buf, sbi->volume.label, FSLABEL_MAX))
@@ -203,6 +277,9 @@ int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
        if (inode->i_flags & S_APPEND)
                stat->attributes |= STATX_ATTR_APPEND;
 
+       if (ni->nodump)
+               stat->attributes |= STATX_ATTR_NODUMP;
+
        if (is_compressed(ni))
                stat->attributes |= STATX_ATTR_COMPRESSED;
 
@@ -1547,6 +1624,8 @@ const struct inode_operations ntfs_file_inode_operations = {
        .get_acl        = ntfs_get_acl,
        .set_acl        = ntfs_set_acl,
        .fiemap         = ntfs_fiemap,
+       .fileattr_get   = ntfs_fileattr_get,
+       .fileattr_set   = ntfs_fileattr_set,
 };
 
 const struct file_operations ntfs_file_operations = {
index 42af1abe17f8838700d4b5174d3ae1e2f864991b..356fc94c5a18047c1be9e03a2ca6a0e4b4b7d512 100644 (file)
@@ -2095,6 +2095,8 @@ const struct inode_operations ntfs_link_inode_operations = {
        .get_link       = ntfs_get_link,
        .setattr        = ntfs_setattr,
        .listxattr      = ntfs_listxattr,
+       .fileattr_get   = ntfs_fileattr_get,
+       .fileattr_set   = ntfs_fileattr_set,
 };
 
 const struct address_space_operations ntfs_aops = {
index 64cde1a856f4477a02b4619f3fa32c12a8c01098..c59de5f2fa977120e74ac39be3ae6c1e52093cec 100644 (file)
@@ -518,6 +518,8 @@ const struct inode_operations ntfs_dir_inode_operations = {
        .getattr        = ntfs_getattr,
        .listxattr      = ntfs_listxattr,
        .fiemap         = ntfs_fiemap,
+       .fileattr_get   = ntfs_fileattr_get,
+       .fileattr_set   = ntfs_fileattr_set,
 };
 
 const struct inode_operations ntfs_special_inode_operations = {
@@ -526,6 +528,8 @@ const struct inode_operations ntfs_special_inode_operations = {
        .listxattr      = ntfs_listxattr,
        .get_acl        = ntfs_get_acl,
        .set_acl        = ntfs_set_acl,
+       .fileattr_get   = ntfs_fileattr_get,
+       .fileattr_set   = ntfs_fileattr_set,
 };
 
 const struct dentry_operations ntfs_dentry_ops = {
index d53febc2559c03ecd5462b1d909eff1a6fa3dc91..9939556dcdc1ef3ecb2c0a5a2e14ad1bf1021f8c 100644 (file)
@@ -392,6 +392,9 @@ struct ntfs_inode {
         */
        u8 ni_bad;
 
+       /* Keep track of FS_NODUMP_FL. */
+       u8 nodump;
+
        union {
                struct ntfs_index dir;
                struct {
@@ -529,6 +532,9 @@ bool dir_is_empty(struct inode *dir);
 extern const struct file_operations ntfs_dir_operations;
 
 /* Globals from file.c */
+int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
+int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
+                     struct file_kattr *fa);
 int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
                 struct kstat *stat, u32 request_mask, u32 flags);
 int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,