xref: /illumos-gate/usr/src/ucbhead/sys/file.h (revision 8c0b080c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef _SYS_FILE_H
41 #define	_SYS_FILE_H
42 
43 #ifndef _SYS_TYPES_H
44 #include <sys/types.h>
45 #endif
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /*
52  * One file structure is allocated for each open/creat/pipe call.
53  * Main use is to hold the read/write pointer associated with
54  * each open file.
55  */
56 
57 typedef struct file
58 {
59 	struct file  *f_next;		/* pointer to next entry */
60 	struct file  *f_prev;		/* pointer to previous entry */
61 	ushort_t f_flag;
62 	cnt_t	f_count;		/* reference count */
63 	struct vnode *f_vnode;		/* pointer to vnode structure */
64 	off_t	f_offset;		/* read/write character pointer */
65 	struct	cred *f_cred;		/* credentials of user who opened it */
66 	struct	aioreq *f_aiof;		/* aio file list forward link	*/
67 	struct	aioreq *f_aiob;		/* aio file list backward link	*/
68 /* #ifdef MERGE */
69 	struct	file *f_slnk;		/* XENIX semaphore queue */
70 /* #endif MERGE */
71 } file_t;
72 
73 
74 #ifndef _SYS_FCNTL_H
75 #include <sys/fcntl.h>
76 #endif
77 
78 /* flags - see also fcntl.h */
79 
80 #ifndef FOPEN
81 #define	FOPEN	0xFFFFFFFF
82 #define	FREAD	0x01
83 #define	FWRITE	0x02
84 #define	FNDELAY	0x04
85 #define	FAPPEND	0x08
86 #define	FSYNC	0x10
87 #define	FNONBLOCK	0x80	/* Non-blocking flag (POSIX).	*/
88 
89 #define	FMASK	0xff		/* should be disjoint from FASYNC */
90 
91 /* open only modes */
92 
93 #define	FCREAT	0x100
94 #define	FTRUNC	0x200
95 #define	FEXCL	0x400
96 #define	FNOCTTY	0x800		/* don't allocate controlling tty (POSIX). */
97 #define	FASYNC	0x1000		/* asyncio is in progress */
98 #define	FPRIV	0x1000		/* open with private access */
99 
100 /* file descriptor flags */
101 #define	FCLOSEXEC	001	/* close on exec */
102 #endif
103 
104 /* record-locking options. */
105 #define	F_ULOCK		0	/* Unlock a previously locked region */
106 #define	F_LOCK		1	/* Lock a region for exclusive use */
107 #define	F_TLOCK		2	/* Test and lock a region for exclusive use */
108 #define	F_TEST		3	/* Test a region for other processes locks */
109 
110 /*
111  * flock operations.
112  */
113 #define	LOCK_SH		1	/* shared lock */
114 #define	LOCK_EX		2	/* exclusive lock */
115 #define	LOCK_NB		4	/* don't block when locking */
116 #define	LOCK_UN		8	/* unlock */
117 
118 /*
119  * Access call.
120  */
121 #define	F_OK		0	/* does file exist */
122 #define	X_OK		1	/* is it executable by caller */
123 #define	W_OK		2	/* writable by caller */
124 #define	R_OK		4	/* readable by caller */
125 
126 /*
127  * Lseek call.
128  */
129 #ifndef L_SET
130 #define	L_SET		0	/* absolute offset */
131 #define	L_INCR		1	/* relative to current offset */
132 #define	L_XTND		2	/* relative to end of file */
133 #endif
134 
135 
136 /* miscellaneous defines */
137 
138 #define	NULLFP ((struct file *)0)
139 
140 /*
141  * Count of number of entries in file list.
142  */
143 extern unsigned int filecnt;
144 
145 /*
146  * routines dealing with user per-open file flags and
147  * user open files.  getf() is declared in systm.h.  It
148  * probably belongs here.
149  */
150 #if defined(__STDC__)
151 extern void setf(int, file_t *);
152 extern void setpof(int, char);
153 extern char getpof(int);
154 extern int fassign(struct vnode **, int, int *);
155 #else
156 extern void setf(), setpof();
157 extern char getpof();
158 extern int fassign();
159 #endif
160 
161 extern off_t lseek();
162 
163 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
164 	!defined(__PRAGMA_REDEFINE_EXTNAME))
165 #if defined(__STDC__)
166 extern off64_t lseek64(int, off64_t, int);
167 #else
168 extern off64_t llseek64();
169 #endif
170 #endif  /* _LARGEFILE64_SOURCE... */
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif	/* _SYS_FILE_H */
177