]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
fs: add helpers name_is_dot{,dot,_dotdot}
authorAmir Goldstein <amir73il@gmail.com>
Wed, 28 Jan 2026 13:24:05 +0000 (14:24 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 29 Jan 2026 09:06:59 +0000 (10:06 +0100)
Rename the helper is_dot_dotdot() into the name_ namespace
and add complementary helpers to check for dot and dotdot
names individually.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://patch.msgid.link/20260128132406.23768-3-amir73il@gmail.com
Reviewed-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/crypto/fname.c
fs/ecryptfs/crypto.c
fs/exportfs/expfs.c
fs/f2fs/dir.c
fs/f2fs/hash.c
fs/namei.c
fs/overlayfs/readdir.c
fs/smb/server/vfs.c
include/linux/fs.h

index a9a4432d12ba18f1e1cc0a8f1846ed8b147e6629..629eb0d72e860ebe9ce4436b74bca49a9eb7b696 100644 (file)
@@ -76,7 +76,7 @@ struct fscrypt_nokey_name {
 
 static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
 {
-       return is_dot_dotdot(str->name, str->len);
+       return name_is_dot_dotdot(str->name, str->len);
 }
 
 /**
index 260f8a4938b01981b9b6cb773051d4bfe19d86bf..3c89f06c7453222f3f73a59b6830fed1ccc6832c 100644 (file)
@@ -1904,7 +1904,7 @@ int ecryptfs_decode_and_decrypt_filename(char **plaintext_name,
 
        if ((mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) &&
            !(mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)) {
-               if (is_dot_dotdot(name, name_size)) {
+               if (name_is_dot_dotdot(name, name_size)) {
                        rc = ecryptfs_copy_filename(plaintext_name,
                                                    plaintext_name_size,
                                                    name, name_size);
index d3e55de4a2a2afe60ec06822ef436f29832dd6a8..6c9be60a3e48dc5e984a826029375550d1494835 100644 (file)
@@ -253,7 +253,8 @@ static bool filldir_one(struct dir_context *ctx, const char *name, int len,
                container_of(ctx, struct getdents_callback, ctx);
 
        buf->sequence++;
-       if (buf->ino == ino && len <= NAME_MAX && !is_dot_dotdot(name, len)) {
+       if (buf->ino == ino && len <= NAME_MAX &&
+           !name_is_dot_dotdot(name, len)) {
                memcpy(buf->name, name, len);
                buf->name[len] = '\0';
                buf->found = 1;
index 48f4f98afb0138aefabaa10608961812165e2312..29412e6e078d0eaf5a50dc8f863f275489b61d94 100644 (file)
@@ -67,7 +67,7 @@ int f2fs_init_casefolded_name(const struct inode *dir,
        int len;
 
        if (IS_CASEFOLDED(dir) &&
-           !is_dot_dotdot(fname->usr_fname->name, fname->usr_fname->len)) {
+           !name_is_dot_dotdot(fname->usr_fname->name, fname->usr_fname->len)) {
                buf = f2fs_kmem_cache_alloc(f2fs_cf_name_slab,
                                            GFP_NOFS, false, F2FS_SB(sb));
                if (!buf)
index 049ce50cec9b097bf0f184f8e6086cda0d15b01b..14082fe5e6b293ad39de1bc4dd2c04da39b40794 100644 (file)
@@ -100,7 +100,7 @@ void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname)
 
        WARN_ON_ONCE(!name);
 
-       if (is_dot_dotdot(name, len)) {
+       if (name_is_dot_dotdot(name, len)) {
                fname->hash = 0;
                return;
        }
index 4e3a5fd370a8a480d20891480928f2c613c1dbbe..aa8fbca81686af7b5961a33fff0c1350ec35ee73 100644 (file)
@@ -3042,7 +3042,7 @@ int lookup_noperm_common(struct qstr *qname, struct dentry *base)
        if (!len)
                return -EACCES;
 
-       if (is_dot_dotdot(name, len))
+       if (name_is_dot_dotdot(name, len))
                return -EACCES;
 
        while (len--) {
index 724ec9d93fc8299f4802ee87d599d31e0e3d6db8..9f6b36f3d4cf8e530b919f2606c5953ee87c1907 100644 (file)
@@ -76,7 +76,8 @@ static int ovl_casefold(struct ovl_readdir_data *rdd, const char *str, int len,
        char *cf_name;
        int cf_len;
 
-       if (!IS_ENABLED(CONFIG_UNICODE) || !rdd->map || is_dot_dotdot(str, len))
+       if (!IS_ENABLED(CONFIG_UNICODE) || !rdd->map ||
+           name_is_dot_dotdot(str, len))
                return 0;
 
        cf_name = kmalloc(NAME_MAX, GFP_KERNEL);
index 98b0eb966d917c413c5cb241e114f539d0fb50c9..e73e968f664d7a03b0cf79391d5fbbe5eb6f8fd4 100644 (file)
@@ -1052,7 +1052,7 @@ static bool __dir_empty(struct dir_context *ctx, const char *name, int namlen,
        struct ksmbd_readdir_data *buf;
 
        buf = container_of(ctx, struct ksmbd_readdir_data, ctx);
-       if (!is_dot_dotdot(name, namlen))
+       if (!name_is_dot_dotdot(name, namlen))
                buf->dirent_count++;
 
        return !buf->dirent_count;
index 094b0adcb035f428fcd617f8cb63d99980503248..95bb9a15e1091509fd6e88c78bf3d6df0d8a680a 100644 (file)
@@ -2844,12 +2844,22 @@ u64 vfsmount_to_propagation_flags(struct vfsmount *mnt);
 
 extern char *file_path(struct file *, char *, int);
 
+static inline bool name_is_dot(const char *name, size_t len)
+{
+       return unlikely(len == 1 && name[0] == '.');
+}
+
+static inline bool name_is_dotdot(const char *name, size_t len)
+{
+       return unlikely(len == 2 && name[0] == '.' && name[1] == '.');
+}
+
 /**
- * is_dot_dotdot - returns true only if @name is "." or ".."
+ * name_is_dot_dotdot - returns true only if @name is "." or ".."
  * @name: file name to check
  * @len: length of file name, in bytes
  */
-static inline bool is_dot_dotdot(const char *name, size_t len)
+static inline bool name_is_dot_dotdot(const char *name, size_t len)
 {
        return len && unlikely(name[0] == '.') &&
                (len == 1 || (len == 2 && name[1] == '.'));