Blame view
include/linux/file.h
3.01 KB
b24413180
|
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4c
|
2 3 4 5 6 7 |
/* * Wrapper functions for accessing the file_struct fd array. */ #ifndef __LINUX_FILE_H #define __LINUX_FILE_H |
1da177e4c
|
8 |
#include <linux/compiler.h> |
0c9e63fd3
|
9 |
#include <linux/types.h> |
9f3acc314
|
10 |
#include <linux/posix_types.h> |
deefa7f35
|
11 |
#include <linux/errno.h> |
1da177e4c
|
12 |
|
9f3acc314
|
13 |
struct file; |
8b7d91eb7
|
14 |
|
b3c975286
|
15 |
extern void fput(struct file *); |
091141a42
|
16 |
extern void fput_many(struct file *, unsigned int); |
1da177e4c
|
17 |
|
ce8d2cdf3
|
18 |
struct file_operations; |
5e876fb43
|
19 |
struct task_struct; |
ce8d2cdf3
|
20 21 |
struct vfsmount; struct dentry; |
d93aa9d82
|
22 |
struct inode; |
2c48b9c45
|
23 |
struct path; |
d93aa9d82
|
24 25 |
extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *, const char *, int flags, const struct file_operations *); |
183266f26
|
26 27 |
extern struct file *alloc_file_clone(struct file *, int flags, const struct file_operations *); |
ce8d2cdf3
|
28 |
|
1da177e4c
|
29 30 |
static inline void fput_light(struct file *file, int fput_needed) { |
c2b3e74b7
|
31 |
if (fput_needed) |
1da177e4c
|
32 33 |
fput(file); } |
a5b470ba0
|
34 35 |
struct fd { struct file *file; |
9c225f265
|
36 |
unsigned int flags; |
a5b470ba0
|
37 |
}; |
9c225f265
|
38 39 |
#define FDPUT_FPUT 1 #define FDPUT_POS_UNLOCK 2 |
a5b470ba0
|
40 41 42 |
static inline void fdput(struct fd fd) { |
9c225f265
|
43 |
if (fd.flags & FDPUT_FPUT) |
a5b470ba0
|
44 45 |
fput(fd.file); } |
b3c975286
|
46 |
extern struct file *fget(unsigned int fd); |
091141a42
|
47 |
extern struct file *fget_many(unsigned int fd, unsigned int refs); |
bd2a31d52
|
48 |
extern struct file *fget_raw(unsigned int fd); |
5e876fb43
|
49 |
extern struct file *fget_task(struct task_struct *task, unsigned int fd); |
bd2a31d52
|
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
|
53 |
extern void __f_unlock_pos(struct file *); |
a5b470ba0
|
54 |
|
bd2a31d52
|
55 |
static inline struct fd __to_fd(unsigned long v) |
a5b470ba0
|
56 |
{ |
bd2a31d52
|
57 |
return (struct fd){(struct file *)(v & ~3),v & 3}; |
a5b470ba0
|
58 |
} |
bd2a31d52
|
59 60 61 62 |
static inline struct fd fdget(unsigned int fd) { return __to_fd(__fdget(fd)); } |
2903ff019
|
63 |
|
a5b470ba0
|
64 65 |
static inline struct fd fdget_raw(unsigned int fd) { |
bd2a31d52
|
66 |
return __to_fd(__fdget_raw(fd)); |
a5b470ba0
|
67 |
} |
63b6df141
|
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
|
79 |
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); |
8280d1617
|
80 |
extern int replace_fd(unsigned fd, struct file *file, unsigned flags); |
b3c975286
|
81 |
extern void set_close_on_exec(unsigned int fd, int flag); |
fe17f22d7
|
82 |
extern bool get_close_on_exec(unsigned int fd); |
4022e7af8
|
83 |
extern int __get_unused_fd_flags(unsigned flags, unsigned long nofile); |
1a7bd2265
|
84 |
extern int get_unused_fd_flags(unsigned flags); |
b3c975286
|
85 |
extern void put_unused_fd(unsigned int fd); |
1da177e4c
|
86 |
|
b3c975286
|
87 |
extern void fd_install(unsigned int fd, struct file *file); |
1da177e4c
|
88 |
|
173817151
|
89 |
extern int __receive_fd(int fd, struct file *file, int __user *ufd, |
665906104
|
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
|
94 95 |
if (ufd == NULL) return -EFAULT; |
173817151
|
96 |
return __receive_fd(-1, file, ufd, o_flags); |
665906104
|
97 |
} |
deefa7f35
|
98 99 |
static inline int receive_fd(struct file *file, unsigned int o_flags) { |
173817151
|
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
|
105 |
} |
665906104
|
106 |
|
4a9d4b024
|
107 108 |
extern void flush_delayed_fput(void); extern void __fput_sync(struct file *); |
2374c09b1
|
109 |
extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max; |
1da177e4c
|
110 |
#endif /* __LINUX_FILE_H */ |