summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/fcntl.h
blob: 22050a3d542c1677385c6bf0f2769e05efd5d6ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
/*	  All Rights Reserved  	*/

/*
 * University Copyright- Copyright (c) 1982, 1986, 1988
 * The Regents of the University of California
 * All Rights Reserved
 *
 * University Acknowledgment- Portions of this document are derived from
 * software developed by the University of California, Berkeley, and its
 * contributors.
 */

#ifndef	_SYS_FCNTL_H
#define	_SYS_FCNTL_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/feature_tests.h>

#include <sys/types.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * Flag values accessible to open(2) and fcntl(2)
 * (the first three can only be set by open(2)).
 */
#define	O_RDONLY	0
#define	O_WRONLY	1
#define	O_RDWR		2
#if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE)
#define	O_NDELAY	0x04	/* non-blocking I/O */
#endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) */
#define	O_APPEND	0x08	/* append (writes guaranteed at the end) */
#if defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) || \
	(_POSIX_C_SOURCE > 2) || defined(_XOPEN_SOURCE)
#define	O_SYNC		0x10	/* synchronized file update option */
#define	O_DSYNC		0x40	/* synchronized data update option */
#define	O_RSYNC		0x8000	/* synchronized file update option */
				/* defines read/write file integrity */
#endif /* defined(__EXTENSIONS__) || !defined(_POSIX_C_SOURCE) ... */
#define	O_NONBLOCK	0x80	/* non-blocking I/O (POSIX) */
#ifdef	SUN_SRC_COMPAT
#define	O_PRIV 		0x1000  /* Private access to file */
#endif /* SUN_SRC_COMPAT */
#ifdef	_LARGEFILE_SOURCE
#define	O_LARGEFILE	0x2000
#endif

/*
 * Flag values accessible only to open(2).
 */
#define	O_CREAT		0x100	/* open with file create (uses third arg) */
#define	O_TRUNC		0x200	/* open with truncation */
#define	O_EXCL		0x400	/* exclusive open */
#define	O_NOCTTY	0x800	/* don't allocate controlling tty (POSIX) */
#define	O_XATTR		0x4000	/* extended attribute */
#define	O_NOFOLLOW	0x20000	/* don't follow symlinks */
#define	O_NOLINKS	0x40000	/* don't allow multiple hard links */

/*
 * fcntl(2) requests
 *
 * N.B.: values are not necessarily assigned sequentially below.
 */
#define	F_DUPFD		0	/* Duplicate fildes */
#define	F_GETFD		1	/* Get fildes flags */
#define	F_SETFD		2	/* Set fildes flags */
#define	F_GETFL		3	/* Get file flags */
#define	F_GETXFL	45	/* Get file flags including open-only flags */
#define	F_SETFL		4	/* Set file flags */

/*
 * Applications that read /dev/mem must be built like the kernel.  A
 * new symbol "_KMEMUSER" is defined for this purpose.
 */
#if defined(_KERNEL) || defined(_KMEMUSER)
#define	F_O_GETLK	5	/* SVR3 Get file lock (need for rfs, across */
				/* the wire compatibility */
/* clustering: lock id contains both per-node sysid and node id */
#define	SYSIDMASK		0x0000ffff
#define	GETSYSID(id)		(id & SYSIDMASK)
#define	NODEIDMASK		0xffff0000
#define	BITS_IN_SYSID		16
#define	GETNLMID(sysid)		((int)(((uint_t)(sysid) & NODEIDMASK) >> \
				    BITS_IN_SYSID))

/* Clustering: Macro used for PXFS locks */
#define	GETPXFSID(sysid)	((int)(((uint_t)(sysid) & NODEIDMASK) >> \
				    BITS_IN_SYSID))
#endif	/* defined(_KERNEL) */

#define	F_CHKFL		8	/* Unused */
#define	F_DUP2FD	9	/* Duplicate fildes at third arg */

