Skip to content

Commit 9a08c35

Browse files
James BottomleyJames Bottomley
authored andcommitted
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 <James.Bottomley@HansenPartnership.com> Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Acked-by: Jan Kara <jack@suse.cz>
1 parent f55532a commit 9a08c35

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

fs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ extern long do_handle_open(int mountdirfd,
108108
struct file_handle __user *ufh, int open_flag);
109109
extern int open_check_o_direct(struct file *f);
110110
extern int vfs_open(const struct path *, struct file *, const struct cred *);
111+
extern struct file *filp_clone_open(struct file *);
111112

112113
/*
113114
* inode.c

fs/open.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,26 @@ struct file *file_open_root(struct dentry *dentry, struct vfsmount *mnt,
10021002
}
10031003
EXPORT_SYMBOL(file_open_root);
10041004

1005+
struct file *filp_clone_open(struct file *oldfile)
1006+
{
1007+
struct file *file;
1008+
int retval;
1009+
1010+
file = get_empty_filp();
1011+
if (IS_ERR(file))
1012+
return file;
1013+
1014+
file->f_flags = oldfile->f_flags;
1015+
retval = vfs_open(&oldfile->f_path, file, oldfile->f_cred);
1016+
if (retval) {
1017+
put_filp(file);
1018+
return ERR_PTR(retval);
1019+
}
1020+
1021+
return file;
1022+
}
1023+
EXPORT_SYMBOL(filp_clone_open);
1024+
10051025
long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
10061026
{
10071027
struct open_flags op;

0 commit comments

Comments
 (0)