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