blob: 64d4e12eba933946f3330fee70d5650960e5bcb5 [file] [log] [blame]
Christoph Hellwigc60166f2020-07-21 11:12:08 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Routines that mimic syscalls, but don't use the user address space or file
4 * descriptors. Only for init/ and related early init code.
5 */
6#include <linux/init.h>
7#include <linux/mount.h>
8#include <linux/namei.h>
9#include <linux/fs.h>
Christoph Hellwigdb63f1e2020-07-22 11:25:21 +020010#include <linux/fs_struct.h>
Christoph Hellwigc60166f2020-07-21 11:12:08 +020011#include <linux/init_syscalls.h>
12#include "internal.h"
13
14int __init init_mount(const char *dev_name, const char *dir_name,
15 const char *type_page, unsigned long flags, void *data_page)
16{
17 struct path path;
18 int ret;
19
20 ret = kern_path(dir_name, LOOKUP_FOLLOW, &path);
21 if (ret)
22 return ret;
23 ret = path_mount(dev_name, &path, type_page, flags, data_page);
24 path_put(&path);
25 return ret;
26}
Christoph Hellwig09267de2020-07-23 08:23:08 +020027
28int __init init_umount(const char *name, int flags)
29{
30 int lookup_flags = LOOKUP_MOUNTPOINT;
31 struct path path;
32 int ret;
33
34 if (!(flags & UMOUNT_NOFOLLOW))
35 lookup_flags |= LOOKUP_FOLLOW;
36 ret = kern_path(name, lookup_flags, &path);
37 if (ret)
38 return ret;
39 return path_umount(&path, flags);
40}
Christoph Hellwig8fb9f732020-07-23 08:23:40 +020041
Christoph Hellwigdb63f1e2020-07-22 11:25:21 +020042int __init init_chdir(const char *filename)
43{
44 struct path path;
45 int error;
46
47 error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
48 if (error)
49 return error;
50 error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
51 if (!error)
52 set_fs_pwd(current->fs, &path);
53 path_put(&path);
54 return error;
55}
56
Christoph Hellwig8fb9f732020-07-23 08:23:40 +020057int __init init_unlink(const char *pathname)
58{
59 return do_unlinkat(AT_FDCWD, getname_kernel(pathname));
60}
Christoph Hellwig20cce022020-07-22 11:11:45 +020061
62int __init init_rmdir(const char *pathname)
63{
64 return do_rmdir(AT_FDCWD, getname_kernel(pathname));
65}