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