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#include <linux/compiler.h> 11#include <linux/spinlock.h> 12 13/* 14 * The default fd array needs to be at least BITS_PER_LONG, 15 * as this is the granularity returned by copy_fdset(). 16 */ 17#define NR_OPEN_DEFAULT BITS_PER_LONG 18 19/* 20 * Open file table structure 21 */ 22struct files_struct { 23 atomic_t count; 24 rwlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */ 25 int max_fds; 26 int max_fdset; 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; 32 fd_set open_fds_init; 33 struct file * fd_array[NR_OPEN_DEFAULT]; 34}; 35 36extern void FASTCALL(__fput(struct file *)); 37extern void FASTCALL(fput(struct file *)); 38extern struct file * FASTCALL(fget(unsigned int fd)); 39extern void FASTCALL(set_close_on_exec(unsigned int fd, int flag)); 40extern void put_filp(struct file *); 41extern int get_unused_fd(void); 42extern void FASTCALL(put_unused_fd(unsigned int fd)); 43 44 45static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd) 46{ 47 struct file * file = NULL; 48 49 if (fd < files->max_fds) 50 file = files->fd[fd]; 51 return file; 52} 53 54/* 55 * Check whether the specified fd has an open file. 56 */ 57#define fcheck(fd) fcheck_files(current->files, fd) 58 59extern void FASTCALL(fd_install(unsigned int fd, struct file * file)); 60void FASTCALL(put_files_struct(struct files_struct *fs)); 61 62#endif /* __LINUX_FILE_H */ 63

