docs/how-to-build.md: use proper markup for directory names
[unleashed/tickless.git] / include / sys / fcntl.h
blob2179003c0c2b5c956a933e62830775c3f30d356a
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
32 * All Rights Reserved
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
36 * contributors.
39 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
40 /* Copyright 2015, Joyent, Inc. */
42 #ifndef _SYS_FCNTL_H
43 #define _SYS_FCNTL_H
45 #include <sys/feature_tests.h>
47 #include <sys/types.h>
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
54 * File status flags: these are used by open(2), fcntl(2).
55 * They are also used (indirectly) in the kernel file structure f_flag,
56 * which is a superset of the open/fcntl flags. Open flags and f_flag
57 * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
58 * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
60 /* open(2)-only flags -- exactly one must be set */
61 #define O_RDONLY 0x00000000
62 #define O_WRONLY 0x00000001
63 #define O_RDWR 0x00000002
64 #define O_SEARCH 0x00200000
65 #define O_EXEC 0x00400000
67 * Kernel encoding of open mode; separate read and write bits that are
68 * independently testable: 1 greater than the above.
69 * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
70 * which was documented to use FREAD/FWRITE, continues to work.
72 #define FREAD (O_RDONLY + 1)
73 #define FWRITE (O_WRONLY + 1)
74 #if defined(_KERNEL) || defined(__UNLEASHED_VISIBLE)
75 #define FSEARCH O_SEARCH
76 #define FEXEC O_EXEC
77 /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
78 #define FFLAGS(oflags) ((oflags) & (O_EXEC|O_SEARCH) ? (oflags) : (oflags) + 1)
79 #define OFLAGS(fflags) ((fflags) & (FEXEC|FSEARCH) ? (fflags) : (fflags) - 1)
80 #endif /* _KERNEL || __UNLEASHED_VISIBLE */
82 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE)
83 #define O_NDELAY 0x00000004 /* non-blocking I/O */
84 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) */
85 #define O_APPEND 0x00000008 /* append (writes guaranteed at the end) */
86 #define O_SYNC 0x00000010 /* synchronized file update option */
87 #define O_DSYNC 0x00000040 /* synchronized data update option */
88 #define O_NONBLOCK 0x00000080 /* non-blocking I/O (POSIX) */
89 #define O_CREAT 0x00000100 /* open with file create (uses third arg) */
90 #define O_TRUNC 0x00000200 /* open with truncation */
91 #define O_EXCL 0x00000400 /* exclusive open */
92 #define O_NOCTTY 0x00000800 /* don't allocate controlling tty (POSIX) */
93 #define O_ASYNC 0x00001000
94 #ifdef _LARGEFILE_SOURCE
95 #define O_LARGEFILE 0x00002000
96 #endif
97 #define O_XATTR 0x00004000 /* extended attribute */
98 #define O_RSYNC 0x00008000 /* synchronized file update option
99 defines read/write file integrity */
100 #define O_NOFOLLOW 0x00020000 /* don't follow symlinks */
101 #define O_NOLINKS 0x00040000 /* don't allow multiple hard links */
102 #define O_CLOEXEC 0x00800000 /* set the close-on-exec flag */
103 #define O_DIRECTORY 0x01000000
105 #if defined(_KERNEL) || defined(__UNLEASHED_VISIBLE)
106 #define FNDELAY O_NDELAY
107 #define FAPPEND O_APPEND
108 #define FSYNC O_SYNC /* file (data+inode) integrity while writing */
109 #define FDSYNC O_DSYNC /* file data only integrity while writing */
110 #define FNONBLOCK O_NONBLOCK
112 #define FCREAT O_CREAT
113 #define FTRUNC O_TRUNC
114 #define FEXCL O_EXCL
115 #define FASYNC O_ASYNC /* asyncio in progress pseudo flag */
116 #define FNOCTTY O_NOCTTY
117 #define FXATTR O_XATTR /* open as extended attribute */
118 #define FRSYNC O_RSYNC /* sync read operations at same level
119 of integrity as specified for writes
120 by FSYNC and FDSYNC flags */
121 #define FNOFOLLOW O_NOFOLLOW /* don't follow symlinks */
122 #define FNOLINKS O_NOLINKS /* don't allow multiple hard links */
123 #define FCLOEXEC O_CLOEXEC
124 #define FDIRECTORY O_DIRECTORY
126 /* Flags modifiable by F_SETFL. Must only contain flags for which O_foo and
127 * Ffoo are equal -- ie. access mode flags don't belong here. */
128 #define FCNTLFLAGS (O_APPEND|O_NDELAY|O_NONBLOCK|O_SYNC|O_DSYNC|O_RSYNC)
130 #define FREVOKED 0x00000020 /* Object reuse Revoked file */
131 #define FOFFMAX 0x00002000 /* large file */
132 #define FNODSYNC 0x00010000 /* fsync pseudo flag */
133 #define FIGNORECASE 0x00080000 /* request case-insensitive lookups */
134 #define FXATTRDIROPEN 0x00100000 /* only opening hidden attribute directory */
135 #define FEPOLLED 0x02000000 /* never user-visible */
137 * A flag originally from flock.h, but since it is ORed with and otherwise
138 * conflated with f_flag all over vfs, put it here and give it a distinct
139 * value.
141 #define F_REMOTELOCK 0x04000000 /* Set if NLM lock */
142 #endif /* _KERNEL || __UNLEASHED_VISIBLE */
145 * fcntl(2) requests
147 * N.B.: values are not necessarily assigned sequentially below.
149 #define F_DUPFD 0 /* Duplicate fildes */
150 #define F_GETFD 1 /* Get fildes flags */
151 #define F_SETFD 2 /* Set fildes flags */
152 #define F_GETFL 3 /* Get file flags */
153 #define F_GETXFL 45 /* Get file flags including open-only flags */
154 #define F_SETFL 4 /* Set file flags */
157 * Applications that read /dev/mem must be built like the kernel. A
158 * new symbol "_KMEMUSER" is defined for this purpose.
160 #if defined(_KERNEL) || defined(_KMEMUSER)
161 #define F_O_GETLK 5 /* SVR3 Get file lock (need for rfs, across */
162 /* the wire compatibility */
163 /* clustering: lock id contains both per-node sysid and node id */
164 #define SYSIDMASK 0x0000ffff
165 #define GETSYSID(id) (id & SYSIDMASK)
166 #define NODEIDMASK 0xffff0000
167 #define BITS_IN_SYSID 16
168 #define GETNLMID(sysid) ((int)(((uint_t)(sysid) & NODEIDMASK) >> \
169 BITS_IN_SYSID))
170 #endif /* defined(_KERNEL) */
172 #define F_CHKFL 8 /* Unused */
173 #define F_DUP2FD 9 /* Duplicate fildes at third arg */
174 #define F_DUP2FD_CLOEXEC 36 /* Like F_DUP2FD with O_CLOEXEC set */
175 /* EINVAL is fildes matches arg1 */
176 #define F_DUPFD_CLOEXEC 37 /* Like F_DUPFD with O_CLOEXEC set */
178 #define F_ISSTREAM 13 /* Is the file desc. a stream ? */
179 #define F_PRIV 15 /* Turn on private access to file */
180 #define F_NPRIV 16 /* Turn off private access to file */
181 #define F_QUOTACTL 17 /* UFS quota call */
182 #define F_BLOCKS 18 /* Get number of BLKSIZE blocks allocated */
183 #define F_BLKSIZE 19 /* Get optimal I/O block size */
185 * Numbers 20-22 have been removed and should not be reused.
187 #define F_GETOWN 23 /* Get owner (socket emulation) */
188 #define F_SETOWN 24 /* Set owner (socket emulation) */
189 #define F_REVOKE 25 /* Object reuse revoke access to file desc. */
191 #define F_HASREMOTELOCKS 26 /* Does vp have NFS locks; private to lock */
192 /* manager */
195 * Commands that refer to flock structures. The argument types differ between
196 * the large and small file environments; therefore, the #defined values must
197 * as well.
198 * The NBMAND forms are private and should not be used.
199 * The FLOCK forms are also private and should not be used.
202 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
203 /* "Native" application compilation environment */
204 #define F_SETLK 6 /* Set file lock */
205 #define F_SETLKW 7 /* Set file lock and wait */
206 #define F_ALLOCSP 10 /* Allocate file space */
207 #define F_FREESP 11 /* Free file space */
208 #define F_GETLK 14 /* Get file lock */
209 #define F_SETLK_NBMAND 42 /* private */
210 #if !defined(_STRICT_SYMBOLS)
211 #define F_OFD_GETLK 47 /* Get file lock owned by file */
212 #define F_OFD_SETLK 48 /* Set file lock owned by file */
213 #define F_OFD_SETLKW 49 /* Set file lock owned by file and wait */
214 #define F_FLOCK 53 /* private - set flock owned by file */
215 #define F_FLOCKW 54 /* private - set flock owned by file and wait */
216 #endif /* _STRICT_SYMBOLS */
217 #else
218 /* ILP32 large file application compilation environment version */
219 #define F_SETLK 34 /* Set file lock */
220 #define F_SETLKW 35 /* Set file lock and wait */
221 #define F_ALLOCSP 28 /* Alllocate file space */
222 #define F_FREESP 27 /* Free file space */
223 #define F_GETLK 33 /* Get file lock */
224 #define F_SETLK_NBMAND 44 /* private */
225 #if !defined(_STRICT_SYMBOLS)
226 #define F_OFD_GETLK 50 /* Get file lock owned by file */
227 #define F_OFD_SETLK 51 /* Set file lock owned by file */
228 #define F_OFD_SETLKW 52 /* Set file lock owned by file and wait */
229 #define F_FLOCK 55 /* private - set flock owned by file */
230 #define F_FLOCKW 56 /* private - set flock owned by file and wait */
231 #endif /* _STRICT_SYMBOLS */
232 #endif /* _LP64 || _FILE_OFFSET_BITS == 32 */
234 #if defined(_LARGEFILE64_SOURCE)
236 #if !defined(_LP64) || defined(_KERNEL)
238 * transitional large file interface version
239 * These are only valid in a 32 bit application compiled with large files
240 * option, for source compatibility, the 64-bit versions are mapped back
241 * to the native versions.
243 #define F_SETLK64 34 /* Set file lock */
244 #define F_SETLKW64 35 /* Set file lock and wait */
245 #define F_ALLOCSP64 28 /* Allocate file space */
246 #define F_FREESP64 27 /* Free file space */
247 #define F_GETLK64 33 /* Get file lock */
248 #define F_SETLK64_NBMAND 44 /* private */
249 #if !defined(_STRICT_SYMBOLS)
250 #define F_OFD_GETLK64 50 /* Get file lock owned by file */
251 #define F_OFD_SETLK64 51 /* Set file lock owned by file */
252 #define F_OFD_SETLKW64 52 /* Set file lock owned by file and wait */
253 #define F_FLOCK64 55 /* private - set flock owned by file */
254 #define F_FLOCKW64 56 /* private - set flock owned by file and wait */
255 #endif /* _STRICT_SYMBOLS */
256 #else
257 #define F_SETLK64 6 /* Set file lock */
258 #define F_SETLKW64 7 /* Set file lock and wait */
259 #define F_ALLOCSP64 10 /* Allocate file space */
260 #define F_FREESP64 11 /* Free file space */
261 #define F_GETLK64 14 /* Get file lock */
262 #define F_SETLK64_NBMAND 42 /* private */
263 #if !defined(_STRICT_SYMBOLS)
264 #define F_OFD_GETLK64 47 /* Get file lock owned by file */
265 #define F_OFD_SETLK64 48 /* Set file lock owned by file */
266 #define F_OFD_SETLKW64 49 /* Set file lock owned by file and wait */
267 #define F_FLOCK64 53 /* private - set flock owned by file */
268 #define F_FLOCKW64 54 /* private - set flock owned by file and wait */
269 #endif /* _STRICT_SYMBOLS */
270 #endif /* !_LP64 || _KERNEL */
272 #endif /* _LARGEFILE64_SOURCE */
274 #define F_SHARE 40 /* Set a file share reservation */
275 #define F_UNSHARE 41 /* Remove a file share reservation */
276 #define F_SHARE_NBMAND 43 /* private */
278 #define F_BADFD 46 /* Create Poison FD */
281 * File segment locking set data type - information passed to system by user.
284 /* regular version, for both small and large file compilation environment */
285 typedef struct flock {
286 short l_type;
287 short l_whence;
288 off_t l_start;
289 off_t l_len; /* len == 0 means until end of file */
290 int l_sysid;
291 pid_t l_pid;
292 long l_pad[4]; /* reserve area */
293 } flock_t;
295 #if defined(_SYSCALL32)
297 /* Kernel's view of ILP32 flock structure */
299 typedef struct flock32 {
300 int16_t l_type;
301 int16_t l_whence;
302 off32_t l_start;
303 off32_t l_len; /* len == 0 means until end of file */
304 int32_t l_sysid;
305 pid32_t l_pid;
306 int32_t l_pad[4]; /* reserve area */
307 } flock32_t;
309 #endif /* _SYSCALL32 */
311 /* transitional large file interface version */
313 #if defined(_LARGEFILE64_SOURCE)
315 typedef struct flock64 {
316 short l_type;
317 short l_whence;
318 off64_t l_start;
319 off64_t l_len; /* len == 0 means until end of file */
320 int l_sysid;
321 pid_t l_pid;
322 long l_pad[4]; /* reserve area */
323 } flock64_t;
325 #if defined(_SYSCALL32)
327 /* Kernel's view of ILP32 flock64 */
329 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
330 #pragma pack(4)
331 #endif
333 typedef struct flock64_32 {
334 int16_t l_type;
335 int16_t l_whence;
336 off64_t l_start;
337 off64_t l_len; /* len == 0 means until end of file */
338 int32_t l_sysid;
339 pid32_t l_pid;
340 int32_t l_pad[4]; /* reserve area */
341 } flock64_32_t;
343 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
344 #pragma pack()
345 #endif
347 /* Kernel's view of LP64 flock64 */
349 typedef struct flock64_64 {
350 int16_t l_type;
351 int16_t l_whence;
352 off64_t l_start;
353 off64_t l_len; /* len == 0 means until end of file */
354 int32_t l_sysid;
355 pid32_t l_pid;
356 int64_t l_pad[4]; /* reserve area */
357 } flock64_64_t;
359 #endif /* _SYSCALL32 */
361 #endif /* _LARGEFILE64_SOURCE */
363 #if defined(_KERNEL) || defined(_KMEMUSER)
364 /* SVr3 flock type; needed for rfs across the wire compatibility */
365 typedef struct o_flock {
366 int16_t l_type;
367 int16_t l_whence;
368 int32_t l_start;
369 int32_t l_len; /* len == 0 means until end of file */
370 int16_t l_sysid;
371 int16_t l_pid;
372 } o_flock_t;
373 #endif /* defined(_KERNEL) */
376 * File segment locking types.
378 #define F_RDLCK 01 /* Read lock */
379 #define F_WRLCK 02 /* Write lock */
380 #define F_UNLCK 03 /* Remove lock(s) */
381 #define F_UNLKSYS 04 /* remove remote locks for a given system */
384 * POSIX constants
387 /* Mask for file access modes */
388 #define O_ACCMODE (O_SEARCH | O_EXEC | 0x3)
389 #define FD_CLOEXEC 1 /* close on exec flag */
392 * DIRECTIO
394 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
395 #define DIRECTIO_OFF (0)
396 #define DIRECTIO_ON (1)
399 * File share reservation type
401 typedef struct fshare {
402 short f_access;
403 short f_deny;
404 int f_id;
405 } fshare_t;
408 * f_access values
410 #define F_RDACC 0x1 /* Read-only share access */
411 #define F_WRACC 0x2 /* Write-only share access */
412 #define F_RWACC 0x3 /* Read-Write share access */
413 #define F_RMACC 0x4 /* private flag: Delete share access */
414 #define F_MDACC 0x20 /* private flag: Metadata share access */
417 * f_deny values
419 #define F_NODNY 0x0 /* Don't deny others access */
420 #define F_RDDNY 0x1 /* Deny others read share access */
421 #define F_WRDNY 0x2 /* Deny others write share access */
422 #define F_RWDNY 0x3 /* Deny others read or write share access */
423 #define F_RMDNY 0x4 /* private flag: Deny delete share access */
424 #define F_COMPAT 0x8 /* Set share to old DOS compatibility mode */
425 #define F_MANDDNY 0x10 /* private flag: mandatory enforcement */
426 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */
429 * Special flags for functions such as openat(), fstatat()....
431 #if !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE) || \
432 defined(__EXTENSIONS__)
433 /* || defined(_XPG7) */
434 #define AT_FDCWD 0xffd19553
435 #define AT_SYMLINK_NOFOLLOW 0x1000
436 #define AT_SYMLINK_FOLLOW 0x2000 /* only for linkat() */
437 #define AT_REMOVEDIR 0x1
438 #define _AT_TRIGGER 0x2
439 #define AT_EACCESS 0x4 /* use EUID/EGID for access */
440 #endif
442 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
443 /* advice for posix_fadvise */
444 #define POSIX_FADV_NORMAL 0
445 #define POSIX_FADV_RANDOM 1
446 #define POSIX_FADV_SEQUENTIAL 2
447 #define POSIX_FADV_WILLNEED 3
448 #define POSIX_FADV_DONTNEED 4
449 #define POSIX_FADV_NOREUSE 5
450 #endif
452 #ifdef __cplusplus
454 #endif
456 #endif /* _SYS_FCNTL_H */