From 173e937552432db9406f04eb7905541b774ac7cd Mon Sep 17 00:00:00 2001 From: Filipe Manana Date: Tue, 13 Jan 2026 12:39:50 +0000 Subject: fs: export may_delete() as may_delete_dentry() For many years btrfs as been using a copy of may_delete() in fs/btrfs/ioctl.c:btrfs_may_delete(). Everytime may_delete() is updated we need to update the btrfs copy, and this is a maintenance burden. Currently there are minor differences between both because the btrfs side lacks updates done in may_delete(). Export may_delete() so that btrfs can use it and with the less generic name may_delete_dentry(). While at it change the calls in vfs_rmdir() to pass a boolean literal instead of 1 and 0 as the last argument since the argument has a bool type. Signed-off-by: Filipe Manana Link: https://patch.msgid.link/e09128fd53f01b19d0a58f0e7d24739f79f47f6d.1768307858.git.fdmanana@suse.com Reviewed-by: David Sterba Signed-off-by: Christian Brauner --- include/linux/fs.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/linux/fs.h b/include/linux/fs.h index 04ceeca12a0d..06632783a76c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2657,6 +2657,9 @@ static inline int path_permission(const struct path *path, int mask) int __check_sticky(struct mnt_idmap *idmap, struct inode *dir, struct inode *inode); +int may_delete_dentry(struct mnt_idmap *idmap, struct inode *dir, + struct dentry *victim, bool isdir); + static inline bool execute_ok(struct inode *inode) { return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode); -- cgit v1.2.3 From 26aab3a485d500cb89ef7340797982bd066f63a5 Mon Sep 17 00:00:00 2001 From: Filipe Manana Date: Tue, 13 Jan 2026 12:39:51 +0000 Subject: fs: export may_create() as may_create_dentry() For many years btrfs as been using a copy of may_create() in fs/btrfs/ioctl.c:btrfs_may_create(). Everytime may_create() is updated we need to update the btrfs copy, and this is a maintenance burden. Currently there are minor differences between both because the btrfs side lacks updates done in may_create(). Export may_create() so that btrfs can use it and with the less generic name may_create_dentry(). Signed-off-by: Filipe Manana Link: https://patch.msgid.link/ce5174bca079f4cdcbb8dd145f0924feb1f227cd.1768307858.git.fdmanana@suse.com Reviewed-by: David Sterba Signed-off-by: Christian Brauner --- fs/namei.c | 19 ++++++++++--------- include/linux/fs.h | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/fs/namei.c b/fs/namei.c index 28aebc786e8f..676b8c016839 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3657,8 +3657,8 @@ EXPORT_SYMBOL(may_delete_dentry); * 4. We should have write and exec permissions on dir * 5. We can't do it if dir is immutable (done in permission()) */ -static inline int may_create(struct mnt_idmap *idmap, - struct inode *dir, struct dentry *child) +int may_create_dentry(struct mnt_idmap *idmap, + struct inode *dir, struct dentry *child) { audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE); if (child->d_inode) @@ -3670,6 +3670,7 @@ static inline int may_create(struct mnt_idmap *idmap, return inode_permission(idmap, dir, MAY_WRITE | MAY_EXEC); } +EXPORT_SYMBOL(may_create_dentry); // p1 != p2, both are on the same filesystem, ->s_vfs_rename_mutex is held static struct dentry *lock_two_directories(struct dentry *p1, struct dentry *p2) @@ -4116,7 +4117,7 @@ int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode, struct inode *dir = d_inode(dentry->d_parent); int error; - error = may_create(idmap, dir, dentry); + error = may_create_dentry(idmap, dir, dentry); if (error) return error; @@ -4142,7 +4143,7 @@ int vfs_mkobj(struct dentry *dentry, umode_t mode, void *arg) { struct inode *dir = dentry->d_parent->d_inode; - int error = may_create(&nop_mnt_idmap, dir, dentry); + int error = may_create_dentry(&nop_mnt_idmap, dir, dentry); if (error) return error; @@ -4961,7 +4962,7 @@ int vfs_mknod(struct mnt_idmap *idmap, struct inode *dir, struct delegated_inode *delegated_inode) { bool is_whiteout = S_ISCHR(mode) && dev == WHITEOUT_DEV; - int error = may_create(idmap, dir, dentry); + int error = may_create_dentry(idmap, dir, dentry); if (error) return error; @@ -5107,7 +5108,7 @@ struct dentry *vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, unsigned max_links = dir->i_sb->s_max_links; struct dentry *de; - error = may_create(idmap, dir, dentry); + error = may_create_dentry(idmap, dir, dentry); if (error) goto err; @@ -5497,7 +5498,7 @@ int vfs_symlink(struct mnt_idmap *idmap, struct inode *dir, { int error; - error = may_create(idmap, dir, dentry); + error = may_create_dentry(idmap, dir, dentry); if (error) return error; @@ -5605,7 +5606,7 @@ int vfs_link(struct dentry *old_dentry, struct mnt_idmap *idmap, if (!inode) return -ENOENT; - error = may_create(idmap, dir, new_dentry); + error = may_create_dentry(idmap, dir, new_dentry); if (error) return error; @@ -5822,7 +5823,7 @@ int vfs_rename(struct renamedata *rd) return error; if (!target) { - error = may_create(rd->mnt_idmap, new_dir, new_dentry); + error = may_create_dentry(rd->mnt_idmap, new_dir, new_dentry); } else { new_is_dir = d_is_dir(new_dentry); diff --git a/include/linux/fs.h b/include/linux/fs.h index 06632783a76c..2d28eff6eb6a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2659,6 +2659,8 @@ int __check_sticky(struct mnt_idmap *idmap, struct inode *dir, int may_delete_dentry(struct mnt_idmap *idmap, struct inode *dir, struct dentry *victim, bool isdir); +int may_create_dentry(struct mnt_idmap *idmap, + struct inode *dir, struct dentry *child); static inline bool execute_ok(struct inode *inode) { -- cgit v1.2.3