fcntl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /* Copyright (C) 1991,1992,1994-2001,2003,2004,2005,2006,2007, 2009
  2. 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. <http://www.gnu.org/licenses/>. */
  15. /*
  16. * POSIX Standard: 6.5 File Control Operations <fcntl.h>
  17. */
  18. #ifndef _FCNTL_H
  19. #define _FCNTL_H 1
  20. #include <features.h>
  21. /* This must be early so <bits/fcntl.h> can define types winningly. */
  22. __BEGIN_DECLS
  23. /* Get the definitions of O_*, F_*, FD_*: all the
  24. numbers and flag bits for `open', `fcntl', et al. */
  25. #include <bits/fcntl.h>
  26. /* For XPG all symbols from <sys/stat.h> should also be available. */
  27. #ifdef __USE_XOPEN
  28. # include <sys/stat.h>
  29. #endif
  30. #ifdef __USE_MISC
  31. # ifndef R_OK /* Verbatim from <unistd.h>. Ugh. */
  32. /* Values for the second argument to access.
  33. These may be OR'd together. */
  34. # define R_OK 4 /* Test for read permission. */
  35. # define W_OK 2 /* Test for write permission. */
  36. # define X_OK 1 /* Test for execute permission. */
  37. # define F_OK 0 /* Test for existence. */
  38. # endif
  39. #endif /* Use misc. */
  40. /* XPG wants the following symbols. */
  41. #ifdef __USE_XOPEN /* <stdio.h> has the same definitions. */
  42. # define SEEK_SET 0 /* Seek from beginning of file. */
  43. # define SEEK_CUR 1 /* Seek from current position. */
  44. # define SEEK_END 2 /* Seek from end of file. */
  45. #endif /* XPG */
  46. #ifdef __USE_ATFILE
  47. # define AT_FDCWD -100 /* Special value used to indicate
  48. the *at functions should use the
  49. current working directory. */
  50. # define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
  51. # define AT_REMOVEDIR 0x200 /* Remove directory instead of
  52. unlinking file. */
  53. # define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
  54. # ifdef __USE_GNU
  55. # define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount
  56. traversal. */
  57. # define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname. */
  58. # define AT_STATX_SYNC_TYPE 0x6000
  59. # define AT_STATX_SYNC_AS_STAT 0x0000
  60. # define AT_STATX_FORCE_SYNC 0x2000
  61. # define AT_STATX_DONT_SYNC 0x4000
  62. # define AT_RECURSIVE 0x8000 /* Apply to the entire subtree. */
  63. # endif
  64. # define AT_EACCESS 0x200 /* Test access permitted for
  65. effective IDs, not real IDs. */
  66. #endif
  67. /* Do the file control operation described by CMD on FD.
  68. The remaining arguments are interpreted depending on CMD.
  69. This function is a cancellation point and therefore not marked with
  70. __THROW. */
  71. #if !defined(__USE_FILE_OFFSET64) || defined(__LP64__)
  72. extern int fcntl (int __fd, int __cmd, ...);
  73. # ifdef _LIBC
  74. extern int __fcntl_nocancel(int, int, long) attribute_hidden;
  75. libc_hidden_proto(fcntl)
  76. # endif
  77. #else
  78. # ifdef __REDIRECT
  79. extern int __REDIRECT (fcntl, (int __fd, int __cmd, ...), fcntl64);
  80. # else
  81. # define fcntl fcntl64
  82. # endif
  83. #endif
  84. #if defined(__USE_LARGEFILE64) && !defined(__LP64__)
  85. extern int fcntl64 (int __fd, int __cmd, ...);
  86. # ifdef _LIBC
  87. extern int __fcntl64_nocancel(int, int, long) attribute_hidden;
  88. libc_hidden_proto(fcntl64)
  89. # endif
  90. #endif
  91. /* Open FILE and return a new file descriptor for it, or -1 on error.
  92. OFLAG determines the type of access used. If O_CREAT or O_TMPFILE
  93. is on OFLAG, the third argument is taken as a `mode_t', the mode of
  94. the created file.
  95. This function is a cancellation point and therefore not marked with
  96. __THROW. */
  97. #ifndef __USE_FILE_OFFSET64
  98. extern int open (const char *__file, int __oflag, ...) __nonnull ((1));
  99. libc_hidden_proto(open)
  100. # ifdef _LIBC
  101. extern int __open2_nocancel(const char *, int) __nonnull ((1)) attribute_hidden;
  102. extern int __open_nocancel(const char *, int, mode_t) __nonnull ((1)) attribute_hidden;
  103. # endif
  104. #else
  105. # ifdef __REDIRECT
  106. extern int __REDIRECT (open, (const char *__file, int __oflag, ...), open64)
  107. __nonnull ((1));
  108. # else
  109. # define open open64
  110. # endif
  111. #endif
  112. #ifdef __USE_LARGEFILE64
  113. extern int open64 (const char *__file, int __oflag, ...) __nonnull ((1));
  114. libc_hidden_proto(open64)
  115. #endif
  116. #ifdef __USE_ATFILE
  117. /* Similar to `open' but a relative path name is interpreted relative to
  118. the directory for which FD is a descriptor.
  119. NOTE: some other `openat' implementation support additional functionality
  120. through this interface, especially using the O_XATTR flag. This is not
  121. yet supported here.
  122. This function is a cancellation point and therefore not marked with
  123. __THROW. */
  124. # ifndef __USE_FILE_OFFSET64
  125. extern int openat (int __fd, const char *__file, int __oflag, ...)
  126. __nonnull ((2));
  127. libc_hidden_proto(openat)
  128. # else
  129. # ifdef __REDIRECT
  130. extern int __REDIRECT (openat, (int __fd, const char *__file, int __oflag,
  131. ...), openat64) __nonnull ((2));
  132. # else
  133. # define openat openat64
  134. # endif
  135. # endif
  136. extern int openat64 (int __fd, const char *__file, int __oflag, ...)
  137. __nonnull ((2));
  138. #endif
  139. /* Create and open FILE, with mode MODE. This takes an `int' MODE
  140. argument because that is what `mode_t' will be widened to.
  141. This function is a cancellation point and therefore not marked with
  142. __THROW. */
  143. #ifndef __USE_FILE_OFFSET64
  144. extern int creat (const char *__file, __mode_t __mode) __nonnull ((1));
  145. #else
  146. # ifdef __REDIRECT
  147. extern int __REDIRECT (creat, (const char *__file, __mode_t __mode),
  148. creat64) __nonnull ((1));
  149. # else
  150. # define creat creat64
  151. # endif
  152. #endif
  153. #ifdef __USE_LARGEFILE64
  154. extern int creat64 (const char *__file, __mode_t __mode) __nonnull ((1));
  155. #endif
  156. #if !defined F_LOCK && (defined __USE_MISC || (defined __USE_XOPEN_EXTENDED \
  157. && !defined __USE_POSIX))
  158. /* NOTE: These declarations also appear in <unistd.h>; be sure to keep both
  159. files consistent. Some systems have them there and some here, and some
  160. software depends on the macros being defined without including both. */
  161. /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
  162. LEN is always relative to the current file position.
  163. The CMD argument is one of the following. */
  164. # define F_ULOCK 0 /* Unlock a previously locked region. */
  165. # define F_LOCK 1 /* Lock a region for exclusive use. */
  166. # define F_TLOCK 2 /* Test and lock a region for exclusive use. */
  167. # define F_TEST 3 /* Test a region for other processes locks. */
  168. # ifndef __USE_FILE_OFFSET64
  169. extern int lockf (int __fd, int __cmd, __off_t __len);
  170. libc_hidden_proto(lockf)
  171. # else
  172. # ifdef __REDIRECT
  173. extern int __REDIRECT (lockf, (int __fd, int __cmd, __off64_t __len), lockf64);
  174. # else
  175. # define lockf lockf64
  176. # endif
  177. # endif
  178. # ifdef __USE_LARGEFILE64
  179. extern int lockf64 (int __fd, int __cmd, __off64_t __len);
  180. # endif
  181. #endif
  182. #if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
  183. /* Advice the system about the expected behaviour of the application with
  184. respect to the file associated with FD. */
  185. # ifndef __USE_FILE_OFFSET64
  186. extern int posix_fadvise (int __fd, __off_t __offset, __off_t __len,
  187. int __advise) __THROW;
  188. # else
  189. # ifdef __REDIRECT_NTH
  190. extern int __REDIRECT_NTH (posix_fadvise, (int __fd, __off64_t __offset,
  191. __off64_t __len, int __advise),
  192. posix_fadvise64);
  193. # else
  194. # define posix_fadvise posix_fadvise64
  195. # endif
  196. # endif
  197. # ifdef __USE_LARGEFILE64
  198. extern int posix_fadvise64 (int __fd, __off64_t __offset, __off64_t __len,
  199. int __advise) __THROW;
  200. # endif
  201. #endif
  202. #if defined __UCLIBC_HAS_ADVANCED_REALTIME__
  203. /* Reserve storage for the data of the file associated with FD.
  204. This function is a possible cancellation point and therefore not
  205. marked with __THROW. */
  206. # ifndef __USE_FILE_OFFSET64
  207. extern int posix_fallocate (int __fd, __off_t __offset, __off_t __len);
  208. # else
  209. # ifdef __REDIRECT
  210. extern int __REDIRECT (posix_fallocate, (int __fd, __off64_t __offset,
  211. __off64_t __len),
  212. posix_fallocate64);
  213. # else
  214. # define posix_fallocate posix_fallocate64
  215. # endif
  216. # endif
  217. # ifdef __USE_LARGEFILE64
  218. extern int posix_fallocate64 (int __fd, __off64_t __offset, __off64_t __len);
  219. # endif
  220. #endif
  221. #if (defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU) || defined _LIBC
  222. /* Reserve storage for the data of a file associated with FD. This function
  223. is Linux-specific. For the portable version, use posix_fallocate().
  224. Unlike the latter, fallocate can operate in different modes. The default
  225. mode = 0 is equivalent to posix_fallocate().
  226. Note: These declarations are used in posix_fallocate.c and
  227. posix_fallocate64.c, so we expose them internally.
  228. */
  229. /* Flags for fallocate's mode. */
  230. # define FALLOC_FL_KEEP_SIZE 1 /* Don't extend size of file
  231. even if offset + len is
  232. greater than file size. */
  233. # define FALLOC_FL_PUNCH_HOLE 2 /* Create a hole in the file. */
  234. # ifndef __USE_FILE_OFFSET64
  235. extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len);
  236. # else
  237. # ifdef __REDIRECT
  238. extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset,
  239. __off64_t __len),
  240. fallocate64);
  241. # else
  242. # define fallocate fallocate64
  243. # endif
  244. # endif
  245. # ifdef __USE_LARGEFILE64
  246. extern int fallocate64 (int __fd, int __mode, __off64_t __offset, __off64_t __len);
  247. # endif
  248. #endif
  249. #if (defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU)
  250. struct file_handle {
  251. unsigned handle_bytes;
  252. int handle_type;
  253. unsigned char f_handle[];
  254. };
  255. #define MAX_HANDLE_SZ 128
  256. int name_to_handle_at(int dirfd, const char *pathname,
  257. struct file_handle *handle, int *mount_id, int flags);
  258. int open_by_handle_at(int mount_fd, struct file_handle *handle, int flags);
  259. #endif
  260. #ifdef __USE_GNU
  261. # define F_SETOWN_EX 15 /* Get owner (thread receiving SIGIO). */
  262. # define F_GETOWN_EX 16 /* Set owner (thread receiving SIGIO). */
  263. /* Owner types. */
  264. enum __pid_type
  265. {
  266. F_OWNER_TID = 0, /* Kernel thread. */
  267. F_OWNER_PID, /* Process. */
  268. F_OWNER_PGRP, /* Process group. */
  269. F_OWNER_GID = F_OWNER_PGRP /* Alternative, obsolete name. */
  270. };
  271. /* Structure to use with F_GETOWN_EX and F_SETOWN_EX. */
  272. struct f_owner_ex
  273. {
  274. enum __pid_type type; /* Owner type of ID. */
  275. __pid_t pid; /* ID of owner. */
  276. };
  277. #endif
  278. __END_DECLS
  279. #endif /* fcntl.h */