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