author: Christoph Hellwig <hch@lst.de> 2020-07-22 11:14:19 +0200
committer: Christoph Hellwig <hch@lst.de> 2020-07-31 08:17:53 +0200
commit: 812931d693da58cc24d2bb8dec01c2b4a7f4668f
parent: eb9d7d390e51108b4c6a9a7993ed9be92548c8f7
Commit Summary:
Diffstat:
1 file changed, 30 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));