1/* O_*, F_*, FD_* bit values for Linux.
2 Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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 <https://www.gnu.org/licenses/>. */
18
19#ifndef _FCNTL_H
20# error "Never use <bits/fcntl-linux.h> directly; include <fcntl.h> instead."
21#endif
22
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.
27
28 A minimal <bits/fcntl.h> contains just:
29
30 struct flock {...}
31 #ifdef __USE_LARGEFILE64
32 struct flock64 {...}
33 #endif
34 #include <bits/fcntl-linux.h>
35*/
36
37#ifdef __USE_GNU
38# include <bits/types/struct_iovec.h>
39#endif
40
41/* open/fcntl. */
42#define O_ACCMODE 0003
43#define O_RDONLY 00
44#define O_WRONLY 01
45#define O_RDWR 02
46#ifndef O_CREAT
47# define O_CREAT 0100 /* Not fcntl. */
48#endif
49#ifndef O_EXCL
50# define O_EXCL 0200 /* Not fcntl. */
51#endif
52#ifndef O_NOCTTY
53# define O_NOCTTY 0400 /* Not fcntl. */
54#endif
55#ifndef O_TRUNC
56# define O_TRUNC 01000 /* Not fcntl. */
57#endif
58#ifndef O_APPEND
59# define O_APPEND 02000
60#endif
61#ifndef O_NONBLOCK
62# define O_NONBLOCK 04000
63#endif
64#ifndef O_NDELAY
65# define O_NDELAY O_NONBLOCK
66#endif
67#ifndef O_SYNC
68# define O_SYNC 04010000
69#endif
70#define O_FSYNC O_SYNC
71#ifndef O_ASYNC
72# define O_ASYNC 020000
73#endif
74#ifndef __O_LARGEFILE
75# define __O_LARGEFILE 0100000
76#endif
77
78#ifndef __O_DIRECTORY
79# define __O_DIRECTORY 0200000
80#endif
81#ifndef __O_NOFOLLOW
82# define __O_NOFOLLOW 0400000
83#endif
84#include <bits/cloexec.h>
85#ifndef __O_DIRECT
86# define __O_DIRECT 040000
87#endif
88#ifndef __O_NOATIME
89# define __O_NOATIME 01000000
90#endif
91#ifndef __O_PATH
92# define __O_PATH 010000000
93#endif
94#ifndef __O_DSYNC
95# define __O_DSYNC 010000
96#endif
97#ifndef __O_TMPFILE
98# define __O_TMPFILE (020000000 | __O_DIRECTORY)
99#endif
100
101#ifndef F_GETLK
102# if !defined __USE_FILE_OFFSET64 && __TIMESIZE != 64
103# define F_GETLK 5 /* Get record locking info. */
104# define F_SETLK 6 /* Set record locking info (non-blocking). */
105# define F_SETLKW 7 /* Set record locking info (blocking). */
106# else
107# define F_GETLK F_GETLK64 /* Get record locking info. */
108# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
109# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
110# endif
111#endif
112#ifndef F_GETLK64
113# define F_GETLK64 12 /* Get record locking info. */
114# define F_SETLK64 13 /* Set record locking info (non-blocking). */
115# define F_SETLKW64 14 /* Set record locking info (blocking). */
116#endif
117
118/* open file description locks.
119
120 Usually record locks held by a process are released on *any* close and are
121 not inherited across a fork.
122
123 These cmd values will set locks that conflict with process-associated record
124 locks, but are "owned" by the opened file description, not the process.
125 This means that they are inherited across fork or clone with CLONE_FILES
126 like BSD (flock) locks, and they are only released automatically when the
127 last reference to the the file description against which they were acquired
128 is put. */
129#ifdef __USE_GNU
130# define F_OFD_GETLK 36
131# define F_OFD_SETLK 37
132# define F_OFD_SETLKW 38
133#endif
134
135#ifdef __USE_LARGEFILE64
136# define O_LARGEFILE __O_LARGEFILE
137#endif
138
139#ifdef __USE_XOPEN2K8
140# define O_DIRECTORY __O_DIRECTORY /* Must be a directory. */
141# define O_NOFOLLOW __O_NOFOLLOW /* Do not follow links. */
142# define O_CLOEXEC __O_CLOEXEC /* Set close_on_exec. */
143#endif
144
145#ifdef __USE_GNU
146# define O_DIRECT __O_DIRECT /* Direct disk access. */
147# define O_NOATIME __O_NOATIME /* Do not set atime. */
148# define O_PATH __O_PATH /* Resolve pathname but do not open file. */
149# define O_TMPFILE __O_TMPFILE /* Atomically create nameless file. */
150#endif
151
152/* For now, Linux has no separate synchronicity options for read
153 operations. We define O_RSYNC therefore as the same as O_SYNC
154 since this is a superset. */
155#if defined __USE_POSIX199309 || defined __USE_UNIX98
156# define O_DSYNC __O_DSYNC /* Synchronize data. */
157# if defined __O_RSYNC
158# define O_RSYNC __O_RSYNC /* Synchronize read operations. */
159# else
160# define O_RSYNC O_SYNC /* Synchronize read operations. */
161# endif
162#endif
163
164/* Values for the second argument to `fcntl'. */
165#define F_DUPFD 0 /* Duplicate file descriptor. */
166#define F_GETFD 1 /* Get file descriptor flags. */
167#define F_SETFD 2 /* Set file descriptor flags. */
168#define F_GETFL 3 /* Get file status flags. */
169#define F_SETFL 4 /* Set file status flags. */
170
171#ifndef __F_SETOWN
172# define __F_SETOWN 8
173# define __F_GETOWN 9
174#endif
175
176#if defined __USE_UNIX98 || defined __USE_XOPEN2K8
177# define F_SETOWN __F_SETOWN /* Get owner (process receiving SIGIO). */
178# define F_GETOWN __F_GETOWN /* Set owner (process receiving SIGIO). */
179#endif
180
181#ifndef __F_SETSIG
182# define __F_SETSIG 10 /* Set number of signal to be sent. */
183# define __F_GETSIG 11 /* Get number of signal to be sent. */
184#endif
185#ifndef __F_SETOWN_EX
186# define __F_SETOWN_EX 15 /* Get owner (thread receiving SIGIO). */
187# define __F_GETOWN_EX 16 /* Set owner (thread receiving SIGIO). */
188#endif
189
190#ifdef __USE_GNU
191# define F_SETSIG __F_SETSIG /* Set number of signal to be sent. */
192# define F_GETSIG __F_GETSIG /* Get number of signal to be sent. */
193# define F_SETOWN_EX __F_SETOWN_EX /* Get owner (thread receiving SIGIO). */
194# define F_GETOWN_EX __F_GETOWN_EX /* Set owner (thread receiving SIGIO). */
195#endif
196
197#ifdef __USE_GNU
198# define F_SETLEASE 1024 /* Set a lease. */
199# define F_GETLEASE 1025 /* Enquire what lease is active. */
200# define F_NOTIFY 1026 /* Request notifications on a directory. */
201# define F_DUPFD_QUERY 1027 /* Compare two file descriptors for sameness. */
202# define F_CREATED_QUERY 1028 /* Was the file just created? */
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
212#endif
213#ifdef __USE_XOPEN2K8
214# define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
215 close-on-exit set. */
216#endif
217
218/* For F_[GET|SET]FD. */
219#define FD_CLOEXEC 1 /* Actually anything with low bit set goes */
220#ifdef __USE_GNU
221# define FD_PIDFS_ROOT -10002 /* Root of the pidfs filesystem */
222#endif
223
224#ifndef F_RDLCK
225/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
226# define F_RDLCK 0 /* Read lock. */
227# define F_WRLCK 1 /* Write lock. */
228# define F_UNLCK 2 /* Remove lock. */
229#endif
230
231
232/* For old implementation of BSD flock. */
233#ifndef F_EXLCK
234# define F_EXLCK 4 /* or 3 */
235# define F_SHLCK 8 /* or 4 */
236#endif
237
238#ifdef __USE_MISC
239/* Operations for BSD flock, also used by the kernel implementation. */
240# define LOCK_SH 1 /* Shared lock. */
241# define LOCK_EX 2 /* Exclusive lock. */
242# define LOCK_NB 4 /* Or'd with one of the above to prevent
243 blocking. */
244# define LOCK_UN 8 /* Remove lock. */
245#endif
246
247#ifdef __USE_GNU
248# define LOCK_MAND 32 /* This is a mandatory flock: */
249# define LOCK_READ 64 /* ... which allows concurrent read operations. */
250# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
251# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
252#endif
253
254#ifdef __USE_GNU
255/* Types of directory notifications that may be requested with F_NOTIFY. */
256# define DN_ACCESS 0x00000001 /* File accessed. */
257# define DN_MODIFY 0x00000002 /* File modified. */
258# define DN_CREATE 0x00000004 /* File created. */
259# define DN_DELETE 0x00000008 /* File removed. */
260# define DN_RENAME 0x00000010 /* File renamed. */
261# define DN_ATTRIB 0x00000020 /* File changed attributes. */
262# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
263#endif
264
265
266#ifdef __USE_GNU
267/* Owner types. */
268enum __pid_type
269 {
270 F_OWNER_TID = 0, /* Kernel thread. */
271 F_OWNER_PID, /* Process. */
272 F_OWNER_PGRP, /* Process group. */
273 F_OWNER_GID = F_OWNER_PGRP /* Alternative, obsolete name. */
274 };
275
276/* Structure to use with F_GETOWN_EX and F_SETOWN_EX. */
277struct f_owner_ex
278 {
279 enum __pid_type type; /* Owner type of ID. */
280 __pid_t pid; /* ID of owner. */
281 };
282#endif
283
284#ifdef __USE_GNU
285/* Types of seals. */
286# define F_SEAL_SEAL 0x0001 /* Prevent further seals from being set. */
287# define F_SEAL_SHRINK 0x0002 /* Prevent file from shrinking. */
288# define F_SEAL_GROW 0x0004 /* Prevent file from growing. */
289# define F_SEAL_WRITE 0x0008 /* Prevent writes. */
290# define F_SEAL_FUTURE_WRITE 0x0010 /* Prevent future writes while
291 mapped. */
292# define F_SEAL_EXEC 0x0020 /* Prevent chmod modifying exec bits. */
293#endif
294
295#ifdef __USE_GNU
296/* Hint values for F_{GET,SET}_RW_HINT. */
297# define RWH_WRITE_LIFE_NOT_SET 0
298# define RWF_WRITE_LIFE_NOT_SET RWH_WRITE_LIFE_NOT_SET
299# define RWH_WRITE_LIFE_NONE 1
300# define RWH_WRITE_LIFE_SHORT 2
301# define RWH_WRITE_LIFE_MEDIUM 3
302# define RWH_WRITE_LIFE_LONG 4
303# define RWH_WRITE_LIFE_EXTREME 5
304#endif
305
306/* Define some more compatibility macros to be backward compatible with
307 BSD systems which did not managed to hide these kernel macros. */
308#ifdef __USE_MISC
309# define FAPPEND O_APPEND
310# define FFSYNC O_FSYNC
311# define FASYNC O_ASYNC
312# define FNONBLOCK O_NONBLOCK
313# define FNDELAY O_NDELAY
314#endif /* Use misc. */
315
316#ifndef __POSIX_FADV_DONTNEED
317# define __POSIX_FADV_DONTNEED 4
318# define __POSIX_FADV_NOREUSE 5
319#endif
320/* Advise to `posix_fadvise'. */
321#ifdef __USE_XOPEN2K
322# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
323# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
324# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
325# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
326# define POSIX_FADV_DONTNEED __POSIX_FADV_DONTNEED /* Don't need these pages. */
327# define POSIX_FADV_NOREUSE __POSIX_FADV_NOREUSE /* Data will be accessed once. */
328#endif
329
330
331#ifdef __USE_GNU
332/* Flags for SYNC_FILE_RANGE. */
333# define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages
334 in the range before performing the
335 write. */
336# define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those
337 dirty pages in the range which are
338 not presently under writeback. */
339# define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in
340 the range after performing the
341 write. */
342/* SYNC_FILE_RANGE_WRITE_AND_WAIT ensures all pages in the range are
343 written to disk before returning. */
344# define SYNC_FILE_RANGE_WRITE_AND_WAIT (SYNC_FILE_RANGE_WRITE \
345 | SYNC_FILE_RANGE_WAIT_BEFORE \
346 | SYNC_FILE_RANGE_WAIT_AFTER)
347
348/* Flags for SPLICE and VMSPLICE. */
349# define SPLICE_F_MOVE 1 /* Move pages instead of copying. */
350# define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing
351 (but we may still block on the fd
352 we splice from/to). */
353# define SPLICE_F_MORE 4 /* Expect more data. */
354# define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */
355
356
357/* Flags for fallocate. */
358# include <linux/falloc.h>
359
360
361/* File handle structure. */
362struct file_handle
363{
364 unsigned int handle_bytes;
365 int handle_type;
366 /* File identifier. */
367 unsigned char f_handle[0];
368};
369
370/* Maximum handle size (for now). */
371# define MAX_HANDLE_SZ 128
372#endif
373
374#ifdef __USE_GNU
375/* Flags for name_to_handle_at. See comment in fcntl.h about the use
376 of the same AT_* flag bits for different purposes in different
377 functions. */
378# define AT_HANDLE_FID AT_REMOVEDIR /* File handle is needed
379 to compare object
380 identity and may not
381 be usable to
382 open_by_handle_at. */
383# define AT_HANDLE_MNT_ID_UNIQUE 1 /* Return the 64-bit unique mount
384 ID. */
385# define AT_HANDLE_CONNECTABLE 2 /* Request a connectable file handle */
386
387/* Flags for execveat2(2). */
388# define AT_EXECVE_CHECK 0x10000 /* Only perform a check if execution
389 would be allowed */
390#endif
391
392__BEGIN_DECLS
393
394#ifdef __USE_GNU
395
396/* Provide kernel hint to read ahead. */
397extern __ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
398 __THROW;
399
400
401/* Selective file content synch'ing.
402
403 This function is a possible cancellation point and therefore not
404 marked with __THROW. */
405extern int sync_file_range (int __fd, __off64_t __offset, __off64_t __count,
406 unsigned int __flags);
407
408
409/* Splice address range into a pipe.
410
411 This function is a possible cancellation point and therefore not
412 marked with __THROW. */
413extern __ssize_t vmsplice (int __fdout, const struct iovec *__iov,
414 size_t __count, unsigned int __flags);
415
416/* Splice two files together.
417
418 This function is a possible cancellation point and therefore not
419 marked with __THROW. */
420extern __ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
421 __off64_t *__offout, size_t __len,
422 unsigned int __flags);
423
424/* In-kernel implementation of tee for pipe buffers.
425
426 This function is a possible cancellation point and therefore not
427 marked with __THROW. */
428extern __ssize_t tee (int __fdin, int __fdout, size_t __len,
429 unsigned int __flags);
430
431/* Reserve storage for the data of the file associated with FD.
432
433 This function is a possible cancellation point and therefore not
434 marked with __THROW. */
435# ifndef __USE_FILE_OFFSET64
436extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len);
437# else
438# ifdef __REDIRECT
439extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset,
440 __off64_t __len),
441 fallocate64);
442# else
443# define fallocate fallocate64
444# endif
445# endif
446# ifdef __USE_LARGEFILE64
447extern int fallocate64 (int __fd, int __mode, __off64_t __offset,
448 __off64_t __len);
449# endif
450
451
452/* Map file name to file handle. */
453extern int name_to_handle_at (int __dfd, const char *__name,
454 struct file_handle *__handle, int *__mnt_id,
455 int __flags) __THROW;
456
457/* Open file using the file handle.
458
459 This function is a possible cancellation point and therefore not
460 marked with __THROW. */
461extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle,
462 int __flags);
463
464#ifdef __has_include
465# if __has_include ("linux/openat2.h")
466# include "linux/openat2.h"
467# define __glibc_has_open_how 1
468# endif
469#endif
470
471#include <bits/openat2.h>
472
473/* Similar to `openat' but the arguments are packed on HOW with the size
474 USIZE. If flags and mode from HOW are non-zero, then openat2 operates
475 like openat.
476
477 Unlike openat, unknown or invalid flags result in an error (EINVAL),
478 rather than being ignored. The mode must be zero unless one of O_CREAT
479 or O_TMPFILE are set.
480
481 The kernel does not support legacy non-LFS interface. */
482extern int openat2 (int __dfd, const char * __filename,
483 const struct open_how * __how,
484 __SIZE_TYPE__ __usize)
485 __nonnull ((2, 3));
486
487#endif /* use GNU */
488
489#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
490# include <bits/fcntl-linux-fortify.h>
491#endif
492
493__END_DECLS
494