Skip to content

Commit 812931d

Browse files
author
Christoph Hellwig
committed
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 <[email protected]>
1 parent eb9d7d3 commit 812931d

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

fs/init.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,39 @@ int __init init_eaccess(const char *filename)
122122
return error;
123123
}
124124

125+
int __init init_link(const char *oldname, const char *newname)
126+
{
127+
struct dentry *new_dentry;
128+
struct path old_path, new_path;
129+
int error;
130+
131+
error = kern_path(oldname, 0, &old_path);
132+
if (error)
133+
return error;
134+
135+
new_dentry = kern_path_create(AT_FDCWD, newname, &new_path, 0);
136+
error = PTR_ERR(new_dentry);
137+
if (IS_ERR(new_dentry))
138+
goto out;
139+
140+
error = -EXDEV;
141+
if (old_path.mnt != new_path.mnt)
142+
goto out_dput;
143+
error = may_linkat(&old_path);
144+
if (unlikely(error))
145+
goto out_dput;
146+
error = security_path_link(old_path.dentry, &new_path, new_dentry);
147+
if (error)
148+
goto out_dput;
149+
error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry,
150+
NULL);
151+
out_dput:
152+
done_path_create(&new_path, new_dentry);
153+
out:
154+
path_put(&old_path);
155+
return error;
156+
}
157+
125158
int __init init_unlink(const char *pathname)
126159
{
127160
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));

fs/internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ long do_rmdir(int dfd, struct filename *name);
6969
long do_unlinkat(int dfd, struct filename *name);
7070
long do_symlinkat(const char __user *oldname, int newdfd,
7171
const char __user *newname);
72-
int do_linkat(int olddfd, const char __user *oldname, int newdfd,
73-
const char __user *newname, int flags);
72+
int may_linkat(struct path *link);
7473

7574
/*
7675
* namespace.c

fs/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ static bool safe_hardlink_source(struct inode *inode)
10241024
*
10251025
* Returns 0 if successful, -ve on error.
10261026
*/
1027-
static int may_linkat(struct path *link)
1027+
int may_linkat(struct path *link)
10281028
{
10291029
struct inode *inode = link->dentry->d_inode;
10301030

@@ -4086,7 +4086,7 @@ EXPORT_SYMBOL(vfs_link);
40864086
* with linux 2.0, and to avoid hard-linking to directories
40874087
* and other special files. --ADM
40884088
*/
4089-
int do_linkat(int olddfd, const char __user *oldname, int newdfd,
4089+
static int do_linkat(int olddfd, const char __user *oldname, int newdfd,
40904090
const char __user *newname, int flags)
40914091
{
40924092
struct dentry *new_dentry;

include/linux/init_syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ int __init init_chroot(const char *filename);
88
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags);
99
int __init init_chmod(const char *filename, umode_t mode);
1010
int __init init_eaccess(const char *filename);
11+
int __init init_link(const char *oldname, const char *newname);
1112
int __init init_unlink(const char *pathname);
1213
int __init init_rmdir(const char *pathname);

include/linux/syscalls.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,15 +1295,6 @@ static inline long ksys_mknod(const char __user *filename, umode_t mode,
12951295
return do_mknodat(AT_FDCWD, filename, mode, dev);
12961296
}
12971297

1298-
extern int do_linkat(int olddfd, const char __user *oldname, int newdfd,
1299-
const char __user *newname, int flags);
1300-
1301-
static inline long ksys_link(const char __user *oldname,
1302-
const char __user *newname)
1303-
{
1304-
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
1305-
}
1306-
13071298
extern int do_fchownat(int dfd, const char __user *filename, uid_t user,
13081299
gid_t group, int flag);
13091300

init/initramfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static int __init maybe_link(void)
312312
char *old = find_link(major, minor, ino, mode, collected);
313313
if (old) {
314314
clean_path(collected, 0);
315-
return (ksys_link(old, collected) < 0) ? -1 : 1;
315+
return (init_link(old, collected) < 0) ? -1 : 1;
316316
}
317317
}
318318
return 0;

0 commit comments

Comments
 (0)