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