init: add an init_mkdir helper
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Jul 2020 09:14:59 +0000 (11:14 +0200)
committerChristoph Hellwig <hch@lst.de>
Fri, 31 Jul 2020 06:17:53 +0000 (08:17 +0200)
Add a simple helper to mkdir with a kernel space file name and switch
the early init code over to it.  Remove the now unused ksys_mkdir.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/init.c
fs/internal.h
fs/namei.c
include/linux/init_syscalls.h
include/linux/syscalls.h
init/do_mounts_initrd.c
init/initramfs.c
init/noinitramfs.c

index 09ef2b5..127033d 100644 (file)
--- a/fs/init.c
+++ b/fs/init.c
@@ -176,6 +176,24 @@ int __init init_unlink(const char *pathname)
        return do_unlinkat(AT_FDCWD, getname_kernel(pathname));
 }
 
+int __init init_mkdir(const char *pathname, umode_t mode)
+{
+       struct dentry *dentry;
+       struct path path;
+       int error;
+
+       dentry = kern_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
+       if (IS_ERR(dentry))
+               return PTR_ERR(dentry);
+       if (!IS_POSIXACL(path.dentry->d_inode))
+               mode &= ~current_umask();
+       error = security_path_mkdir(&path, dentry, mode);
+       if (!error)
+               error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
+       done_path_create(&path, dentry);
+       return error;
+}
+
 int __init init_rmdir(const char *pathname)
 {
        return do_rmdir(AT_FDCWD, getname_kernel(pathname));
index 40b50a2..4741e59 100644 (file)
@@ -64,7 +64,6 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
                           const char *, unsigned int, struct path *);
 long do_mknodat(int dfd, const char __user *filename, umode_t mode,
                unsigned int dev);
-long do_mkdirat(int dfd, const char __user *pathname, umode_t mode);
 long do_rmdir(int dfd, struct filename *name);
 long do_unlinkat(int dfd, struct filename *name);
 int may_linkat(struct path *link);
index 2f6fa53..d6b25dd 100644 (file)
@@ -3645,7 +3645,7 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 }
 EXPORT_SYMBOL(vfs_mkdir);
 
-long do_mkdirat(int dfd, const char __user *pathname, umode_t mode)
+static long do_mkdirat(int dfd, const char __user *pathname, umode_t mode)
 {
        struct dentry *dentry;
        struct path path;
index 125f55a..d808985 100644 (file)
@@ -11,4 +11,5 @@ int __init init_eaccess(const char *filename);
 int __init init_link(const char *oldname, const char *newname);
 int __init init_symlink(const char *oldname, const char *newname);
 int __init init_unlink(const char *pathname);
+int __init init_mkdir(const char *pathname, umode_t mode);
 int __init init_rmdir(const char *pathname);
index 7cdc0d7..5ef77a9 100644 (file)
@@ -1270,13 +1270,6 @@ int compat_ksys_ipc(u32 call, int first, int second,
  * The following kernel syscall equivalents are just wrappers to fs-internal
  * functions. Therefore, provide stubs to be inlined at the callsites.
  */
-extern long do_mkdirat(int dfd, const char __user *pathname, umode_t mode);
-
-static inline long ksys_mkdir(const char __user *pathname, umode_t mode)
-{
-       return do_mkdirat(AT_FDCWD, pathname, mode);
-}
-
 extern long do_mknodat(int dfd, const char __user *filename, umode_t mode,
                       unsigned int dev);
 
index a6b447b..3f5ac81 100644 (file)
@@ -81,7 +81,7 @@ static void __init handle_initrd(void)
        create_dev("/dev/root.old", Root_RAM0);
        /* mount initrd on rootfs' /root */
        mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
-       ksys_mkdir("/old", 0700);
+       init_mkdir("/old", 0700);
        init_chdir("/old");
 
        /*
index c91fc9a..0489eb6 100644 (file)
@@ -348,7 +348,7 @@ static int __init do_name(void)
                        state = CopyFile;
                }
        } else if (S_ISDIR(mode)) {
-               ksys_mkdir(collected, mode);
+               init_mkdir(collected, mode);
                init_chown(collected, uid, gid, 0);
                init_chmod(collected, mode);
                dir_add(collected, mtime);
index fa9cdfa..94cc4df 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/stat.h>
 #include <linux/kdev_t.h>
 #include <linux/syscalls.h>
+#include <linux/init_syscalls.h>
 
 /*
  * Create a simple rootfs that is similar to the default initramfs
@@ -17,7 +18,7 @@ static int __init default_rootfs(void)
 {
        int err;
 
-       err = ksys_mkdir((const char __user __force *) "/dev", 0755);
+       err = init_mkdir("/dev", 0755);
        if (err < 0)
                goto out;
 
@@ -27,7 +28,7 @@ static int __init default_rootfs(void)
        if (err < 0)
                goto out;
 
-       err = ksys_mkdir((const char __user __force *) "/root", 0700);
+       err = init_mkdir("/root", 0700);
        if (err < 0)
                goto out;