summaryrefslogtreecommitdiffstats
path: root/fs/init.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2020-07-28 17:49:47 +0200
committerAl Viro <viro@zeniv.linux.org.uk>2020-08-04 21:02:38 -0400
commitf073531070d24bbb82cb2658952d949f4851024b (patch)
tree064d6a4ec00df1fe854f6266e6e14432126ca2c8 /fs/init.c
parent235e57935bf328c4cce371ffc4dd1d8fab4885cd (diff)
downloadlinux-f073531070d24bbb82cb2658952d949f4851024b.tar.bz2
init: add an init_dup helper
Add a simple helper to grab a reference to a file and install it at the next available fd, and switch the early init code over to it. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/init.c')
-rw-r--r--fs/init.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/fs/init.c b/fs/init.c
index db5c48a85644..e9c320a48cf1 100644
--- a/fs/init.c
+++ b/fs/init.c
@@ -8,6 +8,7 @@
#include <linux/namei.h>
#include <linux/fs.h>
#include <linux/fs_struct.h>
+#include <linux/file.h>
#include <linux/init_syscalls.h>
#include <linux/security.h>
#include "internal.h"
@@ -251,3 +252,14 @@ int __init init_utimes(char *filename, struct timespec64 *ts)
path_put(&path);
return error;
}
+
+int __init init_dup(struct file *file)
+{
+ int fd;
+
+ fd = get_unused_fd_flags(0);
+ if (fd < 0)
+ return fd;
+ fd_install(fd, get_file(file));
+ return 0;
+}