fcntl.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef _FCNTL_H
  2. # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
  3. #endif
  4. #include <sys/types.h>
  5. /*
  6. * open/fcntl - O_SYNC is only implemented on blocks devices and on files
  7. * located on an ext2 file system
  8. */
  9. #define O_ACCMODE 00000003
  10. #define O_RDONLY 00000000
  11. #define O_WRONLY 00000001
  12. #define O_RDWR 00000002
  13. #define O_CREAT 00000100 /* not fcntl */
  14. #define O_EXCL 00000200 /* not fcntl */
  15. #define O_NOCTTY 00000400 /* not fcntl */
  16. #define O_TRUNC 00001000 /* not fcntl */
  17. #define O_APPEND 00002000
  18. #define O_NONBLOCK 00004000
  19. #define O_NDELAY O_NONBLOCK
  20. #define O_SYNC 00010000
  21. #define O_ASYNC 00020000
  22. #ifdef __USE_GNU
  23. # define O_DIRECT 00040000 /* must be a directory */
  24. # define O_DIRECTORY 00200000 /* direct disk access */
  25. # define O_NOFOLLOW 00400000 /* don't follow links */
  26. # define O_NOATIME 01000000 /* don't set atime */
  27. #endif
  28. #ifdef __USE_LARGEFILE64
  29. # define O_LARGEFILE 00100000
  30. #endif
  31. /* For now Linux has synchronisity options for data and read operations.
  32. We define the symbols here but let them do the same as O_SYNC since
  33. this is a superset. */
  34. #if defined __USE_POSIX199309 || defined __USE_UNIX98
  35. # define O_DSYNC O_SYNC /* Synchronize data. */
  36. # define O_RSYNC O_SYNC /* Synchronize read operations. */
  37. #endif
  38. #define F_DUPFD 0 /* dup */
  39. #define F_GETFD 1 /* get close_on_exec */
  40. #define F_SETFD 2 /* set/clear close_on_exec */
  41. #define F_GETFL 3 /* get file->f_flags */
  42. #define F_SETFL 4 /* set file->f_flags */
  43. #ifndef __USE_FILE_OFFSET64
  44. # define F_GETLK 5
  45. # define F_SETLK 6
  46. # define F_SETLKW 7
  47. #else
  48. # define F_GETLK F_GETLK64
  49. # define F_SETLK F_SETLK64
  50. # define F_SETLKW F_SETLKW64
  51. #endif
  52. #define F_GETLK64 12 /* using 'struct flock64' */
  53. #define F_SETLK64 13
  54. #define F_SETLKW64 14
  55. #if defined __USE_BSD || defined __USE_XOPEN2K
  56. # define F_SETOWN 8 /* for sockets. */
  57. # define F_GETOWN 9 /* for sockets. */
  58. #endif
  59. #ifdef __USE_GNU
  60. # define F_SETSIG 10 /* for sockets. */
  61. # define F_GETSIG 11 /* for sockets. */
  62. #endif
  63. #ifdef __USE_GNU
  64. # define F_SETLEASE 1024 /* Set a lease. */
  65. # define F_GETLEASE 1025 /* Enquire what lease is active. */
  66. # define F_NOTIFY 1026 /* Request notfications on a directory. */
  67. #endif
  68. /* for F_[GET|SET]FL */
  69. #define FD_CLOEXEC 1 /* actually anything with low bit set goes */
  70. /* for posix fcntl() and lockf() */
  71. #define F_RDLCK 0
  72. #define F_WRLCK 1
  73. #define F_UNLCK 2
  74. /* for old implementation of bsd flock () */
  75. #define F_EXLCK 4 /* or 3 */
  76. #define F_SHLCK 8 /* or 4 */
  77. /* for leases */
  78. #define F_INPROGRESS 16
  79. #ifdef __USE_BSD
  80. /* operations for bsd flock(), also used by the kernel implementation */
  81. # define LOCK_SH 1 /* shared lock */
  82. # define LOCK_EX 2 /* exclusive lock */
  83. # define LOCK_NB 4 /* or'd with one of the above to prevent
  84. blocking */
  85. # define LOCK_UN 8 /* remove lock */
  86. #endif
  87. #ifdef __USE_GNU
  88. # define LOCK_MAND 32 /* This is a mandatory flock */
  89. # define LOCK_READ 64 /* ... Which allows concurrent
  90. read operations */
  91. # define LOCK_WRITE 128 /* ... Which allows concurrent
  92. write operations */
  93. # define LOCK_RW 192 /* ... Which allows concurrent
  94. read & write ops */
  95. #endif
  96. #ifdef __USE_GNU
  97. /* Types of directory notifications that may be requested with F_NOTIFY. */
  98. # define DN_ACCESS 0x00000001 /* File accessed. */
  99. # define DN_MODIFY 0x00000002 /* File modified. */
  100. # define DN_CREATE 0x00000004 /* File created. */
  101. # define DN_DELETE 0x00000008 /* File removed. */
  102. # define DN_RENAME 0x00000010 /* File renamed. */
  103. # define DN_ATTRIB 0x00000020 /* File changed attibutes. */
  104. # define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
  105. #endif
  106. struct flock {
  107. short l_type;
  108. short l_whence;
  109. #ifndef __USE_FILE_OFFSET64
  110. __off_t l_start;
  111. __off_t l_len;
  112. #else
  113. __off64_t l_start;
  114. __off64_t l_len;
  115. #endif
  116. __pid_t l_pid;
  117. };
  118. #ifdef __USE_LARGEFILE64
  119. struct flock64 {
  120. short l_type;
  121. short l_whence;
  122. __off64_t l_start;
  123. __off64_t l_len;
  124. __pid_t l_pid;
  125. };
  126. #endif
  127. /* Define some more compatibility macros to be backward compatible with
  128. * BSD systems which did not managed to hide these kernel macros. */
  129. #ifdef __USE_BSD
  130. # define FAPPEND O_APPEND
  131. # define FFSYNC O_FSYNC
  132. # define FASYNC O_ASYNC
  133. # define FNONBLOCK O_NONBLOCK
  134. # define FNDELAY O_NDELAY
  135. #endif /* Use BSD. */
  136. /* Advise to `posix_fadvise'. */
  137. #ifdef __USE_XOPEN2K
  138. # define POSIX_FADV_NORMAL 0 /* No further special treatment. */
  139. # define POSIX_FADV_RANDOM 1 /* Expect random page references. */
  140. # define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
  141. # define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
  142. # define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
  143. # define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
  144. #endif