diff options
Diffstat (limited to 'include/linux/file.h')
| -rw-r--r-- | include/linux/file.h | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/include/linux/file.h b/include/linux/file.h index 5206beb9a80e..f5bbd4c508b3 100644 --- a/include/linux/file.h +++ b/include/linux/file.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <linux/posix_types.h> | 9 | #include <linux/posix_types.h> |
| 10 | #include <linux/compiler.h> | 10 | #include <linux/compiler.h> |
| 11 | #include <linux/spinlock.h> | 11 | #include <linux/spinlock.h> |
| 12 | #include <linux/rcupdate.h> | ||
| 12 | 13 | ||
| 13 | /* | 14 | /* |
| 14 | * The default fd array needs to be at least BITS_PER_LONG, | 15 | * The default fd array needs to be at least BITS_PER_LONG, |
| @@ -16,23 +17,33 @@ | |||
| 16 | */ | 17 | */ |
| 17 | #define NR_OPEN_DEFAULT BITS_PER_LONG | 18 | #define NR_OPEN_DEFAULT BITS_PER_LONG |
| 18 | 19 | ||
| 20 | struct fdtable { | ||
| 21 | unsigned int max_fds; | ||
| 22 | int max_fdset; | ||
| 23 | int next_fd; | ||
| 24 | struct file ** fd; /* current fd array */ | ||
| 25 | fd_set *close_on_exec; | ||
| 26 | fd_set *open_fds; | ||
| 27 | struct rcu_head rcu; | ||
| 28 | struct files_struct *free_files; | ||
| 29 | struct fdtable *next; | ||
| 30 | }; | ||
| 31 | |||
| 19 | /* | 32 | /* |
| 20 | * Open file table structure | 33 | * Open file table structure |
| 21 | */ | 34 | */ |
| 22 | struct files_struct { | 35 | struct files_struct { |
| 23 | atomic_t count; | 36 | atomic_t count; |
| 24 | spinlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */ | 37 | spinlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */ |
| 25 | int max_fds; | 38 | struct fdtable *fdt; |
| 26 | int max_fdset; | 39 | struct fdtable fdtab; |
| 27 | int next_fd; | ||
| 28 | struct file ** fd; /* current fd array */ | ||
| 29 | fd_set *close_on_exec; | ||
| 30 | fd_set *open_fds; | ||
| 31 | fd_set close_on_exec_init; | 40 | fd_set close_on_exec_init; |
| 32 | fd_set open_fds_init; | 41 | fd_set open_fds_init; |
| 33 | struct file * fd_array[NR_OPEN_DEFAULT]; | 42 | struct file * fd_array[NR_OPEN_DEFAULT]; |
| 34 | }; | 43 | }; |
| 35 | 44 | ||
| 45 | #define files_fdtable(files) (rcu_dereference((files)->fdt)) | ||
| 46 | |||
| 36 | extern void FASTCALL(__fput(struct file *)); | 47 | extern void FASTCALL(__fput(struct file *)); |
| 37 | extern void FASTCALL(fput(struct file *)); | 48 | extern void FASTCALL(fput(struct file *)); |
| 38 | 49 | ||
| @@ -59,13 +70,16 @@ extern fd_set *alloc_fdset(int); | |||
| 59 | extern void free_fdset(fd_set *, int); | 70 | extern void free_fdset(fd_set *, int); |
| 60 | 71 | ||
| 61 | extern int expand_files(struct files_struct *, int nr); | 72 | extern int expand_files(struct files_struct *, int nr); |
| 73 | extern void free_fdtable(struct fdtable *fdt); | ||
| 74 | extern void __init files_defer_init(void); | ||
| 62 | 75 | ||
| 63 | static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd) | 76 | static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd) |
| 64 | { | 77 | { |
| 65 | struct file * file = NULL; | 78 | struct file * file = NULL; |
| 79 | struct fdtable *fdt = files_fdtable(files); | ||
| 66 | 80 | ||
| 67 | if (fd < files->max_fds) | 81 | if (fd < fdt->max_fds) |
| 68 | file = files->fd[fd]; | 82 | file = rcu_dereference(fdt->fd[fd]); |
| 69 | return file; | 83 | return file; |
| 70 | } | 84 | } |
| 71 | 85 | ||
