Skip to content

Commit

Permalink
fs: add filp_clone_open API
Browse files Browse the repository at this point in the history
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 <James.Bottomley@HansenPartnership.com>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Acked-by: Jan Kara <jack@suse.cz>
  • Loading branch information
James Bottomley authored and James Bottomley committed Mar 30, 2016
1 parent f55532a commit 9a08c35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions fs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ extern long do_handle_open(int mountdirfd,
struct file_handle __user *ufh, int open_flag);
extern int open_check_o_direct(struct file *f);
extern int vfs_open(const struct path *, struct file *, const struct cred *);
extern struct file *filp_clone_open(struct file *);

/*
* inode.c
Expand Down
20 changes: 20 additions & 0 deletions fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9a08c35

Please sign in to comment.