Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h
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 #ifndef __O_CLOEXEC 85 # define __O_CLOEXEC 02000000 86 #endif 87 #ifndef __O_DIRECT 88 # define __O_DIRECT 040000 89 #endif 90 #ifndef __O_NOATIME 91 # define __O_NOATIME 01000000 92 #endif 93 #ifndef __O_PATH 94 # define __O_PATH 010000000 95 #endif 96 #ifndef __O_DSYNC 97 # define __O_DSYNC 010000 98 #endif 99 #ifndef __O_TMPFILE 100 # define __O_TMPFILE (020000000 | __O_DIRECTORY) 101 #endif 102 103 #ifndef F_GETLK 104 # if !defined __USE_FILE_OFFSET64 && __TIMESIZE != 64 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). */ 108 # else 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). */ 112 # endif 113 #endif 114 #ifndef F_GETLK64 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). */ 118 #endif 119 120 /* open file description locks. 121 122 Usually record locks held by a process are released on *any* close and are 123 not inherited across a fork. 124 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 130 is put. */ 131 #ifdef __USE_GNU 132 # define F_OFD_GETLK 36 133 # define F_OFD_SETLK 37 134 # define F_OFD_SETLKW 38 135 #endif 136 137 #ifdef __USE_LARGEFILE64 138 # define O_LARGEFILE __O_LARGEFILE 139 #endif 140 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. */ 145 #endif 146 147 #ifdef __USE_GNU 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. */ 152 #endif 153 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. */ 161 # else 162 # define O_RSYNC O_SYNC /* Synchronize read operations. */ 163 # endif 164 #endif 165 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. */ 172 173 #ifndef __F_SETOWN 174 # define __F_SETOWN 8 175 # define __F_GETOWN 9 176 #endif 177 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). */ 181 #endif 182 183 #ifndef __F_SETSIG 184 # define __F_SETSIG 10 /* Set number of signal to be sent. */ 185 # define __F_GETSIG 11 /* Get number of signal to be sent. */ 186 #endif 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). */ 190 #endif 191 192 #ifdef __USE_GNU 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). */ 197 #endif 198 199 #ifdef __USE_GNU 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_DUPFD_QUERY 1027 /* Compare two file descriptors for sameness. */ 204 # define F_CREATED_QUERY 1028 /* Was the file just created? */ 205 # define F_SETPIPE_SZ 1031 /* Set pipe page size array. */ 206 # define F_GETPIPE_SZ 1032 /* Set pipe page size array. */ 207 # define F_ADD_SEALS 1033 /* Add seals to file. */ 208 # define F_GET_SEALS 1034 /* Get seals for file. */ 209 /* Set / get write life time hints. */ 210 # define F_GET_RW_HINT 1035 211 # define F_SET_RW_HINT 1036 212 # define F_GET_FILE_RW_HINT 1037 213 # define F_SET_FILE_RW_HINT 1038 214 #endif 215 #ifdef __USE_XOPEN2K8 216 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with 217 close-on-exit set. */ 218 #endif 219 220 /* For F_[GET|SET]FD. */ 221 #define FD_CLOEXEC 1 /* Actually anything with low bit set goes */ 222 #ifdef __USE_GNU 223 # define FD_PIDFS_ROOT -10002 /* Root of the pidfs filesystem */ 224 #endif 225 226 #ifndef F_RDLCK 227 /* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */ 228 # define F_RDLCK 0 /* Read lock. */ 229 # define F_WRLCK 1 /* Write lock. */ 230 # define F_UNLCK 2 /* Remove lock. */ 231 #endif 232 233 234 /* For old implementation of BSD flock. */ 235 #ifndef F_EXLCK 236 # define F_EXLCK 4 /* or 3 */ 237 # define F_SHLCK 8 /* or 4 */ 238 #endif 239 240 #ifdef __USE_MISC 241 /* Operations for BSD flock, also used by the kernel implementation. */ 242 # define LOCK_SH 1 /* Shared lock. */ 243 # define LOCK_EX 2 /* Exclusive lock. */ 244 # define LOCK_NB 4 /* Or'd with one of the above to prevent 245 blocking. */ 246 # define LOCK_UN 8 /* Remove lock. */ 247 #endif 248 249 #ifdef __USE_GNU 250 # define LOCK_MAND 32 /* This is a mandatory flock: */ 251 # define LOCK_READ 64 /* ... which allows concurrent read operations. */ 252 # define LOCK_WRITE 128 /* ... which allows concurrent write operations. */ 253 # define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */ 254 #endif 255 256 #ifdef __USE_GNU 257 /* Types of directory notifications that may be requested with F_NOTIFY. */ 258 # define DN_ACCESS 0x00000001 /* File accessed. */ 259 # define DN_MODIFY 0x00000002 /* File modified. */ 260 # define DN_CREATE 0x00000004 /* File created. */ 261 # define DN_DELETE 0x00000008 /* File removed. */ 262 # define DN_RENAME 0x00000010 /* File renamed. */ 263 # define DN_ATTRIB 0x00000020 /* File changed attributes. */ 264 # define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */ 265 #endif 266 267 268 #ifdef __USE_GNU 269 /* Owner types. */ 270 enum __pid_type 271 { 272 F_OWNER_TID = 0, /* Kernel thread. */ 273 F_OWNER_PID, /* Process. */ 274 F_OWNER_PGRP, /* Process group. */ 275 F_OWNER_GID = F_OWNER_PGRP /* Alternative, obsolete name. */ 276 }; 277 278 /* Structure to use with F_GETOWN_EX and F_SETOWN_EX. */ 279 struct f_owner_ex 280 { 281 enum __pid_type type; /* Owner type of ID. */ 282 __pid_t pid; /* ID of owner. */ 283 }; 284 #endif 285 286 #ifdef __USE_GNU 287 /* Types of seals. */ 288 # define F_SEAL_SEAL 0x0001 /* Prevent further seals from being set. */ 289 # define F_SEAL_SHRINK 0x0002 /* Prevent file from shrinking. */ 290 # define F_SEAL_GROW 0x0004 /* Prevent file from growing. */ 291 # define F_SEAL_WRITE 0x0008 /* Prevent writes. */ 292 # define F_SEAL_FUTURE_WRITE 0x0010 /* Prevent future writes while 293 mapped. */ 294 # define F_SEAL_EXEC 0x0020 /* Prevent chmod modifying exec bits. */ 295 #endif 296 297 #ifdef __USE_GNU 298 /* Hint values for F_{GET,SET}_RW_HINT. */ 299 # define RWH_WRITE_LIFE_NOT_SET 0 300 # define RWF_WRITE_LIFE_NOT_SET RWH_WRITE_LIFE_NOT_SET 301 # define RWH_WRITE_LIFE_NONE 1 302 # define RWH_WRITE_LIFE_SHORT 2 303 # define RWH_WRITE_LIFE_MEDIUM 3 304 # define RWH_WRITE_LIFE_LONG 4 305 # define RWH_WRITE_LIFE_EXTREME 5 306 #endif 307 308 /* Define some more compatibility macros to be backward compatible with 309 BSD systems which did not managed to hide these kernel macros. */ 310 #ifdef __USE_MISC 311 # define FAPPEND O_APPEND 312 # define FFSYNC O_FSYNC 313 # define FASYNC O_ASYNC 314 # define FNONBLOCK O_NONBLOCK 315 # define FNDELAY O_NDELAY 316 #endif /* Use misc. */ 317 318 #ifndef __POSIX_FADV_DONTNEED 319 # define __POSIX_FADV_DONTNEED 4 320 # define __POSIX_FADV_NOREUSE 5 321 #endif 322 /* Advise to `posix_fadvise'. */ 323 #ifdef __USE_XOPEN2K 324 # define POSIX_FADV_NORMAL 0 /* No further special treatment. */ 325 # define POSIX_FADV_RANDOM 1 /* Expect random page references. */ 326 # define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */ 327 # define POSIX_FADV_WILLNEED 3 /* Will need these pages. */ 328 # define POSIX_FADV_DONTNEED __POSIX_FADV_DONTNEED /* Don't need these pages. */ 329 # define POSIX_FADV_NOREUSE __POSIX_FADV_NOREUSE /* Data will be accessed once. */ 330 #endif 331 332 333 #ifdef __USE_GNU 334 /* Flags for SYNC_FILE_RANGE. */ 335 # define SYNC_FILE_RANGE_WAIT_BEFORE 1 /* Wait upon writeout of all pages 336 in the range before performing the 337 write. */ 338 # define SYNC_FILE_RANGE_WRITE 2 /* Initiate writeout of all those 339 dirty pages in the range which are 340 not presently under writeback. */ 341 # define SYNC_FILE_RANGE_WAIT_AFTER 4 /* Wait upon writeout of all pages in 342 the range after performing the 343 write. */ 344 /* SYNC_FILE_RANGE_WRITE_AND_WAIT ensures all pages in the range are 345 written to disk before returning. */ 346 # define SYNC_FILE_RANGE_WRITE_AND_WAIT (SYNC_FILE_RANGE_WRITE \ 347 | SYNC_FILE_RANGE_WAIT_BEFORE \ 348 | SYNC_FILE_RANGE_WAIT_AFTER) 349 350 /* Flags for SPLICE and VMSPLICE. */ 351 # define SPLICE_F_MOVE 1 /* Move pages instead of copying. */ 352 # define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing 353 (but we may still block on the fd 354 we splice from/to). */ 355 # define SPLICE_F_MORE 4 /* Expect more data. */ 356 # define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */ 357 358 359 /* Flags for fallocate. */ 360 # include <linux/falloc.h> 361 362 363 /* File handle structure. */ 364 struct file_handle 365 { 366 unsigned int handle_bytes; 367 int handle_type; 368 /* File identifier. */ 369 unsigned char f_handle[0]; 370 }; 371 372 /* Maximum handle size (for now). */ 373 # define MAX_HANDLE_SZ 128 374 #endif 375 376 #ifdef __USE_GNU 377 /* Flags for name_to_handle_at. See comment in fcntl.h about the use 378 of the same AT_* flag bits for different purposes in different 379 functions. */ 380 # define AT_HANDLE_FID AT_REMOVEDIR /* File handle is needed 381 to compare object 382 identity and may not 383 be usable to 384 open_by_handle_at. */ 385 # define AT_HANDLE_MNT_ID_UNIQUE 1 /* Return the 64-bit unique mount 386 ID. */ 387 # define AT_HANDLE_CONNECTABLE 2 /* Request a connectable file handle */ 388 389 /* Flags for execveat2(2). */ 390 # define AT_EXECVE_CHECK 0x10000 /* Only perform a check if execution 391 would be allowed */ 392 #endif 393 394 __BEGIN_DECLS 395 396 #ifdef __USE_GNU 397 398 /* Provide kernel hint to read ahead. */ 399 extern __ssize_t readahead (int __fd, __off64_t __offset, size_t __count) 400 __THROW; 401 402 403 /* Selective file content synch'ing. 404 405 This function is a possible cancellation point and therefore not 406 marked with __THROW. */ 407 extern int sync_file_range (int __fd, __off64_t __offset, __off64_t __count, 408 unsigned int __flags); 409 410 411 /* Splice address range into a pipe. 412 413 This function is a possible cancellation point and therefore not 414 marked with __THROW. */ 415 extern __ssize_t vmsplice (int __fdout, const struct iovec *__iov, 416 size_t __count, unsigned int __flags); 417 418 /* Splice two files together. 419 420 This function is a possible cancellation point and therefore not 421 marked with __THROW. */ 422 extern __ssize_t splice (int __fdin, __off64_t *__offin, int __fdout, 423 __off64_t *__offout, size_t __len, 424 unsigned int __flags); 425 426 /* In-kernel implementation of tee for pipe buffers. 427 428 This function is a possible cancellation point and therefore not 429 marked with __THROW. */ 430 extern __ssize_t tee (int __fdin, int __fdout, size_t __len, 431 unsigned int __flags); 432 433 /* Reserve storage for the data of the file associated with FD. 434 435 This function is a possible cancellation point and therefore not 436 marked with __THROW. */ 437 # ifndef __USE_FILE_OFFSET64 438 extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len); 439 # else 440 # ifdef __REDIRECT 441 extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset, 442 __off64_t __len), 443 fallocate64); 444 # else 445 # define fallocate fallocate64 446 # endif 447 # endif 448 # ifdef __USE_LARGEFILE64 449 extern int fallocate64 (int __fd, int __mode, __off64_t __offset, 450 __off64_t __len); 451 # endif 452 453 454 /* Map file name to file handle. */ 455 extern int name_to_handle_at (int __dfd, const char *__name, 456 struct file_handle *__handle, int *__mnt_id, 457 int __flags) __THROW; 458 459 /* Open file using the file handle. 460 461 This function is a possible cancellation point and therefore not 462 marked with __THROW. */ 463 extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle, 464 int __flags); 465 466 #ifdef __has_include 467 # if __has_include ("linux/openat2.h") 468 # include "linux/openat2.h" 469 # define __glibc_has_open_how 1 470 # endif 471 #endif 472 473 #include <bits/openat2.h> 474 475 /* Similar to `openat' but the arguments are packed on HOW with the size 476 USIZE. If flags and mode from HOW are non-zero, then openat2 operates 477 like openat. 478 479 Unlike openat, unknown or invalid flags result in an error (EINVAL), 480 rather than being ignored. The mode must be zero unless one of O_CREAT 481 or O_TMPFILE are set. 482 483 The kernel does not support legacy non-LFS interface. */ 484 extern int openat2 (int __dfd, const char * __filename, 485 const struct open_how * __how, 486 __SIZE_TYPE__ __usize) 487 __nonnull ((2, 3)); 488 489 #endif /* use GNU */ 490 491 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function 492 # include <bits/fcntl-linux-fortify.h> 493 #endif 494 495 __END_DECLS