#define	F_ISSTREAM	13	/* Is the file desc. a stream ? */
#define	F_PRIV		15	/* Turn on private access to file */
#define	F_NPRIV		16	/* Turn off private access to file */
#define	F_QUOTACTL	17	/* UFS quota call */
#define	F_BLOCKS	18	/* Get number of BLKSIZE blocks allocated */
#define	F_BLKSIZE	19	/* Get optimal I/O block size */
/*
 * Numbers 20-22 have been removed and should not be reused.
 */
#define	F_GETOWN	23	/* Get owner (socket emulation) */
#define	F_SETOWN	24	/* Set owner (socket emulation) */

#ifdef C2_AUDIT
#define	F_REVOKE	25	/* C2 Security. Revoke access to file desc. */
#endif

#define	F_HASREMOTELOCKS 26	/* Does vp have NFS locks; private to lock */
				/* manager */

/*
 * Commands that refer to flock structures.  The argument types differ between
 * the large and small file environments; therefore, the #defined values must
 * as well.
 * The NBMAND forms are private and should not be used.
 */

#if defined(_LP64) || _FILE_OFFSET_BITS == 32
/* "Native" application compilation environment */
#define	F_SETLK		6	/* Set file lock */
#define	F_SETLKW	7	/* Set file lock and wait */
#define	F_ALLOCSP	10	/* Allocate file space */
#define	F_FREESP	11	/* Free file space */
#define	F_GETLK		14	/* Get file lock */
#define	F_SETLK_NBMAND	42	/* private */
#else
/* ILP32 large file application compilation environment version */
#define	F_SETLK		34	/* Set file lock */
#define	F_SETLKW	35	/* Set file lock and wait */
#define	F_ALLOCSP	28	/* Alllocate file space */
#define	F_FREESP	27	/* Free file space */
#define	F_GETLK		33	/* Get file lock */
#define	F_SETLK_NBMAND	44	/* private */
#endif /* _LP64 || _FILE_OFFSET_BITS == 32 */

#if 	defined(_LARGEFILE64_SOURCE)

#if !defined(_LP64) || defined(_KERNEL)
/*
 * transitional large file interface version
 * These are only valid in a 32 bit application compiled with large files
 * option, for source compatibility, the 64-bit versions are mapped back
 * to the native versions.
 */
#define	F_SETLK64	34	/* Set file lock */
#define	F_SETLKW64	35	/* Set file lock and wait */
#define	F_ALLOCSP64	28	/* Allocate file space */
#define	F_FREESP64	27	/* Free file space */
#define	F_GETLK64	33	/* Get file lock */
#define	F_SETLK64_NBMAND	44	/* private */
#else
#define	F_SETLK64	6	/* Set file lock */
#define	F_SETLKW64	7	/* Set file lock and wait */
#define	F_ALLOCSP64	10	/* Allocate file space */
#define	F_FREESP64	11	/* Free file space */
#define	F_GETLK64	14	/* Get file lock */
#define	F_SETLK64_NBMAND	42	/* private */
#endif /* !_LP64 || _KERNEL */

#endif /* _LARGEFILE64_SOURCE */

#define	F_SHARE		40	/* Set a file share reservation */
#define	F_UNSHARE	41	/* Remove a file share reservation */
#define	F_SHARE_NBMAND	43	/* private */

#define	F_BADFD		46	/* Create Poison FD */

/*
 * File segment locking set data type - information passed to system by user.
 */

/* regular version, for both small and large file compilation environment */
typedef struct flock {
	short	l_type;
	short	l_whence;
	off_t	l_start;
	off_t	l_len;		/* len == 0 means until end of file */
	int	l_sysid;
	pid_t	l_pid;
	long	l_pad[4];		/* reserve area */
} flock_t;

#if defined(_SYSCALL32)

/* Kernel's view of ILP32 flock structure */

