fcntl.h 5.3 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. #define O_TMPFILE_MASK (__O_TMPFILE | O_DIRECTORY | O_CREAT)
  87. #ifndef O_NDELAY
  88. #define O_NDELAY O_NONBLOCK
  89. #endif
  90. #define F_DUPFD 0 /* dup */
  91. #define F_GETFD 1 /* get close_on_exec */
  92. #define F_SETFD 2 /* set/clear close_on_exec */
  93. #define F_GETFL 3 /* get file->f_flags */
  94. #define F_SETFL 4 /* set file->f_flags */
  95. #ifndef F_GETLK
  96. #define F_GETLK 5
  97. #define F_SETLK 6
  98. #define F_SETLKW 7
  99. #endif
  100. #ifndef F_SETOWN
  101. #define F_SETOWN 8 /* for sockets. */
  102. #define F_GETOWN 9 /* for sockets. */
  103. #endif
  104. #ifndef F_SETSIG
  105. #define F_SETSIG 10 /* for sockets. */
  106. #define F_GETSIG 11 /* for sockets. */
  107. #endif
  108. #ifndef CONFIG_64BIT
  109. #ifndef F_GETLK64
  110. #define F_GETLK64 12 /* using 'struct flock64' */
  111. #define F_SETLK64 13
  112. #define F_SETLKW64 14
  113. #endif
  114. #endif
  115. #ifndef F_SETOWN_EX
  116. #define F_SETOWN_EX 15
  117. #define F_GETOWN_EX 16
  118. #endif
  119. #ifndef F_GETOWNER_UIDS
  120. #define F_GETOWNER_UIDS 17
  121. #endif
  122. /*
  123. * Open File Description Locks
  124. *
  125. * Usually record locks held by a process are released on *any* close and are
  126. * not inherited across a fork().
  127. *
  128. * These cmd values will set locks that conflict with process-associated
  129. * record locks, but are "owned" by the open file description, not the
  130. * process. This means that they are inherited across fork() like BSD (flock)
  131. * locks, and they are only released automatically when the last reference to
  132. * the the open file against which they were acquired is put.
  133. */
  134. #define F_OFD_GETLK 36
  135. #define F_OFD_SETLK 37
  136. #define F_OFD_SETLKW 38
  137. #define F_OWNER_TID 0
  138. #define F_OWNER_PID 1
  139. #define F_OWNER_PGRP 2
  140. struct f_owner_ex {
  141. int type;
  142. __kernel_pid_t pid;
  143. };
  144. /* for F_[GET|SET]FL */
  145. #define FD_CLOEXEC 1 /* actually anything with low bit set goes */
  146. /* for posix fcntl() and lockf() */
  147. #ifndef F_RDLCK
  148. #define F_RDLCK 0
  149. #define F_WRLCK 1
  150. #define F_UNLCK 2
  151. #endif
  152. /* for old implementation of bsd flock () */
  153. #ifndef F_EXLCK
  154. #define F_EXLCK 4 /* or 3 */
  155. #define F_SHLCK 8 /* or 4 */
  156. #endif
  157. /* operations for bsd flock(), also used by the kernel implementation */
  158. #define LOCK_SH 1 /* shared lock */
  159. #define LOCK_EX 2 /* exclusive lock */
  160. #define LOCK_NB 4 /* or'd with one of the above to prevent
  161. blocking */
  162. #define LOCK_UN 8 /* remove lock */
  163. #define LOCK_MAND 32 /* This is a mandatory flock ... */
  164. #define LOCK_READ 64 /* which allows concurrent read operations */
  165. #define LOCK_WRITE 128 /* which allows concurrent write operations */
  166. #define LOCK_RW 192 /* which allows concurrent read & write ops */
  167. #define F_LINUX_SPECIFIC_BASE 1024
  168. #ifndef HAVE_ARCH_STRUCT_FLOCK
  169. #ifndef __ARCH_FLOCK_PAD
  170. #define __ARCH_FLOCK_PAD
  171. #endif
  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. __ARCH_FLOCK_PAD
  179. };
  180. #endif
  181. #ifndef HAVE_ARCH_STRUCT_FLOCK64
  182. #ifndef __ARCH_FLOCK64_PAD
  183. #define __ARCH_FLOCK64_PAD
  184. #endif
  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. __ARCH_FLOCK64_PAD
  192. };
  193. #endif
  194. #endif /* _ASM_GENERIC_FCNTL_H */