1 /* O_*, F_*, FD_* bit values for Linux.
2 Copyright (C) 2001-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 # error "Never use <bits/fcntl-linux.h> directly; include <fcntl.h> instead."
23 /* This file contains shared definitions between Linux architectures
24 and is included by <bits/fcntl.h> to declare them. The various
25 #ifndef cases allow the architecture specific file to define those
26 values with different values.
28 A minimal <bits/fcntl.h> contains just:
31 #ifdef __USE_LARGEFILE64
34 #include <bits/fcntl-linux.h>
38 # include <bits/types/struct_iovec.h>
42 #define O_ACCMODE 0003
47 # define O_CREAT 0100 /* Not fcntl. */
50 # define O_EXCL 0200 /* Not fcntl. */
53 # define O_NOCTTY 0400 /* Not fcntl. */
56 # define O_TRUNC 01000 /* Not fcntl. */
59 # define O_APPEND 02000
62 # define O_NONBLOCK 04000
65 # define O_NDELAY O_NONBLOCK
68 # define O_SYNC 04010000
70 #define O_FSYNC O_SYNC
72 # define O_ASYNC 020000
75 # define __O_LARGEFILE 0100000
79 # define __O_DIRECTORY 0200000
82 # define __O_NOFOLLOW 0400000
85 # define __O_CLOEXEC 02000000
88 # define __O_DIRECT 040000
91 # define __O_NOATIME 01000000
94 # define __O_PATH 010000000
97 # define __O_DSYNC 010000
100 # define __O_TMPFILE (020000000 | __O_DIRECTORY)
104 # ifndef __USE_FILE_OFFSET64
105 # define F_GETLK 5 /* Get record locking info. */
106 # define F_SETLK 6 /* Set record locking info (non-blocking). */
107 # define F_SETLKW 7 /* Set record locking info (blocking). */
109 # define F_GETLK F_GETLK64 /* Get record locking info. */
110 # define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
111 # define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
115 # define F_GETLK64 12 /* Get record locking info. */
116 # define F_SETLK64 13 /* Set record locking info (non-blocking). */
117 # define F_SETLKW64 14 /* Set record locking info (blocking). */
120 /* open file description locks.
122 Usually record locks held by a process are released on *any* close and are
123 not inherited across a fork.
125 These cmd values will set locks that conflict with process-associated record
126 locks, but are "owned" by the opened file description, not the process.
127 This means that they are inherited across fork or clone with CLONE_FILES
128 like BSD (flock) locks, and they are only released automatically when the
129 last reference to the the file description against which they were acquired
132 # define F_OFD_GETLK 36
133 # define F_OFD_SETLK 37
134 # define F_OFD_SETLKW 38
137 #ifdef __USE_LARGEFILE64
138 # define O_LARGEFILE __O_LARGEFILE
141 #ifdef __USE_XOPEN2K8
142 # define O_DIRECTORY __O_DIRECTORY /* Must be a directory. */
143 # define O_NOFOLLOW __O_NOFOLLOW /* Do not follow links. */
144 # define O_CLOEXEC __O_CLOEXEC /* Set close_on_exec. */
148 # define O_DIRECT __O_DIRECT /* Direct disk access. */
149 # define O_NOATIME __O_NOATIME /* Do not set atime. */
150 # define O_PATH __O_PATH /* Resolve pathname but do not open file. */
151 # define O_TMPFILE __O_TMPFILE /* Atomically create nameless file. */
154 /* For now, Linux has no separate synchronicity options for read
155 operations. We define O_RSYNC therefore as the same as O_SYNC
156 since this is a superset. */
157 #if defined __USE_POSIX199309 || defined __USE_UNIX98
158 # define O_DSYNC __O_DSYNC /* Synchronize data. */
159 # if defined __O_RSYNC
160 # define O_RSYNC __O_RSYNC /* Synchronize read operations. */
162 # define O_RSYNC O_SYNC /* Synchronize read operations. */
166 /* Values for the second argument to `fcntl'. */
167 #define F_DUPFD 0 /* Duplicate file descriptor. */
168 #define F_GETFD 1 /* Get file descriptor flags. */
169 #define F_SETFD 2 /* Set file descriptor flags. */
170 #define F_GETFL 3 /* Get file status flags. */
171 #define F_SETFL 4 /* Set file status flags. */
174 # define __F_SETOWN 8
175 # define __F_GETOWN 9
178 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
179 # define F_SETOWN __F_SETOWN /* Get owner (process receiving SIGIO). */
180 # define F_GETOWN __F_GETOWN /* Set owner (process receiving SIGIO). */
184 # define __F_SETSIG 10 /* Set number of signal to be sent. */
185 # define __F_GETSIG 11 /* Get number of signal to be sent. */
187 #ifndef __F_SETOWN_EX
188 # define __F_SETOWN_EX 15 /* Get owner (thread receiving SIGIO). */
189 # define __F_GETOWN_EX 16 /* Set owner (thread receiving SIGIO). */
193 # define F_SETSIG __F_SETSIG /* Set number of signal to be sent. */
194 # define F_GETSIG __F_GETSIG /* Get number of signal to be sent. */
195 # define F_SETOWN_EX __F_SETOWN_EX /* Get owner (thread receiving SIGIO). */
196 # define F_GETOWN_EX __F_GETOWN_EX /* Set owner (thread receiving SIGIO). */
200 # define F_SETLEASE 1024 /* Set a lease. */
201 # define F_GETLEASE 1025 /* Enquire what lease is active. */
202 # define F_NOTIFY 1026 /* Request notifications on a directory. */
203 # define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
204 # define F_GETPIPE_SZ 1032 /* Set pipe page size array. */
205 # define F_ADD_SEALS 1033 /* Add seals to file. */
206 # define F_GET_SEALS 1034 /* Get seals for file. */
207 /* Set / get write life time hints. */
208 # define F_GET_RW_HINT 1035
209 # define F_SET_RW_HINT 1036
210 # define F_GET_FILE_RW_HINT 1037
211 # define F_SET_FILE_RW_HINT 1038
213 #ifdef __USE_XOPEN2K8
214 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
215 close-on-exit set. */
218 /* For F_[GET|SET]FD. */
219 #define FD_CLOEXEC 1 /* Actually anything with low bit set goes */
222 /* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
223 # define F_RDLCK 0 /* Read lock. */
224 # define F_WRLCK 1 /* Write lock. */
225 # define F_UNLCK 2 /* Remove lock. */
229 /* For old implementation of BSD flock. */
231 # define F_EXLCK 4 /* or 3 */
232 # define F_SHLCK 8 /* or 4 */
236 /* Operations for BSD flock, also used by the kernel implementation. */
237 # define LOCK_SH 1 /* Shared lock. */
238 # define LOCK_EX 2 /* Exclusive lock. */
239 # define LOCK_NB 4 /* Or'd with one of the above to prevent
241 # define LOCK_UN 8 /* Remove lock. */
245 # define LOCK_MAND 32 /* This is a mandatory flock: */
246 # define LOCK_READ 64 /* ... which allows concurrent read operations. */
247 # define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
248 # define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
252 /* Types of directory notifications that may be requested with F_NOTIFY. */
253 # define DN_ACCESS 0x00000001 /* File accessed. */
254 # define DN_MODIFY 0x00000002 /* File modified. */
255 # define DN_CREATE 0x00000004 /* File created. */
256 # define DN_DELETE 0x00000008 /* File removed. */
257 # define DN_RENAME 0x00000010 /* File renamed. */
258 # define DN_ATTRIB 0x00000020 /* File changed attributes. */
259 # define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
267 F_OWNER_TID = 0, /* Kernel thread. */
268 F_OWNER_PID, /* Process. */
269 F_OWNER_PGRP, /* Process group. */
270 F_OWNER_GID = F_OWNER_PGRP /* Alternative, obsolete name. */
273 /* Structure to use with F_GETOWN_EX and F_SETOWN_EX. */
276 enum __pid_type type; /* Owner type of ID. */
277 __pid_t pid; /* ID of owner. */
282 /* Types of seals. */
283 # define F_SEAL_SEAL 0x0001 /* Prevent further seals from being set. */
284 # define F_SEAL_SHRINK 0x0002 /* Prevent file from shrinking. */
285 # define F_SEAL_GROW 0x0004 /* Prevent file from growing. */
286 # define F_SEAL_WRITE 0x0008 /* Prevent writes. */
290 /* Hint values for F_{GET,SET}_RW_HINT. */
291 # define RWF_WRITE_LIFE_NOT_SET 0
292 # define RWH_WRITE_LIFE_NONE 1
293 # define RWH_WRITE_LIFE_SHORT 2
294 # define RWH_WRITE_LIFE_MEDIUM 3
295 # define RWH_WRITE_LIFE_LONG 4
296 # define RWH_WRITE_LIFE_EXTREME 5
299 /* Define some more compatibility macros to be backward compatible with
300 BSD systems which did not managed to hide these kernel macros. */
302 # define FAPPEND O_APPEND
303 # define FFSYNC O_FSYNC
304 # define FASYNC O_ASYNC
305 # define FNONBLOCK O_NONBLOCK
306 # define FNDELAY O_NDELAY
307 #endif /* Use misc. */
309 #ifndef __POSIX_FADV_DONTNEED
310 # define __POSIX_FADV_DONTNEED 4
311 # define __POSIX_FADV_NOREUSE 5
313 /* Advise to `posix_fadvise'. */
315 # define POSIX_FADV_NORMAL 0 /* No further special treatment. */
316 # define POSIX_FADV_RANDOM 1 /* Expect random page references. */
317 # define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
318 # define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
319 # define POSIX_FADV_DONTNEED __POSIX_FADV_DONTNEED /* Don't need these pages. */
320 # define POSIX_FADV_NOREUSE __POSIX_FADV_NOREUSE /* Data will be accessed once. */
325 /* Flags for SYNC_FILE_RANGE. */
326 # define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
327 in the range before performing the
329 # define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
330 dirty pages in the range which are
331 not presently under writeback. */
332 # define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
333 the range after performing the
336 /* Flags for SPLICE and VMSPLICE. */
337 # define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
338 # define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
339 (but we may still block on the fd
340 we splice from/to). */
341 # define SPLICE_F_MORE 4 /* Expect more data. */
342 # define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
345 /* Flags for fallocate. */
346 # include <linux/falloc.h>
349 /* File handle structure. */
352 unsigned int handle_bytes;
354 /* File identifier. */
355 unsigned char f_handle[0];
358 /* Maximum handle size (for now). */
359 # define MAX_HANDLE_SZ 128
362 /* Values for `*at' functions. */
364 # define AT_FDCWD -100 /* Special value used to indicate
365 the *at functions should use the
366 current working directory. */
367 # define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
368 # define AT_REMOVEDIR 0x200 /* Remove directory instead of
370 # define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
372 # define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount
374 # define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname. */
375 # define AT_STATX_SYNC_TYPE 0x6000
376 # define AT_STATX_SYNC_AS_STAT 0x0000
377 # define AT_STATX_FORCE_SYNC 0x2000
378 # define AT_STATX_DONT_SYNC 0x4000
380 # define AT_EACCESS 0x200 /* Test access permitted for
381 effective IDs, not real IDs. */
388 /* Provide kernel hint to read ahead. */
389 extern __ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
393 /* Selective file content synch'ing.
395 This function is a possible cancellation point and therefore not
396 marked with __THROW. */
397 extern int sync_file_range (int __fd, __off64_t __offset, __off64_t __count,
398 unsigned int __flags);
401 /* Splice address range into a pipe.
403 This function is a possible cancellation point and therefore not
404 marked with __THROW. */
405 extern __ssize_t vmsplice (int __fdout, const struct iovec *__iov,
406 size_t __count, unsigned int __flags);
408 /* Splice two files together.
410 This function is a possible cancellation point and therefore not
411 marked with __THROW. */
412 extern __ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
413 __off64_t *__offout, size_t __len,
414 unsigned int __flags);
416 /* In-kernel implementation of tee for pipe buffers.
418 This function is a possible cancellation point and therefore not
419 marked with __THROW. */
420 extern __ssize_t tee (int __fdin, int __fdout, size_t __len,
421 unsigned int __flags);
423 /* Reserve storage for the data of the file associated with FD.
425 This function is a possible cancellation point and therefore not
426 marked with __THROW. */
427 # ifndef __USE_FILE_OFFSET64
428 extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len);
431 extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset,
435 # define fallocate fallocate64
438 # ifdef __USE_LARGEFILE64
439 extern int fallocate64 (int __fd, int __mode, __off64_t __offset,
444 /* Map file name to file handle. */
445 extern int name_to_handle_at (int __dfd, const char *__name,
446 struct file_handle *__handle, int *__mnt_id,
447 int __flags) __THROW;
449 /* Open file using the file handle.
451 This function is a possible cancellation point and therefore not
452 marked with __THROW. */
453 extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle,