file.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. static inline struct fd __to_fd(unsigned long v)
  39. {
  40. return (struct fd){(struct file *)(v & ~3),v & 3};
  41. }
  42. static inline struct fd fdget(unsigned int fd)
  43. {
  44. return __to_fd(__fdget(fd));
  45. }
  46. static inline struct fd fdget_raw(unsigned int fd)
  47. {
  48. return __to_fd(__fdget_raw(fd));
  49. }
  50. extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
  51. extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
  52. extern void set_close_on_exec(unsigned int fd, int flag);
  53. extern bool get_close_on_exec(unsigned int fd);
  54. extern void put_filp(struct file *);
  55. extern int get_unused_fd_flags(unsigned flags);
  56. #define get_unused_fd() get_unused_fd_flags(0)
  57. extern void put_unused_fd(unsigned int fd);
  58. extern void fd_install(unsigned int fd, struct file *file);
  59. extern void flush_delayed_fput(void);
  60. extern void __fput_sync(struct file *);
  61. #endif /* __LINUX_FILE_H */