Subversion Repositories tendra.SVN

Rev

Rev 80 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
72 7u83 1
#ifndef __TENDRA_FCNTL_H
2
#define __TENDRA_FCNTL_H
3
 
4
 
5
/*
6
 * Advisory file segment locking data type -
7
 * information passed to system by user
8
 */
9
 
10
struct flock {
11
	int	l_start;	/* starting offset */
12
	int	l_len;		/* len = 0 means until end of file */
13
	int	l_pid;		/* lock owner */
14
	short	l_type;		/* lock type: read/write, etc. */
15
	short	l_whence;	/* type of l_start */
16
	int	l_sysid;	/* remote system id or zero for local */
17
};
18
 
19
 
20
 
21
/*
22
 * File status flags: these are used by open(2), fcntl(2).
23
 * They are also used (indirectly) in the kernel file structure f_flags,
24
 * which is a superset of the open/fcntl flags.  Open flags and f_flags
25
 * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
26
 * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
27
 */
28
/* open-only flags */
29
#define	O_RDONLY	0x0000		/* open for reading only */
30
#define	O_WRONLY	0x0001		/* open for writing only */
31
#define	O_RDWR		0x0002		/* open for reading and writing */
32
#define	O_ACCMODE	0x0003		/* mask for above modes */
33
 
34
/*
35
 * Kernel encoding of open mode; separate read and write bits that are
36
 * independently testable: 1 greater than the above.
37
 *
38
 * XXX
39
 * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
40
 * which was documented to use FREAD/FWRITE, continues to work.
41
 */
42
#if __BSD_VISIBLE
43
#define	FREAD		0x0001
44
#define	FWRITE		0x0002
45
#endif
46
#define	O_NONBLOCK	0x0004		/* no delay */
47
#define	O_APPEND	0x0008		/* set append mode */
48
#if __BSD_VISIBLE
49
#define	O_SHLOCK	0x0010		/* open with shared file lock */
50
#define	O_EXLOCK	0x0020		/* open with exclusive file lock */
51
#define	O_ASYNC		0x0040		/* signal pgrp when data ready */
52
#define	O_FSYNC		0x0080		/* synchronous writes */
53
#endif
54
#define	O_SYNC		0x0080		/* POSIX synonym for O_FSYNC */
55
#if __POSIX_VISIBLE >= 200809
56
#define	O_NOFOLLOW	0x0100		/* don't follow symlinks */
57
#endif
58
#define	O_CREAT		0x0200		/* create if nonexistent */
59
#define	O_TRUNC		0x0400		/* truncate to zero length */
60
#define	O_EXCL		0x0800		/* error if already exists */
61
#ifdef _KERNEL
62
#define	FHASLOCK	0x4000		/* descriptor holds advisory lock */
63
#endif
64
 
65
/* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */
66
#define	O_NOCTTY	0x8000		/* don't assign controlling terminal */
67
 
68
#if __BSD_VISIBLE
69
/* Attempt to bypass buffer cache */
70
#define	O_DIRECT	0x00010000
71
#endif
72
 
73
#if __POSIX_VISIBLE >= 200809
74
#define	O_DIRECTORY	0x00020000	/* Fail if not directory */
75
#define	O_EXEC		0x00040000	/* Open for execute only */
76
#endif
77
#ifdef	_KERNEL
78
#define	FEXEC		O_EXEC
79
#endif
80
 
81
#if __POSIX_VISIBLE >= 200809
82
/* Defined by POSIX 1003.1-2008; BSD default, but reserve for future use. */
83
#define	O_TTY_INIT	0x00080000	/* Restore default termios attributes */
84
 
85
#define	O_CLOEXEC	0x00100000
86
#endif
87
 
88
#if __BSD_VISIBLE
89
#define	O_VERIFY	0x00200000	/* open only after verification */
90
#endif
91
 
92
/*
93
 * XXX missing O_DSYNC, O_RSYNC.
94
 */
95
 
96
#ifdef _KERNEL
97
 
98
/* Only for devfs d_close() flags. */
99
#define	FLASTCLOSE	O_DIRECTORY
100
#define	FREVOKE		O_VERIFY
101
/* Only for fo_close() from half-succeeded open */
102
#define	FOPENFAILED	O_TTY_INIT
103
 
104
/* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
105
#define	FFLAGS(oflags)	((oflags) & O_EXEC ? (oflags) : (oflags) + 1)
106
#define	OFLAGS(fflags)	((fflags) & O_EXEC ? (fflags) : (fflags) - 1)
107
 
108
/* bits to save after open */
109
#define	FMASK	(FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT|FEXEC)
110
/* bits settable by fcntl(F_SETFL, ...) */
111
#define	FCNTLFLAGS	(FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FRDAHEAD|O_DIRECT)
112
 
113
#if defined(COMPAT_FREEBSD7) || defined(COMPAT_FREEBSD6) || \
114
    defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4)
115
/*
116
 * Set by shm_open(3) in older libc's to get automatic MAP_ASYNC
117
 * behavior for POSIX shared memory objects (which are otherwise
118
 * implemented as plain files).
119
 */
120
#define	FPOSIXSHM	O_NOFOLLOW
121
#undef FCNTLFLAGS
122
#define	FCNTLFLAGS	(FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|FRDAHEAD| \
123
			 O_DIRECT)
124
#endif
125
#endif
126
 
127
/*
128
 * The O_* flags used to have only F* names, which were used in the kernel
129
 * and by fcntl.  We retain the F* names for the kernel f_flag field
130
 * and for backward compatibility for fcntl.  These flags are deprecated.
131
 */
