]>
Commit | Line | Data |
---|---|---|
91447636 | 1 | /* |
8ad349bb | 2 | * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved. |
91447636 | 3 | * |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
91447636 | 5 | * |
8ad349bb A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the | |
10 | * License may not be used to create, or enable the creation or | |
11 | * redistribution of, unlawful or unlicensed copies of an Apple operating | |
12 | * system, or to circumvent, violate, or enable the circumvention or | |
13 | * violation of, any terms of an Apple operating system software license | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
20 | * The Original Code and all software distributed under the License are | |
21 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
22 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
23 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
24 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
25 | * Please see the License for the specific language governing rights and | |
26 | * limitations under the License. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
91447636 A |
29 | */ |
30 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
31 | /* | |
32 | * Copyright (c) 1989, 1993 | |
33 | * The Regents of the University of California. All rights reserved. | |
34 | * | |
35 | * Redistribution and use in source and binary forms, with or without | |
36 | * modification, are permitted provided that the following conditions | |
37 | * are met: | |
38 | * 1. Redistributions of source code must retain the above copyright | |
39 | * notice, this list of conditions and the following disclaimer. | |
40 | * 2. Redistributions in binary form must reproduce the above copyright | |
41 | * notice, this list of conditions and the following disclaimer in the | |
42 | * documentation and/or other materials provided with the distribution. | |
43 | * 3. All advertising materials mentioning features or use of this software | |
44 | * must display the following acknowledgement: | |
45 | * This product includes software developed by the University of | |
46 | * California, Berkeley and its contributors. | |
47 | * 4. Neither the name of the University nor the names of its contributors | |
48 | * may be used to endorse or promote products derived from this software | |
49 | * without specific prior written permission. | |
50 | * | |
51 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
52 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
61 | * SUCH DAMAGE. | |
62 | * | |
63 | * @(#)vnode.h 8.17 (Berkeley) 5/20/95 | |
64 | */ | |
65 | ||
66 | #ifndef _SYS_VNODE_INTERNAL_H_ | |
67 | #define _SYS_VNODE_INTERNAL_H_ | |
68 | ||
69 | #define INTERIM_FSNODE_LOCK 1 | |
70 | ||
71 | #include <sys/appleapiopts.h> | |
72 | #include <sys/cdefs.h> | |
73 | #include <sys/queue.h> | |
74 | #include <sys/lock.h> | |
75 | ||
76 | #include <sys/time.h> | |
77 | #include <sys/uio.h> | |
78 | ||
79 | #include <sys/vm.h> | |
80 | #include <sys/systm.h> | |
81 | #include <kern/locks.h> | |
82 | #include <vm/vm_kern.h> | |
83 | #include <sys/vnode.h> | |
84 | #include <sys/namei.h> | |
85 | #include <sys/vfs_context.h> | |
86 | ||
87 | ||
88 | struct lockf; | |
89 | ||
90 | LIST_HEAD(buflists, buf); | |
91 | ||
92 | ||
93 | struct unsafe_fsnode { | |
94 | lck_mtx_t fsnodelock; | |
95 | int32_t fsnode_count; | |
96 | void * fsnodeowner; | |
97 | }; | |
98 | ||
99 | /* | |
100 | * Reading or writing any of these items requires holding the appropriate lock. | |
101 | * v_freelist is locked by the global vnode_list_lock | |
102 | * v_mntvnodes is locked by the mount_lock | |
103 | * v_nclinks and v_ncchildren are protected by the global name_cache_lock | |
104 | * v_cleanblkhd and v_dirtyblkhd and v_iterblkflags are locked via the global buf_mtxp | |
105 | * the rest of the structure is protected by the vnode_lock | |
106 | */ | |
107 | struct vnode { | |
108 | lck_mtx_t v_lock; /* vnode mutex */ | |
109 | TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */ | |
110 | TAILQ_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */ | |
111 | LIST_HEAD(, namecache) v_nclinks; /* name cache entries that name this vnode */ | |
112 | LIST_HEAD(, namecache) v_ncchildren; /* name cache entries that regard us as there parent */ | |
113 | vnode_t v_defer_reclaimlist; /* in case we have to defer the reclaim to avoid recursion */ | |
114 | u_long v_flag; /* vnode flags (see below) */ | |
115 | u_short v_lflag; /* vnode local and named ref flags */ | |
116 | u_char v_iterblkflags; /* buf iterator flags */ | |
117 | u_char v_references; /* number of times io_count has been granted */ | |
118 | int32_t v_kusecount; /* count of in-kernel refs */ | |
119 | int32_t v_usecount; /* reference count of users */ | |
120 | int32_t v_iocount; /* iocounters */ | |
121 | void * v_owner; /* act that owns the vnode */ | |
122 | enum vtype v_type; /* vnode type */ | |
123 | u_long v_id; /* identity of vnode contents */ | |
124 | union { | |
125 | struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */ | |
126 | struct socket *vu_socket; /* unix ipc (VSOCK) */ | |
127 | struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */ | |
128 | struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */ | |
129 | struct ubc_info *vu_ubcinfo; /* valid for (VREG) */ | |
130 | } v_un; | |
131 | struct buflists v_cleanblkhd; /* clean blocklist head */ | |
132 | struct buflists v_dirtyblkhd; /* dirty blocklist head */ | |
133 | kauth_cred_t v_cred; | |
134 | int v_cred_timestamp; | |
135 | long v_numoutput; /* num of writes in progress */ | |
136 | long v_writecount; /* reference count of writers */ | |
137 | char * v_name; /* name component of the vnode */ | |
138 | vnode_t v_parent; /* pointer to parent vnode */ | |
139 | #ifdef INTERIM_FSNODE_LOCK | |
140 | struct lockf *v_lockf; /* advisory lock list head */ | |
141 | struct unsafe_fsnode *v_unsafefs; /* pointer to struct used to lock */ | |
142 | #endif /* vnodes on unsafe filesystems */ | |
143 | int (**v_op)(void *); /* vnode operations vector */ | |
144 | enum vtagtype v_tag; /* type of underlying data */ | |
145 | mount_t v_mount; /* ptr to vfs we are in */ | |
146 | void * v_data; /* private data for fs */ | |
147 | }; | |
148 | ||
149 | #define v_mountedhere v_un.vu_mountedhere | |
150 | #define v_socket v_un.vu_socket | |
151 | #define v_specinfo v_un.vu_specinfo | |
152 | #define v_fifoinfo v_un.vu_fifoinfo | |
153 | #define v_ubcinfo v_un.vu_ubcinfo | |
154 | ||
155 | ||
156 | /* | |
157 | * v_iterblkflags | |
158 | */ | |
159 | #define VBI_ITER 0x1 | |
160 | #define VBI_ITERWANT 0x2 | |
161 | #define VBI_CLEAN 0x4 | |
162 | #define VBI_DIRTY 0x8 | |
163 | #define VBI_NEWBUF 0x10 | |
164 | ||
165 | ||
166 | /* | |
167 | * v_lflags | |
168 | */ | |
169 | #define VL_SUSPENDED 0x0001 /* vnode is suspended */ | |
170 | #define VL_DRAIN 0x0002 /* vnode is being drained */ | |
171 | #define VL_TERMINATE 0x0004 /* vnode is marked for termination */ | |
172 | #define VL_TERMWANT 0x0008 /* vnode is marked for termination */ | |
173 | #define VL_DEAD 0x0010 /* vnode is dead and completed recycle */ | |
174 | #define VL_MARKTERM 0x0020 /* vnode is dead and completed recycle */ | |
175 | #define VL_MOUNTDEAD 0x0040 /* v_moutnedhere is dead */ | |
176 | #define VL_NEEDINACTIVE 0x0080 /* delay VNOP_INACTIVE until iocount goes to 0 */ | |
177 | ||
178 | #define VNAMED_UBC 0x2000 /* ubc named reference */ | |
179 | #define VNAMED_MOUNT 0x4000 /* mount point named reference */ | |
180 | #define VNAMED_FSHASH 0x8000 /* FS hash named reference */ | |
181 | ||
182 | ||
183 | /* | |
184 | * v_flags | |
185 | */ | |
186 | #define VROOT 0x000001 /* root of its file system */ | |
187 | #define VTEXT 0x000002 /* vnode is a pure text prototype */ | |
188 | #define VSYSTEM 0x000004 /* vnode being used by kernel */ | |
189 | #define VISTTY 0x000008 /* vnode represents a tty */ | |
190 | #define VWASMAPPED 0x000010 /* vnode was mapped before */ | |
191 | #define VTERMINATE 0x000020 /* terminating memory object */ | |
192 | #define VTERMWANT 0x000040 /* wating for memory object death */ | |
193 | #define VMOUNT 0x000080 /* mount operation in progress */ | |
194 | #define VBWAIT 0x000100 /* waiting for output to complete */ | |
195 | #define VALIASED 0x000200 /* vnode has an alias */ | |
196 | #define VNOCACHE_DATA 0x000400 /* don't keep data cached once it's been consumed */ | |
197 | #define VSTANDARD 0x000800 /* vnode obtained from common pool */ | |
198 | #define VAGE 0x001000 /* Insert vnode at head of free list */ | |
199 | #define VRAOFF 0x002000 /* read ahead disabled */ | |
200 | #define VNCACHEABLE 0x004000 /* vnode is allowed to be put back in name cache */ | |
201 | #define VUINACTIVE 0x008000 /* UBC vnode is on inactive list */ | |
202 | #define VSWAP 0x010000 /* vnode is being used as swapfile */ | |
203 | #define VTHROTTLED 0x020000 /* writes or pageouts have been throttled */ | |
204 | /* wakeup tasks waiting when count falls below threshold */ | |
205 | #define VNOFLUSH 0x040000 /* don't vflush() if SKIPSYSTEM */ | |
206 | #define VLOCKLOCAL 0x080000 /* this vnode does adv locking in vfs */ | |
207 | #define VISHARDLINK 0x100000 /* hard link needs special processing on lookup and in volfs */ | |
208 | ||
209 | #define VCRED_EXPIRED 2 /* number of seconds to keep cached credential valid */ | |
210 | ||
211 | ||
212 | /* | |
213 | * Global vnode data. | |
214 | */ | |
215 | extern struct vnode *rootvnode; /* root (i.e. "/") vnode */ | |
216 | ||
217 | ||
218 | /* | |
219 | * Mods for exensibility. | |
220 | */ | |
221 | ||
222 | /* | |
223 | * Flags for vdesc_flags: | |
224 | */ | |
225 | #define VDESC_MAX_VPS 16 | |
226 | /* Low order 16 flag bits are reserved for willrele flags for vp arguments. */ | |
227 | #define VDESC_VP0_WILLRELE 0x0001 | |
228 | #define VDESC_VP1_WILLRELE 0x0002 | |
229 | #define VDESC_VP2_WILLRELE 0x0004 | |
230 | #define VDESC_VP3_WILLRELE 0x0008 | |
231 | #define VDESC_NOMAP_VPP 0x0100 | |
232 | #define VDESC_VPP_WILLRELE 0x0200 | |
233 | ||
234 | /* | |
235 | * VDESC_NO_OFFSET is used to identify the end of the offset list | |
236 | * and in places where no such field exists. | |
237 | */ | |
238 | #define VDESC_NO_OFFSET -1 | |
239 | ||
240 | /* | |
241 | * This structure describes the vnode operation taking place. | |
242 | */ | |
243 | struct vnodeop_desc { | |
244 | int vdesc_offset; /* offset in vector--first for speed */ | |
245 | char *vdesc_name; /* a readable name for debugging */ | |
246 | int vdesc_flags; /* VDESC_* flags */ | |
247 | ||
248 | /* | |
249 | * These ops are used by bypass routines to map and locate arguments. | |
250 | * Creds and procs are not needed in bypass routines, but sometimes | |
251 | * they are useful to (for example) transport layers. | |
252 | * Nameidata is useful because it has a cred in it. | |
253 | */ | |
254 | int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */ | |
255 | int vdesc_vpp_offset; /* return vpp location */ | |
256 | int vdesc_cred_offset; /* cred location, if any */ | |
257 | int vdesc_proc_offset; /* proc location, if any */ | |
258 | int vdesc_componentname_offset; /* if any */ | |
259 | int vdesc_context_offset; /* context location, if any */ | |
260 | /* | |
261 | * Finally, we've got a list of private data (about each operation) | |
262 | * for each transport layer. (Support to manage this list is not | |
263 | * yet part of BSD.) | |
264 | */ | |
265 | caddr_t *vdesc_transports; | |
266 | }; | |
267 | ||
268 | /* | |
269 | * A list of all the operation descs. | |
270 | */ | |
271 | extern struct vnodeop_desc *vnodeop_descs[]; | |
272 | ||
273 | /* | |
274 | * Interlock for scanning list of vnodes attached to a mountpoint | |
275 | */ | |
276 | extern void * mntvnode_slock; | |
277 | ||
278 | /* | |
279 | * This macro is very helpful in defining those offsets in the vdesc struct. | |
280 | * | |
281 | * This is stolen from X11R4. I ingored all the fancy stuff for | |
282 | * Crays, so if you decide to port this to such a serious machine, | |
283 | * you might want to consult Intrisics.h's XtOffset{,Of,To}. | |
284 | */ | |
285 | #define VOPARG_OFFSET(p_type,field) \ | |
286 | ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) | |
287 | #define VOPARG_OFFSETOF(s_type,field) \ | |
288 | VOPARG_OFFSET(s_type*,field) | |
289 | #define VOPARG_OFFSETTO(S_TYPE,S_OFFSET,STRUCT_P) \ | |
290 | ((S_TYPE)(((char*)(STRUCT_P))+(S_OFFSET))) | |
291 | ||
292 | ||
293 | ||
294 | /* | |
295 | * VOCALL calls an op given an ops vector. We break it out because BSD's | |
296 | * vclean changes the ops vector and then wants to call ops with the old | |
297 | * vector. | |
298 | */ | |
299 | #define VOCALL(OPSV,OFF,AP) (( *((OPSV)[(OFF)])) (AP)) | |
300 | ||
301 | /* | |
302 | * This call works for vnodes in the kernel. | |
303 | */ | |
304 | #define VCALL(VP,OFF,AP) VOCALL((VP)->v_op,(OFF),(AP)) | |
305 | #define VDESC(OP) (& __CONCAT(OP,_desc)) | |
306 | #define VOFFSET(OP) (VDESC(OP)->vdesc_offset) | |
307 | ||
8ad349bb | 308 | |
91447636 A |
309 | |
310 | int build_path(vnode_t first_vp, char *buff, int buflen, int *outlen); | |
311 | int bdevvp(dev_t dev, struct vnode **vpp); | |
312 | void cvtstat(struct stat *st, struct ostat *ost); | |
313 | void vprint(const char *label, struct vnode *vp); | |
314 | ||
315 | ||
316 | __private_extern__ int is_package_name(char *name, int len); | |
317 | __private_extern__ int set_package_extensions_table(void *data, int nentries, int maxwidth); | |
318 | int vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, | |
319 | int len, off_t offset, enum uio_seg segflg, int ioflg, | |
320 | struct ucred *cred, int *aresid, struct proc *p); | |
321 | int vn_rdwr_64(enum uio_rw rw, struct vnode *vp, uint64_t base, | |
322 | int64_t len, off_t offset, enum uio_seg segflg, | |
323 | int ioflg, struct ucred *cred, int *aresid, | |
324 | struct proc *p); | |
325 | void fifo_printinfo(struct vnode *vp); | |
326 | int vn_lock(struct vnode *vp, int flags, struct proc *p); | |
327 | int vn_open(struct nameidata *ndp, int fmode, int cmode); | |
328 | int vn_open_modflags(struct nameidata *ndp, int *fmode, int cmode); | |
329 | int vn_open_auth(struct nameidata *ndp, int *fmode, struct vnode_attr *); | |
330 | int vn_close(vnode_t, int flags, struct ucred *cred, struct proc *p); | |
331 | ||
332 | #define VN_CREATE_NOAUTH (1<<0) | |
333 | #define VN_CREATE_NOINHERIT (1<<1) | |
334 | errno_t vn_create(vnode_t, vnode_t *, struct componentname *, struct vnode_attr *, int flags, vfs_context_t); | |
335 | ||
336 | ||
337 | int vn_getxattr(vnode_t, const char *, uio_t, size_t *, int, vfs_context_t); | |
338 | int vn_setxattr(vnode_t, const char *, uio_t, int, vfs_context_t); | |
339 | int vn_removexattr(vnode_t, const char *, int, vfs_context_t); | |
340 | int vn_listxattr(vnode_t, uio_t, size_t *, int, vfs_context_t); | |
341 | ||
342 | void name_cache_lock(void); | |
343 | void name_cache_unlock(void); | |
344 | ||
345 | char * vnode_getname(vnode_t vp); | |
346 | void vnode_putname(char *name); | |
347 | ||
348 | vnode_t vnode_getparent(vnode_t vp); | |
349 | ||
350 | int vn_pathconf(vnode_t, int, register_t *, vfs_context_t); | |
351 | ||
352 | void vnode_list_lock(void); | |
353 | void vnode_list_unlock(void); | |
354 | int vnode_ref_ext(vnode_t, int); | |
355 | void vnode_rele_ext(vnode_t, int, int); | |
356 | void vnode_rele_internal(vnode_t, int, int, int); | |
357 | int vnode_getwithref(vnode_t); | |
358 | int vnode_put_locked(vnode_t); | |
359 | ||
360 | int vnode_issock(vnode_t); | |
361 | ||
362 | void unlock_fsnode(vnode_t, int *); | |
363 | int lock_fsnode(vnode_t, int *); | |
364 | ||
365 | errno_t vnode_resume(vnode_t); | |
366 | ||
367 | errno_t vnode_size(vnode_t, off_t *, vfs_context_t); | |
368 | errno_t vnode_setsize(vnode_t, off_t, int ioflag, vfs_context_t); | |
369 | int vnode_setattr_fallback(vnode_t vp, struct vnode_attr *vap, vfs_context_t ctx); | |
370 | ||
371 | void SPECHASH_LOCK(void); | |
372 | void SPECHASH_UNLOCK(void); | |
373 | ||
374 | int check_cdevmounted(dev_t, enum vtype, int *); | |
375 | ||
376 | void vnode_authorize_init(void); | |
377 | ||
378 | #endif /* !_SYS_VNODE_INTERNAL_H_ */ |