xref: /illumos-gate/usr/src/ucbhead/sys/fcntl.h (revision 2a613b5974ae49c8b068a3998ff554f8c6f0f593)
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 1998 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  * Copyright 2015 Joyent, Inc.  All rights reserved.
26  */
27 
28 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 /*
32  * University Copyright- Copyright (c) 1982, 1986, 1988
33  * The Regents of the University of California
34  * All Rights Reserved
35  *
36  * University Acknowledgment- Portions of this document are derived from
37  * software developed by the University of California, Berkeley, and its
38  * contributors.
39  */
40 
41 #ifndef _SYS_FCNTL_H
42 #define	_SYS_FCNTL_H
43 
44 #ifndef _SYS_TYPES_H
45 #include <sys/types.h>
46 #endif
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /* Flag values accessible to open(2) and fcntl(2) */
53 /*  (The first three can only be set by open) */
54 #define	O_RDONLY 0
55 #define	O_WRONLY 1
56 #define	O_RDWR	 2
57 #define	O_NDELAY 04	/* Non-blocking I/O */
58 #define	O_APPEND 010	/* append (writes guaranteed at the end) */
59 #define	O_SYNC	 020	/* synchronous write option */
60 #define	O_NONBLOCK 0200 /* Non-blocking I/O (POSIX) */
61 #define	O_PRIV 010000   /* Private access to file */
62 
63 #ifdef	_LARGEFILE_SOURCE
64 #define	O_LARGEFILE	0x2000
65 #endif
66 
67 /* Flag values accessible only to open(2) */
68 #define	O_CREAT	00400	/* open with file create (uses third open arg) */
69 #define	O_TRUNC	01000	/* open with truncation */
70 #define	O_EXCL	02000	/* exclusive open */
71 #define	O_NOCTTY 04000	/* don't allocate controlling tty (POSIX) */
72 
73 /* fcntl(2) requests */
74 #define	F_DUPFD		0	/* Duplicate fildes */
75 #define	F_GETFD		1	/* Get fildes flags */
76 #define	F_SETFD		2	/* Set fildes flags */
77 #define	F_GETFL		3	/* Get file flags */
78 #define	F_SETFL		4	/* Set file flags */
79 #define	F_SETLK		6	/* Set file lock */
80 #define	F_SETLKW	7	/* Set file lock and wait */
81 #define	F_FLOCK		53	/* private - flock */
82 #define	F_FLOCKW	54	/* private - flock wait */
83 
84 /*
85  * Applications that read /dev/mem must be built like the kernel. A new
86  * symbol "_KMEMUSER" is defined for this purpose.
87  * Applications that read /dev/mem will migrate with the kernel
88  * to an "_LTYPES" definition.
89  */
90 
91 #if defined(_KERNEL) || defined(_KMEMUSER)
92 #define	F_GETLK		14	/* Get file lock */
93 #define	F_O_GETLK	5	/* SVR3 Get file lock */
94 
95 #else	/* user definition */
96 
97 #if defined(_LTYPES)	/* EFT definition */
98 #define	F_GETLK		14	/* Get file lock */
99 #else
100 #define	F_GETLK		5	/* Get file lock */
101 #endif	/* defined(_LTYPES) */
102 
103 #endif	/* defined(_KERNEL) */
104 
105 #define	F_SETLK		6	/* Set file lock */
106 #define	F_SETLKW	7	/* Set file lock and wait */
107 
108 
109 #define	F_CHKFL		8	/* Reserved */
110 #define	F_ALLOCSP	10	/* Reserved */
111 #define	F_FREESP	11	/* Free file space */
112 #define	F_ISSTREAM	13	/* Is the file desc. a stream ? */
113 #define	F_PRIV		15	/* Turn on private access to file */
114 #define	F_NPRIV		16	/* Turn off private access to file */
115 #define	F_QUOTACTL	17	/* UFS quota call */
116 #define	F_BLOCKS	18	/* Get number of BLKSIZE blocks allocated */
117 #define	F_BLKSIZE	19	/* Get optimal I/O block size */
118 
119 #define	F_GETOWN	23	/* Get owner */
120 #define	F_SETOWN	24	/* Set owner */
121 
122 /* flags for F_GETFL, F_SETFL-- copied from <sys/file.h> */
123 #ifndef FOPEN
124 #define	FOPEN		0xFFFFFFFF
125 #define	FREAD		0x01
126 #define	FWRITE		0x02
127 #define	FNDELAY		0x04
128 #define	FAPPEND		0x08
129 #define	FSYNC		0x10
130 #define	FNONBLOCK	0x80
131 
132 #define	FMASK		0xFF    /* should be disjoint from FASYNC */
133 
134 /* open-only modes */
135 
136 #define	FCREAT		0x0100
137 #define	FTRUNC		0x0200
138 #define	FEXCL		0x0400
139 #define	FNOCTTY		0x0800
140 #define	FASYNC		0x1000
141 
142 /* file descriptor flags */
143 #define	FCLOSEXEC	001	/* close on exec */
144 #endif
145 
146 /*
147  * File segment locking set data type - information passed to system by user.
148  */
149 #if defined(_KERNEL) || defined(_KMEMUSER)
150 	/* EFT definition */
151 typedef struct flock {
152 	short	l_type;
153 	short	l_whence;
154 	off_t	l_start;
155 	off_t	l_len;		/* len == 0 means until end of file */
156 	int	l_sysid;
157 	pid_t	l_pid;
158 	long	pad[4];		/* reserve area */
159 } flock_t;
160 
161 typedef struct o_flock {
162 	short	l_type;
163 	short	l_whence;
164 	int	l_start;
165 	int	l_len;		/* len == 0 means until end of file */
166 	short   l_sysid;
167 	o_pid_t l_pid;
168 } o_flock_t;
169 
170 #else		/* user level definition */
171 
172 #if defined(_STYPES)
173 	/* SVR3 definition */
174 typedef struct flock {
175 	short	l_type;
176 	short	l_whence;
177 	off_t	l_start;
178 	off_t	l_len;		/* len == 0 means until end of file */
179 	short	l_sysid;
180 	o-pid_t	l_pid;
181 } flock_t;
182 
183 #else
184 
185 typedef struct flock {
186 	short	l_type;
187 	short	l_whence;
188 	off_t	l_start;
189 	off_t	l_len;		/* len == 0 means until end of file */
190 	int	l_sysid;
191 	pid_t	l_pid;
192 	long 	pad[4];		/* reserve area */
193 } flock_t;
194 
195 #endif	/* define(_STYPES) */
196 
197 #endif	/* defined(_KERNEL) */
198 
199 /*
200  * File segment locking types.
201  */
202 #define	F_RDLCK	01	/* Read lock */
203 #define	F_WRLCK	02	/* Write lock */
204 #define	F_UNLCK	03	/* Remove lock(s) */
205 
206 /*
207  * POSIX constants
208  */
209 
210 #define	O_ACCMODE	3	/* Mask for file access modes */
211 #define	FD_CLOEXEC	1	/* close on exec flag */
212 
213 /* large file compilation environment setup */
214 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
215 #ifdef __PRAGMA_REDEFINE_EXTNAME
216 #pragma	redefine_extname	open	open64
217 #pragma	redefine_extname	creat	creat64
218 #else
219 #define	open			open64
220 #define	creat			creat64
221 #endif
222 #endif  /* !_LP64 && _FILE_OFFSET_BITS == 64 */
223 
224 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
225 #ifdef __PRAGMA_REDEFINE_EXTNAME
226 #pragma	redefine_extname	open64	open
227 #pragma	redefine_extname	creat64	creat
228 #else
229 #define	open64			open
230 #define	creat64			creat
231 #endif
232 #endif  /* _LP64 && _LARGEFILE64_SOURCE */
233 
234 #if defined(__STDC__)
235 extern int fcntl(int, int, ...);
236 extern int open(const char *, int, ...);
237 extern int creat(const char *, mode_t);
238 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
239 	!defined(__PRAGMA_REDEFINE_EXTNAME))
240 extern int open64(const char *, int, ...);
241 extern int creat64(const char *, mode_t);
242 #endif
243 
244 #endif
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif	/* _SYS_FCNTL_H */
251