file.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 inode;
  16. struct path;
  17. extern struct file *alloc_file_pseudo(struct inode *, struct vfsmount *,
  18. const char *, int flags, const struct file_operations *);
  19. extern struct file *alloc_file_clone(struct file *, int flags,
  20. const struct file_operations *);
  21. static inline void fput_light(struct file *file, int fput_needed)
  22. {
  23. if (fput_needed)
  24. fput(file);
  25. }
  26. struct fd {
  27. struct file *file;
  28. unsigned int flags;
  29. };
  30. #define FDPUT_FPUT 1
  31. #define FDPUT_POS_UNLOCK 2
  32. static inline void fdput(struct fd fd)
  33. {
  34. if (fd.flags & FDPUT_FPUT)
  35. fput(fd.file);
  36. }
  37. extern struct file *fget(unsigned int fd);
  38. extern struct file *fget_raw(unsigned int fd);
  39. extern unsigned long __fdget(unsigned int fd);
  40. extern unsigned long __fdget_raw(unsigned int fd);
  41. extern unsigned long __fdget_pos(unsigned int fd);
  42. extern void __f_unlock_pos(struct file *);
  43. static inline struct fd __to_fd(unsigned long v)
  44. {
  45. return (struct fd){(struct file *)(v & ~3),v & 3};
  46. }
  47. static inline struct fd fdget(unsigned int fd)
  48. {
  49. return __to_fd(__fdget(fd));
  50. }
  51. static inline struct fd fdget_raw(unsigned int fd)
  52. {
  53. return __to_fd(__fdget_raw(fd));
  54. }
  55. static inline struct fd fdget_pos(int fd)
  56. {
  57. return __to_fd(__fdget_pos(fd));
  58. }
  59. static inline void fdput_pos(struct fd f)
  60. {
  61. if (f.flags & FDPUT_POS_UNLOCK)
  62. __f_unlock_pos(f.file);
  63. fdput(f);
  64. }
  65. extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
  66. extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
  67. extern void set_close_on_exec(unsigned int fd, int flag);
  68. extern bool get_close_on_exec(unsigned int fd);
  69. extern int get_unused_fd_flags(unsigned flags);
  70. extern void put_unused_fd(unsigned int fd);
  71. extern void fd_install(unsigned int fd, struct file *file);
  72. extern void flush_delayed_fput(void);
  73. extern void __fput_sync(struct file *);
  74. #endif /* __LINUX_FILE_H */