mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:24:47 +01:00
fs: add helpers name_is_dot{,dot,_dotdot}
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>
This commit is contained in:
parent
1992330d90
commit
55fb177d3a
9 changed files with 22 additions and 10 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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--) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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] == '.'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue