Skip to content

Commit

Permalink
init: add an init_symlink helper
Browse files Browse the repository at this point in the history
Add a simple helper to symlink with a kernel space file name and switch
the early init code over to it.  Remove the now unused ksys_symlink.

Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
Christoph Hellwig committed Jul 31, 2020
1 parent 812931d commit cd3acb6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
16 changes: 16 additions & 0 deletions fs/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ int __init init_link(const char *oldname, const char *newname)
return error;
}

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;
}

int __init init_unlink(const char *pathname)
{
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));
Expand Down
2 changes: 0 additions & 2 deletions fs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ long do_mknodat(int dfd, const char __user *filename, umode_t mode,
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);
long do_symlinkat(const char __user *oldname, int newdfd,
const char __user *newname);
int may_linkat(struct path *link);

/*
Expand Down
2 changes: 1 addition & 1 deletion fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -3955,7 +3955,7 @@ int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
}
EXPORT_SYMBOL(vfs_symlink);

long do_symlinkat(const char __user *oldname, int newdfd,
static long do_symlinkat(const char __user *oldname, int newdfd,
const char __user *newname)
{
int error;
Expand Down
1 change: 1 addition & 0 deletions include/linux/init_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ int __init init_chown(const char *filename, uid_t user, gid_t group, int flags);
int __init init_chmod(const char *filename, umode_t mode);
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_rmdir(const char *pathname);
9 changes: 0 additions & 9 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -1277,15 +1277,6 @@ static inline long ksys_mkdir(const char __user *pathname, umode_t mode)
return do_mkdirat(AT_FDCWD, pathname, mode);
}

extern long do_symlinkat(const char __user *oldname, int newdfd,
const char __user *newname);

static inline long ksys_symlink(const char __user *oldname,
const char __user *newname)
{
return do_symlinkat(oldname, AT_FDCWD, newname);
}

extern long do_mknodat(int dfd, const char __user *filename, umode_t mode,
unsigned int dev);

Expand Down
2 changes: 1 addition & 1 deletion init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static int __init do_symlink(void)
{
collected[N_ALIGN(name_len) + body_len] = '\0';
clean_path(collected, 0);
ksys_symlink(collected + N_ALIGN(name_len), collected);
init_symlink(collected + N_ALIGN(name_len), collected);
init_chown(collected, uid, gid, AT_SYMLINK_NOFOLLOW);
do_utime(collected, mtime);
state = SkipIt;
Expand Down

0 comments on commit cd3acb6

Please sign in to comment.