| [2] | 1 | /* |
|---|
| 2 | * Wrapper functions for accessing the file_struct fd array. |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | #ifndef __LINUX_FILE_H |
|---|
| 6 | #define __LINUX_FILE_H |
|---|
| 7 | |
|---|
| 8 | #include <asm/atomic.h> |
|---|
| 9 | #include <linux/posix_types.h> |
|---|
| 10 | |
|---|
| 11 | /* |
|---|
| 12 | * The default fd array needs to be at least BITS_PER_LONG, |
|---|
| 13 | * as this is the granularity returned by copy_fdset(). |
|---|
| 14 | */ |
|---|
| 15 | #define NR_OPEN_DEFAULT BITS_PER_LONG |
|---|
| 16 | |
|---|
| 17 | /* |
|---|
| 18 | * Open file table structure |
|---|
| 19 | */ |
|---|
| 20 | struct files_struct { |
|---|
| 21 | atomic_t count; |
|---|
| 22 | spinlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */ |
|---|
| 23 | int max_fds; |
|---|
| 24 | int max_fdset; |
|---|
| 25 | int next_fd; |
|---|
| 26 | struct file ** fd; /* current fd array */ |
|---|
| 27 | fd_set *close_on_exec; |
|---|
| 28 | fd_set *open_fds; |
|---|
| 29 | fd_set close_on_exec_init; |
|---|
| 30 | fd_set open_fds_init; |
|---|
| 31 | struct file * fd_array[NR_OPEN_DEFAULT]; |
|---|
| 32 | }; |
|---|
| 33 | |
|---|
| 34 | extern void FASTCALL(__fput(struct file *)); |
|---|
| 35 | extern void FASTCALL(fput(struct file *)); |
|---|
| 36 | |
|---|
| 37 | static inline void fput_light(struct file *file, int fput_needed) |
|---|
| 38 | { |
|---|
| 39 | if (unlikely(fput_needed)) |
|---|
| 40 | fput(file); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | extern struct file * FASTCALL(fget(unsigned int fd)); |
|---|
| 44 | extern struct file * FASTCALL(fget_light(unsigned int fd, int *fput_needed)); |
|---|
| 45 | extern void FASTCALL(set_close_on_exec(unsigned int fd, int flag)); |
|---|
| 46 | extern void put_filp(struct file *); |
|---|
| 47 | extern int get_unused_fd(void); |
|---|
| 48 | extern void FASTCALL(put_unused_fd(unsigned int fd)); |
|---|
| 49 | struct kmem_cache_s; |
|---|
| 50 | extern void filp_ctor(void * objp, struct kmem_cache_s *cachep, unsigned long cflags); |
|---|
| 51 | extern void filp_dtor(void * objp, struct kmem_cache_s *cachep, unsigned long dflags); |
|---|
| 52 | |
|---|
| 53 | extern struct file ** alloc_fd_array(int); |
|---|
| 54 | extern void free_fd_array(struct file **, int); |
|---|
| 55 | |
|---|
| 56 | extern fd_set *alloc_fdset(int); |
|---|
| 57 | extern void free_fdset(fd_set *, int); |
|---|
| 58 | |
|---|
| 59 | extern int expand_files(struct files_struct *, int nr); |
|---|
| 60 | |
|---|
| 61 | static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd) |
|---|
| 62 | { |
|---|
| 63 | struct file * file = NULL; |
|---|
| 64 | |
|---|
| 65 | if (fd < files->max_fds) |
|---|
| 66 | file = files->fd[fd]; |
|---|
| 67 | return file; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | /* |
|---|
| 71 | * Check whether the specified fd has an open file. |
|---|
| 72 | */ |
|---|
| 73 | #define fcheck(fd) fcheck_files(current->files, fd) |
|---|
| 74 | |
|---|
| 75 | extern void FASTCALL(fd_install(unsigned int fd, struct file * file)); |
|---|
| 76 | |
|---|
| 77 | struct task_struct; |
|---|
| 78 | |
|---|
| 79 | struct files_struct *get_files_struct(struct task_struct *); |
|---|
| 80 | void FASTCALL(put_files_struct(struct files_struct *fs)); |
|---|
| 81 | |
|---|
| 82 | #endif /* __LINUX_FILE_H */ |
|---|