Blame view
fs/init.c
5.94 KB
c60166f04 init: add an init... |
1 2 3 4 5 6 7 8 9 |
// SPDX-License-Identifier: GPL-2.0 /* * Routines that mimic syscalls, but don't use the user address space or file * descriptors. Only for init/ and related early init code. */ #include <linux/init.h> #include <linux/mount.h> #include <linux/namei.h> #include <linux/fs.h> |
db63f1e31 init: add an init... |
10 |
#include <linux/fs_struct.h> |
f07353107 init: add an init... |
11 |
#include <linux/file.h> |
c60166f04 init: add an init... |
12 |
#include <linux/init_syscalls.h> |
4b7ca5014 init: add an init... |
13 |
#include <linux/security.h> |
c60166f04 init: add an init... |
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include "internal.h" int __init init_mount(const char *dev_name, const char *dir_name, const char *type_page, unsigned long flags, void *data_page) { struct path path; int ret; ret = kern_path(dir_name, LOOKUP_FOLLOW, &path); if (ret) return ret; ret = path_mount(dev_name, &path, type_page, flags, data_page); path_put(&path); return ret; } |
09267defa init: add an init... |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
int __init init_umount(const char *name, int flags) { int lookup_flags = LOOKUP_MOUNTPOINT; struct path path; int ret; if (!(flags & UMOUNT_NOFOLLOW)) lookup_flags |= LOOKUP_FOLLOW; ret = kern_path(name, lookup_flags, &path); if (ret) return ret; return path_umount(&path, flags); } |
8fb9f73e5 init: add an init... |
43 |
|
db63f1e31 init: add an init... |
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
int __init init_chdir(const char *filename) { struct path path; int error; error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); if (error) return error; error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR); if (!error) set_fs_pwd(current->fs, &path); path_put(&path); return error; } |
4b7ca5014 init: add an init... |
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
int __init init_chroot(const char *filename) { struct path path; int error; error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); if (error) return error; error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR); if (error) goto dput_and_out; error = -EPERM; if (!ns_capable(current_user_ns(), CAP_SYS_CHROOT)) goto dput_and_out; error = security_path_chroot(&path); if (error) goto dput_and_out; set_fs_root(current->fs, &path); dput_and_out: path_put(&path); return error; } |
b873498f9 init: add an init... |
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags) { int lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW; struct path path; int error; error = kern_path(filename, lookup_flags, &path); if (error) return error; error = mnt_want_write(path.mnt); if (!error) { error = chown_common(&path, user, group); mnt_drop_write(path.mnt); } path_put(&path); return error; } |
1097742ef init: add an init... |
97 98 99 100 101 102 103 104 105 106 107 108 |
int __init init_chmod(const char *filename, umode_t mode) { struct path path; int error; error = kern_path(filename, LOOKUP_FOLLOW, &path); if (error) return error; error = chmod_common(&path, mode); path_put(&path); return error; } |
eb9d7d390 init: add an init... |
109 110 111 112 113 114 115 116 117 118 119 120 |
int __init init_eaccess(const char *filename) { struct path path; int error; error = kern_path(filename, LOOKUP_FOLLOW, &path); if (error) return error; error = inode_permission(d_inode(path.dentry), MAY_ACCESS); path_put(&path); return error; } |
716308a53 init: add an init... |
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
int __init init_stat(const char *filename, struct kstat *stat, int flags) { int lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW; struct path path; int error; error = kern_path(filename, lookup_flags, &path); if (error) return error; error = vfs_getattr(&path, stat, STATX_BASIC_STATS, flags | AT_NO_AUTOMOUNT); path_put(&path); return error; } |
5fee64fcd init: add an init... |
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
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 = kern_path_create(AT_FDCWD, filename, &path, 0); if (IS_ERR(dentry)) return PTR_ERR(dentry); if (!IS_POSIXACL(path.dentry->d_inode)) mode &= ~current_umask(); error = security_path_mknod(&path, dentry, mode, dev); if (!error) error = vfs_mknod(path.dentry->d_inode, dentry, mode, new_decode_dev(dev)); done_path_create(&path, dentry); return error; } |
812931d69 init: add an init... |
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
int __init init_link(const char *oldname, const char *newname) { struct dentry *new_dentry; struct path old_path, new_path; int error; error = kern_path(oldname, 0, &old_path); if (error) return error; new_dentry = kern_path_create(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; error = may_linkat(&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, new_path.dentry->d_inode, new_dentry, NULL); out_dput: done_path_create(&new_path, new_dentry); out: path_put(&old_path); return error; } |
cd3acb6a7 init: add an init... |
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
int __init init_symlink(const char *oldname, const char *newname) { struct dentry *dentry; struct path path; int error; dentry = kern_path_create(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(path.dentry->d_inode, dentry, oldname); done_path_create(&path, dentry); return error; } |
8fb9f73e5 init: add an init... |
206 207 208 209 |
int __init init_unlink(const char *pathname) { return do_unlinkat(AT_FDCWD, getname_kernel(pathname)); } |
20cce026c init: add an init... |
210 |
|
83ff98c3e init: add an init... |
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
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; } |
20cce026c init: add an init... |
228 229 230 231 |
int __init init_rmdir(const char *pathname) { return do_rmdir(AT_FDCWD, getname_kernel(pathname)); } |
235e57935 init: add an init... |
232 233 234 235 236 237 238 239 240 241 242 243 244 |
int __init init_utimes(char *filename, struct timespec64 *ts) { struct path path; int error; error = kern_path(filename, 0, &path); if (error) return error; error = vfs_utimes(&path, ts); path_put(&path); return error; } |
f07353107 init: add an init... |
245 246 247 248 249 250 251 252 253 254 255 |
int __init init_dup(struct file *file) { int fd; fd = get_unused_fd_flags(0); if (fd < 0) return fd; fd_install(fd, get_file(file)); return 0; } |