file.h 2.0 KB

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