From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>,
Christian Brauner <brauner@kernel.org>
Cc: Qing Wang <wangqing7171@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org
Subject: [PATCH 2/3] fs: add helpers name_is_dot{,dot,_dotdot}
Date: Wed, 28 Jan 2026 14:24:05 +0100 [thread overview]
Message-ID: <20260128132406.23768-3-amir73il@gmail.com> (raw)
In-Reply-To: <20260128132406.23768-1-amir73il@gmail.com>
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>
---
fs/crypto/fname.c | 2 +-
fs/ecryptfs/crypto.c | 2 +-
fs/exportfs/expfs.c | 3 ++-
fs/f2fs/dir.c | 2 +-
fs/f2fs/hash.c | 2 +-
fs/namei.c | 2 +-
fs/overlayfs/readdir.c | 3 ++-
fs/smb/server/vfs.c | 2 +-
include/linux/fs.h | 14 ++++++++++++--
9 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c
index a9a4432d12ba1..629eb0d72e860 100644
--- a/fs/crypto/fname.c
+++ b/fs/crypto/fname.c
@@ -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);
}
/**
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 260f8a4938b01..3c89f06c74532 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -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);
diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c
index d3e55de4a2a2a..6c9be60a3e48d 100644
--- a/fs/exportfs/expfs.c
+++ b/fs/exportfs/expfs.c
@@ -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;
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 48f4f98afb013..29412e6e078d0 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -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)
diff --git a/fs/f2fs/hash.c b/fs/f2fs/hash.c
index 049ce50cec9b0..14082fe5e6b29 100644
--- a/fs/f2fs/hash.c
+++ b/fs/f2fs/hash.c
@@ -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;
}
diff --git a/fs/namei.c b/fs/namei.c
index b3fe9d4a7037e..63bbcea75bbd3 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3050,7 +3050,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--) {
diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
index 724ec9d93fc82..9f6b36f3d4cf8 100644
--- a/fs/overlayfs/readdir.c
+++ b/fs/overlayfs/readdir.c
@@ -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);
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index b8e648b8300f6..b38eb8e0b3eb7 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -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;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b1310648bb585..43f9baef4dd36 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2846,12 +2846,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] == '.'));
--
2.52.0
next prev parent reply other threads:[~2026-01-28 13:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 13:24 [PATCH 0/3] name_is_dot* cleanup Amir Goldstein
2026-01-28 13:24 ` [PATCH 1/3] ovl: Fix uninit-value in ovl_fill_real Amir Goldstein
2026-01-29 8:44 ` Miklos Szeredi
2026-01-28 13:24 ` Amir Goldstein [this message]
2026-01-28 13:24 ` [PATCH 3/3] ovl: use name_is_dot* helpers in readdir code Amir Goldstein
2026-01-29 0:14 ` Eric Biggers
2026-01-29 8:38 ` Christian Brauner
2026-01-29 0:16 ` [PATCH 0/3] name_is_dot* cleanup Eric Biggers
2026-01-29 9:09 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260128132406.23768-3-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=wangqing7171@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox