fcntl.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _ASM_GENERIC_FCNTL_H
  3. #define _ASM_GENERIC_FCNTL_H
  4. #include <linux/types.h>
  5. /*
  6. * FMODE_EXEC is 0x20
  7. * FMODE_NONOTIFY is 0x4000000
  8. * These cannot be used by userspace O_* until internal and external open
  9. * flags are split.
  10. * -Eric Paris
  11. */
  12. /*
  13. * When introducing new O_* bits, please check its uniqueness in fcntl_init().
  14. */
  15. #define O_ACCMODE 00000003
  16. #define O_RDONLY 00000000
  17. #define O_WRONLY 00000001
  18. #define O_RDWR 00000002
  19. #ifndef O_CREAT
  20. #define O_CREAT 00000100 /* not fcntl */
  21. #endif
  22. #ifndef O_EXCL
  23. #define O_EXCL 00000200 /* not fcntl */
  24. #endif
  25. #ifndef O_NOCTTY
  26. #define O_NOCTTY 00000400 /* not fcntl */
  27. #endif
  28. #ifndef O_TRUNC
  29. #define O_TRUNC 00001000 /* not fcntl */
  30. #endif
  31. #ifndef O_APPEND
  32. #define O_APPEND 00002000
  33. #endif
  34. #ifndef O_NONBLOCK
  35. #define O_NONBLOCK 00004000
  36. #endif
  37. #ifndef O_DSYNC
  38. #define O_DSYNC 00010000 /* used to be O_SYNC, see below */
  39. #endif
  40. #ifndef FASYNC
  41. #define FASYNC 00020000 /* fcntl, for BSD compatibility */
  42. #endif
  43. #ifndef O_DIRECT
  44. #define O_DIRECT 00040000 /* direct disk access hint */
  45. #endif
  46. #ifndef O_LARGEFILE
  47. #define O_LARGEFILE 00100000
  48. #endif
  49. #ifndef O_DIRECTORY
  50. #define O_DIRECTORY 00200000 /* must be a directory */
  51. #endif
  52. #ifndef O_NOFOLLOW
  53. #define O_NOFOLLOW 00400000 /* don't follow links */
  54. #endif
  55. #ifndef O_NOATIME
  56. #define O_NOATIME 01000000
  57. #endif
  58. #ifndef O_CLOEXEC
  59. #define O_CLOEXEC 02000000 /* set close_on_exec */
  60. #endif
  61. /*
  62. * Before Linux 2.6.33 only O_DSYNC semantics were implemented, but using
  63. * the O_SYNC flag. We continue to use the existing numerical value
  64. * for O_DSYNC semantics now, but using the correct symbolic name for it.
  65. * This new value is used to request true Posix O_SYNC semantics. It is
  66. * defined in this strange way to make sure applications compiled against
  67. * new headers get at least O_DSYNC semantics on older kernels.
  68. *
  69. * This has the nice side-effect that we can simply test for O_DSYNC
  70. * wherever we do not care if O_DSYNC or O_SYNC is used.
  71. *
  72. * Note: __O_SYNC must never be used directly.
  73. */
  74. #ifndef O_SYNC
  75. #define __O_SYNC 04000000
  76. #define O_SYNC (__O_SYNC|O_DSYNC)
  77. #endif
  78. #ifndef O_PATH
  79. #define O_PATH 010000000
  80. #endif
  81. #ifndef __O_TMPFILE
  82. #define __O_TMPFILE 020000000
  83. #endif
  84. /* a horrid kludge trying to make sure that this will fail on old kernels */
  85. #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
  86. #ifndef O_NDELAY
  87. #define O_NDELAY O_NONBLOCK
  88. #endif
  89. #define F_DUPFD 0 /* dup */
  90. #define F_GETFD 1 /* get close_on_exec */
  91. #define F_SETFD 2 /* set/clear close_on_exec */
  92. #define F_GETFL 3 /* get file->f_flags */
  93. #define F_SETFL 4 /* set file->f_flags */
  94. #ifndef F_GETLK
  95. #define F_GETLK 5
  96. #define F_SETLK 6
  97. #define F_SETLKW 7
  98. #endif
  99. #ifndef F_SETOWN
  100. #define F_SETOWN 8 /* for sockets. */
  101. #define F_GETOWN 9 /* for sockets. */
  102. #endif
  103. #ifndef F_SETSIG
  104. #define F_SETSIG 10 /* for sockets. */
  105. #define F_GETSIG 11 /* for sockets. */
  106. #endif
  107. #if __BITS_PER_LONG == 32 || defined(__KERNEL__)
  108. #ifndef F_GETLK64
  109. #define F_GETLK64 12 /* using 'struct flock64' */
  110. #define F_SETLK64 13
  111. #define F_SETLKW64 14
  112. #endif
  113. #endif /* __BITS_PER_LONG == 32 || defined(__KERNEL__) */
  114. #ifndef F_SETOWN_EX
  115. #define F_SETOWN_EX 15
  116. #define F_GETOWN_EX 16
  117. #endif
  118. #ifndef F_GETOWNER_UIDS
  119. #define F_GETOWNER_UIDS 17
  120. #endif
  121. /*
  122. * Open File Description Locks
  123. *
  124. * Usually record locks held by a process are released on *any* close and are
  125. * not inherited across a fork().
  126. *
  127. * These cmd values will set locks that conflict with process-associated
  128. * record locks, but are "owned" by the open file description, not the
  129. * process. This means that they are inherited across fork() like BSD (flock)
  130. * locks, and they are only released automatically when the last reference to
  131. * the the open file against which they were acquired is put.
  132. */
  133. #define F_OFD_GETLK 36
  134. #define F_OFD_SETLK 37
  135. #define F_OFD_SETLKW 38
  136. #define F_OWNER_TID 0
  137. #define F_OWNER_PID 1
  138. #define F_OWNER_PGRP 2
  139. struct f_owner_ex {
  140. int type;
  141. __kernel_pid_t pid;
  142. };
  143. /* for F_[GET|SET]FL */
  144. #define FD_CLOEXEC 1 /* actually anything with low bit set goes */
  145. /* for posix fcntl() and lockf() */
  146. #ifndef F_RDLCK
  147. #define F_RDLCK 0
  148. #define F_WRLCK 1
  149. #define F_UNLCK 2
  150. #endif
  151. /* for old implementation of bsd flock () */
  152. #ifndef F_EXLCK
  153. #define F_EXLCK 4 /* or 3 */
  154. #define F_SHLCK 8 /* or 4 */
  155. #endif
  156. /* operations for bsd flock(), also used by the kernel implementation */
  157. #define LOCK_SH 1 /* shared lock */
  158. #define LOCK_EX 2 /* exclusive lock */
  159. #define LOCK_NB 4 /* or'd with one of the above to prevent
  160. blocking */
  161. #define LOCK_UN 8 /* remove lock */
  162. /*
  163. * LOCK_MAND support has been removed from the kernel. We leave the symbols
  164. * here to not break legacy builds, but these should not be used in new code.
  165. */
  166. #define LOCK_MAND 32 /* This is a mandatory flock ... */
  167. #define LOCK_READ 64 /* which allows concurrent read operations */
  168. #define LOCK_WRITE 128 /* which allows concurrent write operations */
  169. #define LOCK_RW 192 /* which allows concurrent read & write ops */
  170. #define F_LINUX_SPECIFIC_BASE 1024
  171. #ifndef HAVE_ARCH_STRUCT_FLOCK
  172. struct flock {
  173. short l_type;
  174. short l_whence;
  175. __kernel_off_t l_start;
  176. __kernel_off_t l_len;
  177. __kernel_pid_t l_pid;
  178. #ifdef __ARCH_FLOCK_EXTRA_SYSID
  179. __ARCH_FLOCK_EXTRA_SYSID
  180. #endif
  181. #ifdef __ARCH_FLOCK_PAD
  182. __ARCH_FLOCK_PAD
  183. #endif
  184. };
  185. struct flock64 {
  186. short l_type;
  187. short l_whence;
  188. __kernel_loff_t l_start;
  189. __kernel_loff_t l_len;
  190. __kernel_pid_t l_pid;
  191. #ifdef __ARCH_FLOCK64_PAD
  192. __ARCH_FLOCK64_PAD
  193. #endif
  194. };
  195. #endif /* HAVE_ARCH_STRUCT_FLOCK */
  196. #endif /* _ASM_GENERIC_FCNTL_H */