From: Chuck Lever <[email protected]>

Upper layers such as NFSD need a way to query whether a filesystem
handles filenames in a case-sensitive manner. Report CIFS/SMB case
handling behavior via the FS_XFLAG_CASEFOLD flag.

CIFS servers (typically Windows or Samba) are usually case-insensitive
but case-preserving, meaning they ignore case during lookups but store
filenames exactly as provided.

The implementation reports case sensitivity based on the nocase mount
option, which reflects whether the client expects the server to perform
case-insensitive comparisons. When nocase is set, the mount is reported
as case-insensitive.

The callback is registered in all three inode_operations structures
(directory, file, and symlink) to ensure consistent reporting across
all inode types.

Signed-off-by: Chuck Lever <[email protected]>
---
 fs/smb/client/cifsfs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c
index d9664634144d..39426a128b3d 100644
--- a/fs/smb/client/cifsfs.c
+++ b/fs/smb/client/cifsfs.c
@@ -30,6 +30,7 @@
 #include <linux/xattr.h>
 #include <linux/mm.h>
 #include <linux/key-type.h>
+#include <linux/fileattr.h>
 #include <uapi/linux/magic.h>
 #include <net/ipv6.h>
 #include "cifsfs.h"
@@ -1193,6 +1194,22 @@ struct file_system_type smb3_fs_type = {
 MODULE_ALIAS_FS("smb3");
 MODULE_ALIAS("smb3");
 
+static int cifs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
+{
+       struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
+       struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
+
+       /*
+        * Case sensitivity is reported based on the nocase mount option.
+        * CIFS servers typically perform case-insensitive lookups while
+        * preserving case in stored filenames. The nocase option indicates
+        * case-insensitive comparison is in effect for this mount.
+        */
+       if (tcon->nocase)
+               fa->fsx_xflags |= FS_XFLAG_CASEFOLD;
+       return 0;
+}
+
 const struct inode_operations cifs_dir_inode_ops = {
        .create = cifs_create,
        .atomic_open = cifs_atomic_open,
@@ -1210,6 +1227,7 @@ const struct inode_operations cifs_dir_inode_ops = {
        .listxattr = cifs_listxattr,
        .get_acl = cifs_get_acl,
        .set_acl = cifs_set_acl,
+       .fileattr_get = cifs_fileattr_get,
 };
 
 const struct inode_operations cifs_file_inode_ops = {
@@ -1220,6 +1238,7 @@ const struct inode_operations cifs_file_inode_ops = {
        .fiemap = cifs_fiemap,
        .get_acl = cifs_get_acl,
        .set_acl = cifs_set_acl,
+       .fileattr_get = cifs_fileattr_get,
 };
 
 const char *cifs_get_link(struct dentry *dentry, struct inode *inode,
@@ -1254,6 +1273,7 @@ const struct inode_operations cifs_symlink_inode_ops = {
        .setattr = cifs_setattr,
        .permission = cifs_permission,
        .listxattr = cifs_listxattr,
+       .fileattr_get = cifs_fileattr_get,
 };
 
 /*
-- 
2.52.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to