[PATCH v4 59/59] switch init_mkdir() to use of do_mkdirat(), etc.

Al Viro
2026-01-08T07:37:00Z

Completely straightforward, the only obstacle is do_mknodat() being
static.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/init.c | 88 ++++-----------------------------------------------
fs/internal.h | 1 +
fs/namei.c | 2 +-
3 files changed, 8 insertions(+), 83 deletions(-)

diff --git a/fs/init.c b/fs/init.c
index e0f5429c0a49..da6500d2ee98 100644
--- a/fs/init.c
+++ b/fs/init.c
@@ -140,78 +140,19 @@ int __init init_stat(const char *filename, struct kstat *stat, int flags)

int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)
{
- struct dentry *dentry;
- struct path path;
- int error;
-
- if (S_ISFIFO(mode) || S_ISSOCK(mode))
- dev = 0;
- else if (!(S_ISBLK(mode) || S_ISCHR(mode)))
- return -EINVAL;
-
- dentry = start_creating_path(AT_FDCWD, filename, &path, 0);
- if (IS_ERR(dentry))
- return PTR_ERR(dentry);
-
- mode = mode_strip_umask(d_inode(path.dentry), mode);
- error = security_path_mknod(&path, dentry, mode, dev);
- if (!error)
- error = vfs_mknod(mnt_idmap(path.mnt), path.dentry->d_inode,
- dentry, mode, new_decode_dev(dev), NULL);
- end_creating_path(&path, dentry);
- return error;
+ return do_mknodat(AT_FDCWD, getname_kernel(filename), mode, dev);
}

int __init init_link(const char *oldname, const char *newname)
{
- struct dentry *new_dentry;
- struct path old_path, new_path;
- struct mnt_idmap *idmap;
- int error;
-
- error = kern_path(oldname, 0, &old_path);
- if (error)
- return error;
-
- new_dentry = start_creating_path(AT_FDCWD, newname, &new_path, 0);
- error = PTR_ERR(new_dentry);
- if (IS_ERR(new_dentry))
- goto out;
-
- error = -EXDEV;
- if (old_path.mnt != new_path.mnt)
- goto out_dput;
- idmap = mnt_idmap(new_path.mnt);
- error = may_linkat(idmap, &old_path);
- if (unlikely(error))
- goto out_dput;
- error = security_path_link(old_path.dentry, &new_path, new_dentry);
- if (error)
- goto out_dput;
- error = vfs_link(old_path.dentry, idmap, new_path.dentry->d_inode,
- new_dentry, NULL);
-out_dput:
- end_creating_path(&new_path, new_dentry);
-out:
- path_put(&old_path);
- return error;
+ return do_linkat(AT_FDCWD, getname_kernel(oldname),
+ AT_FDCWD, getname_kernel(newname), 0);
}

int __init init_symlink(const char *oldname, const char *newname)
{
- struct dentry *dentry;
- struct path path;
- int error;
-
- dentry = start_creating_path(AT_FDCWD, newname, &path, 0);
- if (IS_ERR(dentry))
- return PTR_ERR(dentry);
- error = security_path_symlink(&path, dentry, oldname);
- if (!error)
- error = vfs_symlink(mnt_idmap(path.mnt), path.dentry->d_inode,
- dentry, oldname, NULL);
- end_creating_path(&path, dentry);
- return error;
+ return do_symlinkat(getname_kernel(oldname), AT_FDCWD,
+ getname_kernel(newname));
}

int __init init_unlink(const char *pathname)
@@ -221,24 +162,7 @@ int __init init_unlink(const char *pathname)

int __init init_mkdir(const char *pathname, umode_t mode)
{
- struct dentry *dentry;
- struct path path;
- int error;
-
- dentry = start_creating_path(AT_FDCWD, pathname, &path,
- LOOKUP_DIRECTORY);
- if (IS_ERR(dentry))
- return PTR_ERR(dentry);
- mode = mode_strip_umask(d_inode(path.dentry), mode);
- error = security_path_mkdir(&path, dentry, mode);
- if (!error) {
- dentry = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode,
- dentry, mode, NULL);
- if (IS_ERR(dentry))
- error = PTR_ERR(dentry);
- }
- end_creating_path(&path, dentry);
- return error;
+ return do_mkdirat(AT_FDCWD, getname_kernel(pathname), mode);
}

int __init init_rmdir(const char *pathname)
diff --git a/fs/internal.h b/fs/internal.h
index 5c3e4eac34f2..4c4d2733c47a 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -60,6 +60,7 @@ int may_linkat(struct mnt_idmap *idmap, const struct path *link);
int do_renameat2(int olddfd, struct filename *oldname, int newdfd,
struct filename *newname, unsigned int flags);
int do_mkdirat(int dfd, struct filename *name, umode_t mode);
+int do_mknodat(int dfd, struct filename *name, umode_t mode, unsigned int dev);
int do_symlinkat(struct filename *from, int newdfd, struct filename *to);
int do_linkat(int olddfd, struct filename *old, int newdfd,
struct filename *new, int flags);
diff --git a/fs/namei.c b/fs/namei.c
index cbddd5d44a12..7418a4e725da 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -5038,7 +5038,7 @@ static int may_mknod(umode_t mode)
}
}

-static int do_mknodat(int dfd, struct filename *__name, umode_t mode,
+int do_mknodat(int dfd, struct filename *__name, umode_t mode,
unsigned int dev)
{
CLASS(filename_consume, name)(__name);
--
2.47.3