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