Skip to content

Commit db63f1e

Browse files
author
Christoph Hellwig
committed
init: add an init_chdir helper
Add a simple helper to chdir with a kernel space file name and switch the early init code over to it. Remove the now unused ksys_chdir. Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 20cce02 commit db63f1e

File tree

7 files changed

+24
-13
lines changed

7 files changed

+24
-13
lines changed

drivers/base/devtmpfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int __init devtmpfs_setup(void *p)
412412
err = init_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, NULL);
413413
if (err)
414414
goto out;
415-
ksys_chdir("/.."); /* will traverse into overmounted root */
415+
init_chdir("/.."); /* will traverse into overmounted root */
416416
ksys_chroot(".");
417417
out:
418418
*(int *)p = err;

fs/init.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/mount.h>
88
#include <linux/namei.h>
99
#include <linux/fs.h>
10+
#include <linux/fs_struct.h>
1011
#include <linux/init_syscalls.h>
1112
#include "internal.h"
1213

@@ -38,6 +39,21 @@ int __init init_umount(const char *name, int flags)
3839
return path_umount(&path, flags);
3940
}
4041

42+
int __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+
4157
int __init init_unlink(const char *pathname)
4258
{
4359
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));

fs/open.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ SYSCALL_DEFINE2(access, const char __user *, filename, int, mode)
482482
return do_faccessat(AT_FDCWD, filename, mode, 0);
483483
}
484484

485-
int ksys_chdir(const char __user *filename)
485+
SYSCALL_DEFINE1(chdir, const char __user *, filename)
486486
{
487487
struct path path;
488488
int error;
@@ -508,11 +508,6 @@ int ksys_chdir(const char __user *filename)
508508
return error;
509509
}
510510

511-
SYSCALL_DEFINE1(chdir, const char __user *, filename)
512-
{
513-
return ksys_chdir(filename);
514-
}
515-
516511
SYSCALL_DEFINE1(fchdir, unsigned int, fd)
517512
{
518513
struct fd f = fdget_raw(fd);

include/linux/init_syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
int __init init_mount(const char *dev_name, const char *dir_name,
44
const char *type_page, unsigned long flags, void *data_page);
55
int __init init_umount(const char *name, int flags);
6+
int __init init_chdir(const char *filename);
67
int __init init_unlink(const char *pathname);
78
int __init init_rmdir(const char *pathname);

include/linux/syscalls.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,6 @@ asmlinkage long sys_ni_syscall(void);
12381238

12391239
int ksys_chroot(const char __user *filename);
12401240
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
1241-
int ksys_chdir(const char __user *filename);
12421241
int ksys_fchown(unsigned int fd, uid_t user, gid_t group);
12431242
ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count);
12441243
void ksys_sync(void);

init/do_mounts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static int __init do_mount_root(const char *name, const char *fs,
408408
if (ret)
409409
goto out;
410410

411-
ksys_chdir("/root");
411+
init_chdir("/root");
412412
s = current->fs->pwd.dentry->d_sb;
413413
ROOT_DEV = s->s_dev;
414414
printk(KERN_INFO

init/do_mounts_initrd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int __init init_linuxrc(struct subprocess_info *info, struct cred *new)
6161
ksys_unshare(CLONE_FS | CLONE_FILES);
6262
console_on_rootfs();
6363
/* move initrd over / and chdir/chroot in initrd root */
64-
ksys_chdir("/root");
64+
init_chdir("/root");
6565
init_mount(".", "/", NULL, MS_MOVE, NULL);
6666
ksys_chroot(".");
6767
ksys_setsid();
@@ -82,7 +82,7 @@ static void __init handle_initrd(void)
8282
/* mount initrd on rootfs' /root */
8383
mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
8484
ksys_mkdir("/old", 0700);
85-
ksys_chdir("/old");
85+
init_chdir("/old");
8686

8787
/*
8888
* In case that a resume from disk is carried out by linuxrc or one of
@@ -104,11 +104,11 @@ static void __init handle_initrd(void)
104104
ksys_chroot("..");
105105

106106
if (new_decode_dev(real_root_dev) == Root_RAM0) {
107-
ksys_chdir("/old");
107+
init_chdir("/old");
108108
return;
109109
}
110110

111-
ksys_chdir("/");
111+
init_chdir("/");
112112
ROOT_DEV = new_decode_dev(real_root_dev);
113113
mount_root();
114114

0 commit comments

Comments
 (0)