Blame view
include/linux/fdtable.h
3 KB
9f3acc314
|
1 2 3 4 5 6 |
/* * descriptor table internals; you almost certainly want file.h instead. */ #ifndef __LINUX_FDTABLE_H #define __LINUX_FDTABLE_H |
9f3acc314
|
7 8 9 10 11 |
#include <linux/posix_types.h> #include <linux/compiler.h> #include <linux/spinlock.h> #include <linux/rcupdate.h> #include <linux/types.h> |
21e544592
|
12 |
#include <linux/init.h> |
2c666df80
|
13 |
#include <linux/fs.h> |
21e544592
|
14 |
|
60063497a
|
15 |
#include <linux/atomic.h> |
9f3acc314
|
16 17 18 19 20 21 |
/* * The default fd array needs to be at least BITS_PER_LONG, * as this is the granularity returned by copy_fdset(). */ #define NR_OPEN_DEFAULT BITS_PER_LONG |
9f3acc314
|
22 23 |
struct fdtable { unsigned int max_fds; |
4d2deb40b
|
24 |
struct file __rcu **fd; /* current fd array */ |
1fd36adcd
|
25 26 |
unsigned long *close_on_exec; unsigned long *open_fds; |
9f3acc314
|
27 |
struct rcu_head rcu; |
9f3acc314
|
28 |
}; |
1dce27c5a
|
29 30 |
static inline bool close_on_exec(int fd, const struct fdtable *fdt) { |
1fd36adcd
|
31 |
return test_bit(fd, fdt->close_on_exec); |
1dce27c5a
|
32 |
} |
1dce27c5a
|
33 34 |
static inline bool fd_is_open(int fd, const struct fdtable *fdt) { |
1fd36adcd
|
35 |
return test_bit(fd, fdt->open_fds); |
1dce27c5a
|
36 |
} |
9f3acc314
|
37 38 39 40 41 42 43 44 |
/* * Open file table structure */ struct files_struct { /* * read mostly part */ atomic_t count; |
4d2deb40b
|
45 |
struct fdtable __rcu *fdt; |
9f3acc314
|
46 47 48 49 50 51 |
struct fdtable fdtab; /* * written part on a separate cache line in SMP */ spinlock_t file_lock ____cacheline_aligned_in_smp; int next_fd; |
1fd36adcd
|
52 53 |
unsigned long close_on_exec_init[1]; unsigned long open_fds_init[1]; |
4d2deb40b
|
54 |
struct file __rcu * fd_array[NR_OPEN_DEFAULT]; |
9f3acc314
|
55 |
}; |
9f3acc314
|
56 57 58 |
struct file_operations; struct vfsmount; struct dentry; |
a8d4b8345
|
59 60 61 62 63 64 65 66 67 68 |
#define rcu_dereference_check_fdtable(files, fdtfd) \ rcu_dereference_check((fdtfd), lockdep_is_held(&(files)->file_lock)) #define files_fdtable(files) \ rcu_dereference_check_fdtable((files), (files)->fdt) /* * The caller must ensure that fd table isn't shared or hold rcu or file lock */ static inline struct file *__fcheck_files(struct files_struct *files, unsigned int fd) |
9f3acc314
|
69 |
{ |
a8d4b8345
|
70 |
struct fdtable *fdt = rcu_dereference_raw(files->fdt); |
9f3acc314
|
71 72 |
if (fd < fdt->max_fds) |
a8d4b8345
|
73 74 75 76 77 78 79 80 81 82 |
return rcu_dereference_raw(fdt->fd[fd]); return NULL; } static inline struct file *fcheck_files(struct files_struct *files, unsigned int fd) { rcu_lockdep_assert(rcu_read_lock_held() || lockdep_is_held(&files->file_lock), "suspicious rcu_dereference_check() usage"); return __fcheck_files(files, fd); |
9f3acc314
|
83 84 85 86 87 88 89 90 91 92 93 94 95 |
} /* * Check whether the specified fd has an open file. */ #define fcheck(fd) fcheck_files(current->files, fd) struct task_struct; struct files_struct *get_files_struct(struct task_struct *); void put_files_struct(struct files_struct *fs); void reset_files_struct(struct files_struct *); int unshare_files(struct files_struct **); |
02afc6267
|
96 |
struct files_struct *dup_fd(struct files_struct *, int *); |
6a6d27de3
|
97 |
void do_close_on_exec(struct files_struct *); |
c3c073f80
|
98 99 100 |
int iterate_fd(struct files_struct *, unsigned, int (*)(const void *, struct file *, unsigned), const void *); |
9f3acc314
|
101 |
|
dcfadfa4e
|
102 103 |
extern int __alloc_fd(struct files_struct *files, unsigned start, unsigned end, unsigned flags); |
f869e8a7f
|
104 105 |
extern void __fd_install(struct files_struct *files, unsigned int fd, struct file *file); |
483ce1d4b
|
106 107 |
extern int __close_fd(struct files_struct *files, unsigned int fd); |
dcfadfa4e
|
108 |
|
9f3acc314
|
109 110 111 |
extern struct kmem_cache *files_cachep; #endif /* __LINUX_FDTABLE_H */ |