History

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.

Christoph Hellwig committed 6 years ago

Commit 812931d1 parent eb9d7d36 files · +38 −14Browse files

Unified · Split

6 files
  1. fs/init.c +33 −0
  2. fs/internal.h +1 −2
  3. fs/namei.c +2 −2
  4. include/linux/init_syscalls.h +1 −0
  5. include/linux/syscalls.h +0 −9
  6. init/initramfs.c +1 −1
fs/init.c+33−0
@@ -122,6 +122,39 @@ int __init init_eaccess(const char *filename) · 121 unmodified lines
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+1−2
@@ -69,8 +69,7 @@ long do_rmdir(int dfd, struct filename *name); · 68 unmodified lines
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+2−2
@@ -1024,7 +1024,7 @@ static bool safe_hardlink_source(struct inode *inode) · 1023 unmodified lines
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); · 3055 unmodified lines
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+1−0
@@ -8,5 +8,6 @@ int __init init_chroot(const char *filename); · 7 unmodified lines
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+0−9
@@ -1295,15 +1295,6 @@ static inline long ksys_mknod(const char __user *filename, umode_t mode, · 1294 unmodified lines
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+1−1
@@ -312,7 +312,7 @@ static int __init maybe_link(void) · 311 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t