diff options
author | Christoph Hellwig <hch@lst.de> | 2020-07-22 12:14:19 +0300 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2020-07-31 09:17:53 +0300 |
commit | 812931d693da58cc24d2bb8dec01c2b4a7f4668f (patch) | |
tree | 2e95f34172c407d94ca5a097eae30852c01551cc /fs/init.c | |
parent | eb9d7d390e51108b4c6a9a7993ed9be92548c8f7 (diff) | |
download | linux-812931d693da58cc24d2bb8dec01c2b4a7f4668f.tar.xz |
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: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/init.c')
-rw-r--r-- | fs/init.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/fs/init.c b/fs/init.c index 6d9af40d2897..5db9d9f74868 100644 --- a/fs/init.c +++ b/fs/init.c @@ -122,6 +122,39 @@ int __init init_eaccess(const char *filename) 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) { return do_unlinkat(AT_FDCWD, getname_kernel(pathname)); |