mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
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>
This commit is contained in:
parent
eb9d7d390e
commit
812931d693
6 changed files with 38 additions and 14 deletions
33
fs/init.c
33
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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue