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