From 5656fea4d6aa4af70edb1c2d5514184ff8ff2cae Mon Sep 17 00:00:00 2001 From: Baolin Liu Date: Wed, 23 Sep 2026 14:02:43 +0800 Subject: [PATCH] ntfs: add fileattr query support Add fileattr_get operations for files and directories, as well as the existing symlink and special inode operation tables. Report compression, encryption, immutable and append-only from cached inode state, and FS_CASEFOLD_FL from the mount-wide case sensitivity policy. This introduces querying only. It neither reads a private flag EA nor allows userspace to change the reported flags. Signed-off-by: Baolin Liu Reviewed-by: Hyunchul Lee Signed-off-by: Namjae Jeon --- Documentation/filesystems/ntfs.rst | 8 ++++++++ fs/ntfs/file.c | 33 ++++++++++++++++++++++++++++++ fs/ntfs/namei.c | 1 + fs/ntfs/ntfs.h | 2 ++ 4 files changed, 44 insertions(+) diff --git a/Documentation/filesystems/ntfs.rst b/Documentation/filesystems/ntfs.rst index 556840e0e7e9..fe42a9d22643 100644 --- a/Documentation/filesystems/ntfs.rst +++ b/Documentation/filesystems/ntfs.rst @@ -9,6 +9,7 @@ The Linux NTFS filesystem driver - Overview - Utilities support + - Linux file attributes - Supported mount options @@ -34,6 +35,13 @@ The project is available at: https://github.com/ntfsprogs-plus/ntfsprogs-plus +Linux file attributes +===================== + +The driver supports querying compression, encryption, immutable, append-only +and mount-wide case folding through lsattr(1). Case folding is reported +according to the mount options. + Supported mount options ======================= diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index ddb05e956598..ce3625a3533b 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,35 @@ int ntfs_file_release(struct inode *vi, struct file *filp) return 0; } +/* + * ntfs_fileattr_get - inode_operations::fileattr_get + * @dentry: dentry to report the flags of + * @fa: filled in with the flags of @dentry + */ +int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa) +{ + struct inode *vi = d_inode(dentry); + struct ntfs_inode *ni = NTFS_I(vi); + u32 flags = 0; + + if (NVolShutdown(ni->vol)) + return -EIO; + + if (NInoCompressed(ni) || NInoWofCompressed(ni)) + flags |= FS_COMPR_FL; + if (NInoEncrypted(ni)) + flags |= FS_ENCRYPT_FL; + if (vi->i_flags & S_IMMUTABLE) + flags |= FS_IMMUTABLE_FL; + if (vi->i_flags & S_APPEND) + flags |= FS_APPEND_FL; + if (!NVolCaseSensitive(ni->vol)) + flags |= FS_CASEFOLD_FL; + + fileattr_fill_flags(fa, flags); + return 0; +} + struct ntfs_fsync_attr { struct list_head list; struct inode *inode; @@ -1426,6 +1456,7 @@ const struct file_operations ntfs_file_ops = { }; const struct inode_operations ntfs_file_inode_ops = { + .fileattr_get = ntfs_fileattr_get, .setattr = ntfs_setattr, .getattr = ntfs_getattr, .listxattr = ntfs_listxattr, @@ -1435,12 +1466,14 @@ const struct inode_operations ntfs_file_inode_ops = { }; const struct inode_operations ntfs_symlink_inode_operations = { + .fileattr_get = ntfs_fileattr_get, .get_link = ntfs_get_link, .setattr = ntfs_setattr, .listxattr = ntfs_listxattr, }; const struct inode_operations ntfs_special_inode_operations = { + .fileattr_get = ntfs_fileattr_get, .setattr = ntfs_setattr, .getattr = ntfs_getattr, .listxattr = ntfs_listxattr, diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c index 6038e8cf0714..c9dc26906617 100644 --- a/fs/ntfs/namei.c +++ b/fs/ntfs/namei.c @@ -1660,6 +1660,7 @@ static int ntfs_link(struct dentry *old_dentry, struct inode *dir, * Inode operations for directories. */ const struct inode_operations ntfs_dir_inode_ops = { + .fileattr_get = ntfs_fileattr_get, .lookup = ntfs_lookup, /* VFS: Lookup directory. */ .create = ntfs_create, .unlink = ntfs_unlink, diff --git a/fs/ntfs/ntfs.h b/fs/ntfs/ntfs.h index 9557a5c36b81..8c344794f87e 100644 --- a/fs/ntfs/ntfs.h +++ b/fs/ntfs/ntfs.h @@ -185,6 +185,8 @@ extern const struct inode_operations ntfs_dir_inode_ops; extern const struct file_operations ntfs_empty_file_ops; extern const struct inode_operations ntfs_empty_inode_ops; +int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa); + extern const struct export_operations ntfs_export_ops; /*