2 * Wrapper functions for accessing the file_struct fd array.
8 #include <asm/atomic.h>
9 #include <linux/posix_types.h>
10 #include <linux/compiler.h>
11 #include <linux/spinlock.h>
14 * The default fd array needs to be at least BITS_PER_LONG,
15 * as this is the granularity returned by copy_fdset().
17 #define NR_OPEN_DEFAULT BITS_PER_LONG
23 struct file ** fd; /* current fd array */
24 fd_set *close_on_exec;
29 * Open file table structure
33 spinlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */
35 fd_set close_on_exec_init;
37 struct file * fd_array[NR_OPEN_DEFAULT];
40 #define files_fdtable(files) (&(files)->fdtab)
42 extern void FASTCALL(__fput(struct file *));
43 extern void FASTCALL(fput(struct file *));
45 static inline void fput_light(struct file *file, int fput_needed)
47 if (unlikely(fput_needed))
51 extern struct file * FASTCALL(fget(unsigned int fd));
52 extern struct file * FASTCALL(fget_light(unsigned int fd, int *fput_needed));
53 extern void FASTCALL(set_close_on_exec(unsigned int fd, int flag));
54 extern void put_filp(struct file *);
55 extern int get_unused_fd(void);
56 extern void FASTCALL(put_unused_fd(unsigned int fd));
58 extern void filp_ctor(void * objp, struct kmem_cache_s *cachep, unsigned long cflags);
59 extern void filp_dtor(void * objp, struct kmem_cache_s *cachep, unsigned long dflags);
61 extern struct file ** alloc_fd_array(int);
62 extern void free_fd_array(struct file **, int);
64 extern fd_set *alloc_fdset(int);
65 extern void free_fdset(fd_set *, int);
67 extern int expand_files(struct files_struct *, int nr);
69 static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
71 struct file * file = NULL;
72 struct fdtable *fdt = files_fdtable(files);
74 if (fd < fdt->max_fds)
80 * Check whether the specified fd has an open file.
82 #define fcheck(fd) fcheck_files(current->files, fd)
84 extern void FASTCALL(fd_install(unsigned int fd, struct file * file));
88 struct files_struct *get_files_struct(struct task_struct *);
89 void FASTCALL(put_files_struct(struct files_struct *fs));
91 #endif /* __LINUX_FILE_H */