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