Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | 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 */
138
#define	O_NDELAY	O_NONBLOCK	/* compat */
139
#endif
140
 
141
/*
142
 * We are out of bits in f_flag (which is a short).  However,
143
 * the flag bits not set in FMASK are only meaningful in the
144
 * initial open syscall.  Those bits can thus be given a
145
 * different meaning for fcntl(2).
146
 */
147
#if __BSD_VISIBLE
148
/* Read ahead */
149
#define	FRDAHEAD	O_CREAT
150
#endif
151
 
152
#if __POSIX_VISIBLE >= 200809
153
/*
154
 * Magic value that specify the use of the current working directory
155
 * to determine the target of relative file paths in the openat() and
156
 * similar syscalls.
157
 */
158
#define	AT_FDCWD		-100
159
 
160
/*
161
 * Miscellaneous flags for the *at() syscalls.
162
 */
163
#define	AT_EACCESS		0x100	/* Check access using effective user and group ID */
164
#define	AT_SYMLINK_NOFOLLOW	0x200   /* Do not follow symbolic links */
165
#define	AT_SYMLINK_FOLLOW	0x400	/* Follow symbolic link */
166
#define	AT_REMOVEDIR		0x800	/* Remove directory instead of file */
167
#endif
168
 
169
/*
170
 * Constants used for fcntl(2)
171
 */
172
 
173
/* command values */
174
#define	F_DUPFD		0		/* duplicate file descriptor */
175
#define	F_GETFD		1		/* get file descriptor flags */
176
#define	F_SETFD		2		/* set file descriptor flags */
177
#define	F_GETFL		3		/* get file status flags */
178
#define	F_SETFL		4		/* set file status flags */
179
#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
180
#define	F_GETOWN	5		/* get SIGIO/SIGURG proc/pgrp */
181
#define	F_SETOWN	6		/* set SIGIO/SIGURG proc/pgrp */
182
#endif
183
#if __BSD_VISIBLE
184
#define	F_OGETLK	7		/* get record locking information */
185
#define	F_OSETLK	8		/* set record locking information */
186
#define	F_OSETLKW	9		/* F_SETLK; wait if blocked */
187
#define	F_DUP2FD	10		/* duplicate file descriptor to arg */
188
#endif
189
#define	F_GETLK		11		/* get record locking information */
190
#define	F_SETLK		12		/* set record locking information */
191
#define	F_SETLKW	13		/* F_SETLK; wait if blocked */
192
#if __BSD_VISIBLE
193
#define	F_SETLK_REMOTE	14		/* debugging support for remote locks */
194
#define	F_READAHEAD	15		/* read ahead */
195
#define	F_RDAHEAD	16		/* Darwin compatible read ahead */
196
#endif
197
#if __POSIX_VISIBLE >= 200809
198
#define	F_DUPFD_CLOEXEC	17		/* Like F_DUPFD, but FD_CLOEXEC is set */
199
#endif
200
#if __BSD_VISIBLE
201
#define	F_DUP2FD_CLOEXEC 18		/* Like F_DUP2FD, but FD_CLOEXEC is set */
202
#endif
203
 
204
/* file descriptor flags (F_GETFD, F_SETFD) */
205
#define	FD_CLOEXEC	1		/* close-on-exec flag */
206
 
207
/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
208
#define	F_RDLCK		1		/* shared or read lock */
209
#define	F_UNLCK		2		/* unlock */
210
#define	F_WRLCK		3		/* exclusive or write lock */
211
#if __BSD_VISIBLE
212
#define	F_UNLCKSYS	4		/* purge locks for a given system ID */ 
213
#define	F_CANCEL	5		/* cancel an async lock request */
214
#endif
215
#ifdef _KERNEL
216
#define	F_WAIT		0x010		/* Wait until lock is granted */
217
#define	F_FLOCK		0x020	 	/* Use flock(2) semantics for lock */
218
#define	F_POSIX		0x040	 	/* Use POSIX semantics for lock */
219
#define	F_REMOTE	0x080		/* Lock owner is remote NFS client */
220
#define	F_NOINTR	0x100		/* Ignore signals when waiting */
221
#endif
222
 
223
 
224
#if __BSD_VISIBLE
225
/* lock operations for flock(2) */
226
#define	LOCK_SH		0x01		/* shared file lock */
227
#define	LOCK_EX		0x02		/* exclusive file lock */
228
#define	LOCK_NB		0x04		/* don't block when locking */
229
#define	LOCK_UN		0x08		/* unlock file */
230
#endif
231
 
232
#if __POSIX_VISIBLE >= 200112
233
/*
234
 * Advice to posix_fadvise
235
 */
236
#define	POSIX_FADV_NORMAL	0	/* no special treatment */
237
#define	POSIX_FADV_RANDOM	1	/* expect random page references */
238
#define	POSIX_FADV_SEQUENTIAL	2	/* expect sequential page references */
239
#define	POSIX_FADV_WILLNEED	3	/* will need these pages */
240
#define	POSIX_FADV_DONTNEED	4	/* dont need these pages */
241
#define	POSIX_FADV_NOREUSE	5	/* access data only once */
242
#endif
243
 
244
#endif