source: trunk/src/emx/include/sys/fcntl.h@ 1454

Last change on this file since 1454 was 1454, checked in by bird, 21 years ago

Joined with the fork() tree from netlabs.cvs.

  • Property cvs2svn:cvs-rev set to 1.6
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 11.1 KB
Line 
1/*-
2 * Copyright (c) 1983, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)fcntl.h 8.3 (Berkeley) 1/21/94
39 * $FreeBSD: src/sys/sys/fcntl.h,v 1.14 2002/09/17 22:22:50 mike Exp $
40 */
41
42/** @file
43 * FreeBSD 5.1 + EMX
44 *
45 * @changed bird: EMX isms.
46 * @changed bird: Removed (non KERNEL) stuff we don't implement and added
47 * EMX specific stuff.
48 * @todo Consider implementing the flags and commands we don't currently
49 * include.
50 */
51
52#ifndef _SYS_FCNTL_H_
53#define _SYS_FCNTL_H_
54#define _SYS_FCNTL_H /* bird: EMX */
55
56/*
57 * This file includes the definitions for open and fcntl
58 * described by POSIX for <fcntl.h>; it also includes
59 * related kernel definitions.
60 */
61
62#include <sys/cdefs.h>
63#include <sys/_types.h>
64
65#if !defined(_MODE_T_DECLARED) && !defined(_MODE_T) /* bird: EMX */
66typedef __mode_t mode_t;
67#define _MODE_T_DECLARED
68#define _MODE_T /* bird: EMX */
69#endif
70
71#if !defined(_OFF_T_DECLARED) && !defined(_OFF_T) /* bird: EMX */
72typedef __off_t off_t;
73#define _OFF_T_DECLARED
74#define _OFF_T /* bird: EMX */
75#endif
76
77#if !defined(_PID_T_DECLARED) && !defined(_PID_T) /* bird: EMX */
78typedef __pid_t pid_t;
79#define _PID_T_DECLARED
80#define _PID_T /* bird: EMX */
81#endif
82
83/*
84 * File status flags: these are used by open(2), fcntl(2).
85 * They are also used (indirectly) in the kernel file structure f_flags,
86 * which is a superset of the open/fcntl flags. Open flags and f_flags
87 * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
88 * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
89 */
90/* open-only flags */
91#define O_RDONLY 0x0000 /* open for reading only */
92#define O_WRONLY 0x0001 /* open for writing only */
93#define O_RDWR 0x0002 /* open for reading and writing */
94#define O_ACCMODE 0x0003 /* mask for above modes */
95
96/*
97 * Kernel encoding of open mode; separate read and write bits that are
98 * independently testable: 1 greater than the above.
99 *
100 * XXX
101 * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
102 * which was documented to use FREAD/FWRITE, continues to work.
103 */
104#if __BSD_VISIBLE
105#ifndef FREAD /* bird: safety */
106#define FREAD 0x0001
107#define FWRITE 0x0002
108#endif
109#endif /* bird: safety */
110#define O_NONBLOCK 0x0004 /* no delay */
111#define O_APPEND 0x0008 /* set append mode */
112#if __BSD_VISIBLE
113#if 0 /* bird: not implemented - start */
114#define O_SHLOCK 0x0010 /* open with shared file lock */
115#define O_EXLOCK 0x0020 /* open with exclusive file lock */
116#define O_ASYNC 0x0040 /* signal pgrp when data ready */
117#endif /* bird: not implemented - end */
118#define O_FSYNC 0x0080 /* synchronous writes */
119#endif
120/* bird: EMX used 0x2000 for O_SYNC. */
121#define O_SYNC 0x0080 /* POSIX synonym for O_FSYNC */
122#if 0 /* bird: not implemented - start */
123#if __BSD_VISIBLE
124#define O_NOFOLLOW 0x0100 /* don't follow symlinks */
125#endif
126#endif /* bird: not implemented - end */
127#define O_CREAT 0x0200 /* create if nonexistent */
128#define O_TRUNC 0x0400 /* truncate to zero length */
129#define O_EXCL 0x0800 /* error if already exists */
130#ifdef _KERNEL
131/* FMARK/FDEFER kept in f_gcflags */
132#define FMARK 0x1 /* mark during gc() */
133#define FDEFER 0x2 /* defer for next gc pass */
134#define FHASLOCK 0x4000 /* descriptor holds advisory lock */
135#endif
136
137/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */
138/* bird: EMX used 0x4000 for O_NOCTTY. */
139#define O_NOCTTY 0x8000 /* don't assign controlling terminal */
140
141#if 0 /* bird: not implemented - start */
142#if __BSD_VISIBLE
143/* Attempt to bypass buffer cache */
144#define O_DIRECT 0x00010000
145#endif
146#endif /* bird: not implemented - end */
147
148/*
149 * XXX missing O_DSYNC, O_RSYNC.
150 */
151
152#ifdef _KERNEL
153/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
154#define FFLAGS(oflags) ((oflags) + 1)
155#define OFLAGS(fflags) ((fflags) - 1)
156
157/* bits to save after open */
158#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT)
159/* bits settable by fcntl(F_SETFL, ...) */
160#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|O_DIRECT)
161#endif
162
163/*
164 * The O_* flags used to have only F* names, which were used in the kernel
165 * and by fcntl. We retain the F* names for the kernel f_flag field
166 * and for backward compatibility for fcntl. These flags are deprecated.
167 */
168#if __BSD_VISIBLE
169#define FAPPEND O_APPEND /* kernel/compat */
170#if 0 /* bird: not implemented - start */
171#define FASYNC O_ASYNC /* kernel/compat */
172#endif /* bird: not implemented - end */
173#define FFSYNC O_FSYNC /* kernel */
174#define FNONBLOCK O_NONBLOCK /* kernel */
175#define FNDELAY O_NONBLOCK /* compat */
176#define O_NDELAY O_NONBLOCK /* compat */
177#endif
178
179#if 0 /* bird: not implemented - start */
180/*
181 * We are out of bits in f_flag (which is a short). However,
182 * the flag bits not set in FMASK are only meaningful in the
183 * initial open syscall. Those bits can thus be given a
184 * different meaning for fcntl(2).
185 */
186#if __BSD_VISIBLE
187
188/*
189 * Set by shm_open(3) to get automatic MAP_ASYNC behavior
190 * for POSIX shared memory objects (which are otherwise
191 * implemented as plain files).
192 */
193#define FPOSIXSHM O_NOFOLLOW
194#endif
195#endif /* bird: not implemented - end */
196
197/*
198 * Constants used for fcntl(2)
199 */
200
201/* command values */
202/* bird: EMX used 5 for F_DUPFD. */
203#define F_DUPFD 0 /* duplicate file descriptor */
204/* bird: EMX used 3 for F_GETFD. */
205#define F_GETFD 1 /* get file descriptor flags */
206/* bird: EMX used 4 for F_SETFD. */
207#define F_SETFD 2 /* set file descriptor flags */
208/* bird: EMX used 1 for F_GETFL. */
209#define F_GETFL 3 /* get file status flags */
210/* bird: EMX used 2 for F_SETFL. */
211#define F_SETFL 4 /* set file status flags */
212#if 0 /* bird: not implemented - start */
213#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
214#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */
215#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */
216#endif
217#endif /* bird: not implemented - end */
218#define F_GETLK 7 /* get record locking information */
219#define F_SETLK 8 /* set record locking information */
220#define F_SETLKW 9 /* F_SETLK; wait if blocked */
221
222
223/* file descriptor flags (F_GETFD, F_SETFD) */
224#define FD_CLOEXEC 1 /* close-on-exec flag */
225
226/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
227#define F_RDLCK 1 /* shared or read lock */
228#define F_UNLCK 2 /* unlock */
229#define F_WRLCK 3 /* exclusive or write lock */
230#ifdef _KERNEL
231#define F_WAIT 0x010 /* Wait until lock is granted */
232#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */
233#define F_POSIX 0x040 /* Use POSIX semantics for lock */
234#endif
235
236/*
237 * Advisory file segment locking data type -
238 * information passed to system by user
239 */
240struct flock {
241 off_t l_start; /* starting offset */
242 off_t l_len; /* len = 0 means until end of file */
243 pid_t l_pid; /* lock owner */
244 short l_type; /* lock type: read/write, etc. */
245 short l_whence; /* type of l_start */
246};
247
248
249#if __BSD_VISIBLE
250/* lock operations for flock(2) */
251#define LOCK_SH 0x01 /* shared file lock */
252#define LOCK_EX 0x02 /* exclusive file lock */
253#define LOCK_NB 0x04 /* don't block when locking */
254#define LOCK_UN 0x08 /* unlock file */
255#endif
256
257/*
258 * XXX missing posix_fadvise() and posix_fallocate(), and POSIX_FADV_* macros.
259 */
260
261#ifndef _KERNEL
262__BEGIN_DECLS
263int open(const char *, int, ...);
264int creat(const char *, mode_t);
265int fcntl(int, int, ...);
266#if __BSD_VISIBLE
267int flock(int, int);
268#endif
269__END_DECLS
270#endif
271
272/* bird: EMX stuff - start */
273#if !defined (O_TEXT)
274/* Open flags.
275 As stated in the FreeBSD part, there is supposidly a limited number of bits
276 available. We'll try keep it suitable for 16bit just in case (don't care to
277 check what we use right now) because that'll enable us to share a 32-bit flag
278 variable per handle to both status (O_*) flags and descriptor (FD_*) flags.
279
280 When we've disabled a few BSD flags and leave out KERNEL stuff the following
281 bits are available:
282 0x0010, 0x0020, 0x0040, 0x0100, 0x1000, 0x4000*, 0x2000
283*/
284#define O_TEXT 0x0010
285#define O_BINARY 0x0100
286#define O_SIZE 0x0020 /* EMX used 0x8000 for O_SIZE. */
287#if !defined (_POSIX_SOURCE) || defined(__USE_EMX)
288#define O_NOINHERIT 0x1000 /* EMX used 0x1000 for O_NOINHERIT. */
289#endif
290#endif
291
292/* fcntl command */
293/* bird: EMX specifics - start */
294#define F_GETOSFD 20 /* RSXNT */ /* F_GETOSFD used to be 6 */
295/* bird: EMX specifics - end */
296
297
298#if !defined (F_OK) /* bird: Really defined in unistd.h, but Linux and EMX does it here too. */
299/* access function */
300#define F_OK 0 /* test for existence of file */
301#define X_OK 0x01 /* test for execute or search permission */
302#define W_OK 0x02 /* test for write permission */
303#define R_OK 0x04 /* test for read permission */
304#endif
305
306#if !defined (_POSIX_SOURCE) || defined (_WITH_UNDERSCORE) || defined(__USE_EMX)
307__BEGIN_DECLS
308int _creat (__const__ char *, int);
309int _fcntl (int, int, ...);
310int _flock (int, int);
311int _open (__const__ char *, int, ...);
312__END_DECLS
313#endif
314/* bird: EMX stuff - end */
315
316#endif /* !_SYS_FCNTL_H_ */
Note: See TracBrowser for help on using the repository browser.