1 /* Copyright (c) 2007 Jeff Johnston  <jjohnstn@redhat.com> */
2 
3 #ifndef	_SYS__DEFAULT_FCNTL_H_
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 #define	_SYS__DEFAULT_FCNTL_H_
8 #include <_ansi.h>
9 #include <sys/cdefs.h>
10 #define	_FOPEN		(-1)	/* from sys/file.h, kernel use only */
11 #define	_FREAD		0x0001	/* read enabled */
12 #define	_FWRITE		0x0002	/* write enabled */
13 #define	_FAPPEND	0x0400	/* append (writes guaranteed at the end) */
14 #define	_FMARK		0x0010	/* internal; mark during gc() */
15 #define	_FDEFER		0x0020	/* internal; defer for next gc pass */
16 #define	_FASYNC		0x0008	/* signal pgrp when data ready */
17 #define	_FSHLOCK	0x0080	/* BSD flock() shared lock present */
18 #define	_FEXLOCK	0x0100	/* BSD flock() exclusive lock present */
19 #define	_FCREAT		0x0040	/* open with file create */
20 #define	_FTRUNC		0x0200	/* open with truncation */
21 #define	_FEXCL		0x0800	/* error on open if file exists */
22 #define	_FNBIO		0x1000	/* non blocking I/O (sys5 style) */
23 #define	_FSYNC		0x2000	/* do all writes synchronously */
24 #define	_FNONBLOCK	0x4000	/* non blocking I/O (POSIX style) */
25 #define	_FNDELAY	_FNONBLOCK	/* non blocking I/O (4.2 style) */
26 #define	_FNOCTTY	0x8000	/* don't assign a ctty on this open */
27 #if defined (__CYGWIN__)
28 #define	_FBINARY	0x10000
29 #define	_FTEXT		0x20000
30 #endif
31 #define	_FNOINHERIT	0x40000
32 #define	_FDIRECT	0x80000
33 #define	_FNOFOLLOW	0x100000
34 #define	_FDIRECTORY	0x200000
35 #define	_FEXECSRCH	0x400000
36 #if defined (__CYGWIN__)
37 #define	_FTMPFILE	0x800000
38 #define	_FNOATIME	0x1000000
39 #define	_FPATH		0x2000000
40 #endif
41 
42 #define	O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)
43 
44 /*
45  * Flag values for open(2) and fcntl(2)
46  * The kernel adds 1 to the open modes to turn it into some
47  * combination of FREAD and FWRITE.
48  */
49 #define	O_RDONLY	0		/* +1 == FREAD */
50 #define	O_WRONLY	1		/* +1 == FWRITE */
51 #define	O_RDWR		2		/* +1 == FREAD|FWRITE */
52 #define	O_APPEND	_FAPPEND
53 #define	O_CREAT		_FCREAT
54 #define	O_TRUNC		_FTRUNC
55 #define	O_EXCL		_FEXCL
56 #define O_SYNC		_FSYNC
57 /*	O_NDELAY	_FNDELAY 	set in include/fcntl.h */
58 /*	O_NDELAY	_FNBIO 		set in include/fcntl.h */
59 #define	O_NONBLOCK	_FNONBLOCK
60 #define	O_NOCTTY	_FNOCTTY
61 
62 /* POSIX-1.2008 specific flags */
63 #if __POSIX_VISIBLE >= 200809
64 #define	O_CLOEXEC	_FNOINHERIT
65 #define	O_NOFOLLOW	_FNOFOLLOW
66 #define	O_DIRECTORY	_FDIRECTORY
67 #define	O_EXEC		_FEXECSRCH
68 #define	O_SEARCH	_FEXECSRCH
69 #endif
70 
71 #if __BSD_VISIBLE
72 #define	O_DIRECT	_FDIRECT
73 #endif
74 
75 #if defined (__CYGWIN__)
76 #define O_BINARY	_FBINARY
77 #define O_TEXT		_FTEXT
78 #define O_DSYNC         _FSYNC
79 #define O_RSYNC         _FSYNC
80 
81 /* Linux-specific flags */
82 #if __GNU_VISIBLE
83 #define O_TMPFILE	_FTMPFILE
84 #define O_NOATIME	_FNOATIME
85 #define O_PATH		_FPATH
86 #endif
87 #endif
88 
89 #if __MISC_VISIBLE
90 
91 /*
92  * Flags that work for fcntl(fd, F_SETFL, FXXXX)
93  */
94 #define	FAPPEND		_FAPPEND
95 #define	FSYNC		_FSYNC
96 #define	FASYNC		_FASYNC
97 #define	FNBIO		_FNBIO
98 #define	FNONBIO		_FNONBLOCK	/* XXX fix to be NONBLOCK everywhere */
99 #define	FNDELAY		_FNDELAY
100 
101 /*
102  * Flags that are disallowed for fcntl's (FCNTLCANT);
103  * used for opens, internal state, or locking.
104  */
105 #define	FREAD		_FREAD
106 #define	FWRITE		_FWRITE
107 #define	FMARK		_FMARK
108 #define	FDEFER		_FDEFER
109 #define	FSHLOCK		_FSHLOCK
110 #define	FEXLOCK		_FEXLOCK
111 
112 /*
113  * The rest of the flags, used only for opens
114  */
115 #define	FOPEN		_FOPEN
116 #define	FCREAT		_FCREAT
117 #define	FTRUNC		_FTRUNC
118 #define	FEXCL		_FEXCL
119 #define	FNOCTTY		_FNOCTTY
120 
121 #endif	/* __MISC_VISIBLE */
122 
123 #if __BSD_VISIBLE
124 #define	FNONBLOCK	_FNONBLOCK
125 #endif	/* __BSD_VISIBLE */
126 
127 /* XXX close on exec request; must match UF_EXCLOSE in user.h */
128 #define	FD_CLOEXEC	1	/* posix */
129 
130 /* fcntl(2) requests */
131 #define	F_DUPFD		0	/* Duplicate fildes */
132 #define	F_GETFD		1	/* Get fildes flags (close on exec) */
133 #define	F_SETFD		2	/* Set fildes flags (close on exec) */
134 #define	F_GETFL		3	/* Get file flags */
135 #define	F_SETFL		4	/* Set file flags */
136 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
137 #define	F_GETOWN 	5	/* Get owner - for ASYNC */
138 #define	F_SETOWN 	6	/* Set owner - for ASYNC */
139 #endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 */
140 #define	F_GETLK  	7	/* Get record-locking information */
141 #define	F_SETLK  	8	/* Set or Clear a record-lock (Non-Blocking) */
142 #define	F_SETLKW 	9	/* Set or Clear a record-lock (Blocking) */
143 #if __MISC_VISIBLE
144 #define	F_RGETLK 	10	/* Test a remote lock to see if it is blocked */
145 #define	F_RSETLK 	11	/* Set or unlock a remote lock */
146 #define	F_CNVT 		12	/* Convert a fhandle to an open fd */
147 #define	F_RSETLKW 	13	/* Set or Clear remote record-lock(Blocking) */
148 #endif	/* __MISC_VISIBLE */
149 #if __POSIX_VISIBLE >= 200809
150 #define	F_DUPFD_CLOEXEC	14	/* As F_DUPFD, but set close-on-exec flag */
151 #endif
152 
153 /* fcntl(2) flags (l_type field of flock structure) */
154 #define	F_RDLCK		1	/* read lock */
155 #define	F_WRLCK		2	/* write lock */
156 #define	F_UNLCK		3	/* remove lock(s) */
157 #if __MISC_VISIBLE
158 #define	F_UNLKSYS	4	/* remove remote locks for a given system */
159 #endif	/* __MISC_VISIBLE */
160 
161 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
162 /* Special descriptor value to denote the cwd in calls to openat(2) etc. */
163 #define AT_FDCWD -2
164 
165 /* Flag values for faccessat2) et al. */
166 #define AT_EACCESS                 0x0001
167 #define AT_SYMLINK_NOFOLLOW        0x0002
168 #define AT_SYMLINK_FOLLOW          0x0004
169 #define AT_REMOVEDIR               0x0008
170 #if __GNU_VISIBLE
171 #define AT_EMPTY_PATH              0x0010
172 #define _AT_NULL_PATHNAME_ALLOWED  0x4000 /* Internal flag used by futimesat */
173 #endif
174 #endif
175 
176 #if __BSD_VISIBLE
177 /* lock operations for flock(2) */
178 #define	LOCK_SH		0x01		/* shared file lock */
179 #define	LOCK_EX		0x02		/* exclusive file lock */
180 #define	LOCK_NB		0x04		/* don't block when locking */
181 #define	LOCK_UN		0x08		/* unlock file */
182 #endif
183 
184 /*#include <sys/stdtypes.h>*/
185 
186 #ifndef __CYGWIN__
187 /* file segment locking set data type - information passed to system by user */
188 struct flock {
189 	short	l_type;		/* F_RDLCK, F_WRLCK, or F_UNLCK */
190 	short	l_whence;	/* flag to choose starting offset */
191 	long	l_start;	/* relative offset, in bytes */
192 	long	l_len;		/* length, in bytes; 0 means lock to EOF */
193 	short	l_pid;		/* returned with F_GETLK */
194 	short	l_xxx;		/* reserved for future use */
195 };
196 #endif /* __CYGWIN__ */
197 
198 #if __MISC_VISIBLE
199 /* extended file segment locking set data type */
200 struct eflock {
201 	short	l_type;		/* F_RDLCK, F_WRLCK, or F_UNLCK */
202 	short	l_whence;	/* flag to choose starting offset */
203 	long	l_start;	/* relative offset, in bytes */
204 	long	l_len;		/* length, in bytes; 0 means lock to EOF */
205 	short	l_pid;		/* returned with F_GETLK */
206 	short	l_xxx;		/* reserved for future use */
207 	long	l_rpid;		/* Remote process id wanting this lock */
208 	long	l_rsys;		/* Remote system id wanting this lock */
209 };
210 #endif	/* __MISC_VISIBLE */
211 
212 #include <sys/types.h>
213 #include <sys/stat.h>		/* sigh. for the mode bits for open/creat */
214 
215 extern int open (const char *, int, ...);
216 #if __ATFILE_VISIBLE
217 extern int openat (int, const char *, int, ...);
218 #endif
219 extern int creat (const char *, mode_t);
220 extern int fcntl (int, int, ...);
221 #if __BSD_VISIBLE
222 extern int flock (int, int);
223 #endif
224 #if __GNU_VISIBLE
225 #include <sys/time.h>
226 extern int futimesat (int, const char *, const struct timeval [2]);
227 #endif
228 
229 /* Provide _<systemcall> prototypes for functions provided by some versions
230    of newlib.  */
231 #ifdef _LIBC
232 extern int open (const char *, int, ...);
233 extern int fcntl (int, int, ...);
234 #ifdef __LARGE64_FILES
235 extern int open64 (const char *, int, ...);
236 #endif
237 #endif
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 #endif	/* !_SYS__DEFAULT_FCNTL_H_ */
243