/* [<][>][^][v][top][bottom][index][help] */
1 /*
2 * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008
3 * The President and Fellows of Harvard College.
4 *
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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #ifndef _KERN_FCNTL_H_
31 #define _KERN_FCNTL_H_
32
33 /*
34 * Constants for libc's <fcntl.h>.
35 */
36
37
38 /*
39 * Important
40 */
41
42 /* Flags for open: choose one of these: */
43 #define O_RDONLY 0 /* Open for read */
44 #define O_WRONLY 1 /* Open for write */
45 #define O_RDWR 2 /* Open for read and write */
46 /* then or in any of these: */
47 #define O_CREAT 4 /* Create file if it doesn't exist */
48 #define O_EXCL 8 /* With O_CREAT, fail if file already exists */
49 #define O_TRUNC 16 /* Truncate file upon open */
50 #define O_APPEND 32 /* All writes happen at EOF (optional feature) */
51 #define O_NOCTTY 64 /* Required by POSIX, != 0, but does nothing */
52
53 /* Additional related definition */
54 #define O_ACCMODE 3 /* mask for O_RDONLY/O_WRONLY/O_RDWR */
55
56 /*
57 * Not so important
58 */
59
60 /* operation codes for flock() */
61 #define LOCK_SH 1 /* shared lock */
62 #define LOCK_EX 2 /* exclusive lock */
63 #define LOCK_UN 3 /* release the lock */
64 #define LOCK_NB 4 /* flag: don't block */
65
66 /*
67 * Mostly pretty useless
68 */
69
70 /* fcntl() operations */
71 #define F_DUPFD 0 /* like dup() but not quite */
72 #define F_GETFD 1 /* get per-handle flags */
73 #define F_SETFD 2 /* set per-handle flags */
74 #define F_GETFL 3 /* get per-file flags (O_* open flags) */
75 #define F_SETFL 4 /* set per-file flags (O_* open flags) */
76 #define F_GETOWN 5 /* get process/pgroup for SIGURG and SIGIO */
77 #define F_SETOWN 6 /* set process/pgroup for SIGURG and SIGIO */
78 #define F_GETLK 7 /* inspect record locks */
79 #define F_SETLK 8 /* acquire record locks nonblocking */
80 #define F_SETLKW 9 /* acquire record locks and wait */
81
82 /* flag for F_GETFD and F_SETFD */
83 #define FD_CLOEXEC 1 /* close-on-exec */
84
85 /* modes for fcntl (F_GETLK/SETLK) locking */
86 #define F_RDLCK 0 /* shared lock */
87 #define F_WRLCK 1 /* exclusive lock */
88 #define F_UNLCK 2 /* unlock */
89
90 /* struct for fcntl (F_GETLK/SETLK) locking */
91 struct flock {
92 off_t l_start; /* place in file */
93 int l_whence; /* SEEK_SET, SEEK_CUR, or SEEK_END */
94 int l_type; /* F_RDLCK or F_WRLCK */
95 off_t l_len; /* length of locked region */
96 pid_t l_pid; /* process that holds the lock */
97 };
98
99
100 #endif /* _KERN_FCNTL_H_ */