Skip to content

Commit 1097742

Browse files
author
Christoph Hellwig
committed
init: add an init_chmod helper
Add a simple helper to chmod with a kernel space file name and switch the early init code over to it. Signed-off-by: Christoph Hellwig <[email protected]>
1 parent b873498 commit 1097742

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

fs/init.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ int __init init_chown(const char *filename, uid_t user, gid_t group, int flags)
9696
return error;
9797
}
9898

99+
int __init init_chmod(const char *filename, umode_t mode)
100+
{
101+
struct path path;
102+
int error;
103+
104+
error = kern_path(filename, LOOKUP_FOLLOW, &path);
105+
if (error)
106+
return error;
107+
error = chmod_common(&path, mode);
108+
path_put(&path);
109+
return error;
110+
}
111+
99112
int __init init_unlink(const char *pathname)
100113
{
101114
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));

fs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ extern struct open_how build_open_how(int flags, umode_t mode);
131131
extern int build_open_flags(const struct open_how *how, struct open_flags *op);
132132

133133
long do_sys_ftruncate(unsigned int fd, loff_t length, int small);
134-
int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
134+
int chmod_common(const struct path *path, umode_t mode);
135135
int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
136136
int flag);
137137
int chown_common(const struct path *path, uid_t user, gid_t group);

fs/open.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
563563
return error;
564564
}
565565

566-
static int chmod_common(const struct path *path, umode_t mode)
566+
int chmod_common(const struct path *path, umode_t mode)
567567
{
568568
struct inode *inode = path->dentry->d_inode;
569569
struct inode *delegated_inode = NULL;
@@ -610,7 +610,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
610610
return err;
611611
}
612612

613-
int do_fchmodat(int dfd, const char __user *filename, umode_t mode)
613+
static int do_fchmodat(int dfd, const char __user *filename, umode_t mode)
614614
{
615615
struct path path;
616616
int error;

include/linux/init_syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ int __init init_umount(const char *name, int flags);
66
int __init init_chdir(const char *filename);
77
int __init init_chroot(const char *filename);
88
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags);
9+
int __init init_chmod(const char *filename, umode_t mode);
910
int __init init_unlink(const char *pathname);
1011
int __init init_rmdir(const char *pathname);

include/linux/syscalls.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,13 +1304,6 @@ static inline long ksys_link(const char __user *oldname,
13041304
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
13051305
}
13061306

1307-
extern int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
1308-
1309-
static inline int ksys_chmod(const char __user *filename, umode_t mode)
1310-
{
1311-
return do_fchmodat(AT_FDCWD, filename, mode);
1312-
}
1313-
13141307
long do_faccessat(int dfd, const char __user *filename, int mode, int flags);
13151308

13161309
static inline long ksys_access(const char __user *filename, int mode)

init/initramfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,14 @@ static int __init do_name(void)
350350
} else if (S_ISDIR(mode)) {
351351
ksys_mkdir(collected, mode);
352352
init_chown(collected, uid, gid, 0);
353-
ksys_chmod(collected, mode);
353+
init_chmod(collected, mode);
354354
dir_add(collected, mtime);
355355
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
356356
S_ISFIFO(mode) || S_ISSOCK(mode)) {
357357
if (maybe_link() == 0) {
358358
ksys_mknod(collected, mode, rdev);
359359
init_chown(collected, uid, gid, 0);
360-
ksys_chmod(collected, mode);
360+
init_chmod(collected, mode);
361361
do_utime(collected, mtime);
362362
}
363363
}

0 commit comments

Comments
 (0)