xref: /titanic_51/usr/src/uts/common/sys/fcntl.h (revision a31148363f598def767ac48c5d82e1572e44b935)
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 2009 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 #include <sys/feature_tests.h>
44 
45 #include <sys/types.h>
46 
47 #ifdef	__cplusplus
48 extern "C" {
49 #endif
50 
51 /*
52  * Flag values accessible to open(2) and fcntl(2)
53  * (the first three can only be set by open(2)).
54  */
55 #define	O_RDONLY	0
56 #define	O_WRONLY	1
57 #define	O_RDWR		2
58 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE)
59 #define	O_NDELAY	0x04	/* non-blocking I/O */
60 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) */
61 #define	O_APPEND	0x08	/* append (writes guaranteed at the end) */
62 #if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \
63 	(_POSIX_C_SOURCE > 2) || defined(_XOPEN_SOURCE)
64 #define	O_SYNC		0x10	/* synchronized file update option */
65 #define	O_DSYNC		0x40	/* synchronized data update option */
66 #define	O_RSYNC		0x8000	/* synchronized file update option */
67 				/* defines read/write file integrity */
68 #endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */
69 #define	O_NONBLOCK	0x80	/* non-blocking I/O (POSIX) */
70 #ifdef	SUN_SRC_COMPAT
71 #define	O_PRIV 		0x1000  /* Private access to file */
72 #endif /* SUN_SRC_COMPAT */
73 #ifdef	_LARGEFILE_SOURCE
74 #define	O_LARGEFILE	0x2000
75 #endif
76 
77 /*
78  * Flag values accessible only to open(2).
79  */
80 #define	O_CREAT		0x100	/* open with file create (uses third arg) */
81 #define	O_TRUNC		0x200	/* open with truncation */
82 #define	O_EXCL		0x400	/* exclusive open */
83 #define	O_NOCTTY	0x800	/* don't allocate controlling tty (POSIX) */
84 #define	O_XATTR		0x4000	/* extended attribute */
85 #define	O_NOFOLLOW	0x20000	/* don't follow symlinks */
86 #define	O_NOLINKS	0x40000	/* don't allow multiple hard links */
87 
88 /*
89  * fcntl(2) requests
90  *
91  * N.B.: values are not necessarily assigned sequentially below.
92  */
93 #define	F_DUPFD		0	/* Duplicate fildes */
94 #define	F_GETFD		1	/* Get fildes flags */
95 #define	F_SETFD		2	/* Set fildes flags */
96 #define	F_GETFL		3	/* Get file flags */
97 #define	F_GETXFL	45	/* Get file flags including open-only flags */
98 #define	F_SETFL		4	/* Set file flags */
99 
100 /*
101  * Applications that read /dev/mem must be built like the kernel.  A
102  * new symbol "_KMEMUSER" is defined for this purpose.
103  */
104 #if defined(_KERNEL) || defined(_KMEMUSER)
105 #define	F_O_GETLK	5	/* SVR3 Get file lock (need for rfs, across */
106 				/* the wire compatibility */
107 /* clustering: lock id contains both per-node sysid and node id */
108 #define	SYSIDMASK		0x0000ffff
109 #define	GETSYSID(id)		(id & SYSIDMASK)
110 #define	NODEIDMASK		0xffff0000
111 #define	BITS_IN_SYSID		16
112 #define	GETNLMID(sysid)		((int)(((uint_t)(sysid) & NODEIDMASK) >> \
113 				    BITS_IN_SYSID))
114 
115 /* Clustering: Macro used for PXFS locks */
116 #define	GETPXFSID(sysid)	((int)(((uint_t)(sysid) & NODEIDMASK) >> \
117 				    BITS_IN_SYSID))
118 #endif	/* defined(_KERNEL) */
119 
120 #define	F_CHKFL		8	/* Unused */
121 #define	F_DUP2FD	9	/* Duplicate fildes at third arg */
122 
123 #define	F_ISSTREAM	13	/* Is the file desc. a stream ? */
124 #define	F_PRIV		15	/* Turn on private access to file */
125 #define	F_NPRIV		16	/* Turn off private access to file */
126 #define	F_QUOTACTL	17	/* UFS quota call */
127 #define	F_BLOCKS	18	/* Get number of BLKSIZE blocks allocated */
128 #define	F_BLKSIZE	19	/* Get optimal I/O block size */
129 /*
130  * Numbers 20-22 have been removed and should not be reused.
131  */
132 #define	F_GETOWN	23	/* Get owner (socket emulation) */
133 #define	F_SETOWN	24	/* Set owner (socket emulation) */
134 #define	F_REVOKE	25	/* Object reuse revoke access to file desc. */
135 
136 #define	F_HASREMOTELOCKS 26	/* Does vp have NFS locks; private to lock */
137 				/* manager */
138 
139 /*
140  * Commands that refer to flock structures.  The argument types differ between
141  * the large and small file environments; therefore, the #defined values must
142  * as well.
143  * The NBMAND forms are private and should not be used.
144  */
145 
146 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
147 /* "Native" application compilation environment */
148 #define	F_SETLK		6	/* Set file lock */
149 #define	F_SETLKW	7	/* Set file lock and wait */
150 #define	F_ALLOCSP	10	/* Allocate file space */
151 #define	F_FREESP	11	/* Free file space */
152 #define	F_GETLK		14	/* Get file lock */
153 #define	F_SETLK_NBMAND	42	/* private */
154 #else
155 /* ILP32 large file application compilation environment version */
156 #define	F_SETLK		34	/* Set file lock */
157 #define	F_SETLKW	35	/* Set file lock and wait */
158 #define	F_ALLOCSP	28	/* Alllocate file space */
159 #define	F_FREESP	27	/* Free file space */
160 #define	F_GETLK		33	/* Get file lock */
161 #define	F_SETLK_NBMAND	44	/* private */
162 #endif /* _LP64 || _FILE_OFFSET_BITS == 32 */
163 
164 #if 	defined(_LARGEFILE64_SOURCE)
165 
166 #if !defined(_LP64) || defined(_KERNEL)
167 /*
168  * transitional large file interface version
169  * These are only valid in a 32 bit application compiled with large files
170  * option, for source compatibility, the 64-bit versions are mapped back
171  * to the native versions.
172  */
173 #define	F_SETLK64	34	/* Set file lock */
174 #define	F_SETLKW64	35	/* Set file lock and wait */
175 #define	F_ALLOCSP64	28	/* Allocate file space */
176 #define	F_FREESP64	27	/* Free file space */
177 #define	F_GETLK64	33	/* Get file lock */
178 #define	F_SETLK64_NBMAND	44	/* private */
179 #else
180 #define	F_SETLK64	6	/* Set file lock */
181 #define	F_SETLKW64	7	/* Set file lock and wait */
182 #define	F_ALLOCSP64	10	/* Allocate file space */
183 #define	F_FREESP64	11	/* Free file space */
184 #define	F_GETLK64	14	/* Get file lock */
185 #define	F_SETLK64_NBMAND	42	/* private */
186 #endif /* !_LP64 || _KERNEL */
187 
188 #endif /* _LARGEFILE64_SOURCE */
189 
190 #define	F_SHARE		40	/* Set a file share reservation */
191 #define	F_UNSHARE	41	/* Remove a file share reservation */
192 #define	F_SHARE_NBMAND	43	/* private */
193 
194 #define	F_BADFD		46	/* Create Poison FD */
195 
196 /*
197  * File segment locking set data type - information passed to system by user.
198  */
199 
200 /* regular version, for both small and large file compilation environment */
201 typedef struct flock {
202 	short	l_type;
203 	short	l_whence;
204 	off_t	l_start;
205 	off_t	l_len;		/* len == 0 means until end of file */
206 	int	l_sysid;
207 	pid_t	l_pid;
208 	long	l_pad[4];		/* reserve area */
209 } flock_t;
210 
211 #if defined(_SYSCALL32)
212 
213 /* Kernel's view of ILP32 flock structure */
214 
215 typedef struct flock32 {
216 	int16_t	l_type;
217 	int16_t	l_whence;
218 	off32_t	l_start;
219 	off32_t	l_len;		/* len == 0 means until end of file */
220 	int32_t	l_sysid;
221 	pid32_t	l_pid;
222 	int32_t	l_pad[4];		/* reserve area */
223 } flock32_t;
224 
225 #endif /* _SYSCALL32 */
226 
227 /* transitional large file interface version */
228 
229 #if 	defined(_LARGEFILE64_SOURCE)
230 
231 typedef struct flock64 {
232 	short	l_type;
233 	short	l_whence;
234 	off64_t	l_start;
235 	off64_t	l_len;		/* len == 0 means until end of file */
236 	int	l_sysid;
237 	pid_t	l_pid;
238 	long	l_pad[4];		/* reserve area */
239 } flock64_t;
240 
241 #if defined(_SYSCALL32)
242 
243 /* Kernel's view of ILP32 flock64 */
244 
245 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
246 #pragma	pack(4)
247 #endif
248 
249 typedef struct flock64_32 {
250 	int16_t	l_type;
251 	int16_t	l_whence;
252 	off64_t	l_start;
253 	off64_t	l_len;		/* len == 0 means until end of file */
254 	int32_t	l_sysid;
255 	pid32_t	l_pid;
256 	int32_t	l_pad[4];		/* reserve area */
257 } flock64_32_t;
258 
259 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
260 #pragma pack()
261 #endif
262 
263 /* Kernel's view of LP64 flock64 */
264 
265 typedef struct flock64_64 {
266 	int16_t	l_type;
267 	int16_t	l_whence;
268 	off64_t	l_start;
269 	off64_t	l_len;		/* len == 0 means until end of file */
270 	int32_t	l_sysid;
271 	pid32_t	l_pid;
272 	int64_t	l_pad[4];		/* reserve area */
273 } flock64_64_t;
274 
275 #endif	/* _SYSCALL32 */
276 
277 #endif /* _LARGEFILE64_SOURCE */
278 
279 #if defined(_KERNEL) || defined(_KMEMUSER)
280 /* SVr3 flock type; needed for rfs across the wire compatibility */
281 typedef struct o_flock {
282 	int16_t	l_type;
283 	int16_t	l_whence;
284 	int32_t	l_start;
285 	int32_t	l_len;		/* len == 0 means until end of file */
286 	int16_t	l_sysid;
287 	int16_t	l_pid;
288 } o_flock_t;
289 #endif	/* defined(_KERNEL) */
290 
291 /*
292  * File segment locking types.
293  */
294 #define	F_RDLCK		01	/* Read lock */
295 #define	F_WRLCK		02	/* Write lock */
296 #define	F_UNLCK		03	/* Remove lock(s) */
297 #define	F_UNLKSYS	04	/* remove remote locks for a given system */
298 
299 /*
300  * POSIX constants
301  */
302 
303 #define	O_ACCMODE	3	/* Mask for file access modes */
304 #define	FD_CLOEXEC	1	/* close on exec flag */
305 
306 /*
307  * DIRECTIO
308  */
309 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
310 #define	DIRECTIO_OFF	(0)
311 #define	DIRECTIO_ON	(1)
312 
313 /*
314  * File share reservation type
315  */
316 typedef struct fshare {
317 	short	f_access;
318 	short	f_deny;
319 	int	f_id;
320 } fshare_t;
321 
322 /*
323  * f_access values
324  */
325 #define	F_RDACC		0x1	/* Read-only share access */
326 #define	F_WRACC		0x2	/* Write-only share access */
327 #define	F_RWACC		0x3	/* Read-Write share access */
328 #define	F_RMACC		0x4	/* private flag: Delete share access */
329 #define	F_MDACC		0x20	/* private flag: Metadata share access */
330 
331 /*
332  * f_deny values
333  */
334 #define	F_NODNY		0x0	/* Don't deny others access */
335 #define	F_RDDNY		0x1	/* Deny others read share access */
336 #define	F_WRDNY		0x2	/* Deny others write share access */
337 #define	F_RWDNY		0x3	/* Deny others read or write share access */
338 #define	F_RMDNY		0x4	/* private flag: Deny delete 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 #define	_AT_TRIGGER			0x2
352 #define	AT_EACCESS			0x4	/* use EUID/EGID for access */
353 #endif
354 
355 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
356 /* advice for posix_fadvise */
357 #define	POSIX_FADV_NORMAL	0
358 #define	POSIX_FADV_RANDOM	1
359 #define	POSIX_FADV_SEQUENTIAL	2
360 #define	POSIX_FADV_WILLNEED	3
361 #define	POSIX_FADV_DONTNEED	4
362 #define	POSIX_FADV_NOREUSE	5
363 #endif
364 
365 #ifdef	__cplusplus
366 }
367 #endif
368 
369 #endif	/* _SYS_FCNTL_H */
370