pkg: ship usr/lib/security/amd64/*.so links
[unleashed.git] / include / sys / fcntl.h
blob1059a3f6113f26dc18b37f151c016d644af785d3
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 __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 /* __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 #define O_XATTR 0x00004000 /* extended attribute */
95 #define O_RSYNC 0x00008000 /* synchronized file update option
96 defines read/write file integrity */
97 #define O_NOFOLLOW 0x00020000 /* don't follow symlinks */
98 #define O_NOLINKS 0x00040000 /* don't allow multiple hard links */
99 #define O_CLOEXEC 0x00800000 /* set the close-on-exec flag */
100 #define O_DIRECTORY 0x01000000
102 #if __UNLEASHED_VISIBLE
103 #define FNDELAY O_NDELAY
104 #define FAPPEND O_APPEND
105 #define FSYNC O_SYNC /* file (data+inode) integrity while writing */
106 #define FDSYNC O_DSYNC /* file data only integrity while writing */
107 #define FNONBLOCK O_NONBLOCK
109 #define FCREAT O_CREAT
110 #define FTRUNC O_TRUNC
111 #define FEXCL O_EXCL
112 #define FASYNC O_ASYNC /* asyncio in progress pseudo flag */
113 #define FNOCTTY O_NOCTTY
114 #define FXATTR O_XATTR /* open as extended attribute */
115 #define FRSYNC O_RSYNC /* sync read operations at same level
116 of integrity as specified for writes
117 by FSYNC and FDSYNC flags */
118 #define FNOFOLLOW O_NOFOLLOW /* don't follow symlinks */
119 #define FNOLINKS O_NOLINKS /* don't allow multiple hard links */
120 #define FCLOEXEC O_CLOEXEC
121 #define FDIRECTORY O_DIRECTORY
123 /* Flags modifiable by F_SETFL. Must only contain flags for which O_foo and
124 * Ffoo are equal -- ie. access mode flags don't belong here. */
125 #define FCNTLFLAGS (O_APPEND|O_NDELAY|O_NONBLOCK|O_SYNC|O_DSYNC|O_RSYNC)
127 #define FREVOKED 0x00000020 /* Object reuse Revoked file */
128 #define FNODSYNC 0x00010000 /* fsync pseudo flag */
129 #define FIGNORECASE 0x00080000 /* request case-insensitive lookups */
130 #define FXATTRDIROPEN 0x00100000 /* only opening hidden attribute directory */
131 #define FEPOLLED 0x02000000 /* never user-visible */
133 * A flag originally from flock.h, but since it is ORed with and otherwise
134 * conflated with f_flag all over vfs, put it here and give it a distinct
135 * value.
137 #define F_REMOTELOCK 0x04000000 /* Set if NLM lock */
138 #endif /* __UNLEASHED_VISIBLE */
141 * fcntl(2) requests
143 * N.B.: values are not necessarily assigned sequentially below.
145 #define F_DUPFD 0 /* Duplicate fildes */
146 #define F_GETFD 1 /* Get fildes flags */
147 #define F_SETFD 2 /* Set fildes flags */
148 #define F_GETFL 3 /* Get file flags */
149 #define F_GETXFL 45 /* Get file flags including open-only flags */
150 #define F_SETFL 4 /* Set file flags */
153 * Applications that read /dev/mem must be built like the kernel. A
154 * new symbol "_KMEMUSER" is defined for this purpose.
156 #if defined(_KERNEL) || defined(_KMEMUSER)
157 #define F_O_GETLK 5 /* SVR3 Get file lock (need for rfs, across */
158 /* the wire compatibility */
159 /* clustering: lock id contains both per-node sysid and node id */
160 #define SYSIDMASK 0x0000ffff
161 #define GETSYSID(id) (id & SYSIDMASK)
162 #define NODEIDMASK 0xffff0000
163 #define BITS_IN_SYSID 16
164 #define GETNLMID(sysid) ((int)(((uint_t)(sysid) & NODEIDMASK) >> \
165 BITS_IN_SYSID))
166 #endif /* defined(_KERNEL) */
168 #define F_CHKFL 8 /* Unused */
169 #define F_DUP2FD 9 /* Duplicate fildes at third arg */
170 #define F_DUP2FD_CLOEXEC 36 /* Like F_DUP2FD with O_CLOEXEC set */
171 /* EINVAL is fildes matches arg1 */
172 #define F_DUPFD_CLOEXEC 37 /* Like F_DUPFD with O_CLOEXEC set */
174 #define F_ISSTREAM 13 /* Is the file desc. a stream ? */
175 #define F_PRIV 15 /* Turn on private access to file */
176 #define F_NPRIV 16 /* Turn off private access to file */
177 #define F_QUOTACTL 17 /* UFS quota call */
178 #define F_BLOCKS 18 /* Get number of BLKSIZE blocks allocated */
179 #define F_BLKSIZE 19 /* Get optimal I/O block size */
181 * Numbers 20-22 have been removed and should not be reused.
183 #define F_GETOWN 23 /* Get owner (socket emulation) */
184 #define F_SETOWN 24 /* Set owner (socket emulation) */
185 #define F_REVOKE 25 /* Object reuse revoke access to file desc. */
187 #define F_HASREMOTELOCKS 26 /* Does vp have NFS locks; private to lock */
188 /* manager */
191 * Commands that refer to flock structures. The argument types differ between
192 * the large and small file environments; therefore, the #defined values must
193 * as well.
194 * The NBMAND forms are private and should not be used.
195 * The FLOCK forms are also private and should not be used.
198 #if defined(_LP64)
199 /* "Native" application compilation environment */
200 #define F_SETLK 6 /* Set file lock */
201 #define F_SETLKW 7 /* Set file lock and wait */
202 #define F_ALLOCSP 10 /* Allocate file space */
203 #define F_FREESP 11 /* Free file space */
204 #define F_GETLK 14 /* Get file lock */
205 #define F_SETLK_NBMAND 42 /* private */
206 #if !defined(_STRICT_SYMBOLS)
207 #define F_OFD_GETLK 47 /* Get file lock owned by file */
208 #define F_OFD_SETLK 48 /* Set file lock owned by file */
209 #define F_OFD_SETLKW 49 /* Set file lock owned by file and wait */
210 #define F_FLOCK 53 /* private - set flock owned by file */
211 #define F_FLOCKW 54 /* private - set flock owned by file and wait */
212 #endif /* _STRICT_SYMBOLS */
213 #else
214 /* ILP32 large file application compilation environment version */
215 #define F_SETLK 34 /* Set file lock */
216 #define F_SETLKW 35 /* Set file lock and wait */
217 #define F_ALLOCSP 28 /* Alllocate file space */
218 #define F_FREESP 27 /* Free file space */
219 #define F_GETLK 33 /* Get file lock */
220 #define F_SETLK_NBMAND 44 /* private */
221 #if !defined(_STRICT_SYMBOLS)
222 #define F_OFD_GETLK 50 /* Get file lock owned by file */
223 #define F_OFD_SETLK 51 /* Set file lock owned by file */
224 #define F_OFD_SETLKW 52 /* Set file lock owned by file and wait */
225 #define F_FLOCK 55 /* private - set flock owned by file */
226 #define F_FLOCKW 56 /* private - set flock owned by file and wait */
227 #endif /* _STRICT_SYMBOLS */
228 #endif /* _LP64 */
230 #if !defined(_LP64) || defined(_KERNEL)
232 * transitional large file interface version
233 * These are only valid in a 32 bit application compiled with large files
234 * option, for source compatibility, the 64-bit versions are mapped back
235 * to the native versions.
237 #define F_SETLK64 34 /* Set file lock */
238 #define F_SETLKW64 35 /* Set file lock and wait */
239 #define F_ALLOCSP64 28 /* Allocate file space */
240 #define F_FREESP64 27 /* Free file space */
241 #define F_GETLK64 33 /* Get file lock */
242 #define F_SETLK64_NBMAND 44 /* private */
243 #if !defined(_STRICT_SYMBOLS)
244 #define F_OFD_GETLK64 50 /* Get file lock owned by file */
245 #define F_OFD_SETLK64 51 /* Set file lock owned by file */
246 #define F_OFD_SETLKW64 52 /* Set file lock owned by file and wait */
247 #define F_FLOCK64 55 /* private - set flock owned by file */
248 #define F_FLOCKW64 56 /* private - set flock owned by file and wait */
249 #endif /* _STRICT_SYMBOLS */
250 #else
251 #define F_SETLK64 6 /* Set file lock */
252 #define F_SETLKW64 7 /* Set file lock and wait */
253 #define F_ALLOCSP64 10 /* Allocate file space */
254 #define F_FREESP64 11 /* Free file space */
255 #define F_GETLK64 14 /* Get file lock */
256 #define F_SETLK64_NBMAND 42 /* private */
257 #if !defined(_STRICT_SYMBOLS)
258 #define F_OFD_GETLK64 47 /* Get file lock owned by file */
259 #define F_OFD_SETLK64 48 /* Set file lock owned by file */
260 #define F_OFD_SETLKW64 49 /* Set file lock owned by file and wait */
261 #define F_FLOCK64 53 /* private - set flock owned by file */
262 #define F_FLOCKW64 54 /* private - set flock owned by file and wait */
263 #endif /* _STRICT_SYMBOLS */
264 #endif /* !_LP64 || _KERNEL */
266 #define F_SHARE 40 /* Set a file share reservation */
267 #define F_UNSHARE 41 /* Remove a file share reservation */
268 #define F_SHARE_NBMAND 43 /* private */
270 #define F_BADFD 46 /* Create Poison FD */
273 * File segment locking set data type - information passed to system by user.
276 /* regular version, for both small and large file compilation environment */
277 typedef struct flock {
278 short l_type;
279 short l_whence;
280 off_t l_start;
281 off_t l_len; /* len == 0 means until end of file */
282 int l_sysid;
283 pid_t l_pid;
284 long l_pad[4]; /* reserve area */
285 } flock_t;
287 #if defined(_SYSCALL32)
289 /* Kernel's view of ILP32 flock structure */
291 typedef struct flock32 {
292 int16_t l_type;
293 int16_t l_whence;
294 off_t l_start;
295 off_t l_len; /* len == 0 means until end of file */
296 int32_t l_sysid;
297 pid32_t l_pid;
298 int32_t l_pad[4]; /* reserve area */
299 } flock32_t;
301 #endif /* _SYSCALL32 */
303 /* transitional large file interface version */
305 typedef struct flock64 {
306 short l_type;
307 short l_whence;
308 off64_t l_start;
309 off64_t l_len; /* len == 0 means until end of file */
310 int l_sysid;
311 pid_t l_pid;
312 long l_pad[4]; /* reserve area */
313 } flock64_t;
315 #if defined(_SYSCALL32)
317 /* Kernel's view of ILP32 flock64 */
319 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
320 #pragma pack(4)
321 #endif
323 typedef struct flock64_32 {
324 int16_t l_type;
325 int16_t l_whence;
326 off64_t l_start;
327 off64_t l_len; /* len == 0 means until end of file */
328 int32_t l_sysid;
329 pid32_t l_pid;
330 int32_t l_pad[4]; /* reserve area */
331 } flock64_32_t;
333 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
334 #pragma pack()
335 #endif
337 /* Kernel's view of LP64 flock64 */
339 typedef struct flock64_64 {
340 int16_t l_type;
341 int16_t l_whence;
342 off64_t l_start;
343 off64_t l_len; /* len == 0 means until end of file */
344 int32_t l_sysid;
345 pid32_t l_pid;
346 int64_t l_pad[4]; /* reserve area */
347 } flock64_64_t;
349 #endif /* _SYSCALL32 */
351 #if defined(_KERNEL) || defined(_KMEMUSER)
352 /* SVr3 flock type; needed for rfs across the wire compatibility */
353 typedef struct o_flock {
354 int16_t l_type;
355 int16_t l_whence;
356 int32_t l_start;
357 int32_t l_len; /* len == 0 means until end of file */
358 int16_t l_sysid;
359 int16_t l_pid;
360 } o_flock_t;
361 #endif /* defined(_KERNEL) */
364 * File segment locking types.
366 #define F_RDLCK 01 /* Read lock */
367 #define F_WRLCK 02 /* Write lock */
368 #define F_UNLCK 03 /* Remove lock(s) */
369 #define F_UNLKSYS 04 /* remove remote locks for a given system */
372 * POSIX constants
375 /* Mask for file access modes */
376 #define O_ACCMODE (O_SEARCH | O_EXEC | 0x3)
377 #define FD_CLOEXEC 1 /* close on exec flag */
380 * DIRECTIO
382 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
383 #define DIRECTIO_OFF (0)
384 #define DIRECTIO_ON (1)
387 * File share reservation type
389 typedef struct fshare {
390 short f_access;
391 short f_deny;
392 int f_id;
393 } fshare_t;
396 * f_access values
398 #define F_RDACC 0x1 /* Read-only share access */
399 #define F_WRACC 0x2 /* Write-only share access */
400 #define F_RWACC 0x3 /* Read-Write share access */
401 #define F_RMACC 0x4 /* private flag: Delete share access */
402 #define F_MDACC 0x20 /* private flag: Metadata share access */
405 * f_deny values
407 #define F_NODNY 0x0 /* Don't deny others access */
408 #define F_RDDNY 0x1 /* Deny others read share access */
409 #define F_WRDNY 0x2 /* Deny others write share access */
410 #define F_RWDNY 0x3 /* Deny others read or write share access */
411 #define F_RMDNY 0x4 /* private flag: Deny delete share access */
412 #define F_COMPAT 0x8 /* Set share to old DOS compatibility mode */
413 #define F_MANDDNY 0x10 /* private flag: mandatory enforcement */
414 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */
417 * Special flags for functions such as openat(), fstatat()....
419 #if !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE) || \
420 defined(__EXTENSIONS__)
421 /* || defined(_XPG7) */
422 #define AT_FDCWD 0xffd19553
423 #define AT_SYMLINK_NOFOLLOW 0x1000
424 #define AT_SYMLINK_FOLLOW 0x2000 /* only for linkat() */
425 #define AT_REMOVEDIR 0x1
426 #define _AT_TRIGGER 0x2
427 #define AT_EACCESS 0x4 /* use EUID/EGID for access */
428 #endif
430 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
431 /* advice for posix_fadvise */
432 #define POSIX_FADV_NORMAL 0
433 #define POSIX_FADV_RANDOM 1
434 #define POSIX_FADV_SEQUENTIAL 2
435 #define POSIX_FADV_WILLNEED 3
436 #define POSIX_FADV_DONTNEED 4
437 #define POSIX_FADV_NOREUSE 5
438 #endif
440 #ifdef __cplusplus
442 #endif
444 #endif /* _SYS_FCNTL_H */