Commit 812931d6 authored by Christoph Hellwig's avatar Christoph Hellwig

init: add an init_link helper

Add a simple helper to link with a kernel space file name and switch
the early init code over to it.  Remove the now unused ksys_link.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent eb9d7d39
...@@ -122,6 +122,39 @@ int __init init_eaccess(const char *filename) ...@@ -122,6 +122,39 @@ int __init init_eaccess(const char *filename)
return error; return error;
} }
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;
}
int __init init_unlink(const char *pathname) int __init init_unlink(const char *pathname)
{ {
return do_unlinkat(AT_FDCWD, getname_kernel(pathname)); return do_unlinkat(AT_FDCWD, getname_kernel(pathname));
......
...@@ -69,8 +69,7 @@ long do_rmdir(int dfd, struct filename *name); ...@@ -69,8 +69,7 @@ long do_rmdir(int dfd, struct filename *name);
long do_unlinkat(int dfd, struct filename *name); long do_unlinkat(int dfd, struct filename *name);
long do_symlinkat(const char __user *oldname, int newdfd, long do_symlinkat(const char __user *oldname, int newdfd,
const char __user *newname); const char __user *newname);
int do_linkat(int olddfd, const char __user *oldname, int newdfd, int may_linkat(struct path *link);
const char __user *newname, int flags);
/* /*
* namespace.c * namespace.c
......
...@@ -1024,7 +1024,7 @@ static bool safe_hardlink_source(struct inode *inode) ...@@ -1024,7 +1024,7 @@ static bool safe_hardlink_source(struct inode *inode)
* *
* Returns 0 if successful, -ve on error. * Returns 0 if successful, -ve on error.
*/ */
static int may_linkat(struct path *link) int may_linkat(struct path *link)
{ {
struct inode *inode = link->dentry->d_inode; struct inode *inode = link->dentry->d_inode;
...@@ -4086,7 +4086,7 @@ EXPORT_SYMBOL(vfs_link); ...@@ -4086,7 +4086,7 @@ EXPORT_SYMBOL(vfs_link);
* with linux 2.0, and to avoid hard-linking to directories * with linux 2.0, and to avoid hard-linking to directories
* and other special files. --ADM * and other special files. --ADM
*/ */
int do_linkat(int olddfd, const char __user *oldname, int newdfd, static int do_linkat(int olddfd, const char __user *oldname, int newdfd,
const char __user *newname, int flags) const char __user *newname, int flags)
{ {
struct dentry *new_dentry; struct dentry *new_dentry;
......
...@@ -8,5 +8,6 @@ int __init init_chroot(const char *filename); ...@@ -8,5 +8,6 @@ int __init init_chroot(const char *filename);
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags); 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_chmod(const char *filename, umode_t mode);
int __init init_eaccess(const char *filename); int __init init_eaccess(const char *filename);
int __init init_link(const char *oldname, const char *newname);
int __init init_unlink(const char *pathname); int __init init_unlink(const char *pathname);
int __init init_rmdir(const char *pathname); int __init init_rmdir(const char *pathname);
...@@ -1295,15 +1295,6 @@ static inline long ksys_mknod(const char __user *filename, umode_t mode, ...@@ -1295,15 +1295,6 @@ static inline long ksys_mknod(const char __user *filename, umode_t mode,
return do_mknodat(AT_FDCWD, filename, mode, dev); return do_mknodat(AT_FDCWD, filename, mode, dev);
} }
extern int do_linkat(int olddfd, const char __user *oldname, int newdfd,
const char __user *newname, int flags);
static inline long ksys_link(const char __user *oldname,
const char __user *newname)
{
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
}
extern int do_fchownat(int dfd, const char __user *filename, uid_t user, extern int do_fchownat(int dfd, const char __user *filename, uid_t user,
gid_t group, int flag); gid_t group, int flag);
......
...@@ -312,7 +312,7 @@ static int __init maybe_link(void) ...@@ -312,7 +312,7 @@ static int __init maybe_link(void)
char *old = find_link(major, minor, ino, mode, collected); char *old = find_link(major, minor, ino, mode, collected);
if (old) { if (old) {
clean_path(collected, 0); clean_path(collected, 0);
return (ksys_link(old, collected) < 0) ? -1 : 1; return (init_link(old, collected) < 0) ? -1 : 1;
} }
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment