This introduces a function which can be used to fetch a file, given an arbitrary task. As long as the user holds a reference (refcnt) to the task_struct it is safe to call, and will either return NULL on failure, or a pointer to the file, with a refcnt. This patch is based on Oleg Nesterov's (cf. [1]) patch from September 2018. [1]: Link: https://lore.kernel.org/r/20180915160423.GA31461@redhat.com
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -16,6 +16,7 @@ extern void fput(struct file *); · 15 unmodified lines | ||
| 16 | 16 | extern void fput_many(struct file *, unsigned int); |
| 17 | 17 | |
| 18 | 18 | struct file_operations; |
| 19 | +struct task_struct; | |
| 19 | 20 | struct vfsmount; |
| 20 | 21 | struct dentry; |
| 21 | 22 | struct inode; |
| @@ -47,6 +48,7 @@ static inline void fdput(struct fd fd) · 25 unmodified lines | ||
| 47 | 48 | extern struct file *fget(unsigned int fd); |
| 48 | 49 | extern struct file *fget_many(unsigned int fd, unsigned int refs); |
| 49 | 50 | extern struct file *fget_raw(unsigned int fd); |
| 51 | +extern struct file *fget_task(struct task_struct *task, unsigned int fd); | |
| 50 | 52 | extern unsigned long __fdget(unsigned int fd); |
| 51 | 53 | extern unsigned long __fdget_raw(unsigned int fd); |
| 52 | 54 | extern unsigned long __fdget_pos(unsigned int fd); |