xref: /titanic_50/usr/src/uts/common/sys/file.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef _SYS_FILE_H
32 #define	_SYS_FILE_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 11.28 */
35 
36 #include <sys/t_lock.h>
37 #ifdef _KERNEL
38 #include <sys/model.h>
39 #include <sys/user.h>
40 #endif
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * fio locking:
48  *   f_rwlock	protects f_vnode and f_cred
49  *   f_tlock	protects the rest
50  *
51  *   The purpose of locking in this layer is to keep the kernel
52  *   from panicing if, for example, a thread calls close() while
53  *   another thread is doing a read().  It is up to higher levels
54  *   to make sure 2 threads doing I/O to the same file don't
55  *   screw each other up.
56  */
57 /*
58  * One file structure is allocated for each open/creat/pipe call.
59  * Main use is to hold the read/write pointer associated with
60  * each open file.
61  */
62 typedef struct file {
63 	kmutex_t	f_tlock;	/* short term lock */
64 	ushort_t	f_flag;
65 	ushort_t	f_pad;		/* Explicit pad to 4 byte boundary */
66 	struct vnode	*f_vnode;	/* pointer to vnode structure */
67 	offset_t	f_offset;	/* read/write character pointer */
68 	struct cred	*f_cred;	/* credentials of user who opened it */
69 	struct f_audit_data	*f_audit_data;	/* file audit data */
70 	int		f_count;	/* reference count */
71 } file_t;
72 
73 /*
74  * fpollinfo struct - used by poll caching to track who has polled the fd
75  */
76 typedef struct fpollinfo {
77 	struct _kthread		*fp_thread;	/* thread caching poll info */
78 	struct fpollinfo	*fp_next;
79 } fpollinfo_t;
80 
81 /* flags */
82 
83 #define	FOPEN		0xffffffff
84 #define	FREAD		0x01	/* <sys/aiocb.h> LIO_READ must be identical */
85 #define	FWRITE		0x02	/* <sys/aiocb.h> LIO_WRITE must be identical */
86 #define	FNDELAY		0x04
87 #define	FAPPEND		0x08
88 #define	FSYNC		0x10	/* file (data+inode) integrity while writing */
89 #ifdef C2_AUDIT
90 #define	FREVOKED	0x20	/* C2 Security - Revoke Subsystem */
91 #endif
92 #define	FDSYNC		0x40	/* file data only integrity while writing */
93 #define	FRSYNC		0x8000	/* sync read operations at same level of */
94 				/* integrity as specified for writes by */
95 				/* FSYNC and FDSYNC flags */
96 #define	FOFFMAX		0x2000	/* large file */
97 #define	FNONBLOCK	0x80
98 
99 #define	FMASK		0xa0ff	/* all flags that can be changed by F_SETFL */
100 
101 /* open-only modes */
102 
103 #define	FCREAT		0x0100
104 #define	FTRUNC		0x0200
105 #define	FEXCL		0x0400
106 #define	FNOCTTY		0x0800
107 #define	FXATTR		0x4000	/* open as extended attribute */
108 
109 #define	FASYNC		0x1000	/* asyncio in progress pseudo flag */
110 #define	FNODSYNC	0x10000 /* fsync pseudo flag */
111 
112 #define	FNOFOLLOW	0x20000	/* don't follow symlinks */
113 #define	FNOLINKS	0x40000	/* don't allow multiple hard links */
114 
115 #ifdef _KERNEL
116 
117 /*
118  * Fake flags for driver ioctl calls to inform them of the originating
119  * process' model.  See <sys/model.h>
120  *
121  * Part of the Solaris 2.6+ DDI/DKI
122  */
123 #define	FMODELS	DATAMODEL_MASK	/* Note: 0x0ff00000 */
124 #define	FILP32	DATAMODEL_ILP32
125 #define	FLP64	DATAMODEL_LP64
126 #define	FNATIVE	DATAMODEL_NATIVE
127 
128 /*
129  * Large Files: The macro gets the offset maximum (refer to LFS API doc)
130  * corresponding to a file descriptor. We had the choice of storing
131  * this value in file descriptor. Right now we only have two
132  * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is
133  * inefficient to store these two values in a separate member in
134  * file descriptor. To avoid wasting spaces we define this macro.
135  * The day there are more than two offset maximum we may want to
136  * rewrite this macro.
137  */
138 
139 #define	OFFSET_MAX(fd)	((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T)
140 
141 /*
142  * Fake flag => internal ioctl call for layered drivers.
143  * Note that this flag deliberately *won't* fit into
144  * the f_flag field of a file_t.
145  *
146  * Part of the Solaris 2.x DDI/DKI.
147  */
148 #define	FKIOCTL		0x80000000	/* ioctl addresses are from kernel */
149 
150 /*
151  * Fake flag => this time to specify that the open(9E)
152  * comes from another part of the kernel, not userland.
153  *
154  * Part of the Solaris 2.x DDI/DKI.
155  */
156 #define	FKLYR		0x40000000	/* layered driver call */
157 
158 #endif	/* _KERNEL */
159 
160 /* miscellaneous defines */
161 
162 #ifndef L_SET
163 #define	L_SET	0	/* for lseek */
164 #endif /* L_SET */
165 
166 #if defined(_KERNEL)
167 
168 /*
169  * Routines dealing with user per-open file flags and
170  * user open files.
171  */
172 struct proc;	/* forward reference for function prototype */
173 struct vnodeops;
174 
175 extern file_t *getf(int);
176 extern void releasef(int);
177 extern void areleasef(int, uf_info_t *);
178 #ifndef	_BOOT
179 extern void closeall(uf_info_t *);
180 #endif
181 extern void flist_fork(uf_info_t *, uf_info_t *);
182 extern int closef(file_t *);
183 extern int closeandsetf(int, file_t *);
184 extern int ufalloc_file(int, file_t *);
185 extern int ufalloc(int);
186 extern int ufcanalloc(proc_t *, uint_t);
187 extern int falloc(struct vnode *, int, file_t **, int *);
188 extern void finit(void);
189 extern void unfalloc(file_t *);
190 extern void setf(int, file_t *);
191 extern int f_getfd_error(int, int *);
192 extern char f_getfd(int);
193 extern int f_setfd_error(int, int);
194 extern void f_setfd(int, char);
195 extern int f_getfl(int, int *);
196 extern int fassign(struct vnode **, int, int *);
197 extern void fcnt_add(uf_info_t *, int);
198 extern void close_exec(uf_info_t *);
199 extern void clear_stale_fd(void);
200 extern void clear_active_fd(int);
201 extern void free_afd(afd_t *afd);
202 extern int fisopen(struct vnode *);
203 extern void delfpollinfo(int);
204 extern void addfpollinfo(int);
205 extern int sock_getfasync(struct vnode *);
206 extern int files_can_change_zones(void);
207 #ifdef DEBUG
208 /* The following functions are only used in ASSERT()s */
209 extern void checkwfdlist(struct vnode *, fpollinfo_t *);
210 extern void checkfpollinfo(void);
211 extern int infpollinfo(int);
212 #endif	/* DEBUG */
213 
214 #endif	/* defined(_KERNEL) */
215 
216 #ifdef	__cplusplus
217 }
218 #endif
219 
220 #endif	/* _SYS_FILE_H */
221