file.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Wrapper functions for accessing the file_struct fd array.
  3. */
  4. #ifndef __LINUX_FILE_H
  5. #define __LINUX_FILE_H
  6. #include <linux/compiler.h>
  7. #include <linux/types.h>
  8. #include <linux/posix_types.h>
  9. struct file;
  10. extern void fput(struct file *);
  11. struct file_operations;
  12. struct vfsmount;
  13. struct dentry;
  14. struct path;
  15. extern struct file *alloc_file(struct path *, fmode_t mode,
  16. const struct file_operations *fop);
  17. static inline void fput_light(struct file *file, int fput_needed)
  18. {
  19. if (fput_needed)
  20. fput(file);
  21. }
  22. struct fd {
  23. struct file *file;
  24. unsigned int flags;
  25. };
  26. #define FDPUT_FPUT 1
  27. #define FDPUT_POS_UNLOCK 2
  28. static inline void fdput(struct fd fd)
  29. {
  30. if (fd.flags & FDPUT_FPUT)
  31. fput(fd.file);
  32. }
  33. extern struct file *fget(unsigned int fd);
  34. extern struct file *fget_raw(unsigned int fd);
  35. extern unsigned long __fdget(unsigned int fd);
  36. extern unsigned long __fdget_raw(unsigned int fd);
  37. extern unsigned long __fdget_pos(unsigned int fd);
  38. extern void __f_unlock_pos(struct file *);
  39. static inline struct fd __to_fd(unsigned long v)
  40. {
  41. return (struct fd){(struct file *)(v & ~3),v & 3};
  42. }
  43. static inline struct fd fdget(unsigned int fd)
  44. {
  45. return __to_fd(__fdget(fd));
  46. }
  47. static inline struct fd fdget_raw(unsigned int fd)
  48. {
  49. return __to_fd(__fdget_raw(fd));
  50. }
  51. static inline struct fd fdget_pos(int fd)
  52. {
  53. return __to_fd(__fdget_pos(fd));
  54. }
  55. static inline void fdput_pos(struct fd f)
  56. {
  57. if (f.flags & FDPUT_POS_UNLOCK)
  58. __f_unlock_pos(f.file);
  59. fdput(f);
  60. }
  61. extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
  62. extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
  63. extern void set_close_on_exec(unsigned int fd, int flag);
  64. extern bool get_close_on_exec(unsigned int fd);
  65. extern void put_filp(struct file *);
  66. extern int get_unused_fd_flags(unsigned flags);
  67. extern void put_unused_fd(unsigned int fd);
  68. extern void fd_install(unsigned int fd, struct file *file);
  69. extern void flush_delayed_fput(void);
  70. extern void __fput_sync(struct file *);
  71. #endif /* __LINUX_FILE_H */