1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 27 /* All Rights Reserved */ 28 29 /* 30 * University Copyright- Copyright (c) 1982, 1986, 1988 31 * The Regents of the University of California 32 * All Rights Reserved 33 * 34 * University Acknowledgment- Portions of this document are derived from 35 * software developed by the University of California, Berkeley, and its 36 * contributors. 37 */ 38 39 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */ 40 /* Copyright 2020 Joyent, Inc. */ 41 42 #ifndef _SYS_FCNTL_H 43 #define _SYS_FCNTL_H 44 45 #include <sys/feature_tests.h> 46 47 #include <sys/types.h> 48 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /* 54 * Flag values accessible to open(2) and fcntl(2) 55 * The first five can only be set (exclusively) by open(2). 56 */ 57 #define O_RDONLY 0 58 #define O_WRONLY 1 59 #define O_RDWR 2 60 #define O_SEARCH 0x200000 61 #define O_EXEC 0x400000 62 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) 63 #define O_NDELAY 0x04 /* non-blocking I/O */ 64 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) */ 65 #define O_APPEND 0x08 /* append (writes guaranteed at the end) */ 66 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \ 67 (_POSIX_C_SOURCE > 2) || defined(_XOPEN_SOURCE) 68 #define O_SYNC 0x10 /* synchronized file update option */ 69 #define O_DSYNC 0x40 /* synchronized data update option */ 70 #define O_RSYNC 0x8000 /* synchronized file update option */ 71 /* defines read/write file integrity */ 72 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */ 73 #define O_NONBLOCK 0x80 /* non-blocking I/O (POSIX) */ 74 #ifdef _LARGEFILE_SOURCE 75 #define O_LARGEFILE 0x2000 76 #endif 77 78 /* 79 * Flag values accessible only to open(2). 80 */ 81 #define O_CREAT 0x100 /* open with file create (uses third arg) */ 82 #define O_TRUNC 0x200 /* open with truncation */ 83 #define O_EXCL 0x400 /* exclusive open */ 84 #define O_NOCTTY 0x800 /* don't allocate controlling tty (POSIX) */ 85 #define O_XATTR 0x4000 /* extended attribute */ 86 #define O_NOFOLLOW 0x20000 /* don't follow symlinks */ 87 #define O_NOLINKS 0x40000 /* don't allow multiple hard links */ 88 #define O_CLOEXEC 0x800000 /* set the close-on-exec flag */ 89 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7) 90 #define O_DIRECTORY 0x1000000 /* fail if not a directory */ 91 #endif 92 #if !defined(_STRICT_SYMBOLS) 93 #define O_DIRECT 0x2000000 /* direct disk access hint */ 94 #endif 95 96 /* 97 * fcntl(2) requests 98 * 99 * N.B.: values are not necessarily assigned sequentially below. 100 */ 101 #define F_DUPFD 0 /* Duplicate fildes */ 102 #define F_GETFD 1 /* Get fildes flags */ 103 #define F_SETFD 2 /* Set fildes flags */ 104 #define F_GETFL 3 /* Get file flags */ 105 #define F_GETXFL 45 /* Get file flags including open-only flags */ 106 #define F_SETFL 4 /* Set file flags */ 107 108 /* 109 * Applications that read /dev/mem must be built like the kernel. A 110 * new symbol "_KMEMUSER" is defined for this purpose. 111 */ 112 #if defined(_KERNEL) || defined(_KMEMUSER) 113 #define F_O_GETLK 5 /* SVR3 Get file lock (need for rfs, across */ 114 /* the wire compatibility */ 115 /* clustering: lock id contains both per-node sysid and node id */ 116 #define SYSIDMASK 0x0000ffff 117 #define GETSYSID(id) (id & SYSIDMASK) 118 #define NODEIDMASK 0xffff0000 119 #define BITS_IN_SYSID 16 120 #define GETNLMID(sysid) ((int)(((uint_t)(sysid) & NODEIDMASK) >> \ 121 BITS_IN_SYSID)) 122 123 /* Clustering: Macro used for PXFS locks */ 124 #define GETPXFSID(sysid) ((int)(((uint_t)(sysid) & NODEIDMASK) >> \ 125 BITS_IN_SYSID)) 126 #endif /* defined(_KERNEL) */ 127 128 #define F_CHKFL 8 /* Unused */ 129 #define F_DUP2FD 9 /* Duplicate fildes at third arg */ 130 #define F_DUP2FD_CLOEXEC 36 /* Like F_DUP2FD with O_CLOEXEC set */ 131 /* EINVAL is fildes matches arg1 */ 132 #define F_DUPFD_CLOEXEC 37 /* Like F_DUPFD with O_CLOEXEC set */ 133 134 #define F_ISSTREAM 13 /* Is the file desc. a stream ? */ 135 #define F_PRIV 15 /* Turn on private access to file */ 136 #define F_NPRIV 16 /* Turn off private access to file */ 137 #define F_QUOTACTL 17 /* UFS quota call */ 138 #define F_BLOCKS 18 /* Get number of BLKSIZE blocks allocated */ 139 #define F_BLKSIZE 19 /* Get optimal I/O block size */ 140 /* 141 * Numbers 20-22 have been removed and should not be reused. 142 */ 143 #define F_GETOWN 23 /* Get owner (socket emulation) */ 144 #define F_SETOWN 24 /* Set owner (socket emulation) */ 145 #define F_REVOKE 25 /* Object reuse revoke access to file desc. */ 146 147 #define F_HASREMOTELOCKS 26 /* Does vp have NFS locks; private to lock */ 148 /* manager */ 149 150 /* 151 * Commands that refer to flock structures. The argument types differ between 152 * the large and small file environments; therefore, the #defined values must 153 * as well. 154 * The NBMAND forms are private and should not be used. 155 * The FLOCK forms are also private and should not be used. 156 */ 157 158 #if defined(_LP64) || _FILE_OFFSET_BITS == 32 159 /* "Native" application compilation environment */ 160 #define F_SETLK 6 /* Set file lock */ 161 #define F_SETLKW 7 /* Set file lock and wait */ 162 #define F_ALLOCSP 10 /* Allocate file space */ 163 #define F_FREESP 11 /* Free file space */ 164 #define F_GETLK 14 /* Get file lock */ 165 #define F_SETLK_NBMAND 42 /* private */ 166 #if !defined(_STRICT_SYMBOLS) 167 #define F_OFD_GETLK 47 /* Get file lock owned by file */ 168 #define F_OFD_SETLK 48 /* Set file lock owned by file */ 169 #define F_OFD_SETLKW 49 /* Set file lock owned by file and wait */ 170 #define F_FLOCK 53 /* private - set flock owned by file */ 171 #define F_FLOCKW 54 /* private - set flock owned by file and wait */ 172 #endif /* _STRICT_SYMBOLS */ 173 #else 174 /* ILP32 large file application compilation environment version */ 175 #define F_SETLK 34 /* Set file lock */ 176 #define F_SETLKW 35 /* Set file lock and wait */ 177 #define F_ALLOCSP 28 /* Alllocate file space */ 178 #define F_FREESP 27 /* Free file space */ 179 #define F_GETLK 33 /* Get file lock */ 180 #define F_SETLK_NBMAND 44 /* private */ 181 #if !defined(_STRICT_SYMBOLS) 182 #define F_OFD_GETLK 50 /* Get file lock owned by file */ 183 #define F_OFD_SETLK 51 /* Set file lock owned by file */ 184 #define F_OFD_SETLKW 52 /* Set file lock owned by file and wait */ 185 #define F_FLOCK 55 /* private - set flock owned by file */ 186 #define F_FLOCKW 56 /* private - set flock owned by file and wait */ 187 #endif /* _STRICT_SYMBOLS */ 188 #endif /* _LP64 || _FILE_OFFSET_BITS == 32 */ 189 190 #if defined(_LARGEFILE64_SOURCE) 191 192 #if !defined(_LP64) || defined(_KERNEL) 193 /* 194 * transitional large file interface version 195 * These are only valid in a 32 bit application compiled with large files 196 * option, for source compatibility, the 64-bit versions are mapped back 197 * to the native versions. 198 */ 199 #define F_SETLK64 34 /* Set file lock */ 200 #define F_SETLKW64 35 /* Set file lock and wait */ 201 #define F_ALLOCSP64 28 /* Allocate file space */ 202 #define F_FREESP64 27 /* Free file space */ 203 #define F_GETLK64 33 /* Get file lock */ 204 #define F_SETLK64_NBMAND 44 /* private */ 205 #if !defined(_STRICT_SYMBOLS) 206 #define F_OFD_GETLK64 50 /* Get file lock owned by file */ 207 #define F_OFD_SETLK64 51 /* Set file lock owned by file */ 208 #define F_OFD_SETLKW64 52 /* Set file lock owned by file and wait */ 209 #define F_FLOCK64 55 /* private - set flock owned by file */ 210 #define F_FLOCKW64 56 /* private - set flock owned by file and wait */ 211 #endif /* _STRICT_SYMBOLS */ 212 #else 213 #define F_SETLK64 6 /* Set file lock */ 214 #define F_SETLKW64 7 /* Set file lock and wait */ 215 #define F_ALLOCSP64 10 /* Allocate file space */ 216 #define F_FREESP64 11 /* Free file space */ 217 #define F_GETLK64 14 /* Get file lock */ 218 #define F_SETLK64_NBMAND 42 /* private */ 219 #if !defined(_STRICT_SYMBOLS) 220 #define F_OFD_GETLK64 47 /* Get file lock owned by file */ 221 #define F_OFD_SETLK64 48 /* Set file lock owned by file */ 222 #define F_OFD_SETLKW64 49 /* Set file lock owned by file and wait */ 223 #define F_FLOCK64 53 /* private - set flock owned by file */ 224 #define F_FLOCKW64 54 /* private - set flock owned by file and wait */ 225 #endif /* _STRICT_SYMBOLS */ 226 #endif /* !_LP64 || _KERNEL */ 227 228 #endif /* _LARGEFILE64_SOURCE */ 229 230 #define F_SHARE 40 /* Set a file share reservation */ 231 #define F_UNSHARE 41 /* Remove a file share reservation */ 232 #define F_SHARE_NBMAND 43 /* private */ 233 234 #define F_BADFD 46 /* Create Poison FD */ 235 236 /* 237 * File segment locking set data type - information passed to system by user. 238 */ 239 240 /* regular version, for both small and large file compilation environment */ 241 typedef struct flock { 242 short l_type; 243 short l_whence; 244 off_t l_start; 245 off_t l_len; /* len == 0 means until end of file */ 246 int l_sysid; 247 pid_t l_pid; 248 long l_pad[4]; /* reserve area */ 249 } flock_t; 250 251 #if defined(_SYSCALL32) 252 253 /* Kernel's view of ILP32 flock structure */ 254 255 typedef struct flock32 { 256 int16_t l_type; 257 int16_t l_whence; 258 off32_t l_start; 259 off32_t l_len; /* len == 0 means until end of file */ 260 int32_t l_sysid; 261 pid32_t l_pid; 262 int32_t l_pad[4]; /* reserve area */ 263 } flock32_t; 264 265 #endif /* _SYSCALL32 */ 266 267 /* transitional large file interface version */ 268 269 #if defined(_LARGEFILE64_SOURCE) 270 271 typedef struct flock64 { 272 short l_type; 273 short l_whence; 274 off64_t l_start; 275 off64_t l_len; /* len == 0 means until end of file */ 276 int l_sysid; 277 pid_t l_pid; 278 long l_pad[4]; /* reserve area */ 279 } flock64_t; 280 281 #if defined(_SYSCALL32) 282 283 /* Kernel's view of ILP32 flock64 */ 284 285 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 286 #pragma pack(4) 287 #endif 288 289 typedef struct flock64_32 { 290 int16_t l_type; 291 int16_t l_whence; 292 off64_t l_start; 293 off64_t l_len; /* len == 0 means until end of file */ 294 int32_t l_sysid; 295 pid32_t l_pid; 296 int32_t l_pad[4]; /* reserve area */ 297 } flock64_32_t; 298 299 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 300 #pragma pack() 301 #endif 302 303 /* Kernel's view of LP64 flock64 */ 304 305 typedef struct flock64_64 { 306 int16_t l_type; 307 int16_t l_whence; 308 off64_t l_start; 309 off64_t l_len; /* len == 0 means until end of file */ 310 int32_t l_sysid; 311 pid32_t l_pid; 312 int64_t l_pad[4]; /* reserve area */ 313 } flock64_64_t; 314 315 #endif /* _SYSCALL32 */ 316 317 #endif /* _LARGEFILE64_SOURCE */ 318 319 #if defined(_KERNEL) || defined(_KMEMUSER) 320 /* SVr3 flock type; needed for rfs across the wire compatibility */ 321 typedef struct o_flock { 322 int16_t l_type; 323 int16_t l_whence; 324 int32_t l_start; 325 int32_t l_len; /* len == 0 means until end of file */ 326 int16_t l_sysid; 327 int16_t l_pid; 328 } o_flock_t; 329 #endif /* defined(_KERNEL) */ 330 331 /* 332 * File segment locking types. 333 */ 334 #define F_RDLCK 01 /* Read lock */ 335 #define F_WRLCK 02 /* Write lock */ 336 #define F_UNLCK 03 /* Remove lock(s) */ 337 #define F_UNLKSYS 04 /* remove remote locks for a given system */ 338 339 /* 340 * POSIX constants 341 */ 342 343 /* Mask for file access modes */ 344 #define O_ACCMODE (O_SEARCH | O_EXEC | 0x3) 345 #define FD_CLOEXEC 1 /* close on exec flag */ 346 347 /* 348 * DIRECTIO 349 */ 350 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) 351 #define DIRECTIO_OFF (0) 352 #define DIRECTIO_ON (1) 353 354 /* 355 * File share reservation type 356 */ 357 typedef struct fshare { 358 short f_access; 359 short f_deny; 360 int f_id; 361 } fshare_t; 362 363 /* 364 * f_access values 365 */ 366 #define F_RDACC 0x1 /* Read-only share access */ 367 #define F_WRACC 0x2 /* Write-only share access */ 368 #define F_RWACC 0x3 /* Read-Write share access */ 369 #define F_RMACC 0x4 /* private flag: Delete share access */ 370 #define F_MDACC 0x20 /* private flag: Metadata share access */ 371 372 /* 373 * f_deny values 374 */ 375 #define F_NODNY 0x0 /* Don't deny others access */ 376 #define F_RDDNY 0x1 /* Deny others read share access */ 377 #define F_WRDNY 0x2 /* Deny others write share access */ 378 #define F_RWDNY 0x3 /* Deny others read or write share access */ 379 #define F_RMDNY 0x4 /* private flag: Deny delete share access */ 380 #define F_COMPAT 0x8 /* Set share to old DOS compatibility mode */ 381 #define F_MANDDNY 0x10 /* private flag: mandatory enforcement */ 382 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */ 383 384 /* 385 * Special flags for functions such as openat(), fstatat().... 386 */ 387 #if !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE) || \ 388 defined(__EXTENSIONS__) 389 /* || defined(_XPG7) */ 390 #define AT_FDCWD 0xffd19553 391 #define AT_SYMLINK_NOFOLLOW 0x1000 392 #define AT_SYMLINK_FOLLOW 0x2000 /* only for linkat() */ 393 #define AT_REMOVEDIR 0x1 394 #define _AT_TRIGGER 0x2 395 #define AT_EACCESS 0x4 /* use EUID/EGID for access */ 396 #endif 397 398 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 399 /* advice for posix_fadvise */ 400 #define POSIX_FADV_NORMAL 0 401 #define POSIX_FADV_RANDOM 1 402 #define POSIX_FADV_SEQUENTIAL 2 403 #define POSIX_FADV_WILLNEED 3 404 #define POSIX_FADV_DONTNEED 4 405 #define POSIX_FADV_NOREUSE 5 406 #endif 407 408 #ifdef __cplusplus 409 } 410 #endif 411 412 #endif /* _SYS_FCNTL_H */ 413