Blame view

include/linux/file.h 3.01 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
  /*
   * Wrapper functions for accessing the file_struct fd array.
   */
  
  #ifndef __LINUX_FILE_H
  #define __LINUX_FILE_H
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
  #include <linux/compiler.h>
0c9e63fd3   Eric Dumazet   [PATCH] Shrinks s...
9
  #include <linux/types.h>
9f3acc314   Al Viro   [PATCH] split lin...
10
  #include <linux/posix_types.h>
deefa7f35   Kees Cook   fs: Add receive_f...
11
  #include <linux/errno.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12

9f3acc314   Al Viro   [PATCH] split lin...
13
  struct file;
8b7d91eb7   Christoph Lameter   [PATCH] Move file...
14

b3c975286   Harvey Harrison   include/linux: Re...
15
  extern void fput(struct file *);
091141a42   Jens Axboe   fs: add fget_many...
16
  extern void fput_many(struct file *, unsigned int);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17

ce8d2cdf3   Dave Hansen   r/o bind mounts: ...
18
  struct file_operations;
5e876fb43   Sargun Dhillon   vfs, fdtable: Add...
19
  struct task_struct;
ce8d2cdf3   Dave Hansen   r/o bind mounts: ...
20
21
  struct vfsmount;
  struct dentry;
d93aa9d82   Al Viro   new wrapper: allo...
22
  struct inode;
2c48b9c45   Al Viro   switch alloc_file...
23
  struct path;
d93aa9d82   Al Viro   new wrapper: allo...
24
25
  extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *,
  	const char *, int flags, const struct file_operations *);
183266f26   Al Viro   new helper: alloc...
26
27
  extern struct file *alloc_file_clone(struct file *, int flags,
  	const struct file_operations *);
ce8d2cdf3   Dave Hansen   r/o bind mounts: ...
28

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
  static inline void fput_light(struct file *file, int fput_needed)
  {
c2b3e74b7   Steven Rostedt   fs: Remove unlike...
31
  	if (fput_needed)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
  		fput(file);
  }
a5b470ba0   Al Viro   new helpers: fdge...
34
35
  struct fd {
  	struct file *file;
9c225f265   Linus Torvalds   vfs: atomic f_pos...
36
  	unsigned int flags;
a5b470ba0   Al Viro   new helpers: fdge...
37
  };
9c225f265   Linus Torvalds   vfs: atomic f_pos...
38
39
  #define FDPUT_FPUT       1
  #define FDPUT_POS_UNLOCK 2
a5b470ba0   Al Viro   new helpers: fdge...
40
41
42
  
  static inline void fdput(struct fd fd)
  {
9c225f265   Linus Torvalds   vfs: atomic f_pos...
43
  	if (fd.flags & FDPUT_FPUT)
a5b470ba0   Al Viro   new helpers: fdge...
44
45
  		fput(fd.file);
  }
b3c975286   Harvey Harrison   include/linux: Re...
46
  extern struct file *fget(unsigned int fd);
091141a42   Jens Axboe   fs: add fget_many...
47
  extern struct file *fget_many(unsigned int fd, unsigned int refs);
bd2a31d52   Al Viro   get rid of fget_l...
48
  extern struct file *fget_raw(unsigned int fd);
5e876fb43   Sargun Dhillon   vfs, fdtable: Add...
49
  extern struct file *fget_task(struct task_struct *task, unsigned int fd);
bd2a31d52   Al Viro   get rid of fget_l...
50
51
52
  extern unsigned long __fdget(unsigned int fd);
  extern unsigned long __fdget_raw(unsigned int fd);
  extern unsigned long __fdget_pos(unsigned int fd);
63b6df141   Al Viro   give readdir(2)/g...
53
  extern void __f_unlock_pos(struct file *);
a5b470ba0   Al Viro   new helpers: fdge...
54

bd2a31d52   Al Viro   get rid of fget_l...
55
  static inline struct fd __to_fd(unsigned long v)
a5b470ba0   Al Viro   new helpers: fdge...
56
  {
bd2a31d52   Al Viro   get rid of fget_l...
57
  	return (struct fd){(struct file *)(v & ~3),v & 3};
a5b470ba0   Al Viro   new helpers: fdge...
58
  }
bd2a31d52   Al Viro   get rid of fget_l...
59
60
61
62
  static inline struct fd fdget(unsigned int fd)
  {
  	return __to_fd(__fdget(fd));
  }
2903ff019   Al Viro   switch simple cas...
63

a5b470ba0   Al Viro   new helpers: fdge...
64
65
  static inline struct fd fdget_raw(unsigned int fd)
  {
bd2a31d52   Al Viro   get rid of fget_l...
66
  	return __to_fd(__fdget_raw(fd));
a5b470ba0   Al Viro   new helpers: fdge...
67
  }
63b6df141   Al Viro   give readdir(2)/g...
68
69
70
71
72
73
74
75
76
77
78
  static inline struct fd fdget_pos(int fd)
  {
  	return __to_fd(__fdget_pos(fd));
  }
  
  static inline void fdput_pos(struct fd f)
  {
  	if (f.flags & FDPUT_POS_UNLOCK)
  		__f_unlock_pos(f.file);
  	fdput(f);
  }
fe17f22d7   Al Viro   take purely descr...
79
  extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
8280d1617   Al Viro   new helper: repla...
80
  extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
b3c975286   Harvey Harrison   include/linux: Re...
81
  extern void set_close_on_exec(unsigned int fd, int flag);
fe17f22d7   Al Viro   take purely descr...
82
  extern bool get_close_on_exec(unsigned int fd);
4022e7af8   Jens Axboe   io_uring: make su...
83
  extern int __get_unused_fd_flags(unsigned flags, unsigned long nofile);
1a7bd2265   Al Viro   make get_unused_f...
84
  extern int get_unused_fd_flags(unsigned flags);
b3c975286   Harvey Harrison   include/linux: Re...
85
  extern void put_unused_fd(unsigned int fd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86

b3c975286   Harvey Harrison   include/linux: Re...
87
  extern void fd_install(unsigned int fd, struct file *file);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88

173817151   Kees Cook   fs: Expand __rece...
89
  extern int __receive_fd(int fd, struct file *file, int __user *ufd,
665906104   Kees Cook   fs: Move __scm_in...
90
91
92
93
  			unsigned int o_flags);
  static inline int receive_fd_user(struct file *file, int __user *ufd,
  				  unsigned int o_flags)
  {
deefa7f35   Kees Cook   fs: Add receive_f...
94
95
  	if (ufd == NULL)
  		return -EFAULT;
173817151   Kees Cook   fs: Expand __rece...
96
  	return __receive_fd(-1, file, ufd, o_flags);
665906104   Kees Cook   fs: Move __scm_in...
97
  }
deefa7f35   Kees Cook   fs: Add receive_f...
98
99
  static inline int receive_fd(struct file *file, unsigned int o_flags)
  {
173817151   Kees Cook   fs: Expand __rece...
100
101
102
103
104
  	return __receive_fd(-1, file, NULL, o_flags);
  }
  static inline int receive_fd_replace(int fd, struct file *file, unsigned int o_flags)
  {
  	return __receive_fd(fd, file, NULL, o_flags);
deefa7f35   Kees Cook   fs: Add receive_f...
105
  }
665906104   Kees Cook   fs: Move __scm_in...
106

4a9d4b024   Al Viro   switch fput to ta...
107
108
  extern void flush_delayed_fput(void);
  extern void __fput_sync(struct file *);
2374c09b1   Christoph Hellwig   sysctl: remove al...
109
  extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
  #endif /* __LINUX_FILE_H */