file.h 2.3 KB

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