]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/vnode_internal.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / sys / vnode_internal.h
CommitLineData
91447636 1/*
316670eb 2 * Copyright (c) 2000-2012 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 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.
0a7de745 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.
0a7de745 17 *
2d21ac55
A
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.
0a7de745 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
91447636
A
73#include <sys/appleapiopts.h>
74#include <sys/cdefs.h>
75#include <sys/queue.h>
76#include <sys/lock.h>
77
78#include <sys/time.h>
79#include <sys/uio.h>
80
81#include <sys/vm.h>
82#include <sys/systm.h>
83#include <kern/locks.h>
84#include <vm/vm_kern.h>
85#include <sys/vnode.h>
86#include <sys/namei.h>
87#include <sys/vfs_context.h>
2d21ac55 88#include <sys/sysctl.h>
91447636
A
89
90
91struct lockf;
2d21ac55 92struct label;
91447636
A
93
94LIST_HEAD(buflists, buf);
95
6d2010ae
A
96#if CONFIG_TRIGGERS
97/*
98 * VFS Internal (private) trigger vnode resolver info.
99 */
100struct vnode_resolve {
0a7de745
A
101 lck_mtx_t vr_lock; /* protects vnode_resolve_t fields */
102 trigger_vnode_resolve_callback_t vr_resolve_func;
103 trigger_vnode_unresolve_callback_t vr_unresolve_func;
104 trigger_vnode_rearm_callback_t vr_rearm_func;
105 trigger_vnode_reclaim_callback_t vr_reclaim_func;
106 void * vr_data; /* private data for resolver */
107 uint32_t vr_flags;
108 uint32_t vr_lastseq;
6d2010ae
A
109};
110typedef struct vnode_resolve *vnode_resolve_t;
111
112/* private vr_flags */
113#define VNT_RESOLVED (1UL << 31)
114#define VNT_VFS_UNMOUNTED (1UL << 30)
0a7de745 115#define VNT_EXTERNAL (1UL << 29)
6d2010ae
A
116
117#endif /* CONFIG_TRIGGERS */
118
91447636
A
119/*
120 * Reading or writing any of these items requires holding the appropriate lock.
121 * v_freelist is locked by the global vnode_list_lock
122 * v_mntvnodes is locked by the mount_lock
123 * v_nclinks and v_ncchildren are protected by the global name_cache_lock
c3c9b80d 124 * v_cleanblkhd and v_dirtyblkhd and v_iterblkflags are locked via the global buf_mtx
91447636
A
125 * the rest of the structure is protected by the vnode_lock
126 */
127struct vnode {
0a7de745
A
128 lck_mtx_t v_lock; /* vnode mutex */
129 TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */
130 TAILQ_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */
131 TAILQ_HEAD(, namecache) v_ncchildren; /* name cache entries that regard us as their parent */
132 LIST_HEAD(, namecache) v_nclinks; /* name cache entries that name this vnode */
133 vnode_t v_defer_reclaimlist; /* in case we have to defer the reclaim to avoid recursion */
134 uint32_t v_listflag; /* flags protected by the vnode_list_lock (see below) */
135 uint32_t v_flag; /* vnode flags (see below) */
136 uint16_t v_lflag; /* vnode local and named ref flags */
137 uint8_t v_iterblkflags; /* buf iterator flags */
138 uint8_t v_references; /* number of times io_count has been granted */
139 int32_t v_kusecount; /* count of in-kernel refs */
140 int32_t v_usecount; /* reference count of users */
141 int32_t v_iocount; /* iocounters */
f427ee49 142 void * XNU_PTRAUTH_SIGNED_PTR("vnode.v_owner") v_owner; /* act that owns the vnode */
0a7de745
A
143 uint16_t v_type; /* vnode type */
144 uint16_t v_tag; /* type of underlying data */
145 uint32_t v_id; /* identity of vnode contents */
91447636 146 union {
f427ee49
A
147 struct mount * XNU_PTRAUTH_SIGNED_PTR("vnode.v_data") vu_mountedhere; /* ptr to mounted vfs (VDIR) */
148 struct socket * XNU_PTRAUTH_SIGNED_PTR("vnode.vu_socket") vu_socket; /* unix ipc (VSOCK) */
149 struct specinfo * XNU_PTRAUTH_SIGNED_PTR("vnode.vu_specinfo") vu_specinfo; /* device (VCHR, VBLK) */
150 struct fifoinfo * XNU_PTRAUTH_SIGNED_PTR("vnode.vu_fifoinfo") vu_fifoinfo; /* fifo (VFIFO) */
151 struct ubc_info * XNU_PTRAUTH_SIGNED_PTR("vnode.vu_ubcinfo") vu_ubcinfo; /* valid for (VREG) */
91447636 152 } v_un;
0a7de745
A
153 struct buflists v_cleanblkhd; /* clean blocklist head */
154 struct buflists v_dirtyblkhd; /* dirty blocklist head */
155 struct klist v_knotes; /* knotes attached to this vnode */
156 /*
2d21ac55 157 * the following 4 fields are protected
0a7de745 158 * by the name_cache_lock held in
2d21ac55
A
159 * excluive mode
160 */
f427ee49 161 kauth_cred_t XNU_PTRAUTH_SIGNED_PTR("vnode.v_cred") v_cred; /* last authorized credential */
0a7de745
A
162 kauth_action_t v_authorized_actions; /* current authorized actions for v_cred */
163 int v_cred_timestamp; /* determine if entry is stale for MNTK_AUTH_OPAQUE */
164 int v_nc_generation; /* changes when nodes are removed from the name cache */
165 /*
2d21ac55
A
166 * back to the vnode lock for protection
167 */
0a7de745
A
168 int32_t v_numoutput; /* num of writes in progress */
169 int32_t v_writecount; /* reference count of writers */
170 const char *v_name; /* name component of the vnode */
f427ee49 171 vnode_t XNU_PTRAUTH_SIGNED_PTR("vnode.v_parent") v_parent; /* pointer to parent vnode */
0a7de745
A
172 struct lockf *v_lockf; /* advisory lock list head */
173 int(**v_op)(void *); /* vnode operations vector */
f427ee49 174 mount_t XNU_PTRAUTH_SIGNED_PTR("vnode.v_mount") v_mount; /* ptr to vfs we are in */
0a7de745 175 void * v_data; /* private data for fs */
2d21ac55 176#if CONFIG_MACF
0a7de745 177 struct label *v_label; /* MAC security label */
2d21ac55 178#endif
6d2010ae 179#if CONFIG_TRIGGERS
0a7de745 180 vnode_resolve_t v_resolve; /* trigger vnode resolve info (VDIR only) */
6d2010ae 181#endif /* CONFIG_TRIGGERS */
cb323159
A
182#if CONFIG_FIRMLINKS
183 vnode_t v_fmlink; /* firmlink if set (VDIR only), Points to source
184 * if VFLINKTARGET is set, if VFLINKTARGET is not
185 * set, points to target */
186#endif /* CONFIG_FIRMLINKS */
c3c9b80d
A
187#if CONFIG_IO_COMPRESSION_STATS
188 io_compression_stats_t io_compression_stats; /* IO compression statistics */
189#endif /* CONFIG_IO_COMPRESSION_STATS */
91447636
A
190};
191
0a7de745
A
192#define v_mountedhere v_un.vu_mountedhere
193#define v_socket v_un.vu_socket
194#define v_specinfo v_un.vu_specinfo
195#define v_fifoinfo v_un.vu_fifoinfo
196#define v_ubcinfo v_un.vu_ubcinfo
91447636
A
197
198
199/*
200 * v_iterblkflags
201 */
0a7de745
A
202#define VBI_ITER 0x1
203#define VBI_ITERWANT 0x2
204#define VBI_CLEAN 0x4
205#define VBI_DIRTY 0x8
206#define VBI_NEWBUF 0x10
91447636 207
2d21ac55
A
208/*
209 * v_listflag
210 */
0a7de745
A
211#define VLIST_RAGE 0x01 /* vnode is currently in the rapid age list */
212#define VLIST_DEAD 0x02 /* vnode is currently in the dead list */
213#define VLIST_ASYNC_WORK 0x04 /* vnode is currently on the deferred async work queue */
91447636
A
214
215/*
216 * v_lflags
217 */
0a7de745
A
218#define VL_SUSPENDED 0x0001 /* vnode is suspended */
219#define VL_DRAIN 0x0002 /* vnode is being drained */
220#define VL_TERMINATE 0x0004 /* vnode is in the process of being recycled */
221#define VL_TERMWANT 0x0008 /* there's a waiter for recycle finish (vnode_getiocount)*/
222#define VL_DEAD 0x0010 /* vnode is dead, cleaned of filesystem-specific info */
223#define VL_MARKTERM 0x0020 /* vnode should be recycled when no longer referenced */
224#define VL_NEEDINACTIVE 0x0080 /* delay VNOP_INACTIVE until iocount goes to 0 */
225
226#define VL_LABEL 0x0100 /* vnode is marked for labeling */
227#define VL_LABELWAIT 0x0200 /* vnode is marked for labeling */
228#define VL_LABELED 0x0400 /* vnode is labeled */
229#define VL_LWARNED 0x0800
230#define VL_HASSTREAMS 0x1000 /* vnode has had at least one associated named stream vnode (may not have one any longer) */
231
232#define VNAMED_UBC 0x2000 /* ubc named reference */
233#define VNAMED_MOUNT 0x4000 /* mount point named reference */
234#define VNAMED_FSHASH 0x8000 /* FS hash named reference */
91447636 235
91447636
A
236/*
237 * v_flags
238 */
0a7de745
A
239#define VROOT 0x000001 /* root of its file system */
240#define VTEXT 0x000002 /* vnode is a pure text prototype */
241#define VSYSTEM 0x000004 /* vnode being used by kernel */
242#define VISTTY 0x000008 /* vnode represents a tty */
243#define VRAGE 0x000010 /* vnode is in rapid age state */
244#define VBDEVVP 0x000020 /* vnode created by bdevvp */
245#define VDEVFLUSH 0x000040 /* device vnode after vflush */
246#define VMOUNT 0x000080 /* mount operation in progress */
247#define VBWAIT 0x000100 /* waiting for output to complete */
248#define VSHARED_DYLD 0x000200 /* vnode is a dyld shared cache file */
249#define VNOCACHE_DATA 0x000400 /* don't keep data cached once it's been consumed */
250#define VSTANDARD 0x000800 /* vnode obtained from common pool */
251#define VAGE 0x001000 /* Insert vnode at head of free list */
252#define VRAOFF 0x002000 /* read ahead disabled */
253#define VNCACHEABLE 0x004000 /* vnode is allowed to be put back in name cache */
c910b4d9 254#if NAMEDSTREAMS
0a7de745 255#define VISSHADOW 0x008000 /* vnode is a shadow file */
c910b4d9 256#endif
0a7de745
A
257#define VSWAP 0x010000 /* vnode is being used as swapfile */
258#define VTHROTTLED 0x020000 /* writes or pageouts have been throttled */
259/* wakeup tasks waiting when count falls below threshold */
260#define VNOFLUSH 0x040000 /* don't vflush() if SKIPSYSTEM */
261#define VLOCKLOCAL 0x080000 /* this vnode does adv locking in vfs */
262#define VISHARDLINK 0x100000 /* hard link needs special processing on lookup and in volfs */
263#define VISUNION 0x200000 /* union special processing */
264#define VISNAMEDSTREAM 0x400000 /* vnode is a named stream (eg HFS resource fork) */
2d21ac55 265#define VOPENEVT 0x800000 /* if process is P_CHECKOPENEVT, then or in the O_EVTONLY flag on open */
6d2010ae 266#define VNEEDSSNAPSHOT 0x1000000
0a7de745
A
267#define VNOCS 0x2000000 /* is there no code signature available */
268#define VISDIRTY 0x4000000 /* vnode will need IO if reclaimed */
3e170ce0
A
269#define VFASTDEVCANDIDATE 0x8000000 /* vnode is a candidate to store on a fast device */
270#define VAUTOCANDIDATE 0x10000000 /* vnode was automatically marked as a fast-dev candidate */
cb323159 271#define VFMLINKTARGET 0x20000000 /* vnode is firmlink target */
3e170ce0 272/*
0a7de745
A
273 * 0x40000000 not used
274 * 0x80000000 not used.
275 */
fe8ab488
A
276
277/*
278 * This structure describes vnode data which is specific to a file descriptor.
279 * It is currently used only for file descriptors which are for opened for
280 * directories.
281 */
282struct fd_vn_data {
283 lck_mtx_t fv_lock; /* Used to serialize directory enumeration on fd */
284 off_t fv_offset; /* Offset to be used */
285 void *fv_dircookie; /* If FS doesn't like offsets in directories */
286 caddr_t fv_buf; /* Temporary buffer to store directory entries */
287 size_t fv_bufsiz; /* Valid size of fv_buf */
288 size_t fv_bufdone; /* How much of fv_buf is processed */
289 size_t fv_bufallocsiz; /* Allocation size determined for Buffer*/
290 off_t fv_soff; /* Starting FS offset for this buffer */
291 off_t fv_eoff; /* Ending FS offset for this buffer */
292 int fv_eofflag;/* Does fv_eoff represent EOF ? */
293};
294
295/*
296 * FV_DIRBUF_START_SIZ is the initial size of the buffer passed to VNOP_READDIR.
297 * That may not be enough for some filesytems so the current algorithm works its
298 * way upto FV_DIRBUF_MAX_SIZ
299 */
0a7de745
A
300#define FV_DIRBUF_DIRENTRY_SIZ (sizeof(struct direntry))
301#define FV_DIRBUF_START_SIZ FV_DIRBUF_DIRENTRY_SIZ
302#define FV_DIRBUF_MAX_SIZ (4*(sizeof(struct direntry)))
fe8ab488
A
303
304#define FV_LOCK(fvd) lck_mtx_lock(&(((struct fd_vn_data *)fvd)->fv_lock))
305#define FV_UNLOCK(fvd) lck_mtx_unlock(&(((struct fd_vn_data *)fvd)->fv_lock))
91447636
A
306
307/*
308 * Global vnode data.
309 */
0a7de745 310extern struct vnode *rootvnode; /* root (i.e. "/") vnode */
91447636 311
b7266188 312#ifdef CONFIG_IMGSRC_ACCESS
0a7de745
A
313#define MAX_IMAGEBOOT_NESTING 2
314extern struct vnode *imgsrc_rootvnodes[];
b7266188
A
315#endif /* CONFIG_IMGSRC_ACCESS */
316
91447636
A
317
318/*
319 * Mods for exensibility.
320 */
321
322/*
323 * Flags for vdesc_flags:
324 */
0a7de745 325#define VDESC_MAX_VPS 16
91447636 326/* Low order 16 flag bits are reserved for willrele flags for vp arguments. */
0a7de745
A
327#define VDESC_VP0_WILLRELE 0x00001
328#define VDESC_VP1_WILLRELE 0x00002
329#define VDESC_VP2_WILLRELE 0x00004
330#define VDESC_VP3_WILLRELE 0x00008
331#define VDESC_NOMAP_VPP 0x00100
332#define VDESC_VPP_WILLRELE 0x00200
813fb2f6 333
0a7de745 334#define VDESC_DISABLED 0x10000 /* descriptor defined but op is unused, has no op slot */
91447636
A
335
336/*
337 * VDESC_NO_OFFSET is used to identify the end of the offset list
338 * and in places where no such field exists.
339 */
340#define VDESC_NO_OFFSET -1
341
342/*
343 * This structure describes the vnode operation taking place.
344 */
345struct vnodeop_desc {
0a7de745
A
346 int vdesc_offset; /* offset in vector--first for speed */
347 const char *vdesc_name; /* a readable name for debugging */
348 int vdesc_flags; /* VDESC_* flags */
91447636
A
349
350 /*
351 * These ops are used by bypass routines to map and locate arguments.
352 * Creds and procs are not needed in bypass routines, but sometimes
353 * they are useful to (for example) transport layers.
354 * Nameidata is useful because it has a cred in it.
355 */
0a7de745
A
356 int *vdesc_vp_offsets; /* list ended by VDESC_NO_OFFSET */
357 int vdesc_vpp_offset; /* return vpp location */
358 int vdesc_cred_offset; /* cred location, if any */
359 int vdesc_proc_offset; /* proc location, if any */
360 int vdesc_componentname_offset; /* if any */
361 int vdesc_context_offset; /* context location, if any */
91447636
A
362 /*
363 * Finally, we've got a list of private data (about each operation)
364 * for each transport layer. (Support to manage this list is not
365 * yet part of BSD.)
366 */
0a7de745 367 caddr_t *vdesc_transports;
91447636
A
368};
369
370/*
371 * A list of all the operation descs.
372 */
373extern struct vnodeop_desc *vnodeop_descs[];
374
91447636
A
375
376/*
377 * This macro is very helpful in defining those offsets in the vdesc struct.
378 *
379 * This is stolen from X11R4. I ingored all the fancy stuff for
380 * Crays, so if you decide to port this to such a serious machine,
381 * you might want to consult Intrisics.h's XtOffset{,Of,To}.
382 */
0a7de745
A
383#define VOPARG_OFFSET(p_type, field) \
384 ((int) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
385#define VOPARG_OFFSETOF(s_type, field) \
91447636 386 VOPARG_OFFSET(s_type*,field)
0a7de745 387#define VOPARG_OFFSETTO(S_TYPE, S_OFFSET, STRUCT_P) \
91447636
A
388 ((S_TYPE)(((char*)(STRUCT_P))+(S_OFFSET)))
389
390
391
392/*
393 * VOCALL calls an op given an ops vector. We break it out because BSD's
394 * vclean changes the ops vector and then wants to call ops with the old
395 * vector.
396 */
0a7de745 397#define VOCALL(OPSV, OFF, AP) (( *((OPSV)[(OFF)])) (AP))
91447636
A
398
399/*
400 * This call works for vnodes in the kernel.
401 */
0a7de745 402#define VCALL(VP, OFF, AP) VOCALL((VP)->v_op,(OFF),(AP))
91447636
A
403#define VDESC(OP) (& __CONCAT(OP,_desc))
404#define VOFFSET(OP) (VDESC(OP)->vdesc_offset)
405
0c530ab8 406struct ostat;
91447636 407
39037602 408/* bdevvp moved to vnode.h as private KPI */
0a7de745
A
409void cvtstat(struct stat *st, struct ostat *ost);
410void vprint(const char *label, struct vnode *vp);
91447636
A
411
412
b0d623f7 413__private_extern__ int set_package_extensions_table(user_addr_t data, int nentries, int maxwidth);
0a7de745
A
414int vn_rdwr_64(enum uio_rw rw, struct vnode *vp, uint64_t base,
415 int64_t len, off_t offset, enum uio_seg segflg,
416 int ioflg, kauth_cred_t cred, int64_t *aresid,
417 struct proc *p);
2d21ac55 418#if CONFIG_MACF
0a7de745
A
419int vn_setlabel(struct vnode *vp, struct label *intlabel,
420 vfs_context_t context);
2d21ac55 421#endif
0a7de745
A
422void fifo_printinfo(struct vnode *vp);
423int vn_open(struct nameidata *ndp, int fmode, int cmode);
424int vn_open_modflags(struct nameidata *ndp, int *fmode, int cmode);
425int vn_open_auth(struct nameidata *ndp, int *fmode, struct vnode_attr *);
426int vn_close(vnode_t, int flags, vfs_context_t ctx);
6d2010ae
A
427errno_t vn_remove(vnode_t dvp, vnode_t *vpp, struct nameidata *ndp, int32_t flags, struct vnode_attr *vap, vfs_context_t ctx);
428errno_t vn_rename(struct vnode *fdvp, struct vnode **fvpp, struct componentname *fcnp, struct vnode_attr *fvap,
0a7de745
A
429 struct vnode *tdvp, struct vnode **tvpp, struct componentname *tcnp, struct vnode_attr *tvap,
430 uint32_t flags, vfs_context_t ctx);
91447636 431
0a7de745 432void lock_vnode_and_post(vnode_t, int);
b0d623f7
A
433
434#define post_event_if_success(_vp, _error, _event) \
435 do { \
0a7de745
A
436 if (0 == (_error)) { \
437 lock_vnode_and_post((_vp), (_event)); \
438 } \
439 } while (0)
440
6d2010ae 441/* Authorization subroutines */
0a7de745
A
442int vn_authorize_open_existing(vnode_t vp, struct componentname *cnp, int fmode, vfs_context_t ctx, void *reserved);
443int vn_authorize_create(vnode_t, struct componentname *, struct vnode_attr *, vfs_context_t, void*);
444int vn_attribute_prepare(vnode_t dvp, struct vnode_attr *vap, uint32_t *defaulted_fieldsp, vfs_context_t ctx);
445void vn_attribute_cleanup(struct vnode_attr *vap, uint32_t defaulted_fields);
0a7de745
A
446int vn_authorize_rename(struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
447 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp,
448 vfs_context_t ctx, void *reserved);
449int vn_authorize_renamex(struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
450 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp,
451 vfs_context_t ctx, vfs_rename_flags_t flags, void *reserved);
452int vn_authorize_renamex_with_paths(struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp, const char *from_path,
453 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp, const char *to_path,
454 vfs_context_t ctx, vfs_rename_flags_t flags, void *reserved);
6d2010ae
A
455
456typedef int (*vn_create_authorizer_t)(vnode_t, struct componentname *, struct vnode_attr *, vfs_context_t, void*);
457int vn_authorize_mkdir(vnode_t, struct componentname *, struct vnode_attr *, vfs_context_t, void*);
458int vn_authorize_null(vnode_t, struct componentname *, struct vnode_attr *, vfs_context_t, void*);
813fb2f6
A
459int vnode_attr_authorize_dir_clone(struct vnode_attr *vap, kauth_action_t action,
460 struct vnode_attr *dvap, vnode_t sdvp, mount_t mp, dir_clone_authorizer_op_t vattr_op,
5ba3f43e 461 uint32_t flags, vfs_context_t ctx, void *reserved);
6d2010ae 462/* End of authorization subroutines */
b0d623f7 463
f427ee49
A
464void vnode_attr_handle_mnt_ignore_ownership(struct vnode_attr *vap, mount_t mp, vfs_context_t ctx);
465
0a7de745
A
466#define VN_CREATE_NOAUTH (1<<0)
467#define VN_CREATE_NOINHERIT (1<<1)
468#define VN_CREATE_UNION (1<<2)
469#define VN_CREATE_NOLABEL (1<<3)
470#define VN_CREATE_DOOPEN (1<<4) /* Open file if a batched operation is available */
6d2010ae 471errno_t vn_create(vnode_t, vnode_t *, struct nameidata *, struct vnode_attr *, uint32_t, int, uint32_t*, vfs_context_t);
0a7de745
A
472int vn_mkdir(vnode_t dvp, vnode_t *vpp, struct nameidata *ndp, struct vnode_attr *vap, vfs_context_t ctx);
473int vn_rmdir(vnode_t dvp, vnode_t *vpp, struct nameidata *ndp, struct vnode_attr *vap, vfs_context_t ctx);
91447636 474
0a7de745
A
475int vn_getxattr(vnode_t, const char *, uio_t, size_t *, int, vfs_context_t);
476int vn_setxattr(vnode_t, const char *, uio_t, int, vfs_context_t);
477int vn_removexattr(vnode_t, const char *, int, vfs_context_t);
478int vn_listxattr(vnode_t, uio_t, size_t *, int, vfs_context_t);
91447636 479
2d21ac55
A
480#if NAMEDSTREAMS
481errno_t vnode_getnamedstream(vnode_t, vnode_t *, const char *, enum nsoperation, int, vfs_context_t);
482errno_t vnode_makenamedstream(vnode_t, vnode_t *, const char *, int, vfs_context_t);
483errno_t vnode_removenamedstream(vnode_t, vnode_t, const char *, int, vfs_context_t);
484errno_t vnode_flushnamedstream(vnode_t vp, vnode_t svp, vfs_context_t context);
39236c6e 485errno_t vnode_relenamedstream(vnode_t vp, vnode_t svp);
0a7de745 486errno_t vnode_verifynamedstream(vnode_t vp);
2d21ac55
A
487#endif
488
2d21ac55 489
0a7de745
A
490void nchinit(void);
491int resize_namecache(int newsize);
492void name_cache_lock_shared(void);
493void name_cache_lock(void);
494void name_cache_unlock(void);
495void cache_enter_with_gen(vnode_t dvp, vnode_t vp, struct componentname *cnp, int gen);
b0d623f7 496const char *cache_enter_create(vnode_t dvp, vnode_t vp, struct componentname *cnp);
91447636 497
0a7de745 498extern int nc_disabled;
91447636 499
0a7de745 500#define vnode_lock_convert(v) lck_mtx_convert_spin(&(v)->v_lock)
2d21ac55 501
0a7de745 502void vnode_lock_spin(vnode_t);
2d21ac55
A
503
504
0a7de745
A
505void vnode_list_lock(void);
506void vnode_list_unlock(void);
6d2010ae 507
0a7de745
A
508#define VNODE_REF_FORCE 0x1
509int vnode_ref_ext(vnode_t, int, int);
6d2010ae 510
0a7de745 511void vnode_rele_internal(vnode_t, int, int, int);
593a1d5f 512#ifdef BSD_KERNEL_PRIVATE
0a7de745 513int vnode_getalways(vnode_t);
f427ee49 514int vnode_getalways_from_pager(vnode_t);
0a7de745 515int vget_internal(vnode_t, int, int);
6d2010ae 516errno_t vnode_getiocount(vnode_t, unsigned int, int);
593a1d5f 517#endif /* BSD_KERNEL_PRIVATE */
0a7de745
A
518int vnode_get_locked(vnode_t);
519int vnode_put_locked(vnode_t);
f427ee49
A
520#ifdef BSD_KERNEL_PRIVATE
521int vnode_put_from_pager(vnode_t);
522#endif /* BSD_KERNEL_PRIVATE */
91447636 523
0a7de745
A
524int vnode_issock(vnode_t);
525int vnode_isaliased(vnode_t);
91447636 526
0a7de745
A
527void unlock_fsnode(vnode_t, int *);
528int lock_fsnode(vnode_t, int *);
91447636 529
0a7de745
A
530errno_t vnode_resume(vnode_t);
531errno_t vnode_suspend(vnode_t);
2d21ac55 532
91447636 533
0a7de745 534errno_t vnode_mtime(vnode_t, struct timespec *, vfs_context_t);
fe8ab488 535errno_t vnode_flags(vnode_t, uint32_t *, vfs_context_t);
15129b1c 536
0a7de745
A
537errno_t vnode_size(vnode_t, off_t *, vfs_context_t);
538errno_t vnode_setsize(vnode_t, off_t, int ioflag, vfs_context_t);
539int vnode_setattr_fallback(vnode_t vp, struct vnode_attr *vap, vfs_context_t ctx);
540int vnode_isspec(vnode_t vp);
91447636 541
6d2010ae
A
542
543#ifdef BSD_KERNEL_PRIVATE
544
545typedef uint32_t compound_vnop_id_t;
0a7de745
A
546#define COMPOUND_VNOP_OPEN 0x01
547#define COMPOUND_VNOP_MKDIR 0x02
548#define COMPOUND_VNOP_RENAME 0x04
549#define COMPOUND_VNOP_REMOVE 0x08
550#define COMPOUND_VNOP_RMDIR 0x10
551
552int vnode_compound_rename_available(vnode_t vp);
553int vnode_compound_rmdir_available(vnode_t vp);
554int vnode_compound_mkdir_available(vnode_t vp);
555int vnode_compound_remove_available(vnode_t vp);
556int vnode_compound_open_available(vnode_t vp);
557int vnode_compound_op_available(vnode_t, compound_vnop_id_t);
6d2010ae
A
558#endif /* BSD_KERNEL_PRIVATE */
559
2d21ac55
A
560void vn_setunionwait(vnode_t);
561void vn_checkunionwait(vnode_t);
562void vn_clearunionwait(vnode_t, int);
563
91447636
A
564void SPECHASH_LOCK(void);
565void SPECHASH_UNLOCK(void);
566
0a7de745 567void vnode_authorize_init(void);
2d21ac55 568
0a7de745 569void vfsinit(void);
b0d623f7
A
570void vnode_lock(vnode_t);
571void vnode_unlock(vnode_t);
2d21ac55 572
3e170ce0 573void vn_print_state(vnode_t /* vp */, const char * /* fmt */, ...)
0a7de745 574__printflike(2, 3);
3e170ce0
A
575
576#if DEVELOPMENT || DEBUG
0a7de745
A
577#define VNASSERT(exp, vp, msg) \
578do { \
579 if (__improbable(!(exp))) { \
580 vn_print_state(vp, "VNASSERT failed %s:%d\n", __FILE__, \
581 __LINE__); \
582 panic msg; \
583 } \
3e170ce0
A
584} while (0)
585#else
586#define VNASSERT(exp, vp, msg)
587#endif /* DEVELOPMENT || DEBUG */
588
2d21ac55
A
589/*
590 * XXX exported symbols; should be static
591 */
0a7de745
A
592void vfs_op_init(void);
593void vfs_opv_init(void);
91447636 594
b0d623f7 595#ifdef BSD_KERNEL_PRIVATE
fe8ab488 596int vfs_sysctl_node SYSCTL_HANDLER_ARGS;
b0d623f7 597void vnode_setneedinactive(vnode_t);
0a7de745 598int vnode_hasnamedstreams(vnode_t); /* Does this vnode have associated named streams? */
6d2010ae 599
fe8ab488
A
600errno_t
601vnode_readdir64(struct vnode *vp, struct uio *uio, int flags, int *eofflag,
0a7de745 602 int *numdirent, vfs_context_t ctxp);
fe8ab488
A
603
604void vnode_setswapmount(vnode_t);
0a7de745 605int64_t vnode_getswappin_avail(vnode_t);
fe8ab488 606
0a7de745 607int vnode_get_snapdir(vnode_t, vnode_t *, vfs_context_t);
39037602 608
6d2010ae
A
609#if CONFIG_TRIGGERS
610/* VFS Internal Vnode Trigger Interfaces (Private) */
611int vnode_trigger_resolve(vnode_t, struct nameidata *, vfs_context_t);
612void vnode_trigger_rearm(vnode_t, vfs_context_t);
613void vfs_nested_trigger_unmounts(mount_t, int, vfs_context_t);
614#endif /* CONFIG_TRIGGERS */
615
eb6b6ca3 616int build_path_with_parent(vnode_t, vnode_t /* parent */, char *, int, int *, size_t *, int, vfs_context_t);
5ba3f43e 617
cb323159
A
618void nspace_resolver_init(void);
619void nspace_resolver_exited(struct proc *);
620
621int vnode_materialize_dataless_file(vnode_t, uint64_t);
622
f427ee49
A
623int vnode_isinuse_locked(vnode_t, int, int );
624
6d2010ae 625#endif /* BSD_KERNEL_PRIVATE */
b0d623f7 626
c3c9b80d
A
627#if CONFIG_IO_COMPRESSION_STATS
628/*
629 * update the IO compression stats tracked at block granularity
630 */
631int vnode_updateiocompressionblockstats(vnode_t vp, uint32_t size_bucket);
632
633/*
634 * update the IO compression stats tracked for the buffer
635 */
636int vnode_updateiocompressionbufferstats(vnode_t vp, uint64_t uncompressed_size, uint64_t compressed_size, uint32_t size_bucket, uint32_t compression_bucket);
637
638#endif /* CONFIG_IO_COMPRESSION_STATS */
639
f427ee49
A
640extern bool rootvp_is_ssd;
641
91447636 642#endif /* !_SYS_VNODE_INTERNAL_H_ */