fcntl.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #ifndef _FCNTL_H
  2. # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
  3. #endif
  4. #include <sys/types.h>
  5. #ifdef __USE_GNU
  6. # include <bits/uio.h>
  7. #endif
  8. /*
  9. * open/fcntl - O_SYNC is only implemented on blocks devices and on files
  10. * located on an ext2 file system
  11. */
  12. #define O_ACCMODE 00000003
  13. #define O_RDONLY 00000000
  14. #define O_WRONLY 00000001
  15. #define O_RDWR 00000002
  16. #define O_CREAT 00000100 /* not fcntl */
  17. #define O_EXCL 00000200 /* not fcntl */
  18. #define O_NOCTTY 00000400 /* not fcntl */
  19. #define O_TRUNC 00001000 /* not fcntl */
  20. #define O_APPEND 00002000
  21. #define O_NONBLOCK 00004000
  22. #define O_NDELAY O_NONBLOCK
  23. #define O_SYNC 00010000
  24. #define O_ASYNC 00020000
  25. #ifdef __USE_XOPEN2K8
  26. # define O_DIRECTORY 00200000 /* direct disk access */
  27. # define O_NOFOLLOW 00400000 /* don't follow links */
  28. # define O_CLOEXEC 02000000 /* set close_on_exec */
  29. #endif
  30. #ifdef __USE_GNU
  31. # define O_DIRECT 00040000 /* must be a directory */
  32. # define O_NOATIME 01000000 /* don't set atime */
  33. # define O_PATH 010000000 /* Resolve pathname but do not open file. */
  34. # define O_TMPFILE 020200000 /* Atomically create nameless file. */
  35. #endif
  36. #ifdef __USE_LARGEFILE64
  37. # define O_LARGEFILE 00100000
  38. #endif
  39. /* For now Linux has synchronisity options for data and read operations.
  40. We define the symbols here but let them do the same as O_SYNC since
  41. this is a superset. */
  42. #if defined __USE_POSIX199309 || defined __USE_UNIX98
  43. # define O_DSYNC O_SYNC /* Synchronize data. */
  44. # define O_RSYNC O_SYNC /* Synchronize read operations. */
  45. #endif
  46. #define F_DUPFD 0 /* dup */
  47. #define F_GETFD 1 /* get close_on_exec */
  48. #define F_SETFD 2 /* set/clear close_on_exec */
  49. #define F_GETFL 3 /* get file->f_flags */
  50. #define F_SETFL 4 /* set file->f_flags */
  51. #ifndef __USE_FILE_OFFSET64
  52. # define F_GETLK 5
  53. # define F_SETLK 6
  54. # define F_SETLKW 7
  55. #else
  56. # define F_GETLK F_GETLK64
  57. # define F_SETLK F_SETLK64
  58. # define F_SETLKW F_SETLKW64
  59. #endif
  60. #define F_GETLK64 12 /* using 'struct flock64' */
  61. #define F_SETLK64 13
  62. #define F_SETLKW64 14
  63. #if defined __USE_BSD || defined __USE_XOPEN2K
  64. # define F_SETOWN 8 /* for sockets. */
  65. # define F_GETOWN 9 /* for sockets. */
  66. #endif
  67. #ifdef __USE_GNU
  68. # define F_SETSIG 10 /* for sockets. */
  69. # define F_GETSIG 11 /* for sockets. */
  70. #endif
  71. #ifdef __USE_GNU
  72. # define F_SETLEASE 1024 /* Set a lease. */
  73. # define F_GETLEASE 1025 /* Enquire what lease is active. */
  74. # define F_NOTIFY 1026 /* Request notfications on a directory. */
  75. #endif
  76. /* for F_[GET|SET]FL */
  77. #define FD_CLOEXEC 1 /* actually anything with low bit set goes */
  78. /* for posix fcntl() and lockf() */
  79. #define F_RDLCK 0
  80. #define F_WRLCK 1
  81. #define F_UNLCK 2
  82. /* for old implementation of bsd flock () */
  83. #define F_EXLCK 4 /* or 3 */
  84. #define F_SHLCK 8 /* or 4 */
  85. /* for leases */
  86. #define F_INPROGRESS 16
  87. #ifdef __USE_BSD
  88. /* operations for bsd flock(), also used by the kernel implementation */
  89. # define LOCK_SH 1 /* shared lock */
  90. # define LOCK_EX 2 /* exclusive lock */
  91. # define LOCK_NB 4 /* or'd with one of the above to prevent
  92. blocking */
  93. # define LOCK_UN 8 /* remove lock */
  94. #endif
  95. #ifdef __USE_GNU
  96. # define LOCK_MAND 32 /* This is a mandatory flock */
  97. # define LOCK_READ 64 /* ... Which allows concurrent
  98. read operations */
  99. # define LOCK_WRITE 128 /* ... Which allows concurrent
  100. write operations */
  101. # define LOCK_RW 192 /* ... Which allows concurrent
  102. read & write ops */
  103. #endif
  104. #ifdef __USE_GNU
  105. /* Types of directory notifications that may be requested with F_NOTIFY. */
  106. # define DN_ACCESS 0x00000001 /* File accessed. */
  107. # define DN_MODIFY 0x00000002 /* File modified. */
  108. # define DN_CREATE 0x00000004 /* File created. */
  109. # define DN_DELETE 0x00000008 /* File removed. */
  110. # define DN_RENAME 0x00000010 /* File renamed. */
  111. # define DN_ATTRIB 0x00000020 /* File changed attibutes. */
  112. # define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
  113. #endif
  114. struct flock {
  115. short l_type;
  116. short l_whence;
  117. #ifndef __USE_FILE_OFFSET64
  118. __off_t l_start;
  119. __off_t l_len;
  120. #else
  121. __off64_t l_start;
  122. __off64_t l_len;
  123. #endif
  124. __pid_t l_pid;
  125. };
  126. #ifdef __USE_LARGEFILE64
  127. struct flock64 {
  128. short l_type;
  129. short l_whence;
  130. __off64_t l_start;
  131. __off64_t l_len;
  132. __pid_t l_pid;
  133. };
  134. #endif
  135. /* Define some more compatibility macros to be backward compatible with
  136. * BSD systems which did not managed to hide these kernel macros. */
  137. #ifdef __USE_BSD
  138. # define FAPPEND O_APPEND
  139. # define FFSYNC O_FSYNC
  140. # define FASYNC O_ASYNC
  141. # define FNONBLOCK O_NONBLOCK
  142. # define FNDELAY O_NDELAY
  143. #endif /* Use BSD. */
  144. /* Advise to `posix_fadvise'. */
  145. #ifdef __USE_XOPEN2K
  146. # define POSIX_FADV_NORMAL 0 /* No further special treatment. */
  147. # define POSIX_FADV_RANDOM 1 /* Expect random page references. */
  148. # define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
  149. # define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
  150. # define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
  151. # define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
  152. #endif
  153. #if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__
  154. /* Flags for SYNC_FILE_RANGE. */
  155. # define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
  156. in the range before performing
  157. the write */
  158. # define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
  159. dirty pages in the range which are
  160. not presently under writeback */
  161. # define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages
  162. in the range after performing the
  163. write */
  164. /* Flags for splice() and vmsplice() */
  165. # define SPLICE_F_MOVE 1 /* Move pages instead of copying */
  166. # define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
  167. (but we may still block on the fd
  168. we splice from/to) */
  169. # define SPLICE_F_MORE 4 /* Expect more data */
  170. # define SPLICE_F_GIFT 8 /* Pages passed in are a gift */
  171. __BEGIN_DECLS
  172. /* Provide kernel hint to read ahead. */
  173. extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count) __THROW;
  174. /* Selective file content synch'ing */
  175. extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
  176. unsigned int __flags);
  177. /* Splice address range into a pipe */
  178. extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
  179. size_t __count, unsigned int __flags);
  180. /* Splice two files together */
  181. extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
  182. __off64_t *__offout, size_t __len,
  183. unsigned int __flags);
  184. /* In-kernel implementation of tee for pipe buffers */
  185. extern ssize_t tee (int __fdin, int __fdout, size_t __len,
  186. unsigned int __flags);
  187. __END_DECLS
  188. #endif