132
#if __BSD_VISIBLE
133
#define	FAPPEND		O_APPEND	/* kernel/compat */
134
#define	FASYNC		O_ASYNC		/* kernel/compat */
135
#define	FFSYNC		O_FSYNC		/* kernel */
136
#define	FNONBLOCK	O_NONBLOCK	/* kernel */
137
#define	FNDELAY		O_NONBLOCK	/* compat */
80 7u83 138
#endif
139
 
140
#if defined (_SVID_SOURCE )
72 7u83 141
#define	O_NDELAY	O_NONBLOCK	/* compat */
142
#endif
143
 
80 7u83 144
 
72 7u83 145
/*
146
 * We are out of bits in f_flag (which is a short).  However,
147
 * the flag bits not set in FMASK are only meaningful in the
148
 * initial open syscall.  Those bits can thus be given a
149
 * different meaning for fcntl(2).
150
 */
151
#if __BSD_VISIBLE
152
/* Read ahead */
153
#define	FRDAHEAD	O_CREAT
154
#endif
155
 
156
#if __POSIX_VISIBLE >= 200809
157
/*
158
 * Magic value that specify the use of the current working directory
159
 * to determine the target of relative file paths in the openat() and
160
 * similar syscalls.
161
 */
162
#define	AT_FDCWD		-100
163
 
164
/*
165
 * Miscellaneous flags for the *at() syscalls.
166
 */
167
#define	AT_EACCESS		0x100	/* Check access using effective user and group ID */
168
#define	AT_SYMLINK_NOFOLLOW	0x200   /* Do not follow symbolic links */
169
#define	AT_SYMLINK_FOLLOW	0x400	/* Follow symbolic link */
170
#define	AT_REMOVEDIR		0x800	/* Remove directory instead of file */
171
#endif
172
 
173
/*
174
 * Constants used for fcntl(2)
175
 */
176
 
177
/* command values */
178
#define	F_DUPFD		0		/* duplicate file descriptor */
179
#define	F_GETFD		1		/* get file descriptor flags */
180
#define	F_SETFD		2		/* set file descriptor flags */
181
#define	F_GETFL		3		/* get file status flags */
182
#define	F_SETFL		4		/* set file status flags */
183
#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
184
#define	F_GETOWN	5		/* get SIGIO/SIGURG proc/pgrp */
185
#define	F_SETOWN	6		/* set SIGIO/SIGURG proc/pgrp */
186
#endif
187
#if __BSD_VISIBLE
188
#define	F_OGETLK	7		/* get record locking information */
189
#define	F_OSETLK	8		/* set record locking information */
190
#define	F_OSETLKW	9		/* F_SETLK; wait if blocked */
191
#define	F_DUP2FD	10		/* duplicate file descriptor to arg */
192
#endif
193
#define	F_GETLK		11		/* get record locking information */
194
#define	F_SETLK		12		/* set record locking information */
195
#define	F_SETLKW	13		/* F_SETLK; wait if blocked */
196
#if __BSD_VISIBLE
197
#define	F_SETLK_REMOTE	14		/* debugging support for remote locks */
198
#define	F_READAHEAD	15		/* read ahead */
199
#define	F_RDAHEAD	16		/* Darwin compatible read ahead */
200
#endif
201
#if __POSIX_VISIBLE >= 200809
202
#define	F_DUPFD_CLOEXEC	17		/* Like F_DUPFD, but FD_CLOEXEC is set */
203
#endif
204
#if __BSD_VISIBLE
205
#define	F_DUP2FD_CLOEXEC 18		/* Like F_DUP2FD, but FD_CLOEXEC is set */
206
#endif
207
 
208
/* file descriptor flags (F_GETFD, F_SETFD) */
209
#define	FD_CLOEXEC	1		/* close-on-exec flag */
210
 
211
/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
212
#define	F_RDLCK		1		/* shared or read lock */
213
#define	F_UNLCK		2		/* unlock */
214
#define	F_WRLCK		3		/* exclusive or write lock */
215
#if __BSD_VISIBLE
216
#define	F_UNLCKSYS	4		/* purge locks for a given system ID */ 
217
#define	F_CANCEL	5		/* cancel an async lock request */
218
#endif
219
#ifdef _KERNEL
220
#define	F_WAIT		0x010		/* Wait until lock is granted */
221
#define	F_FLOCK		0x020	 	/* Use flock(2) semantics for lock */
222
#define	F_POSIX		0x040	 	/* Use POSIX semantics for lock */
223
#define	F_REMOTE	0x080		/* Lock owner is remote NFS client */
224
#define	F_NOINTR	0x100		/* Ignore signals when waiting */
225
#endif
226
 
227
 
228
#if __BSD_VISIBLE
229
/* lock operations for flock(2) */
230
#define	LOCK_SH		0x01		/* shared file lock */
231
#define	LOCK_EX		0x02		/* exclusive file lock */
232
#define	LOCK_NB		0x04		/* don't block when locking */
233
#define	LOCK_UN		0x08		/* unlock file */
234
#endif
235
 
236
#if __POSIX_VISIBLE >= 200112
237
/*
238
 * Advice to posix_fadvise
239
 */
240
#define	POSIX_FADV_NORMAL	0	/* no special treatment */
241
#define	POSIX_FADV_RANDOM	1	/* expect random page references */
242
#define	POSIX_FADV_SEQUENTIAL	2	/* expect sequential page references */
243
#define	POSIX_FADV_WILLNEED	3	/* will need these pages */
244
#define	POSIX_FADV_DONTNEED	4	/* dont need these pages */
245
#define	POSIX_FADV_NOREUSE	5	/* access data only once */
246
#endif
247
 
248
#endif