From 9a08c352d05305ca7651540c3b107da1e4e1f40b Mon Sep 17 00:00:00 2001 From: James Bottomley Date: Wed, 17 Feb 2016 16:49:38 -0800 Subject: fs: add filp_clone_open API I need an API that allows me to obtain a clone of the current file pointer to pass in to an exec handler. I've labelled this as an internal API because I can't see how it would be useful outside of the fs subsystem. The use case will be a persistent binfmt_misc handler. Signed-off-by: James Bottomley Acked-by: Serge Hallyn Acked-by: Jan Kara --- fs/open.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'fs/open.c') diff --git a/fs/open.c b/fs/open.c index 17cb6b1dab75..bfe6f2b8345f 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1002,6 +1002,26 @@ struct file *file_open_root(struct dentry *dentry, struct vfsmount *mnt, } EXPORT_SYMBOL(file_open_root); +struct file *filp_clone_open(struct file *oldfile) +{ + struct file *file; + int retval; + + file = get_empty_filp(); + if (IS_ERR(file)) + return file; + + file->f_flags = oldfile->f_flags; + retval = vfs_open(&oldfile->f_path, file, oldfile->f_cred); + if (retval) { + put_filp(file); + return ERR_PTR(retval); + } + + return file; +} +EXPORT_SYMBOL(filp_clone_open); + long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode) { struct open_flags op; -- cgit v1.2.3-59-g8ed1b