Commit | Line | Data |
---|---|---|
c9017fa0 KB |
1 | /*- |
2 | * Copyright (c) 1983, 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
bb0cfa24 | 4 | * |
af359dea C |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
c9017fa0 | 20 | * |
af359dea C |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
33 | * @(#)fcntl.h 5.14 (Berkeley) 7/1/91 | |
bb0cfa24 | 34 | */ |
c9d055bc | 35 | |
91befe9c KB |
36 | #ifndef _FCNTL_H_ |
37 | #define _FCNTL_H_ | |
fd200b4a | 38 | |
40ac131e MK |
39 | /* |
40 | * This file includes the definitions for open and fcntl | |
41 | * described by POSIX for <fcntl.h>; it also includes | |
42 | * related kernel definitions. | |
43 | */ | |
44 | ||
91befe9c KB |
45 | #ifndef KERNEL |
46 | #include <sys/types.h> | |
47 | #endif | |
c9017fa0 | 48 | |
40ac131e MK |
49 | /* |
50 | * File status flags: these are used by open(2), fcntl(2). | |
af359dea C |
51 | * They are also used (indirectly) in the kernel file structure f_flags, |
52 | * which is a superset of the open/fcntl flags. Open flags and f_flags | |
53 | * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). | |
54 | * Open/fcntl flags begin with O_; kernel-internal flags begin with F. | |
40ac131e MK |
55 | */ |
56 | /* open-only flags */ | |
57 | #define O_RDONLY 0x0000 /* open for reading only */ | |
58 | #define O_WRONLY 0x0001 /* open for writing only */ | |
59 | #define O_RDWR 0x0002 /* open for reading and writing */ | |
60 | #define O_ACCMODE 0x0003 /* mask for above modes */ | |
61 | ||
62 | #ifdef KERNEL | |
63 | /* | |
64 | * Kernel encoding of open mode; separate read and write bits | |
65 | * that are independently testable: 1 greater than the above. | |
66 | */ | |
67 | #define FREAD 0x0001 | |
68 | #define FWRITE 0x0002 | |
69 | #endif | |
70 | #define O_NONBLOCK 0x0004 /* no delay */ | |
71 | #define O_APPEND 0x0008 /* set append mode */ | |
40ac131e | 72 | #ifndef _POSIX_SOURCE |
af359dea C |
73 | #define O_SHLOCK 0x0010 /* open with shared file lock */ |
74 | #define O_EXLOCK 0x0020 /* open with exclusive file lock */ | |
40ac131e | 75 | #define O_ASYNC 0x0040 /* signal pgrp when data ready */ |
af359dea | 76 | #define O_FSYNC 0x0080 /* synchronous writes */ |
40ac131e MK |
77 | #endif |
78 | #define O_CREAT 0x0200 /* create if nonexistant */ | |
79 | #define O_TRUNC 0x0400 /* truncate to zero length */ | |
80 | #define O_EXCL 0x0800 /* error if already exists */ | |
af359dea C |
81 | #ifdef KERNEL |
82 | #define FMARK 0x1000 /* mark during gc() */ | |
83 | #define FDEFER 0x2000 /* defer for next gc pass */ | |
84 | #define FHASLOCK 0x4000 /* descriptor holds advisory lock */ | |
85 | #endif | |
40ac131e MK |
86 | |
87 | /* defined by POSIX 1003.1; BSD default, so no bit required */ | |
88 | #define O_NOCTTY 0 /* don't assign controlling terminal */ | |
89 | ||
90 | #ifdef KERNEL | |
91 | /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ | |
92 | #define FFLAGS(oflags) ((oflags) + 1) | |
93 | #define OFLAGS(fflags) ((fflags) - 1) | |
94 | ||
95 | /* bits to save after open */ | |
af359dea | 96 | #define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK) |
40ac131e | 97 | /* bits settable by fcntl(F_SETFL, ...) */ |
af359dea | 98 | #define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK) |
40ac131e MK |
99 | #endif |
100 | ||
101 | /* | |
102 | * The O_* flags used to have only F* names, which were used in the kernel | |
103 | * and by fcntl. We retain the F* names for the kernel f_flags field | |
104 | * and for backward compatibility for fcntl. | |
105 | */ | |
106 | #ifndef _POSIX_SOURCE | |
af359dea C |
107 | #define FAPPEND O_APPEND /* kernel/compat */ |
108 | #define FASYNC O_ASYNC /* kernel/compat */ | |
109 | #define FFSYNC O_FSYNC /* kernel */ | |
110 | #define FNONBLOCK O_NONBLOCK /* kernel */ | |
111 | #define FNDELAY O_NONBLOCK /* compat */ | |
112 | #define O_NDELAY O_NONBLOCK /* compat */ | |
40ac131e MK |
113 | #endif |
114 | ||
40ac131e MK |
115 | /* |
116 | * Constants used for fcntl(2) | |
117 | */ | |
118 | ||
119 | /* command values */ | |
c9017fa0 KB |
120 | #define F_DUPFD 0 /* duplicate file descriptor */ |
121 | #define F_GETFD 1 /* get file descriptor flags */ | |
122 | #define F_SETFD 2 /* set file descriptor flags */ | |
123 | #define F_GETFL 3 /* get file status flags */ | |
124 | #define F_SETFL 4 /* set file status flags */ | |
125 | #ifndef _POSIX_SOURCE | |
126 | #define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ | |
127 | #define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ | |
128 | #endif | |
129 | #define F_GETLK 7 /* get record locking information */ | |
130 | #define F_SETLK 8 /* set record locking information */ | |
131 | #define F_SETLKW 9 /* F_SETLK; wait if blocked */ | |
132 | ||
133 | /* file descriptor flags (F_GETFD, F_SETFD) */ | |
134 | #define FD_CLOEXEC 1 /* close-on-exec flag */ | |
135 | ||
136 | /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ | |
137 | #define F_RDLCK 1 /* shared or read lock */ | |
138 | #define F_UNLCK 2 /* unlock */ | |
139 | #define F_WRLCK 3 /* exclusive or write lock */ | |
a4128336 KM |
140 | #ifdef KERNEL |
141 | #define F_WAIT 0x010 /* Wait until lock is granted */ | |
142 | #define F_FLOCK 0x020 /* Use flock(2) semantics for lock */ | |
143 | #define F_POSIX 0x040 /* Use POSIX semantics for lock */ | |
144 | #endif | |
c9017fa0 | 145 | |
40ac131e MK |
146 | /* |
147 | * Advisory file segment locking data type - | |
148 | * information passed to system by user | |
149 | */ | |
150 | struct flock { | |
151 | short l_type; /* lock type: read/write, etc. */ | |
152 | short l_whence; /* type of l_start */ | |
153 | off_t l_start; /* starting offset */ | |
154 | off_t l_len; /* len = 0 means until end of file */ | |
155 | pid_t l_pid; /* lock owner */ | |
156 | }; | |
157 | ||
158 | ||
c9017fa0 KB |
159 | #ifndef _POSIX_SOURCE |
160 | /* lock operations for flock(2) */ | |
161 | #define LOCK_SH 0x01 /* shared file lock */ | |
162 | #define LOCK_EX 0x02 /* exclusive file lock */ | |
163 | #define LOCK_NB 0x04 /* don't block when locking */ | |
164 | #define LOCK_UN 0x08 /* unlock file */ | |
ccf9310d | 165 | #endif |
f7532098 | 166 | |
a4128336 | 167 | |
0f9e0ffb | 168 | #ifndef KERNEL |
91befe9c KB |
169 | #include <sys/cdefs.h> |
170 | ||
171 | __BEGIN_DECLS | |
40ac131e | 172 | int open __P((const char *, int, ...)); |
91befe9c KB |
173 | int creat __P((const char *, mode_t)); |
174 | int fcntl __P((int, int, ...)); | |
92cdaf35 DS |
175 | #ifndef _POSIX_SOURCE |
176 | int flock __P((int, int)); | |
177 | #endif /* !_POSIX_SOURCE */ | |
91befe9c | 178 | __END_DECLS |
0f9e0ffb | 179 | #endif |
c9017fa0 | 180 | |
91befe9c | 181 | #endif /* !_FCNTL_H_ */ |