fcntl-linux.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /* O_*, F_*, FD_* bit values for Linux.
  2. Copyright (C) 2001-2021 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _FCNTL_H
  16. # error "Never use <bits/fcntl-linux.h> directly; include <fcntl.h> instead."
  17. #endif
  18. /* This file contains shared definitions between Linux architectures
  19. and is included by <bits/fcntl.h> to declare them. The various
  20. #ifndef cases allow the architecture specific file to define those
  21. values with different values.
  22. A minimal <bits/fcntl.h> contains just:
  23. struct flock {...}
  24. #ifdef __USE_LARGEFILE64
  25. struct flock64 {...}
  26. #endif
  27. #include <bits/fcntl-linux.h>
  28. */
  29. #ifdef __USE_GNU
  30. # include <bits/types/struct_iovec.h>
  31. #endif
  32. /* open/fcntl. */
  33. #define O_ACCMODE 0003
  34. #define O_RDONLY 00
  35. #define O_WRONLY 01
  36. #define O_RDWR 02
  37. #ifndef O_CREAT
  38. # define O_CREAT 0100 /* Not fcntl. */
  39. #endif
  40. #ifndef O_EXCL
  41. # define O_EXCL 0200 /* Not fcntl. */
  42. #endif
  43. #ifndef O_NOCTTY
  44. # define O_NOCTTY 0400 /* Not fcntl. */
  45. #endif
  46. #ifndef O_TRUNC
  47. # define O_TRUNC 01000 /* Not fcntl. */
  48. #endif
  49. #ifndef O_APPEND
  50. # define O_APPEND 02000
  51. #endif
  52. #ifndef O_NONBLOCK
  53. # define O_NONBLOCK 04000
  54. #endif
  55. #ifndef O_NDELAY
  56. # define O_NDELAY O_NONBLOCK
  57. #endif
  58. #ifndef O_SYNC
  59. # define O_SYNC 04010000
  60. #endif
  61. #define O_FSYNC O_SYNC
  62. #ifndef O_ASYNC
  63. # define O_ASYNC 020000
  64. #endif
  65. #ifndef __O_LARGEFILE
  66. # define __O_LARGEFILE 0100000
  67. #endif
  68. #ifndef __O_DIRECTORY
  69. # define __O_DIRECTORY 0200000
  70. #endif
  71. #ifndef __O_NOFOLLOW
  72. # define __O_NOFOLLOW 0400000
  73. #endif
  74. #ifndef __O_CLOEXEC
  75. # define __O_CLOEXEC 02000000
  76. #endif
  77. #ifndef __O_DIRECT
  78. # define __O_DIRECT 040000
  79. #endif
  80. #ifndef __O_NOATIME
  81. # define __O_NOATIME 01000000
  82. #endif
  83. #ifndef __O_PATH
  84. # define __O_PATH 010000000
  85. #endif
  86. #ifndef __O_DSYNC
  87. # define __O_DSYNC 010000
  88. #endif
  89. #ifndef __O_TMPFILE
  90. # define __O_TMPFILE (020000000 | __O_DIRECTORY)
  91. #endif
  92. #ifndef F_GETLK
  93. # ifndef __USE_FILE_OFFSET64
  94. # define F_GETLK 5 /* Get record locking info. */
  95. # define F_SETLK 6 /* Set record locking info (non-blocking). */
  96. # define F_SETLKW 7 /* Set record locking info (blocking). */
  97. # else
  98. # define F_GETLK F_GETLK64 /* Get record locking info. */
  99. # define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
  100. # define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
  101. # endif
  102. #endif
  103. #ifndef F_GETLK64
  104. # define F_GETLK64 12 /* Get record locking info. */
  105. # define F_SETLK64 13 /* Set record locking info (non-blocking). */
  106. # define F_SETLKW64 14 /* Set record locking info (blocking). */
  107. #endif
  108. /* open file description locks.
  109. Usually record locks held by a process are released on *any* close and are
  110. not inherited across a fork.
  111. These cmd values will set locks that conflict with process-associated record
  112. locks, but are "owned" by the opened file description, not the process.
  113. This means that they are inherited across fork or clone with CLONE_FILES
  114. like BSD (flock) locks, and they are only released automatically when the
  115. last reference to the the file description against which they were acquired
  116. is put. */
  117. #ifdef __USE_GNU
  118. # define F_OFD_GETLK 36
  119. # define F_OFD_SETLK 37
  120. # define F_OFD_SETLKW 38
  121. #endif
  122. #ifdef __USE_LARGEFILE64
  123. # define O_LARGEFILE __O_LARGEFILE
  124. #endif
  125. #ifdef __USE_XOPEN2K8
  126. # define O_DIRECTORY __O_DIRECTORY /* Must be a directory. */
  127. # define O_NOFOLLOW __O_NOFOLLOW /* Do not follow links. */
  128. # define O_CLOEXEC __O_CLOEXEC /* Set close_on_exec. */
  129. #endif
  130. #ifdef __USE_GNU
  131. # define O_DIRECT __O_DIRECT /* Direct disk access. */
  132. # define O_NOATIME __O_NOATIME /* Do not set atime. */
  133. # define O_PATH __O_PATH /* Resolve pathname but do not open file. */
  134. # define O_TMPFILE __O_TMPFILE /* Atomically create nameless file. */
  135. #endif
  136. /* For now, Linux has no separate synchronicity options for read
  137. operations. We define O_RSYNC therefore as the same as O_SYNC
  138. since this is a superset. */
  139. #if defined __USE_POSIX199309 || defined __USE_UNIX98
  140. # define O_DSYNC __O_DSYNC /* Synchronize data. */
  141. # if defined __O_RSYNC
  142. # define O_RSYNC __O_RSYNC /* Synchronize read operations. */
  143. # else
  144. # define O_RSYNC O_SYNC /* Synchronize read operations. */
  145. # endif
  146. #endif
  147. /* Values for the second argument to `fcntl'. */
  148. #define F_DUPFD 0 /* Duplicate file descriptor. */
  149. #define F_GETFD 1 /* Get file descriptor flags. */
  150. #define F_SETFD 2 /* Set file descriptor flags. */
  151. #define F_GETFL 3 /* Get file status flags. */
  152. #define F_SETFL 4 /* Set file status flags. */
  153. #ifndef __F_SETOWN
  154. # define __F_SETOWN 8
  155. # define __F_GETOWN 9
  156. #endif
  157. #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
  158. # define F_SETOWN __F_SETOWN /* Get owner (process receiving SIGIO). */
  159. # define F_GETOWN __F_GETOWN /* Set owner (process receiving SIGIO). */
  160. #endif
  161. #ifndef __F_SETSIG
  162. # define __F_SETSIG 10 /* Set number of signal to be sent. */
  163. # define __F_GETSIG 11 /* Get number of signal to be sent. */
  164. #endif
  165. #ifndef __F_SETOWN_EX
  166. # define __F_SETOWN_EX 15 /* Get owner (thread receiving SIGIO). */
  167. # define __F_GETOWN_EX 16 /* Set owner (thread receiving SIGIO). */
  168. #endif
  169. #ifdef __USE_GNU
  170. # define F_SETSIG __F_SETSIG /* Set number of signal to be sent. */
  171. # define F_GETSIG __F_GETSIG /* Get number of signal to be sent. */
  172. # define F_SETOWN_EX __F_SETOWN_EX /* Get owner (thread receiving SIGIO). */
  173. # define F_GETOWN_EX __F_GETOWN_EX /* Set owner (thread receiving SIGIO). */
  174. #endif
  175. #ifdef __USE_GNU
  176. # define F_SETLEASE 1024 /* Set a lease. */
  177. # define F_GETLEASE 1025 /* Enquire what lease is active. */
  178. # define F_NOTIFY 1026 /* Request notifications on a directory. */
  179. # define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
  180. # define F_GETPIPE_SZ 1032 /* Set pipe page size array. */
  181. # define F_ADD_SEALS 1033 /* Add seals to file. */
  182. # define F_GET_SEALS 1034 /* Get seals for file. */
  183. /* Set / get write life time hints. */
  184. # define F_GET_RW_HINT 1035
  185. # define F_SET_RW_HINT 1036
  186. # define F_GET_FILE_RW_HINT 1037
  187. # define F_SET_FILE_RW_HINT 1038
  188. #endif
  189. #ifdef __USE_XOPEN2K8
  190. # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
  191. close-on-exit set. */
  192. #endif
  193. /* For F_[GET|SET]FD. */
  194. #define FD_CLOEXEC 1 /* Actually anything with low bit set goes */
  195. #ifndef F_RDLCK
  196. /* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
  197. # define F_RDLCK 0 /* Read lock. */
  198. # define F_WRLCK 1 /* Write lock. */
  199. # define F_UNLCK 2 /* Remove lock. */
  200. #endif
  201. /* For old implementation of BSD flock. */
  202. #ifndef F_EXLCK
  203. # define F_EXLCK 4 /* or 3 */
  204. # define F_SHLCK 8 /* or 4 */
  205. #endif
  206. #ifdef __USE_MISC
  207. /* Operations for BSD flock, also used by the kernel implementation. */
  208. # define LOCK_SH 1 /* Shared lock. */
  209. # define LOCK_EX 2 /* Exclusive lock. */
  210. # define LOCK_NB 4 /* Or'd with one of the above to prevent
  211. blocking. */
  212. # define LOCK_UN 8 /* Remove lock. */
  213. #endif
  214. #ifdef __USE_GNU
  215. # define LOCK_MAND 32 /* This is a mandatory flock: */
  216. # define LOCK_READ 64 /* ... which allows concurrent read operations. */
  217. # define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
  218. # define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
  219. #endif
  220. #ifdef __USE_GNU
  221. /* Types of directory notifications that may be requested with F_NOTIFY. */
  222. # define DN_ACCESS 0x00000001 /* File accessed. */
  223. # define DN_MODIFY 0x00000002 /* File modified. */
  224. # define DN_CREATE 0x00000004 /* File created. */
  225. # define DN_DELETE 0x00000008 /* File removed. */
  226. # define DN_RENAME 0x00000010 /* File renamed. */
  227. # define DN_ATTRIB 0x00000020 /* File changed attributes. */
  228. # define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
  229. #endif
  230. #ifdef __USE_GNU
  231. /* Owner types. */
  232. enum __pid_type
  233. {
  234. F_OWNER_TID = 0, /* Kernel thread. */
  235. F_OWNER_PID, /* Process. */
  236. F_OWNER_PGRP, /* Process group. */
  237. F_OWNER_GID = F_OWNER_PGRP /* Alternative, obsolete name. */
  238. };
  239. /* Structure to use with F_GETOWN_EX and F_SETOWN_EX. */
  240. struct f_owner_ex
  241. {
  242. enum __pid_type type; /* Owner type of ID. */
  243. __pid_t pid; /* ID of owner. */
  244. };
  245. #endif
  246. #ifdef __USE_GNU
  247. /* Types of seals. */
  248. # define F_SEAL_SEAL 0x0001 /* Prevent further seals from being set. */
  249. # define F_SEAL_SHRINK 0x0002 /* Prevent file from shrinking. */
  250. # define F_SEAL_GROW 0x0004 /* Prevent file from growing. */
  251. # define F_SEAL_WRITE 0x0008 /* Prevent writes. */
  252. # define F_SEAL_FUTURE_WRITE 0x0010 /* Prevent future writes while
  253. mapped. */
  254. #endif
  255. #ifdef __USE_GNU
  256. /* Hint values for F_{GET,SET}_RW_HINT. */
  257. # define RWH_WRITE_LIFE_NOT_SET 0
  258. # define RWF_WRITE_LIFE_NOT_SET RWH_WRITE_LIFE_NOT_SET
  259. # define RWH_WRITE_LIFE_NONE 1
  260. # define RWH_WRITE_LIFE_SHORT 2
  261. # define RWH_WRITE_LIFE_MEDIUM 3
  262. # define RWH_WRITE_LIFE_LONG 4
  263. # define RWH_WRITE_LIFE_EXTREME 5
  264. #endif
  265. /* Define some more compatibility macros to be backward compatible with
  266. BSD systems which did not managed to hide these kernel macros. */
  267. #ifdef __USE_MISC
  268. # define FAPPEND O_APPEND
  269. # define FFSYNC O_FSYNC
  270. # define FASYNC O_ASYNC
  271. # define FNONBLOCK O_NONBLOCK
  272. # define FNDELAY O_NDELAY
  273. #endif /* Use misc. */
  274. #ifndef __POSIX_FADV_DONTNEED
  275. # define __POSIX_FADV_DONTNEED 4
  276. # define __POSIX_FADV_NOREUSE 5
  277. #endif
  278. /* Advise to `posix_fadvise'. */
  279. #ifdef __USE_XOPEN2K
  280. # define POSIX_FADV_NORMAL 0 /* No further special treatment. */
  281. # define POSIX_FADV_RANDOM 1 /* Expect random page references. */
  282. # define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
  283. # define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
  284. # define POSIX_FADV_DONTNEED __POSIX_FADV_DONTNEED /* Don't need these pages. */
  285. # define POSIX_FADV_NOREUSE __POSIX_FADV_NOREUSE /* Data will be accessed once. */
  286. #endif
  287. #ifdef __USE_GNU
  288. /* Flags for SYNC_FILE_RANGE. */
  289. # define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
  290. in the range before performing the
  291. write. */
  292. # define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
  293. dirty pages in the range which are
  294. not presently under writeback. */
  295. # define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
  296. the range after performing the
  297. write. */
  298. /* SYNC_FILE_RANGE_WRITE_AND_WAIT ensures all pages in the range are
  299. written to disk before returning. */
  300. # define SYNC_FILE_RANGE_WRITE_AND_WAIT (SYNC_FILE_RANGE_WRITE \
  301. | SYNC_FILE_RANGE_WAIT_BEFORE \
  302. | SYNC_FILE_RANGE_WAIT_AFTER)
  303. /* Flags for SPLICE and VMSPLICE. */
  304. # define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
  305. # define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
  306. (but we may still block on the fd
  307. we splice from/to). */
  308. # define SPLICE_F_MORE 4 /* Expect more data. */
  309. # define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
  310. /* Flags for fallocate. */
  311. # include <linux/falloc.h>
  312. /* File handle structure. */
  313. struct file_handle
  314. {
  315. unsigned int handle_bytes;
  316. int handle_type;
  317. /* File identifier. */
  318. unsigned char f_handle[0];
  319. };
  320. /* Maximum handle size (for now). */
  321. # define MAX_HANDLE_SZ 128
  322. #endif
  323. __BEGIN_DECLS
  324. #ifdef __USE_GNU
  325. /* Provide kernel hint to read ahead. */
  326. extern __ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
  327. __THROW;
  328. /* Selective file content synch'ing.
  329. This function is a possible cancellation point and therefore not
  330. marked with __THROW. */
  331. extern int sync_file_range (int __fd, __off64_t __offset, __off64_t __count,
  332. unsigned int __flags);
  333. /* Splice address range into a pipe.
  334. This function is a possible cancellation point and therefore not
  335. marked with __THROW. */
  336. extern __ssize_t vmsplice (int __fdout, const struct iovec *__iov,
  337. size_t __count, unsigned int __flags);
  338. /* Splice two files together.
  339. This function is a possible cancellation point and therefore not
  340. marked with __THROW. */
  341. extern __ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
  342. __off64_t *__offout, size_t __len,
  343. unsigned int __flags);
  344. /* In-kernel implementation of tee for pipe buffers.
  345. This function is a possible cancellation point and therefore not
  346. marked with __THROW. */
  347. extern __ssize_t tee (int __fdin, int __fdout, size_t __len,
  348. unsigned int __flags);
  349. /* Reserve storage for the data of the file associated with FD.
  350. This function is a possible cancellation point and therefore not
  351. marked with __THROW. */
  352. # ifndef __USE_FILE_OFFSET64
  353. extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len);
  354. # else
  355. # ifdef __REDIRECT
  356. extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset,
  357. __off64_t __len),
  358. fallocate64);
  359. # else
  360. # define fallocate fallocate64
  361. # endif
  362. # endif
  363. # ifdef __USE_LARGEFILE64
  364. extern int fallocate64 (int __fd, int __mode, __off64_t __offset,
  365. __off64_t __len);
  366. # endif
  367. /* Map file name to file handle. */
  368. extern int name_to_handle_at (int __dfd, const char *__name,
  369. struct file_handle *__handle, int *__mnt_id,
  370. int __flags) __THROW;
  371. /* Open file using the file handle.
  372. This function is a possible cancellation point and therefore not
  373. marked with __THROW. */
  374. extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle,
  375. int __flags);
  376. #endif /* use GNU */
  377. __END_DECLS