xref: /titanic_52/usr/src/lib/libbc/inc/include/sys/fcntlcom.h (revision c2580b931007758eab8cb5ae8726ebe1588e259b)
1 /*
2  * Copyright (c) 1998,2001 by Sun Microsystems, Inc.
3  * All rights reserved.
4  */
5 
6 /*
7  * Copyright (c) 1983 Regents of the University of California.
8  * All rights reserved.  The Berkeley software License Agreement
9  * specifies the terms and conditions for redistribution.
10  */
11 
12 #ifndef	__SYS_FCNTLCOM_H
13 #define	__SYS_FCNTLCOM_H
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 #ifdef	__cplusplus
18 extern "C" {
19 #endif
20 
21 /*
22  * Rewack the FXXXXX values as _FXXXX so that _POSIX_SOURCE works.
23  */
24 #define	_FOPEN		(-1)	/* from sys/file.h, kernel use only */
25 #define	_FREAD		0x0001	/* read enabled */
26 #define	_FWRITE		0x0002	/* write enabled */
27 #define	_FNDELAY	0x0004	/* non blocking I/O (4.2 style) */
28 #define	_FAPPEND	0x0008	/* append (writes guaranteed at the end) */
29 #define	_FMARK		0x0010	/* internal; mark during gc() */
30 #define	_FDEFER		0x0020	/* internal; defer for next gc pass */
31 #define	_FASYNC		0x0040	/* signal pgrp when data ready */
32 #define	_FSHLOCK	0x0080	/* BSD flock() shared lock present */
33 #define	_FEXLOCK	0x0100	/* BSD flock() exclusive lock present */
34 #define	_FCREAT		0x0200	/* open with file create */
35 #define	_FTRUNC		0x0400	/* open with truncation */
36 #define	_FEXCL		0x0800	/* error on open if file exists */
37 #define	_FNBIO		0x1000	/* non blocking I/O (sys5 style) */
38 #define	_FSYNC		0x2000	/* do all writes synchronously */
39 #define	_FNONBLOCK	0x4000	/* non blocking I/O (POSIX style) */
40 #define	_FNOCTTY	0x8000	/* don't assign a ctty on this open */
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 /*	O_SYNC		_FSYNC		not posix, defined below */
57 /*	O_NDELAY	_FNDELAY 	set in include/fcntl.h */
58 /*	O_NDELAY	_FNBIO 		set in 5include/fcntl.h */
59 #define	O_NONBLOCK	_FNONBLOCK
60 #define	O_NOCTTY	_FNOCTTY
61 
62 #ifndef	_POSIX_SOURCE
63 
64 #define	O_SYNC		_FSYNC
65 
66 /*
67  * Flags that work for fcntl(fd, F_SETFL, FXXXX)
68  */
69 #define	FAPPEND		_FAPPEND
70 #define	FSYNC		_FSYNC
71 #define	FASYNC		_FASYNC
72 #define	FNBIO		_FNBIO
73 #define	FNONBIO		_FNONBLOCK	/* XXX fix to be NONBLOCK everywhere */
74 #define	FNDELAY		_FNDELAY
75 
76 /*
77  * Flags that are disallowed for fcntl's (FCNTLCANT);
78  * used for opens, internal state, or locking.
79  */
80 #define	FREAD		_FREAD
81 #define	FWRITE		_FWRITE
82 #define	FMARK		_FMARK
83 #define	FDEFER		_FDEFER
84 #define	FSHLOCK		_FSHLOCK
85 #define	FEXLOCK		_FEXLOCK
86 
87 /*
88  * The rest of the flags, used only for opens
89  */
90 #define	FOPEN		_FOPEN
91 #define	FCREAT		_FCREAT
92 #define	FTRUNC		_FTRUNC
93 #define	FEXCL		_FEXCL
94 #define	FNOCTTY		_FNOCTTY
95 
96 #endif	/* !_POSIX_SOURCE */
97 
98 /* XXX close on exec request; must match UF_EXCLOSE in user.h */
99 #define	FD_CLOEXEC	1	/* posix */
100 
101 /* fcntl(2) requests */
102 #define	F_DUPFD		0	/* Duplicate fildes */
103 #define	F_GETFD		1	/* Get fildes flags (close on exec) */
104 #define	F_SETFD		2	/* Set fildes flags (close on exec) */
105 #define	F_GETFL		3	/* Get file flags */
106 #define	F_SETFL		4	/* Set file flags */
107 #ifndef	_POSIX_SOURCE
108 #define	F_GETOWN 	5	/* Get owner - for ASYNC */
109 #define	F_SETOWN 	6	/* Set owner - for ASYNC */
110 #endif	/* !_POSIX_SOURCE */
111 #define	F_GETLK  	7	/* Get record-locking information */
112 #define	F_SETLK  	8	/* Set or Clear a record-lock (Non-Blocking) */
113 #define	F_SETLKW 	9	/* Set or Clear a record-lock (Blocking) */
114 #ifndef	_POSIX_SOURCE
115 #define	F_CNVT 		12	/* Convert a fhandle to an open fd */
116 #endif	/* !_POSIX_SOURCE */
117 
118 /* fcntl(2) flags (l_type field of flock structure) */
119 #define	F_RDLCK		1	/* read lock */
120 #define	F_WRLCK		2	/* write lock */
121 #define	F_UNLCK		3	/* remove lock(s) */
122 #ifndef	_POSIX_SOURCE
123 #define	F_UNLKSYS	4	/* remove remote locks for a given system */
124 #endif	/* !_POSIX_SOURCE */
125 
126 #include <sys/stdtypes.h>
127 
128 /* file segment locking set data type - information passed to system by user */
129 struct flock {
130 	short	l_type;		/* F_RDLCK, F_WRLCK, or F_UNLCK */
131 	short	l_whence;	/* flag to choose starting offset */
132 	long	l_start;	/* relative offset, in bytes */
133 	long	l_len;		/* length, in bytes; 0 means lock to EOF */
134 	short	l_pid;		/* returned with F_GETLK */
135 	short	l_xxx;		/* reserved for future use */
136 };
137 
138 #ifndef	_POSIX_SOURCE
139 /* extended file segment locking set data type */
140 struct eflock {
141 	short	l_type;		/* F_RDLCK, F_WRLCK, or F_UNLCK */
142 	short	l_whence;	/* flag to choose starting offset */
143 	long	l_start;	/* relative offset, in bytes */
144 	long	l_len;		/* length, in bytes; 0 means lock to EOF */
145 	short	l_pid;		/* returned with F_GETLK */
146 	short	l_xxx;		/* reserved for future use */
147 	long	l_rpid;		/* Remote process id wanting this lock */
148 	long	l_rsys;		/* Remote system id wanting this lock */
149 };
150 #endif	/* !_POSIX_SOURCE */
151 
152 #ifndef	KERNEL
153 #include <sys/stat.h>		/* sigh. for the mode bits for open/creat */
154 
155 int	open(/* char *path, int flags, mode_t modes */);
156 int	creat(/* char *path, mode_t modes */);
157 int	fcntl(/* int fd, cmd, ... */);
158 #endif	/* !KERNEL */
159 
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif	/* __SYS_FCNTLCOM_H */
165