typedef struct flock32 {
	int16_t	l_type;
	int16_t	l_whence;
	off32_t	l_start;
	off32_t	l_len;		/* len == 0 means until end of file */
	int32_t	l_sysid;
	pid32_t	l_pid;
	int32_t	l_pad[4];		/* reserve area */
} flock32_t;

#endif /* _SYSCALL32 */

/* transitional large file interface version */

#if 	defined(_LARGEFILE64_SOURCE)

typedef struct flock64 {
	short	l_type;
	short	l_whence;
	off64_t	l_start;
	off64_t	l_len;		/* len == 0 means until end of file */
	int	l_sysid;
	pid_t	l_pid;
	long	l_pad[4];		/* reserve area */
} flock64_t;

#if defined(_SYSCALL32)

/* Kernel's view of ILP32 flock64 */

#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma	pack(4)
#endif

typedef struct flock64_32 {
	int16_t	l_type;
	int16_t	l_whence;
	off64_t	l_start;
	off64_t	l_len;		/* len == 0 means until end of file */
	int32_t	l_sysid;
	pid32_t	l_pid;
	int32_t	l_pad[4];		/* reserve area */
} flock64_32_t;

#if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
#pragma pack()
#endif

/* Kernel's view of LP64 flock64 */

typedef struct flock64_64 {
	int16_t	l_type;
	int16_t	l_whence;
	off64_t	l_start;
	off64_t	l_len;		/* len == 0 means until end of file */
	int32_t	l_sysid;
	pid32_t	l_pid;
	int64_t	l_pad[4];		/* reserve area */
} flock64_64_t;

#endif	/* _SYSCALL32 */

#endif /* _LARGEFILE64_SOURCE */

#if defined(_KERNEL) || defined(_KMEMUSER)
/* SVr3 flock type; needed for rfs across the wire compatibility */
typedef struct o_flock {
	int16_t	l_type;
	int16_t	l_whence;
	int32_t	l_start;
	int32_t	l_len;		/* len == 0 means until end of file */
	int16_t	l_sysid;
	int16_t	l_pid;
} o_flock_t;
#endif	/* defined(_KERNEL) */

/*
 * File segment locking types.
 */
#define	F_RDLCK		01	/* Read lock */
#define	F_WRLCK		02	/* Write lock */
#define	F_UNLCK		03	/* Remove lock(s) */
#define	F_UNLKSYS	04	/* remove remote locks for a given system */

/*
 * POSIX constants
 */

#define	O_ACCMODE	3	/* Mask for file access modes */
#define	FD_CLOEXEC	1	/* close on exec flag */

/*
 * DIRECTIO
 */
#if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
#define	DIRECTIO_OFF	(0)
#define	DIRECTIO_ON	(1)

/*
 * File share reservation type
 */
typedef struct fshare {
	short	f_access;
	short	f_deny;
	int	f_id;
} fshare_t;

/*
 * f_access values
 */
#define	F_RDACC		0x1	/* Read-only share access */
#define	F_WRACC		0x2	/* Write-only share access */
#define	F_RWACC		0x3	/* Read-Write share access */

/*
 * f_deny values
 */
#define	F_NODNY		0x0	/* Don't deny others access */
#define	F_RDDNY		0x1	/* Deny others read share access */
#define	F_WRDNY		0x2	/* Deny others write share access */
#define	F_RWDNY		0x3	/* Deny others read or write share access */
#define	F_COMPAT	0x8	/* Set share to old DOS compatibility mode */
#define	F_MANDDNY	0x10	/* private flag: mandatory enforcement */
#endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */

/*
 * Special flags for functions such as openat(), fstatat()....
 */
#if !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE) || \
	defined(__EXTENSIONS__)
#define	AT_FDCWD			0xffd19553
#define	AT_SYMLINK_NOFOLLOW		0x1000
#define	AT_REMOVEDIR			0x1
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_FCNTL_H */