1/*
2 * Copyright (c) 2000-2017 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#ifndef _VNODE_H_
65#define _VNODE_H_
66
67#include <sys/appleapiopts.h>
68#include <sys/cdefs.h>
69#ifdef KERNEL
70#include <sys/kernel_types.h>
71#include <sys/param.h>
72#include <sys/signal.h>
73#endif
74
75/*
76 * The vnode is the focus of all file activity in UNIX. There is a
77 * unique vnode allocated for each active file, each current directory,
78 * each mounted-on file, text file, and the root.
79 */
80
81/*
82 * Vnode types. VNON means no type.
83 */
84enum vtype {
85 /* 0 */
86 VNON,
87 /* 1 - 5 */
88 VREG, VDIR, VBLK, VCHR, VLNK,
89 /* 6 - 10 */
90 VSOCK, VFIFO, VBAD, VSTR, VCPLX
91};
92
93/*
94 * Vnode tag types.
95 * These are for the benefit of external programs only (e.g., pstat)
96 * and should NEVER be inspected by the kernel.
97 */
98enum vtagtype {
99 /* 0 */
100 VT_NON,
101 /* 1 reserved, overlaps with (CTL_VFS, VFS_NUMMNTOPS) */
102 VT_UFS,
103 /* 2 - 5 */
104 VT_NFS, VT_MFS, VT_MSDOSFS, VT_LFS,
105 /* 6 - 10 */
106 VT_LOFS, VT_FDESC, VT_PORTAL, VT_NULL, VT_UMAP,
107 /* 11 - 15 */
108 VT_KERNFS, VT_PROCFS, VT_AFS, VT_ISOFS, VT_MOCKFS,
109 /* 16 - 20 */
110 VT_HFS, VT_ZFS, VT_DEVFS, VT_WEBDAV, VT_UDF,
111 /* 21 - 25 */
112 VT_AFP, VT_CDDA, VT_CIFS, VT_OTHER, VT_APFS
113};
114
115/*
116 * flags for VNOP_BLOCKMAP
117 */
118#define VNODE_READ 0x01
119#define VNODE_WRITE 0x02
120#define VNODE_BLOCKMAP_NO_TRACK 0x04 // APFS Fusion: Do not track this request
121
122
123/* flags for VNOP_ALLOCATE */
124#define PREALLOCATE 0x00000001 /* preallocate allocation blocks */
125#define ALLOCATECONTIG 0x00000002 /* allocate contigious space */
126#define ALLOCATEALL 0x00000004 /* allocate all requested space */
127 /* or no space at all */
128#define FREEREMAINDER 0x00000008 /* deallocate allocated but */
129 /* unfilled blocks */
130#define ALLOCATEFROMPEOF 0x00000010 /* allocate from the physical eof */
131#define ALLOCATEFROMVOL 0x00000020 /* allocate from the volume offset */
132
133/*
134 * Token indicating no attribute value yet assigned. some user source uses this
135 */
136#define VNOVAL (-1)
137
138
139#ifdef KERNEL
140
141/*
142 * Flags for ioflag.
143 */
144#define IO_UNIT 0x0001 /* do I/O as atomic unit */
145#define IO_APPEND 0x0002 /* append write to end */
146#define IO_SYNC 0x0004 /* do I/O synchronously */
147#define IO_NODELOCKED 0x0008 /* underlying node already locked */
148#define IO_NDELAY 0x0010 /* FNDELAY flag set in file table */
149#define IO_NOZEROFILL 0x0020 /* F_SETSIZE fcntl uses to prevent zero filling */
150#ifdef XNU_KERNEL_PRIVATE
151#define IO_REVOKE IO_NOZEROFILL /* revoked close for tty, will Not be used in conjunction */
152#endif /* XNU_KERNEL_PRIVATE */
153#define IO_TAILZEROFILL 0x0040 /* zero fills at the tail of write */
154#define IO_HEADZEROFILL 0x0080 /* zero fills at the head of write */
155#define IO_NOZEROVALID 0x0100 /* do not zero fill if valid page */
156#define IO_NOZERODIRTY 0x0200 /* do not zero fill if page is dirty */
157#define IO_CLOSE 0x0400 /* I/O issued from close path */
158#define IO_NOCACHE 0x0800 /* same effect as VNOCACHE_DATA, but only for this 1 I/O */
159#define IO_RAOFF 0x1000 /* same effect as VRAOFF, but only for this 1 I/O */
160#define IO_DEFWRITE 0x2000 /* defer write if vfs.defwrite is set */
161#define IO_PASSIVE 0x4000 /* this I/O is marked as background I/O so it won't throttle Throttleable I/O */
162#define IO_BACKGROUND IO_PASSIVE /* used for backward compatibility. to be removed after IO_BACKGROUND is no longer
163 * used by DiskImages in-kernel mode */
164#define IO_NOAUTH 0x8000 /* No authorization checks. */
165#define IO_NODIRECT 0x10000 /* don't use direct synchronous writes if IO_NOCACHE is specified */
166#define IO_ENCRYPTED 0x20000 /* Retrieve encrypted blocks from the filesystem */
167#define IO_RETURN_ON_THROTTLE 0x40000
168#define IO_SINGLE_WRITER 0x80000
169#define IO_SYSCALL_DISPATCH 0x100000 /* I/O was originated from a file table syscall */
170#define IO_SWAP_DISPATCH 0x200000 /* I/O was originated from the swap layer */
171#define IO_SKIP_ENCRYPTION 0x400000 /* Skips en(de)cryption on the IO. Must be initiated from kernel */
172#define IO_EVTONLY 0x800000 /* the i/o is being done on an fd that's marked O_EVTONLY */
173
174/*
175 * Component Name: this structure describes the pathname
176 * information that is passed through the VNOP interface.
177 */
178struct componentname {
179 /*
180 * Arguments to lookup.
181 */
182 uint32_t cn_nameiop; /* lookup operation */
183 uint32_t cn_flags; /* flags (see below) */
184#ifdef BSD_KERNEL_PRIVATE
185 vfs_context_t cn_context;
186 struct nameidata *cn_ndp; /* pointer back to nameidata */
187
188/* XXX use of these defines are deprecated */
189#define cn_proc (cn_context->vc_proc + 0) /* non-lvalue */
190#define cn_cred (cn_context->vc_ucred + 0) /* non-lvalue */
191
192#else
193 void * cn_reserved1; /* use vfs_context_t */
194 void * cn_reserved2; /* use vfs_context_t */
195#endif
196 /*
197 * Shared between lookup and commit routines.
198 */
199 char *cn_pnbuf; /* pathname buffer */
200 int cn_pnlen; /* length of allocated buffer */
201 char *cn_nameptr; /* pointer to looked up name */
202 int cn_namelen; /* length of looked up component */
203 uint32_t cn_hash; /* hash value of looked up name */
204 uint32_t cn_consume; /* chars to consume in lookup() */
205};
206
207/*
208 * component name operations (for VNOP_LOOKUP)
209 */
210#define LOOKUP 0 /* perform name lookup only */
211#define CREATE 1 /* setup for file creation */
212#define DELETE 2 /* setup for file deletion */
213#define RENAME 3 /* setup for file renaming */
214#define OPMASK 3 /* mask for operation */
215
216/*
217 * component name operational modifier flags
218 */
219#define FOLLOW 0x00000040 /* follow symbolic links */
220
221/*
222 * component name parameter descriptors.
223 */
224#define ISDOTDOT 0x00002000 /* current component name is .. */
225#define MAKEENTRY 0x00004000 /* entry is to be added to name cache */
226#define ISLASTCN 0x00008000 /* this is last component of pathname */
227
228/* The following structure specifies a vnode for creation */
229struct vnode_fsparam {
230 struct mount * vnfs_mp; /* mount point to which this vnode_t is part of */
231 enum vtype vnfs_vtype; /* vnode type */
232 const char * vnfs_str; /* File system Debug aid */
233 struct vnode * vnfs_dvp; /* The parent vnode */
234 void * vnfs_fsnode; /* inode */
235 int (**vnfs_vops)(void *); /* vnode dispatch table */
236 int vnfs_markroot; /* is this a root vnode in FS (not a system wide one) */
237 int vnfs_marksystem; /* is a system vnode */
238 dev_t vnfs_rdev; /* dev_t for block or char vnodes */
239 off_t vnfs_filesize; /* that way no need for getattr in UBC */
240 struct componentname * vnfs_cnp; /* component name to add to namecache */
241 uint32_t vnfs_flags; /* flags */
242};
243
244#define VNFS_NOCACHE 0x01 /* do not add to name cache at this time */
245#define VNFS_CANTCACHE 0x02 /* never add this instance to the name cache */
246#define VNFS_ADDFSREF 0x04 /* take fs (named) reference */
247
248#define VNCREATE_FLAVOR 0
249#define VCREATESIZE sizeof(struct vnode_fsparam)
250#ifdef KERNEL_PRIVATE
251/*
252 * For use with SPI to create trigger vnodes.
253 */
254struct vnode_trigger_param;
255#define VNCREATE_TRIGGER (('T' << 8) + ('V'))
256#define VNCREATE_TRIGGER_SIZE sizeof(struct vnode_trigger_param)
257#endif /* KERNEL_PRIVATE */
258
259
260#ifdef KERNEL_PRIVATE
261/*
262 * Resolver callback SPI for trigger vnodes
263 *
264 * Only available from kernels built with CONFIG_TRIGGERS option
265 */
266
267/*!
268 @enum Pathname Lookup Operations
269 @abstract Constants defining pathname operations (passed to resolver callbacks)
270 */
271enum path_operation {
272 OP_LOOKUP,
273 OP_MOUNT,
274 OP_UNMOUNT,
275 OP_STATFS,
276 OP_OPEN,
277 OP_LINK,
278 OP_UNLINK,
279 OP_RENAME,
280 OP_CHDIR,
281 OP_CHROOT,
282 OP_MKNOD,
283 OP_MKFIFO,
284 OP_SYMLINK,
285 OP_ACCESS,
286 OP_PATHCONF,
287 OP_READLINK,
288 OP_GETATTR,
289 OP_SETATTR,
290 OP_TRUNCATE,
291 OP_COPYFILE,
292 OP_MKDIR,
293 OP_RMDIR,
294 OP_REVOKE,
295 OP_EXCHANGEDATA,
296 OP_SEARCHFS,
297 OP_FSCTL,
298 OP_GETXATTR,
299 OP_SETXATTR,
300 OP_REMOVEXATTR,
301 OP_LISTXATTR,
302 OP_MAXOP /* anything beyond previous entry is invalid */
303};
304
305/*!
306 @enum resolver status
307 @abstract Constants defining resolver status
308 @constant RESOLVER_RESOLVED the resolver has finished (typically means a successful mount)
309 @constant RESOLVER_NOCHANGE the resolver status didn't change
310 @constant RESOLVER_UNRESOLVED the resolver has finished (typically means a successful unmount)
311 @constant RESOLVER_ERROR the resolver encountered an error (errno passed in aux value)
312 @constant RESOLVER_STOP a request to destroy trigger XXX do we need this???
313 */
314enum resolver_status {
315 RESOLVER_RESOLVED,
316 RESOLVER_NOCHANGE,
317 RESOLVER_UNRESOLVED,
318 RESOLVER_ERROR,
319 RESOLVER_STOP
320};
321
322typedef uint64_t resolver_result_t;
323
324/*
325 * Compound resolver result
326 *
327 * The trigger vnode callbacks use a compound result value. In addition
328 * to the resolver status, it contains a sequence number and an auxiliary
329 * value.
330 *
331 * The sequence value is used by VFS to sequence-stamp trigger vnode
332 * state transitions. It is expected to be incremented each time a
333 * resolver changes state (ie resolved or unresolved). A result
334 * containing a stale sequence (older than a trigger vnode's current
335 * value) will be ignored by VFS.
336 *
337 * The auxiliary value is currently only used to deliver the errno
338 * value for RESOLVER_ERROR status conditions. When a RESOLVER_ERROR
339 * occurs, VFS will propagate this error back to the syscall that
340 * encountered the trigger vnode.
341 */
342extern resolver_result_t vfs_resolver_result(uint32_t seq, enum resolver_status stat, int aux);
343
344/*
345 * Extract values from a compound resolver result
346 */
347extern enum resolver_status vfs_resolver_status(resolver_result_t);
348extern uint32_t vfs_resolver_sequence(resolver_result_t);
349extern int vfs_resolver_auxiliary(resolver_result_t);
350
351
352/*!
353 @typedef trigger_vnode_resolve_callback_t
354 @abstract function prototype for a trigger vnode resolve callback
355 @discussion This function is associated with a trigger vnode during a vnode create. It is
356 typically called when a lookup operation occurs for a trigger vnode
357 @param vp The trigger vnode which needs resolving
358 @param cnp Various data about lookup, e.g. filename and state flags
359 @param pop The pathname operation that initiated the lookup (see enum path_operation).
360 @param flags resolve flags
361 @param data Arbitrary data supplied by vnode trigger creator
362 @param ctx Context for authentication.
363 @return RESOLVER_RESOLVED, RESOLVER_NOCHANGE, RESOLVER_UNRESOLVED or RESOLVER_ERROR
364*/
365typedef resolver_result_t (* trigger_vnode_resolve_callback_t)(
366 vnode_t vp,
367 const struct componentname * cnp,
368 enum path_operation pop,
369 int flags,
370 void * data,
371 vfs_context_t ctx);
372
373/*!
374 @typedef trigger_vnode_unresolve_callback_t
375 @abstract function prototype for a trigger vnode unresolve callback
376 @discussion This function is associated with a trigger vnode during a vnode create. It is
377 called to unresolve a trigger vnode (typically this means unmount).
378 @param vp The trigger vnode which needs unresolving
379 @param flags Unmount flags
380 @param data Arbitrary data supplied by vnode trigger creator
381 @param ctx Context for authentication.
382 @return RESOLVER_NOCHANGE, RESOLVER_UNRESOLVED or RESOLVER_ERROR
383*/
384typedef resolver_result_t (* trigger_vnode_unresolve_callback_t)(
385 vnode_t vp,
386 int flags,
387 void * data,
388 vfs_context_t ctx);
389
390/*!
391 @typedef trigger_vnode_rearm_callback_t
392 @abstract function prototype for a trigger vnode rearm callback
393 @discussion This function is associated with a trigger vnode during a vnode create. It is
394 called to verify a rearm from VFS (i.e. should VFS rearm the trigger?).
395 @param vp The trigger vnode which needs rearming
396 @param flags rearm flags
397 @param data Arbitrary data supplied by vnode trigger creator
398 @param ctx Context for authentication.
399 @return RESOLVER_NOCHANGE or RESOLVER_ERROR
400*/
401typedef resolver_result_t (* trigger_vnode_rearm_callback_t)(
402 vnode_t vp,
403 int flags,
404 void * data,
405 vfs_context_t ctx);
406
407/*!
408 @typedef trigger_vnode_reclaim_callback_t
409 @abstract function prototype for a trigger vnode reclaim callback
410 @discussion This function is associated with a trigger vnode during a vnode create. It is
411 called to deallocate private callback argument data
412 @param vp The trigger vnode associated with the data
413 @param data The arbitrary data supplied by vnode trigger creator
414*/
415typedef void (* trigger_vnode_reclaim_callback_t)(
416 vnode_t vp,
417 void * data);
418
419/*!
420 @function vnode_trigger_update
421 @abstract Update a trigger vnode's state.
422 @discussion This allows a resolver to notify VFS of a state change in a trigger vnode.
423 @param vp The trigger vnode whose information to update.
424 @param result A compound resolver result value
425 @return EINVAL if result value is invalid or vp isn't a trigger vnode
426 */
427extern int vnode_trigger_update(vnode_t vp, resolver_result_t result);
428
429struct vnode_trigger_info {
430 trigger_vnode_resolve_callback_t vti_resolve_func;
431 trigger_vnode_unresolve_callback_t vti_unresolve_func;
432 trigger_vnode_rearm_callback_t vti_rearm_func;
433 trigger_vnode_reclaim_callback_t vti_reclaim_func;
434 void * vti_data; /* auxiliary data (optional) */
435 uint32_t vti_flags; /* optional flags (see below) */
436};
437
438/*
439 * SPI for creating a trigger vnode
440 *
441 * Uses the VNCREATE_TRIGGER flavor with existing vnode_create() KPI
442 *
443 * Only one resolver per vnode.
444 *
445 * ERRORS (in addition to vnode_create errors):
446 * EINVAL (invalid resolver info, like invalid flags)
447 * ENOTDIR (only directories can have a resolver)
448 * EPERM (vnode cannot be a trigger - eg root dir of a file system)
449 * ENOMEM
450 */
451struct vnode_trigger_param {
452 struct vnode_fsparam vnt_params; /* same as for VNCREATE_FLAVOR */
453 trigger_vnode_resolve_callback_t vnt_resolve_func;
454 trigger_vnode_unresolve_callback_t vnt_unresolve_func;
455 trigger_vnode_rearm_callback_t vnt_rearm_func;
456 trigger_vnode_reclaim_callback_t vnt_reclaim_func;
457 void * vnt_data; /* auxiliary data (optional) */
458 uint32_t vnt_flags; /* optional flags (see below) */
459};
460
461/*
462 * vnode trigger flags (vnt_flags)
463 *
464 * VNT_AUTO_REARM:
465 * On unmounts of a trigger mount, automatically re-arm the trigger.
466 *
467 * VNT_NO_DIRECT_MOUNT:
468 * A trigger vnode instance that doesn't directly trigger a mount,
469 * instead it triggers the mounting of sub-trigger nodes.
470 */
471#define VNT_AUTO_REARM (1 << 0)
472#define VNT_NO_DIRECT_MOUNT (1 << 1)
473#define VNT_VALID_MASK (VNT_AUTO_REARM | VNT_NO_DIRECT_MOUNT)
474
475#endif /* KERNEL_PRIVATE */
476
477
478/*
479 * Vnode attributes, new-style.
480 *
481 * The vnode_attr structure is used to transact attribute changes and queries
482 * with the filesystem.
483 *
484 * Note that this structure may be extended, but existing fields must not move.
485 */
486
487#define VATTR_INIT(v) do {(v)->va_supported = (v)->va_active = 0ll; (v)->va_vaflags = 0; } while(0)
488#define VATTR_SET_ACTIVE(v, a) ((v)->va_active |= VNODE_ATTR_ ## a)
489#define VATTR_SET_SUPPORTED(v, a) ((v)->va_supported |= VNODE_ATTR_ ## a)
490#define VATTR_IS_SUPPORTED(v, a) ((v)->va_supported & VNODE_ATTR_ ## a)
491#define VATTR_CLEAR_ACTIVE(v, a) ((v)->va_active &= ~VNODE_ATTR_ ## a)
492#define VATTR_CLEAR_SUPPORTED(v, a) ((v)->va_supported &= ~VNODE_ATTR_ ## a)
493#define VATTR_CLEAR_SUPPORTED_ALL(v) ((v)->va_supported = 0)
494#define VATTR_IS_ACTIVE(v, a) ((v)->va_active & VNODE_ATTR_ ## a)
495#define VATTR_ALL_SUPPORTED(v) (((v)->va_active & (v)->va_supported) == (v)->va_active)
496#define VATTR_INACTIVE_SUPPORTED(v) do {(v)->va_active &= ~(v)->va_supported; (v)->va_supported = 0;} while(0)
497#define VATTR_SET(v, a, x) do { (v)-> a = (x); VATTR_SET_ACTIVE(v, a);} while(0)
498#define VATTR_WANTED(v, a) VATTR_SET_ACTIVE(v, a)
499#define VATTR_RETURN(v, a, x) do { (v)-> a = (x); VATTR_SET_SUPPORTED(v, a);} while(0)
500#define VATTR_NOT_RETURNED(v, a) (VATTR_IS_ACTIVE(v, a) && !VATTR_IS_SUPPORTED(v, a))
501
502/*
503 * Two macros to simplify conditional checking in kernel code.
504 */
505#define VATTR_IS(v, a, x) (VATTR_IS_SUPPORTED(v, a) && (v)-> a == (x))
506#define VATTR_IS_NOT(v, a, x) (VATTR_IS_SUPPORTED(v, a) && (v)-> a != (x))
507
508#define VNODE_ATTR_va_rdev (1LL<< 0) /* 00000001 */
509#define VNODE_ATTR_va_nlink (1LL<< 1) /* 00000002 */
510#define VNODE_ATTR_va_total_size (1LL<< 2) /* 00000004 */
511#define VNODE_ATTR_va_total_alloc (1LL<< 3) /* 00000008 */
512#define VNODE_ATTR_va_data_size (1LL<< 4) /* 00000010 */
513#define VNODE_ATTR_va_data_alloc (1LL<< 5) /* 00000020 */
514#define VNODE_ATTR_va_iosize (1LL<< 6) /* 00000040 */
515#define VNODE_ATTR_va_uid (1LL<< 7) /* 00000080 */
516#define VNODE_ATTR_va_gid (1LL<< 8) /* 00000100 */
517#define VNODE_ATTR_va_mode (1LL<< 9) /* 00000200 */
518#define VNODE_ATTR_va_flags (1LL<<10) /* 00000400 */
519#define VNODE_ATTR_va_acl (1LL<<11) /* 00000800 */
520#define VNODE_ATTR_va_create_time (1LL<<12) /* 00001000 */
521#define VNODE_ATTR_va_access_time (1LL<<13) /* 00002000 */
522#define VNODE_ATTR_va_modify_time (1LL<<14) /* 00004000 */
523#define VNODE_ATTR_va_change_time (1LL<<15) /* 00008000 */
524#define VNODE_ATTR_va_backup_time (1LL<<16) /* 00010000 */
525#define VNODE_ATTR_va_fileid (1LL<<17) /* 00020000 */
526#define VNODE_ATTR_va_linkid (1LL<<18) /* 00040000 */
527#define VNODE_ATTR_va_parentid (1LL<<19) /* 00080000 */
528#define VNODE_ATTR_va_fsid (1LL<<20) /* 00100000 */
529#define VNODE_ATTR_va_filerev (1LL<<21) /* 00200000 */
530#define VNODE_ATTR_va_gen (1LL<<22) /* 00400000 */
531#define VNODE_ATTR_va_encoding (1LL<<23) /* 00800000 */
532#define VNODE_ATTR_va_type (1LL<<24) /* 01000000 */
533#define VNODE_ATTR_va_name (1LL<<25) /* 02000000 */
534#define VNODE_ATTR_va_uuuid (1LL<<26) /* 04000000 */
535#define VNODE_ATTR_va_guuid (1LL<<27) /* 08000000 */
536#define VNODE_ATTR_va_nchildren (1LL<<28) /* 10000000 */
537#define VNODE_ATTR_va_dirlinkcount (1LL<<29) /* 20000000 */
538#define VNODE_ATTR_va_addedtime (1LL<<30) /* 40000000 */
539#define VNODE_ATTR_va_dataprotect_class (1LL<<31) /* 80000000 */
540#define VNODE_ATTR_va_dataprotect_flags (1LL<<32) /* 100000000 */
541#define VNODE_ATTR_va_document_id (1LL<<33) /* 200000000 */
542#define VNODE_ATTR_va_devid (1LL<<34) /* 400000000 */
543#define VNODE_ATTR_va_objtype (1LL<<35) /* 800000000 */
544#define VNODE_ATTR_va_objtag (1LL<<36) /* 1000000000 */
545#define VNODE_ATTR_va_user_access (1LL<<37) /* 2000000000 */
546#define VNODE_ATTR_va_finderinfo (1LL<<38) /* 4000000000 */
547#define VNODE_ATTR_va_rsrc_length (1LL<<39) /* 8000000000 */
548#define VNODE_ATTR_va_rsrc_alloc (1LL<<40) /* 10000000000 */
549#define VNODE_ATTR_va_fsid64 (1LL<<41) /* 20000000000 */
550#define VNODE_ATTR_va_write_gencount (1LL<<42) /* 40000000000 */
551#define VNODE_ATTR_va_private_size (1LL<<43) /* 80000000000 */
552
553#define VNODE_ATTR_BIT(n) (VNODE_ATTR_ ## n)
554
555/*
556 * ALL of the attributes.
557 */
558#define VNODE_ATTR_ALL (VNODE_ATTR_BIT(va_rdev) | \
559 VNODE_ATTR_BIT(va_nlink) | \
560 VNODE_ATTR_BIT(va_total_size) | \
561 VNODE_ATTR_BIT(va_total_alloc) | \
562 VNODE_ATTR_BIT(va_data_size) | \
563 VNODE_ATTR_BIT(va_data_alloc) | \
564 VNODE_ATTR_BIT(va_iosize) | \
565 VNODE_ATTR_BIT(va_uid) | \
566 VNODE_ATTR_BIT(va_gid) | \
567 VNODE_ATTR_BIT(va_mode) | \
568 VNODE_ATTR_BIT(va_flags) | \
569 VNODE_ATTR_BIT(va_acl) | \
570 VNODE_ATTR_BIT(va_create_time) | \
571 VNODE_ATTR_BIT(va_access_time) | \
572 VNODE_ATTR_BIT(va_modify_time) | \
573 VNODE_ATTR_BIT(va_change_time) | \
574 VNODE_ATTR_BIT(va_backup_time) | \
575 VNODE_ATTR_BIT(va_fileid) | \
576 VNODE_ATTR_BIT(va_linkid) | \
577 VNODE_ATTR_BIT(va_parentid) | \
578 VNODE_ATTR_BIT(va_fsid) | \
579 VNODE_ATTR_BIT(va_filerev) | \
580 VNODE_ATTR_BIT(va_gen) | \
581 VNODE_ATTR_BIT(va_encoding) | \
582 VNODE_ATTR_BIT(va_type) | \
583 VNODE_ATTR_BIT(va_name) | \
584 VNODE_ATTR_BIT(va_uuuid) | \
585 VNODE_ATTR_BIT(va_guuid) | \
586 VNODE_ATTR_BIT(va_nchildren) | \
587 VNODE_ATTR_BIT(va_dirlinkcount) | \
588 VNODE_ATTR_BIT(va_addedtime) | \
589 VNODE_ATTR_BIT(va_dataprotect_class) | \
590 VNODE_ATTR_BIT(va_dataprotect_flags) | \
591 VNODE_ATTR_BIT(va_document_id) | \
592 VNODE_ATTR_BIT(va_devid) | \
593 VNODE_ATTR_BIT(va_objtype) | \
594 VNODE_ATTR_BIT(va_objtag) | \
595 VNODE_ATTR_BIT(va_user_access) | \
596 VNODE_ATTR_BIT(va_finderinfo) | \
597 VNODE_ATTR_BIT(va_rsrc_length) | \
598 VNODE_ATTR_BIT(va_rsrc_alloc) | \
599 VNODE_ATTR_BIT(va_fsid64) | \
600 VNODE_ATTR_BIT(va_write_gencount) | \
601 VNODE_ATTR_BIT(va_private_size))
602
603/*
604 * Read-only attributes.
605 */
606#define VNODE_ATTR_RDONLY (VNODE_ATTR_BIT(va_rdev) | \
607 VNODE_ATTR_BIT(va_nlink) | \
608 VNODE_ATTR_BIT(va_total_size) | \
609 VNODE_ATTR_BIT(va_total_alloc) | \
610 VNODE_ATTR_BIT(va_data_alloc) | \
611 VNODE_ATTR_BIT(va_iosize) | \
612 VNODE_ATTR_BIT(va_fileid) | \
613 VNODE_ATTR_BIT(va_linkid) | \
614 VNODE_ATTR_BIT(va_parentid) | \
615 VNODE_ATTR_BIT(va_fsid) | \
616 VNODE_ATTR_BIT(va_filerev) | \
617 VNODE_ATTR_BIT(va_gen) | \
618 VNODE_ATTR_BIT(va_name) | \
619 VNODE_ATTR_BIT(va_type) | \
620 VNODE_ATTR_BIT(va_nchildren) | \
621 VNODE_ATTR_BIT(va_dirlinkcount) | \
622 VNODE_ATTR_BIT(va_devid) | \
623 VNODE_ATTR_BIT(va_objtype) | \
624 VNODE_ATTR_BIT(va_objtag) | \
625 VNODE_ATTR_BIT(va_user_access) | \
626 VNODE_ATTR_BIT(va_finderinfo) | \
627 VNODE_ATTR_BIT(va_rsrc_length) | \
628 VNODE_ATTR_BIT(va_rsrc_alloc) | \
629 VNODE_ATTR_BIT(va_fsid64) | \
630 VNODE_ATTR_BIT(va_write_gencount) | \
631 VNODE_ATTR_BIT(va_private_size))
632/*
633 * Attributes that can be applied to a new file object.
634 */
635#define VNODE_ATTR_NEWOBJ (VNODE_ATTR_BIT(va_rdev) | \
636 VNODE_ATTR_BIT(va_uid) | \
637 VNODE_ATTR_BIT(va_gid) | \
638 VNODE_ATTR_BIT(va_mode) | \
639 VNODE_ATTR_BIT(va_flags) | \
640 VNODE_ATTR_BIT(va_acl) | \
641 VNODE_ATTR_BIT(va_create_time) | \
642 VNODE_ATTR_BIT(va_modify_time) | \
643 VNODE_ATTR_BIT(va_change_time) | \
644 VNODE_ATTR_BIT(va_encoding) | \
645 VNODE_ATTR_BIT(va_type) | \
646 VNODE_ATTR_BIT(va_uuuid) | \
647 VNODE_ATTR_BIT(va_guuid) | \
648 VNODE_ATTR_BIT(va_dataprotect_class) | \
649 VNODE_ATTR_BIT(va_dataprotect_flags) | \
650 VNODE_ATTR_BIT(va_document_id))
651
652#include <sys/_types/_fsid_t.h>
653
654struct vnode_attr {
655 /* bitfields */
656 uint64_t va_supported;
657 uint64_t va_active;
658
659 /*
660 * Control flags. The low 16 bits are reserved for the
661 * ioflags being passed for truncation operations.
662 */
663 int va_vaflags;
664
665 /* traditional stat(2) parameter fields */
666 dev_t va_rdev; /* device id (device nodes only) */
667 uint64_t va_nlink; /* number of references to this file */
668 uint64_t va_total_size; /* size in bytes of all forks */
669 uint64_t va_total_alloc; /* disk space used by all forks */
670 uint64_t va_data_size; /* size in bytes of the fork managed by current vnode */
671 uint64_t va_data_alloc; /* disk space used by the fork managed by current vnode */
672 uint32_t va_iosize; /* optimal I/O blocksize */
673
674 /* file security information */
675 uid_t va_uid; /* owner UID */
676 gid_t va_gid; /* owner GID */
677 mode_t va_mode; /* posix permissions */
678 uint32_t va_flags; /* file flags */
679 struct kauth_acl *va_acl; /* access control list */
680
681 /* timestamps */
682 struct timespec va_create_time; /* time of creation */
683 struct timespec va_access_time; /* time of last access */
684 struct timespec va_modify_time; /* time of last data modification */
685 struct timespec va_change_time; /* time of last metadata change */
686 struct timespec va_backup_time; /* time of last backup */
687
688 /* file parameters */
689 uint64_t va_fileid; /* file unique ID in filesystem */
690 uint64_t va_linkid; /* file link unique ID */
691 uint64_t va_parentid; /* parent ID */
692 uint32_t va_fsid; /* filesystem ID */
693 uint64_t va_filerev; /* file revision counter */ /* XXX */
694 uint32_t va_gen; /* file generation count */ /* XXX - relationship of
695 * these two? */
696 /* misc parameters */
697 uint32_t va_encoding; /* filename encoding script */
698
699 enum vtype va_type; /* file type */
700 char * va_name; /* Name for ATTR_CMN_NAME; MAXPATHLEN bytes */
701 guid_t va_uuuid; /* file owner UUID */
702 guid_t va_guuid; /* file group UUID */
703
704 /* Meaningful for directories only */
705 uint64_t va_nchildren; /* Number of items in a directory */
706 uint64_t va_dirlinkcount; /* Real references to dir (i.e. excluding "." and ".." refs) */
707
708#ifdef BSD_KERNEL_PRIVATE
709 struct kauth_acl *va_base_acl;
710#else
711 void * va_reserved1;
712#endif /* BSD_KERNEL_PRIVATE */
713 struct timespec va_addedtime; /* timestamp when item was added to parent directory */
714
715 /* Data Protection fields */
716 uint32_t va_dataprotect_class; /* class specified for this file if it didn't exist */
717 uint32_t va_dataprotect_flags; /* flags from NP open(2) to the filesystem */
718
719 /* Document revision tracking */
720 uint32_t va_document_id;
721
722 /* Fields for Bulk args */
723 uint32_t va_devid; /* devid of filesystem */
724 uint32_t va_objtype; /* type of object */
725 uint32_t va_objtag; /* vnode tag of filesystem */
726 uint32_t va_user_access; /* access for user */
727 uint8_t va_finderinfo[32]; /* Finder Info */
728 uint64_t va_rsrc_length; /* Resource Fork length */
729 uint64_t va_rsrc_alloc; /* Resource Fork allocation size */
730 fsid_t va_fsid64; /* fsid, of the correct type */
731
732 uint32_t va_write_gencount; /* counter that increments each time the file changes */
733
734 uint64_t va_private_size; /* If the file were deleted, how many bytes would be freed immediately */
735
736 /* add new fields here only */
737};
738
739#ifdef BSD_KERNEL_PRIVATE
740/*
741 * Flags for va_dataprotect_flags
742 */
743#define VA_DP_RAWENCRYPTED 0x0001
744#define VA_DP_RAWUNENCRYPTED 0x0002
745
746#endif
747
748/*
749 * Flags for va_vaflags.
750 */
751#define VA_UTIMES_NULL 0x010000 /* utimes argument was NULL */
752#define VA_EXCLUSIVE 0x020000 /* exclusive create request */
753#define VA_NOINHERIT 0x040000 /* Don't inherit ACLs from parent */
754#define VA_NOAUTH 0x080000
755#define VA_64BITOBJIDS 0x100000 /* fileid/linkid/parentid are 64 bit */
756
757/*
758 * Modes. Some values same as Ixxx entries from inode.h for now.
759 */
760#define VSUID 0x800 /*04000*/ /* set user id on execution */
761#define VSGID 0x400 /*02000*/ /* set group id on execution */
762#define VSVTX 0x200 /*01000*/ /* save swapped text even after use */
763#define VREAD 0x100 /*00400*/ /* read, write, execute permissions */
764#define VWRITE 0x080 /*00200*/
765#define VEXEC 0x040 /*00100*/
766
767/*
768 * Convert between vnode types and inode formats (since POSIX.1
769 * defines mode word of stat structure in terms of inode formats).
770 */
771extern enum vtype iftovt_tab[];
772extern int vttoif_tab[];
773#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
774#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
775#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
776
777/*
778 * Flags to various vnode functions.
779 */
780#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */
781#define FORCECLOSE 0x0002 /* vflush: force file closeure */
782#define WRITECLOSE 0x0004 /* vflush: only close writeable files */
783#define SKIPSWAP 0x0008 /* vflush: skip vnodes marked VSWAP */
784#define SKIPROOT 0x0010 /* vflush: skip root vnodes marked VROOT */
785
786#define DOCLOSE 0x0008 /* vclean: close active files */
787
788#define V_SAVE 0x0001 /* vinvalbuf: sync file first */
789#define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */
790
791#define REVOKEALL 0x0001 /* vnop_revoke: revoke all aliases */
792
793/* VNOP_REMOVE/unlink flags */
794#define VNODE_REMOVE_NODELETEBUSY 0x0001 /* Don't delete busy files (Carbon) */
795#define VNODE_REMOVE_SKIP_NAMESPACE_EVENT 0x0002 /* Do not upcall to userland handlers */
796#define VNODE_REMOVE_NO_AUDIT_PATH 0x0004 /* Do not audit the path */
797
798/* VNOP_READDIR flags: */
799#define VNODE_READDIR_EXTENDED 0x0001 /* use extended directory entries */
800#define VNODE_READDIR_REQSEEKOFF 0x0002 /* requires seek offset (cookies) */
801#define VNODE_READDIR_SEEKOFF32 0x0004 /* seek offset values should fit in 32 bits */
802#define VNODE_READDIR_NAMEMAX 0x0008 /* For extended readdir, try to limit names to NAME_MAX bytes */
803
804/* VNOP_CLONEFILE flags: */
805#define VNODE_CLONEFILE_DEFAULT 0x0000
806#define VNODE_CLONEFILE_NOOWNERCOPY 0x0001 /* Don't copy ownership information */
807
808
809#define NULLVP ((struct vnode *)NULL)
810
811#ifndef BSD_KERNEL_PRIVATE
812struct vnodeop_desc;
813#endif
814
815extern int desiredvnodes; /* number of vnodes desired */
816
817
818/*
819 * This structure is used to configure the new vnodeops vector.
820 */
821struct vnodeopv_entry_desc {
822 struct vnodeop_desc *opve_op; /* which operation this is */
823 int (*opve_impl)(void *); /* code implementing this operation */
824};
825struct vnodeopv_desc {
826 /* ptr to the ptr to the vector where op should go */
827 int (***opv_desc_vector_p)(void *);
828 struct vnodeopv_entry_desc *opv_desc_ops; /* null terminated list */
829};
830
831/*!
832 @function vn_default_error
833 @abstract Default vnode operation to fill unsupported slots in vnode operation vectors.
834 @return ENOTSUP
835 */
836int vn_default_error(void);
837
838/*
839 * A generic structure.
840 * This can be used by bypass routines to identify generic arguments.
841 */
842struct vnop_generic_args {
843 struct vnodeop_desc *a_desc;
844 /* other random data follows, presumably */
845};
846
847#include <sys/vnode_if.h>
848
849__BEGIN_DECLS
850
851/*!
852 @function vnode_create
853 @abstract Create and initialize a vnode.
854 @discussion Returns wth an iocount held on the vnode which must eventually be dropped with vnode_put().
855 @param flavor Should be VNCREATE_FLAVOR.
856 @param size Size of the struct vnode_fsparam in "data".
857 @param data Pointer to a struct vnode_fsparam containing initialization information.
858 @param vpp Pointer to a vnode pointer, to be filled in with newly created vnode.
859 @return 0 for success, error code otherwise.
860 */
861errno_t vnode_create(uint32_t flavor, uint32_t size, void *data, vnode_t *vpp);
862
863#ifdef KERNEL_PRIVATE
864/*!
865 @function vnode_create_empty
866 @abstract Create an empty, uninitialized vnode.
867 @discussion Returns with an iocount held on the vnode which must eventually be
868 dropped with vnode_put(). The next operation performed on the vnode must be
869 vnode_initialize (or vnode_put if the vnode is not needed anymore).
870 This interface is provided as a mechanism to pre-flight obtaining a vnode for
871 certain filesystem operations which may need to get a vnode without filesystem
872 locks held. It is imperative that nothing be done with the vnode till the
873 succeeding vnode_initialize (or vnode_put as the case may be) call.
874 @param vpp Pointer to a vnode pointer, to be filled in with newly created vnode.
875 @return 0 for success, error code otherwise.
876 */
877errno_t vnode_create_empty(vnode_t *vpp);
878
879/*!
880 @function vnode_initialize
881 @abstract Initialize a vnode obtained by vnode_create_empty
882 @discussion Does not drop iocount held on the vnode which must eventually be
883 dropped with vnode_put(). In case of an error however, the vnode's iocount is
884 dropped and the vnode must not be referenced again by the caller.
885 @param flavor Should be VNCREATE_FLAVOR.
886 @param size Size of the struct vnode_fsparam in "data".
887 @param data Pointer to a struct vnode_fsparam containing initialization information.
888 @param vpp Pointer to a vnode pointer, to be filled in with newly created vnode.
889 @return 0 for success, error code otherwise.
890 */
891errno_t vnode_initialize(uint32_t flavor, uint32_t size, void *data, vnode_t *vpp);
892#endif /* KERNEL_PRIVATE */
893
894/*!
895 @function vnode_addfsref
896 @abstract Mark a vnode as being stored in a filesystem hash.
897 @discussion Should only be called once on a vnode, and never if that vnode was created with VNFS_ADDFSREF.
898 There should be a corresponding call to vnode_removefsref() when the vnode is reclaimed; VFS assumes that a
899 n unused vnode will not be marked as referenced by a filesystem.
900 @param vp The vnode to mark.
901 @return Always 0.
902 */
903int vnode_addfsref(vnode_t vp);
904
905/*!
906 @function vnode_removefsref
907 @abstract Mark a vnode as no longer being stored in a filesystem hash.
908 @discussion Should only be called once on a vnode (during a reclaim), and only after the vnode has either been created with VNFS_ADDFSREF or marked by vnode_addfsref().
909 @param vp The vnode to unmark.
910 @return Always 0.
911 */
912int vnode_removefsref(vnode_t vp);
913
914/*!
915 @function vnode_hasdirtyblks
916 @abstract Check if a vnode has dirty data waiting to be written to disk.
917 @discussion Note that this routine is unsynchronized; it is only a snapshot and its result may cease to be true at the moment it is returned..
918 @param vp The vnode to test.
919 @return Nonzero if there are dirty blocks, 0 otherwise
920 */
921int vnode_hasdirtyblks(vnode_t vp);
922
923/*!
924 @function vnode_hascleanblks
925 @abstract Check if a vnode has clean buffers associated with it.
926 @discussion Note that this routine is unsynchronized; it is only a snapshot and its result may cease to be true at the moment it is returned..
927 @param vp The vnode to test.
928 @return Nonzero if there are clean blocks, 0 otherwise.
929 */
930int vnode_hascleanblks(vnode_t vp);
931
932#define VNODE_ASYNC_THROTTLE 15
933/*!
934 @function vnode_waitforwrites
935 @abstract Wait for the number of pending writes on a vnode to drop below a target.
936 @param vp The vnode to monitor.
937 @param output_target Max pending write count with which to return.
938 @param slpflag Flags for msleep().
939 @param slptimeout Frequency with which to force a check for completion; increments of 10 ms.
940 @param msg String to pass msleep() .
941 @return 0 for success, or an error value from msleep().
942 */
943int vnode_waitforwrites(vnode_t vp, int output_target, int slpflag, int slptimeout, const char *msg);
944
945/*!
946 @function vnode_startwrite
947 @abstract Increment the count of pending writes on a vnode.
948 @param vp The vnode whose count to increment.
949 */
950void vnode_startwrite(vnode_t vp);
951
952/*!
953 @function vnode_startwrite
954 @abstract Decrement the count of pending writes on a vnode .
955 @discussion Also wakes up threads waiting for the write count to drop, as in vnode_waitforwrites.
956 @param vp The vnode whose count to decrement.
957 */
958void vnode_writedone(vnode_t vp);
959
960/*!
961 @function vnode_vtype
962 @abstract Return a vnode's type.
963 @param vp The vnode whose type to grab.
964 @return The vnode's type.
965 */
966enum vtype vnode_vtype(vnode_t vp);
967
968/*!
969 @function vnode_vid
970 @abstract Return a vnode's vid (generation number), which is constant from creation until reclaim.
971 @param vp The vnode whose vid to grab.
972 @return The vnode's vid.
973 */
974uint32_t vnode_vid(vnode_t vp);
975
976/*!
977 @function vnode_mountedhere
978 @abstract Returns a pointer to a mount placed on top of a vnode, should it exist.
979 @param vp The vnode from whom to take the covering mount.
980 @return Pointer to mount covering a vnode, or NULL if none exists.
981 */
982mount_t vnode_mountedhere(vnode_t vp);
983
984/*!
985 @function vnode_mount
986 @abstract Get the mount structure for the filesystem that a vnode belongs to.
987 @param vp The vnode whose mount to grab.
988 @return The mount, directly.
989 */
990mount_t vnode_mount(vnode_t vp);
991
992/*!
993 @function vnode_specrdev
994 @abstract Return the device id of the device associated with a special file.
995 @param vp The vnode whose device id to extract--vnode must be a special file.
996 @return The device id.
997 */
998dev_t vnode_specrdev(vnode_t vp);
999
1000/*!
1001 @function vnode_fsnode
1002 @abstract Gets the filesystem-specific data associated with a vnode.
1003 @param vp The vnode whose data to grab.
1004 @return The filesystem-specific data, directly.
1005 */
1006void * vnode_fsnode(vnode_t vp);
1007
1008/*!
1009 @function vnode_clearfsnode
1010 @abstract Sets a vnode's filesystem-specific data to be NULL.
1011 @discussion This routine should only be called when a vnode is no longer in use, i.e. during a VNOP_RECLAIM.
1012 @param vp The vnode whose data to clear out.
1013 */
1014void vnode_clearfsnode(vnode_t vp);
1015
1016/*!
1017 @function vnode_isvroot
1018 @abstract Determine if a vnode is the root of its filesystem.
1019 @param vp The vnode to test.
1020 @return Nonzero if the vnode is the root, 0 if it is not.
1021 */
1022int vnode_isvroot(vnode_t vp);
1023
1024/*!
1025 @function vnode_issystem
1026 @abstract Determine if a vnode is marked as a System vnode.
1027 @param vp The vnode to test.
1028 @return Nonzero if the vnode is a system vnode, 0 if it is not.
1029 */
1030int vnode_issystem(vnode_t vp);
1031
1032/*!
1033 @function vnode_ismount
1034 @abstract Determine if there is currently a mount occurring which will cover this vnode.
1035 @discussion Note that this is only a snapshot; a mount may begin or end at any time.
1036 @param vp The vnode to test.
1037 @return Nonzero if there is a mount in progress, 0 otherwise.
1038 */
1039int vnode_ismount(vnode_t vp);
1040
1041/*!
1042 @function vnode_isreg
1043 @abstract Determine if a vnode is a regular file.
1044 @param vp The vnode to test.
1045 @return Nonzero if the vnode is of type VREG, 0 otherwise.
1046 */
1047int vnode_isreg(vnode_t vp);
1048
1049/*!
1050 @function vnode_isdir
1051 @abstract Determine if a vnode is a directory.
1052 @param vp The vnode to test.
1053 @return Nonzero if the vnode is of type VDIR, 0 otherwise.
1054 */
1055int vnode_isdir(vnode_t vp);
1056
1057/*!
1058 @function vnode_islnk
1059 @abstract Determine if a vnode is a symbolic link.
1060 @param vp The vnode to test.
1061 @return Nonzero if the vnode is of type VLNK, 0 otherwise.
1062 */
1063int vnode_islnk(vnode_t vp);
1064
1065/*!
1066 @function vnode_isfifo
1067 @abstract Determine if a vnode is a named pipe.
1068 @param vp The vnode to test.
1069 @return Nonzero if the vnode is of type VFIFO, 0 otherwise.
1070 */
1071int vnode_isfifo(vnode_t vp);
1072
1073/*!
1074 @function vnode_isblk
1075 @abstract Determine if a vnode is a block device special file.
1076 @param vp The vnode to test.
1077 @return Nonzero if the vnode is of type VBLK, 0 otherwise.
1078 */
1079int vnode_isblk(vnode_t vp);
1080
1081/*!
1082 @function vnode_ischr
1083 @abstract Determine if a vnode is a character device special file.
1084 @param vp The vnode to test.
1085 @return Nonzero if the vnode is of type VCHR, 0 otherwise.
1086 */
1087int vnode_ischr(vnode_t vp);
1088
1089/*!
1090 @function vnode_isswap
1091 @abstract Determine if a vnode is being used as a swap file.
1092 @param vp The vnode to test.
1093 @return Nonzero if the vnode is being used as swap, 0 otherwise.
1094 */
1095int vnode_isswap(vnode_t vp);
1096
1097/*!
1098 @function vnode_isnamedstream
1099 @abstract Determine if a vnode is a named stream.
1100 @param vp The vnode to test.
1101 @return Nonzero if the vnode is a named stream, 0 otherwise.
1102 */
1103int vnode_isnamedstream(vnode_t vp);
1104
1105#ifdef KERNEL_PRIVATE
1106/*!
1107 @function vnode_setasnamedstream
1108 @abstract Set svp as a named stream of vp and take appropriate references.
1109 @param vp The vnode whose namedstream has to be set.
1110 @param svp The namedstream vnode.
1111 @return 0 if the operation is successful, an error otherwise.
1112 */
1113errno_t vnode_setasnamedstream(vnode_t vp, vnode_t svp);
1114#endif
1115
1116/*!
1117 @function vnode_ismountedon
1118 @abstract Determine if a vnode is a block device on which a filesystem has been mounted.
1119 @discussion A block device marked as being mounted on cannot be opened.
1120 @param vp The vnode to test.
1121 @return Nonzero if the vnode is a block device on which an filesystem is mounted, 0 otherwise.
1122 */
1123int vnode_ismountedon(vnode_t vp);
1124
1125/*!
1126 @function vnode_setmountedon
1127 @abstract Set flags indicating that a block device vnode has been mounted as a filesystem.
1128 @discussion A block device marked as being mounted on cannot be opened.
1129 @param vp The vnode to set flags on, a block device.
1130 */
1131void vnode_setmountedon(vnode_t vp);
1132
1133/*!
1134 @function vnode_clearmountedon
1135 @abstract Clear flags indicating that a block device vnode has been mounted as a filesystem.
1136 @param vp The vnode to clear flags on, a block device.
1137 */
1138void vnode_clearmountedon(vnode_t vp);
1139
1140/*!
1141 @function vnode_isrecycled
1142 @abstract Check if a vnode is dead or in the process of being killed (recycled).
1143 @discussion This is only a snapshot: a vnode may start to be recycled, or go from dead to in use, at any time.
1144 @param vp The vnode to test.
1145 @return Nonzero if vnode is dead or being recycled, 0 otherwise.
1146 */
1147int vnode_isrecycled(vnode_t vp);
1148
1149/*!
1150 @function vnode_isnocache
1151 @abstract Check if a vnode is set to not have its data cached in memory (i.e. we write-through to disk and always read from disk).
1152 @param vp The vnode to test.
1153 @return Nonzero if vnode is set to not have data chached, 0 otherwise.
1154 */
1155int vnode_isnocache(vnode_t vp);
1156
1157/*!
1158 @function vnode_israge
1159 @abstract Check if a vnode is marked for rapid aging
1160 @param vp The vnode to test.
1161 @return Nonzero if vnode is marked for rapid aging, 0 otherwise
1162 */
1163int vnode_israge(vnode_t vp);
1164
1165/*!
1166 @function vnode_needssnapshots
1167 @abstract Check if a vnode needs snapshots events (regardless of its ctime status)
1168 @param vp The vnode to test.
1169 @return Nonzero if vnode needs snapshot events, 0 otherwise
1170 */
1171int vnode_needssnapshots(vnode_t vp);
1172
1173/*!
1174 @function vnode_setnocache
1175 @abstract Set a vnode to not have its data cached in memory (i.e. we write-through to disk and always read from disk).
1176 @param vp The vnode whose flags to set.
1177 */
1178void vnode_setnocache(vnode_t vp);
1179
1180/*!
1181 @function vnode_clearnocache
1182 @abstract Clear the flag on a vnode indicating that data should not be cached in memory (i.e. we write-through to disk and always read from disk).
1183 @param vp The vnode whose flags to clear.
1184 */
1185void vnode_clearnocache(vnode_t vp);
1186
1187/*!
1188 @function vnode_isnoreadahead
1189 @abstract Check if a vnode is set to not have data speculatively read in in hopes of future cache hits.
1190 @param vp The vnode to test.
1191 @return Nonzero if readahead is disabled, 0 otherwise.
1192 */
1193int vnode_isnoreadahead(vnode_t vp);
1194
1195/*!
1196 @function vnode_setnoreadahead
1197 @abstract Set a vnode to not have data speculatively read in in hopes of hitting in cache.
1198 @param vp The vnode on which to prevent readahead.
1199 */
1200void vnode_setnoreadahead(vnode_t vp);
1201
1202/*!
1203 @function vnode_clearnoreadahead
1204 @abstract Clear the flag indicating that a vnode should not have data speculatively read in.
1205 @param vp The vnode whose flag to clear.
1206 */
1207void vnode_clearnoreadahead(vnode_t vp);
1208
1209/*!
1210 @function vnode_isfastdevicecandidate
1211 @abstract Check if a vnode is a candidate to store on the fast device of a composite disk system
1212 @param vp The vnode which you want to test.
1213 @return Nonzero if the vnode is marked as a fast-device candidate
1214 */
1215int vnode_isfastdevicecandidate(vnode_t vp);
1216
1217/*!
1218 @function vnode_setfastdevicecandidate
1219 @abstract Mark a vnode as a candidate to store on the fast device of a composite disk system
1220 @discussion If the vnode is a directory, all its children will inherit this bit.
1221 @param vp The vnode which you want marked.
1222 */
1223void vnode_setfastdevicecandidate(vnode_t vp);
1224
1225/*!
1226 @function vnode_clearfastdevicecandidate
1227 @abstract Clear the status of a vnode being a candidate to store on the fast device of a composite disk system.
1228 @param vp The vnode whose flag to clear.
1229 */
1230void vnode_clearfastdevicecandidate(vnode_t vp);
1231
1232/*!
1233 @function vnode_isautocandidate
1234 @abstract Check if a vnode was automatically selected to be fast-dev candidate (see vnode_setfastdevicecandidate)
1235 @param vp The vnode which you want to test.
1236 @return Nonzero if the vnode was automatically marked as a fast-device candidate
1237 */
1238int vnode_isautocandidate(vnode_t vp);
1239
1240/*!
1241 @function vnode_setfastdevicecandidate
1242 @abstract Mark a vnode as an automatically selected candidate for storing on the fast device of a composite disk system
1243 @discussion If the vnode is a directory, all its children will inherit this bit.
1244 @param vp The vnode which you want marked.
1245 */
1246void vnode_setautocandidate(vnode_t vp);
1247
1248/*!
1249 @function vnode_clearautocandidate
1250 @abstract Clear the status of a vnode being an automatic candidate (see above)
1251 @param vp The vnode whose flag to clear.
1252 */
1253void vnode_clearautocandidate(vnode_t vp);
1254
1255/* left only for compat reasons as User code depends on this from getattrlist, for ex */
1256
1257/*!
1258 @function vnode_settag
1259 @abstract Set a vnode filesystem-specific "tag."
1260 @discussion Sets a tag indicating which filesystem a vnode belongs to, e.g. VT_HFS, VT_UDF, VT_ZFS. The kernel never inspects this data, though the filesystem tags are defined in vnode.h; it is for the benefit of user programs via getattrlist.
1261 @param vp The vnode whose tag to set.
1262 */
1263void vnode_settag(vnode_t vp, int tag);
1264
1265/*!
1266 @function vnode_tag
1267 @abstract Get the vnode filesystem-specific "tag."
1268 @discussion Gets the tag indicating which filesystem a vnode belongs to, e.g. VT_HFS, VT_UDF, VT_ZFS. The kernel never inspects this data, though the filesystem tags are defined in vnode.h; it is for the benefit of user programs via getattrlist.
1269 @param vp The vnode whose tag to grab.
1270 @return The tag.
1271 */
1272int vnode_tag(vnode_t vp);
1273
1274/*!
1275 @function vnode_getattr
1276 @abstract Get vnode attributes.
1277 @discussion Desired attributes are set with VATTR_SET_ACTIVE and VNODE_ATTR* macros. Supported attributes are determined after call with VATTR_IS_SUPPORTED.
1278 @param vp The vnode whose attributes to grab.
1279 @param vap Structure containing: 1) A list of requested attributes 2) Space to indicate which attributes are supported and being returned 3) Space to return attributes.
1280 @param ctx Context for authentication.
1281 @return 0 for success or an error code.
1282 */
1283int vnode_getattr(vnode_t vp, struct vnode_attr *vap, vfs_context_t ctx);
1284
1285/*!
1286 @function vnode_setattr
1287 @abstract Set vnode attributes.
1288 @discussion Attributes to set are marked with VATTR_SET_ACTIVE and VNODE_ATTR* macros. Attributes successfully set are determined after call with VATTR_IS_SUPPORTED.
1289 @param vp The vnode whose attributes to set.
1290 @param vap Structure containing: 1) A list of attributes to set 2) Space for values for those attributes 3) Space to indicate which attributes were set.
1291 @param ctx Context for authentication.
1292 @return 0 for success or an error code.
1293 */
1294int vnode_setattr(vnode_t vp, struct vnode_attr *vap, vfs_context_t ctx);
1295
1296/*!
1297 @function vfs_rootvnode
1298 @abstract Returns the root vnode with an iocount.
1299 @discussion Caller must vnode_put() the root node when done.
1300 @return Pointer to root vnode if successful; error code if there is a problem taking an iocount.
1301 */
1302vnode_t vfs_rootvnode(void);
1303
1304/*!
1305 @function vnode_uncache_credentials
1306 @abstract Clear out cached credentials on a vnode.
1307 @discussion When we authorize an action on a vnode, we cache the credential that was authorized and the actions it was authorized for in case a similar request follows. This function destroys that caching.
1308 @param vp The vnode whose cache to clear.
1309 */
1310void vnode_uncache_credentials(vnode_t vp);
1311
1312/*!
1313 @function vnode_setmultipath
1314 @abstract Mark a vnode as being reachable by multiple paths, i.e. as a hard link.
1315 @discussion "Multipath" vnodes can be reached through more than one entry in the filesystem, and so must be handled differently for caching and event notification purposes. A filesystem should mark a vnode with multiple hardlinks this way.
1316 @param vp The vnode to mark.
1317 */
1318void vnode_setmultipath(vnode_t vp);
1319
1320/*!
1321 @function vnode_vfsmaxsymlen
1322 @abstract Determine the maximum length of a symbolic link for the filesystem on which a vnode resides.
1323 @param vp The vnode for which to get filesystem symlink size cap.
1324 @return Max symlink length.
1325 */
1326uint32_t vnode_vfsmaxsymlen(vnode_t vp);
1327
1328/*!
1329 @function vnode_vfsisrdonly
1330 @abstract Determine if the filesystem to which a vnode belongs is mounted read-only.
1331 @param vp The vnode for which to get filesystem writeability.
1332 @return Nonzero if the filesystem is read-only, 0 otherwise.
1333 */
1334int vnode_vfsisrdonly(vnode_t vp);
1335
1336/*!
1337 @function vnode_vfstypenum
1338 @abstract Get the "type number" of the filesystem to which a vnode belongs.
1339 @discussion This is an archaic construct; most filesystems are assigned a type number based on the order in which they are registered with the system.
1340 @param vp The vnode whose filesystem to examine.
1341 @return The type number of the fileystem to which the vnode belongs.
1342 */
1343int vnode_vfstypenum(vnode_t vp);
1344
1345/*!
1346 @function vnode_vfsname
1347 @abstract Get the name of the filesystem to which a vnode belongs.
1348 @param vp The vnode whose filesystem to examine.
1349 @param buf Destination for vfs name: should have size MFSNAMELEN or greater.
1350 */
1351void vnode_vfsname(vnode_t vp, char *buf);
1352
1353/*!
1354 @function vnode_vfs64bitready
1355 @abstract Determine if the filesystem to which a vnode belongs is marked as ready to interact with 64-bit user processes.
1356 @param vp The vnode whose filesystem to examine.
1357 @return Nonzero if filesystem is marked ready for 64-bit interactions; 0 otherwise.
1358 */
1359int vnode_vfs64bitready(vnode_t vp);
1360
1361/* These should move to private ... not documenting for now */
1362int vfs_context_get_special_port(vfs_context_t, int, ipc_port_t *);
1363int vfs_context_set_special_port(vfs_context_t, int, ipc_port_t);
1364
1365/*!
1366 @function vfs_context_proc
1367 @abstract Get the BSD process structure associated with a vfs_context_t.
1368 @param ctx Context whose associated process to find.
1369 @return Process if available, NULL otherwise.
1370 */
1371proc_t vfs_context_proc(vfs_context_t ctx);
1372
1373/*!
1374 @function vfs_context_ucred
1375 @abstract Get the credential associated with a vfs_context_t.
1376 @discussion Succeeds if and only if the context has a thread, the thread has a task, and the task has a BSD proc.
1377 @param ctx Context whose associated process to find.
1378 @returns credential if process available; NULL otherwise
1379 */
1380kauth_cred_t vfs_context_ucred(vfs_context_t ctx);
1381
1382/*!
1383 @function vfs_context_pid
1384 @abstract Get the process id of the BSD process associated with a vfs_context_t.
1385 @param ctx Context whose associated process to find.
1386 @return Process id.
1387 */
1388int vfs_context_pid(vfs_context_t ctx);
1389
1390/*!
1391 @function vfs_context_issignal
1392 @abstract Get a bitfield of pending signals for the BSD process associated with a vfs_context_t.
1393 @discussion The bitfield is constructed using the sigmask() macro, in the sense of bits |= sigmask(SIGSEGV).
1394 @param ctx Context whose associated process to find.
1395 @return Bitfield of pending signals.
1396 */
1397int vfs_context_issignal(vfs_context_t ctx, sigset_t mask);
1398
1399/*!
1400 @function vfs_context_suser
1401 @abstract Determine if a vfs_context_t corresponds to the superuser.
1402 @param ctx Context to examine.
1403 @return 0 if context belongs to superuser, EPERM otherwise.
1404 */
1405int vfs_context_suser(vfs_context_t ctx);
1406
1407/*!
1408 @function vfs_context_is64bit
1409 @abstract Determine if a vfs_context_t corresponds to a 64-bit user process.
1410 @param ctx Context to examine.
1411 @return Nonzero if context is of 64-bit process, 0 otherwise.
1412 */
1413int vfs_context_is64bit(vfs_context_t ctx);
1414
1415/*!
1416 @function vfs_context_create
1417 @abstract Create a new vfs_context_t with appropriate references held.
1418 @discussion The context must be released with vfs_context_rele() when no longer in use.
1419 @param ctx Context to copy, or NULL to use information from running thread.
1420 @return The new context, or NULL in the event of failure.
1421 */
1422vfs_context_t vfs_context_create(vfs_context_t ctx);
1423
1424/*!
1425 @function vfs_context_rele
1426 @abstract Release references on components of a context and deallocate it.
1427 @discussion A context should not be referenced after vfs_context_rele has been called.
1428 @param ctx Context to release.
1429 @return Always 0.
1430 */
1431int vfs_context_rele(vfs_context_t ctx);
1432
1433/*!
1434 @function vfs_context_current
1435 @abstract Get the vfs_context for the current thread, or the kernel context if there is no context for current thread.
1436 @discussion Kexts should not use this function--it is preferred to use vfs_context_create(NULL) and vfs_context_rele(), which ensure proper reference counting of underlying structures.
1437 @return Context for current thread, or kernel context if thread context is unavailable.
1438 */
1439vfs_context_t vfs_context_current(void);
1440#ifdef KERNEL_PRIVATE
1441int vfs_context_bind(vfs_context_t);
1442
1443/*!
1444 @function vfs_ctx_skipatime
1445 @abstract Check to see if this context should skip updating a vnode's access times.
1446 @discussion This is currently tied to the vnode rapid aging process. If the process is marked for rapid aging,
1447 then the kernel should not update vnodes it touches for access time purposes. This will check to see if the
1448 specified process and/or thread is marked for rapid aging when it manipulates vnodes.
1449 @param ctx The context being investigated.
1450 @return 1 if we should skip access time updates.
1451 @return 0 if we should NOT skip access time updates.
1452 */
1453
1454int vfs_ctx_skipatime(vfs_context_t ctx);
1455
1456#endif
1457
1458/*!
1459 @function vflush
1460 @abstract Reclaim the vnodes associated with a mount.
1461 @param mp The mount whose vnodes to kill.
1462 @param skipvp A specific vnode to not reclaim or to let interrupt an un-forced flush
1463 @param flags Control which
1464 @discussion This function is used to clear out the vnodes associated with a mount as part of the unmount process.
1465 Its parameters can determine which vnodes to skip in the process and whether in-use vnodes should be forcibly reclaimed.
1466 Filesystems should call this function from their unmount code, because VFS code will always call it with SKIPROOT | SKIPSWAP | SKIPSYSTEM; filesystems
1467 must take care of such vnodes themselves.
1468 SKIPSYSTEM skip vnodes marked VSYSTEM
1469 FORCECLOSE force file closeure
1470 WRITECLOSE only close writeable files
1471 SKIPSWAP skip vnodes marked VSWAP
1472 SKIPROOT skip root vnodes marked VROOT
1473 @return 0 for success, EBUSY if vnodes were busy and FORCECLOSE was not set.
1474 */
1475int vflush(struct mount *mp, struct vnode *skipvp, int flags);
1476
1477/*!
1478 @function vnode_get
1479 @abstract Increase the iocount on a vnode.
1480 @discussion If vnode_get() succeeds, the resulting io-reference must be dropped with vnode_put().
1481 This function succeeds unless the vnode in question is dead or in the process of dying AND the current iocount is zero.
1482 This means that it can block an ongoing reclaim which is blocked behind some other iocount.
1483
1484 On success, vnode_get() returns with an iocount held on the vnode; this type of reference is intended to be held only for short periods of time (e.g.
1485 across a function call) and provides a strong guarantee about the life of the vnode; vnodes with positive iocounts cannot be
1486 recycled, and an iocount is required for any operation on a vnode. However, vnode_get() does not provide any guarantees
1487 about the identity of the vnode it is called on; unless there is a known existing iocount on the vnode at time the call is made,
1488 it could be recycled and put back in use before the vnode_get() succeeds, so the caller may be referencing a
1489 completely different vnode than was intended. vnode_getwithref() and vnode_getwithvid()
1490 provide guarantees about vnode identity.
1491
1492 @return 0 for success, ENOENT if the vnode is dead and without existing io-reference.
1493 */
1494int vnode_get(vnode_t);
1495
1496/*!
1497 @function vnode_getwithvid
1498 @abstract Increase the iocount on a vnode, checking that the vnode is alive and has not changed vid (i.e. been recycled)
1499 @discussion If vnode_getwithvid() succeeds, the resulting io-reference must be dropped with vnode_put().
1500 This function succeeds unless the vnode in question is dead, in the process of dying, or has been recycled (and given a different vnode id).
1501 The intended usage is that a vnode is stored and its vid (vnode_vid(vp)) recorded while an iocount is held (example: a filesystem hash). The
1502 iocount is then dropped, and time passes (perhaps locks are dropped and picked back up). Subsequently, vnode_getwithvid() is called to get an iocount,
1503 but we are alerted if the vnode has been recycled.
1504
1505 On success, vnode_getwithvid() returns with an iocount held on the vnode; this type of reference is intended to be held only for short periods of time (e.g.
1506 across a function call) and provides a strong guarantee about the life of the vnode. vnodes with positive iocounts cannot be
1507 recycled. An iocount is required for any operation on a vnode.
1508 @return 0 for success, ENOENT if the vnode is dead, in the process of being reclaimed, or has been recycled and reused.
1509 */
1510int vnode_getwithvid(vnode_t, uint32_t);
1511
1512#ifdef BSD_KERNEL_PRIVATE
1513int vnode_getwithvid_drainok(vnode_t, uint32_t);
1514#endif /* BSD_KERNEL_PRIVATE */
1515
1516/*!
1517 @function vnode_getwithref
1518 @abstract Increase the iocount on a vnode on which a usecount (persistent reference) is held.
1519 @discussion If vnode_getwithref() succeeds, the resulting io-reference must be dropped with vnode_put().
1520 vnode_getwithref() will succeed on dead vnodes; it should fail with ENOENT on vnodes which are in the process of being reclaimed.
1521 Because it is only called with a usecount on the vnode, the caller is guaranteed that the vnode has not been
1522 reused for a different file, though it may now be dead and have deadfs vnops (which return errors like EIO, ENXIO, ENOTDIR).
1523 On success, vnode_getwithref() returns with an iocount held on the vnode; this type of reference is intended to be held only for short periods of time (e.g.
1524 across a function call) and provides a strong guarantee about the life of the vnode. vnodes with positive iocounts cannot be
1525 recycled. An iocount is required for any operation on a vnode.
1526 @return 0 for success, ENOENT if the vnode is dead, in the process of being reclaimed, or has been recycled and reused.
1527 */
1528int vnode_getwithref(vnode_t vp);
1529
1530/*!
1531 @function vnode_put
1532 @abstract Decrement the iocount on a vnode.
1533 @discussion vnode_put() is called to indicate that a vnode is no longer in active use. It removes the guarantee that a
1534 vnode will not be recycled. This routine should be used to release io references no matter how they were obtained.
1535 @param vp The vnode whose iocount to drop.
1536 @return Always 0.
1537 */
1538int vnode_put(vnode_t vp);
1539
1540/*!
1541 @function vnode_ref
1542 @abstract Increment the usecount on a vnode.
1543 @discussion If vnode_ref() succeeds, the resulting usecount must be released with vnode_rele(). vnode_ref() is called to obtain
1544 a persistent reference on a vnode. This type of reference does not provide the same strong guarantee that a vnode will persist
1545 as does an iocount--it merely ensures that a vnode will not be reused to represent a different file. However, a usecount may be
1546 held for extended periods of time, whereas an iocount is intended to be obtained and released quickly as part of performing a
1547 vnode operation. A holder of a usecount must call vnode_getwithref()/vnode_put() in order to perform any operations on that vnode.
1548 @param vp The vnode on which to obtain a persistent reference.
1549 @return 0 for success; ENOENT if the vnode is dead or in the process of being recycled AND the calling thread is not the vnode owner.
1550 */
1551int vnode_ref(vnode_t vp);
1552
1553/*!
1554 @function vnode_rele
1555 @abstract Decrement the usecount on a vnode.
1556 @discussion vnode_rele() is called to relese a persistent reference on a vnode. Releasing the last usecount
1557 opens the door for a vnode to be reused as a new file; it also triggers a VNOP_INACTIVE call to the filesystem,
1558 though that will not happen immediately if there are outstanding iocount references.
1559 @param vp The vnode whose usecount to drop.
1560 */
1561void vnode_rele(vnode_t vp);
1562
1563/*!
1564 @function vnode_isinuse
1565 @abstract Determine if the number of persistent (usecount) references on a vnode is greater than a given count.
1566 @discussion vnode_isinuse() compares a vnode's usecount (corresponding to vnode_ref() calls) to its refcnt parameter
1567 (the number of references the caller expects to be on the vnode). Note that "kusecount" references, corresponding
1568 to parties interested only in event notifications, e.g. open(..., O_EVTONLY), are not counted towards the total; the comparison is
1569 (usecount - kusecount > recnt). It is
1570 also important to note that the result is only a snapshot; usecounts can change from moment to moment, and the result of vnode_isinuse
1571 may no longer be correct the very moment that the caller receives it.
1572 @param vp The vnode whose use-status to check.
1573 @param refcnt The threshold for saying that a vnode is in use.
1574 */
1575int vnode_isinuse(vnode_t vp, int refcnt);
1576
1577/*!
1578 @function vnode_recycle
1579 @abstract Cause a vnode to be reclaimed and prepared for reuse.
1580 @discussion Like all vnode KPIs, must be called with an iocount on the target vnode.
1581 vnode_recycle() will mark that vnode for reclaim when all existing references are dropped.
1582 @param vp The vnode to recycle.
1583 @return 1 if the vnode was reclaimed (i.e. there were no existing references), 0 if it was only marked for future reclaim.
1584 */
1585int vnode_recycle(vnode_t vp);
1586
1587#ifdef KERNEL_PRIVATE
1588
1589#define VNODE_EVENT_DELETE 0x00000001 /* file was removed */
1590#define VNODE_EVENT_WRITE 0x00000002 /* file or directory contents changed */
1591#define VNODE_EVENT_EXTEND 0x00000004 /* ubc size increased */
1592#define VNODE_EVENT_ATTRIB 0x00000008 /* attributes changed (suitable for permission changes if type unknown)*/
1593#define VNODE_EVENT_LINK 0x00000010 /* link count changed */
1594#define VNODE_EVENT_RENAME 0x00000020 /* vnode was renamed */
1595#define VNODE_EVENT_PERMS 0x00000040 /* permissions changed: will cause a NOTE_ATTRIB */
1596#define VNODE_EVENT_FILE_CREATED 0x00000080 /* file created in directory: will cause NOTE_WRITE */
1597#define VNODE_EVENT_DIR_CREATED 0x00000100 /* directory created inside this directory: will cause NOTE_WRITE */
1598#define VNODE_EVENT_FILE_REMOVED 0x00000200 /* file removed from this directory: will cause NOTE_WRITE */
1599#define VNODE_EVENT_DIR_REMOVED 0x00000400 /* subdirectory from this directory: will cause NOTE_WRITE */
1600
1601#ifdef BSD_KERNEL_PRIVATE
1602#define VNODE_NOTIFY_ATTRS (VNODE_ATTR_BIT(va_fsid) | \
1603 VNODE_ATTR_BIT(va_fileid)| \
1604 VNODE_ATTR_BIT(va_mode) | \
1605 VNODE_ATTR_BIT(va_uid) | \
1606 VNODE_ATTR_BIT(va_gid) | \
1607 VNODE_ATTR_BIT(va_dirlinkcount) | \
1608 VNODE_ATTR_BIT(va_nlink))
1609
1610
1611
1612#endif /* BSD_KERNEL_PRIVATE */
1613
1614/*!
1615 @function vnode_ismonitored
1616 @abstract Check whether a file has watchers that would make it useful to query a server
1617 for file changes.
1618 @param vp Vnode to examine.
1619 @discussion Will not reenter the filesystem.
1620 @return Zero if not monitored, nonzero if monitored.
1621 */
1622int vnode_ismonitored(vnode_t vp);
1623
1624
1625/*!
1626 @function vnode_isdyldsharedcache
1627 @abstract Check whether a file is a dyld shared cache file.
1628 @param vp Vnode to examine.
1629 @discussion Will not reenter the filesystem.
1630 @return nonzero if a dyld shared cache file, zero otherwise.
1631 */
1632int vnode_isdyldsharedcache(vnode_t vp);
1633
1634
1635/*!
1636 @function vn_getpath_fsenter
1637 @abstract Attempt to get a vnode's path, willing to enter the filesystem.
1638 @discussion Paths to vnodes are not always straightforward: a file with multiple hard-links will have multiple pathnames,
1639 and it is sometimes impossible to determine a vnode's full path. vn_getpath_fsenter() may enter the filesystem
1640 to try to construct a path, so filesystems should be wary of calling it.
1641 @param vp Vnode whose path to get
1642 @param pathbuf Buffer in which to store path.
1643 @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len"
1644 will be strlen(pathbuf) + 1.
1645 @return 0 for success or an error.
1646 */
1647int vn_getpath_fsenter(struct vnode *vp, char *pathbuf, int *len);
1648
1649/*!
1650 @function vn_getpath_fsenter_with_parent
1651 @abstract Attempt to get a vnode's path by entering the file system if needed given a vnode and it's directory vnode.
1652 @discussion Same as vn_getpath_fsenter but is given the directory vnode as well as the target vnode. Used
1653to get the path from the vnode while performing rename, rmdir, and unlink. This is done to avoid potential
1654dead lock if another thread is doing a forced unmount.
1655 @param dvp Containing directory vnode. Must be holding an IO count.
1656 @param vp Vnode whose path to get. Must be holding an IO count.
1657 @param pathbuf Buffer in which to store path.
1658 @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len"
1659 will be strlen(pathbuf) + 1.
1660 @return 0 for success or an error.
1661*/
1662int vn_getpath_fsenter_with_parent(struct vnode *dvp, struct vnode *vp, char *pathbuf, int *len);
1663
1664#endif /* KERNEL_PRIVATE */
1665
1666#define VNODE_UPDATE_PARENT 0x01
1667#define VNODE_UPDATE_NAMEDSTREAM_PARENT VNODE_UPDATE_PARENT
1668#define VNODE_UPDATE_NAME 0x02
1669#define VNODE_UPDATE_CACHE 0x04
1670#define VNODE_UPDATE_PURGE 0x08
1671/*!
1672 @function vnode_update_identity
1673 @abstract Update vnode data associated with the vfs cache.
1674 @discussion The vfs namecache is central to tracking vnode-identifying data and to locating files on the system. vnode_update_identity()
1675 is used to update vnode data associated with the cache. It can set a vnode's parent and/or name (also potentially set by vnode_create())
1676 or flush cache data.
1677 @param vp The vnode whose information to update.
1678 @param dvp Parent to set on the vnode if VNODE_UPDATE_PARENT is used.
1679 @param name Name to set in the cache for the vnode if VNODE_UPDATE_NAME is used. The buffer passed in can be subsequently freed, as the cache
1680 does its own name storage. String should be NULL-terminated unless length and hash value are specified.
1681 @param name_len Length of name, if known. Passing 0 causes the cache to determine the length itself.
1682 @param name_hashval Hash value of name, if known. Passing 0 causes the cache to hash the name itself.
1683 @param flags VNODE_UPDATE_PARENT: set parent. VNODE_UPDATE_NAME: set name. VNODE_UPDATE_CACHE: flush cache entries for hard links
1684 associated with this file. VNODE_UPDATE_PURGE: flush cache entries for hard links and children of this file.
1685 */
1686void vnode_update_identity(vnode_t vp, vnode_t dvp, const char *name, int name_len, uint32_t name_hashval, int flags);
1687
1688/*!
1689 @function vn_bwrite
1690 @abstract System-provided implementation of "bwrite" vnop.
1691 @discussion This routine is available for filesystems which do not want to implement their own "bwrite" vnop. It just calls
1692 buf_bwrite() without modifying its arguments.
1693 @param ap Standard parameters to a bwrite vnop.
1694 @return Results of buf_bwrite directly.
1695 */
1696int vn_bwrite(struct vnop_bwrite_args *ap);
1697
1698/*!
1699 @function vnode_authorize
1700 @abstract Authorize a kauth-style action on a vnode.
1701 @discussion Operations on dead vnodes are always allowed (though never do anything).
1702 @param vp Vnode on which to authorize action.
1703 @param dvp Parent of "vp," can be NULL.
1704 @param action Action to authorize, e.g. KAUTH_VNODE_READ_DATA. See bsd/sys/kauth.h.
1705 @param ctx Context for which to authorize actions.
1706 @return EACCESS if permission is denied. 0 if operation allowed. Various errors from lower layers.
1707 */
1708int vnode_authorize(vnode_t vp, vnode_t dvp, kauth_action_t action, vfs_context_t ctx);
1709
1710#ifdef KERNEL_PRIVATE
1711/*!
1712 @function vnode_attr_authorize_init
1713 @abstract Initialize attributes for authorization of a kauth-style action on a file system object based on its attributes.
1714 @discussion This function tells the caller what attributes may be required for a authorizing
1715 a kauth style action.
1716 @param vap attributes of file system object on which to authorize action.
1717 @param dvap attributes of parent of file system object, can be NULL.
1718 @param action Action to authorize, e.g. KAUTH_VNODE_READ_DATA. See bsd/sys/kauth.h.
1719 @param ctx Context for which to authorize actions.
1720 @return EINVAL if a required parameters are not passed (for eg. not passing dvap when the action is KAUTH_ACTION_DELETE), 0 otherwise.
1721 */
1722#define VNODE_ATTR_AUTHORIZE_AVAILABLE 0x01
1723int vnode_attr_authorize_init(struct vnode_attr *vap, struct vnode_attr *dvap, kauth_action_t action, vfs_context_t ctx);
1724
1725/*!
1726 @function vnode_attr_authorize
1727 @abstract Authorize a kauth-style action on a file system object based on its attributes.
1728 @discussion This function should be preceded by a call to vnode_attr_authorize_init to get what attributes are required.
1729 @param vap attributes of file system object on which to authorize action.
1730 @param dvap attributes of parent of file system object, can be NULL.
1731 @param mp mountpoint to which file system object belongs, can be NULL.
1732 @param action Action to authorize, e.g. KAUTH_VNODE_READ_DATA. See bsd/sys/kauth.h.
1733 @param ctx Context for which to authorize actions.
1734 @return EACCESS if permission is denied. 0 if operation allowed. Various errors from lower layers.
1735 */
1736int vnode_attr_authorize(struct vnode_attr *vap, struct vnode_attr *dvap, mount_t mp, kauth_action_t action, vfs_context_t ctx);
1737#endif /* KERNEL_PRIVATE */
1738
1739/*!
1740 @function vnode_authattr
1741 @abstract Given a vnode_attr structure, determine what kauth-style actions must be authorized in order to set those attributes.
1742 @discussion vnode_authorize requires kauth-style actions; if we want to set a vnode_attr structure on a vnode, we need to translate
1743 the set of attributes to a set of kauth-style actions. This routine will return errors for certain obviously disallowed, or
1744 incoherent, actions.
1745 @param vp The vnode on which to authorize action.
1746 @param vap Pointer to vnode_attr struct containing desired attributes to set and their values.
1747 @param actionp Destination for set of actions to authorize
1748 @param ctx Context for which to authorize actions.
1749 @return 0 (and a result in "actionp" for success. Otherwise, an error code.
1750 */
1751int vnode_authattr(vnode_t vp, struct vnode_attr *vap, kauth_action_t *actionp, vfs_context_t ctx);
1752
1753/*!
1754 @function vnode_authattr_new
1755 @abstract Initialize and validate file creation parameters with respect to the current context.
1756 @discussion vnode_authattr_new() will fill in unitialized values in the vnode_attr struct with defaults, and will validate the structure
1757 with respect to the current context for file creation.
1758 @param dvp The directory in which creation will occur.
1759 @param vap Pointer to vnode_attr struct containing desired attributes to set and their values.
1760 @param noauth If 1, treat the caller as the superuser, i.e. do not check permissions.
1761 @param ctx Context for which to authorize actions.
1762 @return KAUTH_RESULT_ALLOW for success, an error to indicate invalid or disallowed attributes.
1763 */
1764int vnode_authattr_new(vnode_t dvp, struct vnode_attr *vap, int noauth, vfs_context_t ctx);
1765
1766/*!
1767 @function vnode_close
1768 @abstract Close a file as opened with vnode_open().
1769 @discussion vnode_close() drops the refcount (persistent reference) picked up in vnode_open() and calls down to the filesystem with VNOP_CLOSE. It should
1770 be called with both an iocount and a refcount on the vnode and will drop both.
1771 @param vp The vnode to close.
1772 @param flags Flags to close: FWASWRITTEN indicates that the file was written to.
1773 @param ctx Context against which to validate operation.
1774 @return 0 for success or an error from the filesystem.
1775 */
1776errno_t vnode_close(vnode_t vp, int flags, vfs_context_t ctx);
1777
1778/*!
1779 @function vn_getpath
1780 @abstract Construct the path to a vnode.
1781 @discussion Paths to vnodes are not always straightforward: a file with multiple hard-links will have multiple pathnames,
1782 and it is sometimes impossible to determine a vnode's full path. vn_getpath() will not enter the filesystem.
1783 @param vp The vnode whose path to obtain.
1784 @param pathbuf Destination for pathname; should be of size MAXPATHLEN
1785 @param len Destination for length of resulting path string. Result will include NULL-terminator in count--that is, "len"
1786 will be strlen(pathbuf) + 1.
1787 @return 0 for success or an error code.
1788 */
1789int vn_getpath(struct vnode *vp, char *pathbuf, int *len);
1790
1791/*!
1792 @function vnode_notify
1793 @abstract Send a notification up to VFS.
1794 @param vp Vnode for which to provide notification.
1795 @param vap Attributes for that vnode, to be passed to fsevents.
1796 @discussion Filesystem determines which attributes to pass up using
1797 vfs_get_notify_attributes(&vap). The most specific events possible should be passed,
1798 e.g. VNODE_EVENT_FILE_CREATED on a directory rather than just VNODE_EVENT_WRITE, but
1799 a less specific event can be passed up if more specific information is not available.
1800 Will not reenter the filesystem.
1801 @return 0 for success, else an error code.
1802 */
1803int vnode_notify(vnode_t vp, uint32_t events, struct vnode_attr *vap);
1804
1805/*!
1806 @function vfs_get_notify_attributes
1807 @abstract Determine what attributes are required to send up a notification with vnode_notify().
1808 @param vap Structure to initialize and activate required attributes on.
1809 @discussion Will not reenter the filesystem.
1810 @return 0 for success, nonzero for error (currently always succeeds).
1811 */
1812int vfs_get_notify_attributes(struct vnode_attr *vap);
1813
1814/*
1815 * Flags for the vnode_lookup and vnode_open
1816 */
1817#define VNODE_LOOKUP_NOFOLLOW 0x01
1818#define VNODE_LOOKUP_NOCROSSMOUNT 0x02
1819#define VNODE_LOOKUP_CROSSMOUNTNOWAIT 0x04
1820/*!
1821 @function vnode_lookup
1822 @abstract Convert a path into a vnode.
1823 @discussion This routine is a thin wrapper around xnu-internal lookup routines; if successful,
1824 it returns with an iocount held on the resulting vnode which must be dropped with vnode_put().
1825 @param path Path to look up.
1826 @param flags VNODE_LOOKUP_NOFOLLOW: do not follow symbolic links. VNODE_LOOKUP_NOCROSSMOUNT: do not cross mount points.
1827 @return Results 0 for success or an error code.
1828 */
1829errno_t vnode_lookup(const char *path, int flags, vnode_t *vpp, vfs_context_t ctx);
1830
1831/*!
1832 @function vnode_open
1833 @abstract Open a file identified by a path--roughly speaking an in-kernel open(2).
1834 @discussion If vnode_open() succeeds, it returns with both an iocount and a usecount on the returned vnode. These must
1835 be released eventually; the iocount should be released with vnode_put() as soon as any initial operations
1836 on the vnode are over, whereas the usecount should be released via vnode_close().
1837 @param path Path to look up.
1838 @param fmode e.g. O_NONBLOCK, O_APPEND; see bsd/sys/fcntl.h.
1839 @param cmode Permissions with which to create file if it does not exist.
1840 @param flags Same as vnode_lookup().
1841 @param vpp Destination for vnode.
1842 @param ctx Context with which to authorize open/creation.
1843 @return 0 for success or an error code.
1844 */
1845errno_t vnode_open(const char *path, int fmode, int cmode, int flags, vnode_t *vpp, vfs_context_t ctx);
1846
1847/*
1848 * exported vnode operations
1849 */
1850
1851/*!
1852 @function vnode_iterate
1853 @abstract Perform an operation on (almost) all vnodes from a given mountpoint.
1854 @param mp Mount whose vnodes to operate on.
1855 @param flags
1856 VNODE_RELOAD Mark inactive vnodes for recycle.
1857 VNODE_WAIT
1858 VNODE_WRITEABLE Only examine vnodes with writes in progress.
1859 VNODE_WITHID No effect.
1860 VNODE_NOLOCK_INTERNAL No effect.
1861 VNODE_NODEAD No effect.
1862 VNODE_NOSUSPEND No effect.
1863 VNODE_ITERATE_ALL No effect.
1864 VNODE_ITERATE_ACTIVE No effect.
1865 VNODE_ITERATE_INACTIVE No effect.
1866
1867 @param callout Function to call on each vnode.
1868 @param arg Argument which will be passed to callout along with each vnode.
1869 @return Zero for success, else an error code. Will return 0 immediately if there are no vnodes hooked into the mount.
1870 @discussion Skips vnodes which are dead, in the process of reclaim, suspended, or of type VNON.
1871 */
1872int vnode_iterate(struct mount *mp, int flags, int (*callout)(struct vnode *, void *), void *arg);
1873
1874/*
1875 * flags passed into vnode_iterate
1876 */
1877#define VNODE_RELOAD 0x01
1878#define VNODE_WAIT 0x02
1879#define VNODE_WRITEABLE 0x04
1880#define VNODE_WITHID 0x08
1881#define VNODE_NOLOCK_INTERNAL 0x10
1882#define VNODE_NODEAD 0x20
1883#define VNODE_NOSUSPEND 0x40
1884#define VNODE_ITERATE_ALL 0x80
1885#define VNODE_ITERATE_ACTIVE 0x100
1886#define VNODE_ITERATE_INACTIVE 0x200
1887#ifdef BSD_KERNEL_PRIVATE
1888#define VNODE_ALWAYS 0x400
1889#define VNODE_DRAINO 0x800
1890#endif /* BSD_KERNEL_PRIVATE */
1891
1892/*
1893 * return values from callback
1894 */
1895#define VNODE_RETURNED 0 /* done with vnode, reference can be dropped */
1896#define VNODE_RETURNED_DONE 1 /* done with vnode, reference can be dropped, terminate iteration */
1897#define VNODE_CLAIMED 2 /* don't drop reference */
1898#define VNODE_CLAIMED_DONE 3 /* don't drop reference, terminate iteration */
1899
1900/*!
1901 @function vn_revoke
1902 @abstract Invalidate all references to a vnode.
1903 @discussion Reclaims the vnode, giving it deadfs vnops (though not halting operations which are already in progress).
1904 Also reclaims all aliased vnodes (important for devices). People holding usecounts on the vnode, e.g. processes
1905 with the file open, will find that all subsequent operations but closing the file fail.
1906 @param vp The vnode to revoke.
1907 @param flags Unused.
1908 @param ctx Context against which to validate operation.
1909 @return 0 always.
1910 */
1911int vn_revoke(vnode_t vp, int flags, vfs_context_t ctx);
1912
1913/* namecache function prototypes */
1914/*!
1915 @function cache_lookup
1916 @abstract Check for a filename in a directory using the VFS name cache.
1917 @discussion cache_lookup() will flush negative cache entries and return 0 if the operation of the cn_nameiop is CREATE or RENAME.
1918 Often used from the filesystem during a lookup vnop. The filesystem will be called to if there is a negative cache entry for a file,
1919 so it can make sense to initially check for negative entries (and possibly lush them).
1920 @param dvp Directory in which lookup is occurring.
1921 @param vpp Destination for vnode pointer.
1922 @param cnp Various data about lookup, e.g. filename and intended operation.
1923 @return ENOENT: the filesystem has previously added a negative entry with cache_enter() to indicate that there is no
1924 file of the given name in "dp." -1: successfully found a cached vnode (vpp is set). 0: No data in the cache, or operation is CRETE/RENAME.
1925 */
1926int cache_lookup(vnode_t dvp, vnode_t *vpp, struct componentname *cnp);
1927
1928/*!
1929 @function cache_enter
1930 @abstract Add a (name,vnode) entry to the VFS namecache.
1931 @discussion Generally used to add a cache entry after a successful filesystem-level lookup or to add a
1932 negative entry after one which did not find its target.
1933 @param dvp Directory in which file lives.
1934 @param vp File to add to cache. A non-NULL vp is stored for rapid access; a NULL vp indicates
1935 that there is no such file in the directory and speeds future failed lookups.
1936 @param cnp Various data about lookup, e.g. filename and intended operation.
1937 */
1938void cache_enter(vnode_t dvp, vnode_t vp, struct componentname *cnp);
1939
1940/*!
1941 @function cache_purge
1942 @abstract Remove all data relating to a vnode from the namecache.
1943 @discussion Will flush all hardlinks to the vnode as well as all children (should any exist). Logical
1944 to use when cached data about a vnode becomes invalid, for instance in an unlink.
1945 @param vp The vnode to purge.
1946 */
1947void cache_purge(vnode_t vp);
1948
1949/*!
1950 @function cache_purge_negatives
1951 @abstract Remove all negative cache entries which are children of a given vnode.
1952 @discussion Appropriate to use when negative cache information for a directory could have
1953 become invalid, e.g. after file creation.
1954 @param vp The vnode whose negative children to purge.
1955 */
1956void cache_purge_negatives(vnode_t vp);
1957
1958
1959/*
1960 * Global string-cache routines. You can pass zero for nc_hash
1961 * if you don't know it (add_name() will then compute the hash).
1962 * There are no flags for now but maybe someday.
1963 */
1964/*!
1965 @function vfs_addname
1966 @abstract Deprecated
1967 @discussion vnode_update_identity() and vnode_create() make vfs_addname() unnecessary for kexts.
1968 */
1969const char *vfs_addname(const char *name, uint32_t len, uint32_t nc_hash, uint32_t flags);
1970
1971/*!
1972 @function vfs_removename
1973 @abstract Deprecated
1974 @discussion vnode_update_identity() and vnode_create() make vfs_addname() unnecessary for kexts.
1975 */
1976int vfs_removename(const char *name);
1977
1978/*!
1979 @function vcount
1980 @abstract Count total references to a given file, disregarding "kusecount" (event listener, as with O_EVTONLY) references.
1981 @discussion For a regular file, just return (usecount-kusecount); for device files, return the sum over all
1982 vnodes 'v' which reference that device of (usecount(v) - kusecount(v)). Note that this is merely a snapshot and could be
1983 invalid by the time the caller checks the result.
1984 @param vp The vnode whose references to count.
1985 @return Count of references.
1986 */
1987int vcount(vnode_t vp);
1988
1989/*!
1990 @function vn_path_package_check
1991 @abstract Figure out if a path corresponds to a Mac OS X package.
1992 @discussion Determines if the extension on a path is a known OS X extension type.
1993 @param vp Unused.
1994 @param path Path to check.
1995 @param pathlen Size of path buffer.
1996 @param component Set to index of start of last path component if the path is found to be a package. Set to -1 if
1997 the path is not a known package type.
1998 @return 0 unless some parameter was invalid, in which case EINVAL is returned. Determine package-ness by checking
1999 what *component is set to.
2000 */
2001int vn_path_package_check(vnode_t vp, char *path, int pathlen, int *component);
2002
2003#ifdef KERNEL_PRIVATE
2004/*!
2005 @function vn_searchfs_inappropriate_name
2006 @abstract Figure out if the component is inappropriate for a SearchFS query.
2007 @param name component to check
2008 @param len length of component.
2009 @return 0 if no match, 1 if inappropriate.
2010 */
2011int vn_searchfs_inappropriate_name(const char *name, int len);
2012#endif
2013
2014/*!
2015 @function vn_rdwr
2016 @abstract Read from or write to a file.
2017 @discussion vn_rdwr() abstracts the details of constructing a uio and picking a vnode operation to allow
2018 simple in-kernel file I/O.
2019 @param rw UIO_READ for a read, UIO_WRITE for a write.
2020 @param vp The vnode on which to perform I/O.
2021 @param base Start of buffer into which to read or from which to write data.
2022 @param len Length of buffer.
2023 @param offset Offset within the file at which to start I/O.
2024 @param segflg What kind of address "base" is. See uio_seg definition in sys/uio.h. UIO_SYSSPACE for kernelspace, UIO_USERSPACE for userspace.
2025 UIO_USERSPACE32 and UIO_USERSPACE64 are in general preferred, but vn_rdwr will make sure that has the correct address sizes.
2026 @param ioflg Defined in vnode.h, e.g. IO_NOAUTH, IO_NOCACHE.
2027 @param cred Credential to pass down to filesystem for authentication.
2028 @param aresid Destination for amount of requested I/O which was not completed, as with uio_resid().
2029 @param p Process requesting I/O.
2030 @return 0 for success; errors from filesystem, and EIO if did not perform all requested I/O and the "aresid" parameter is NULL.
2031 */
2032int vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, int len, off_t offset, enum uio_seg segflg, int ioflg, kauth_cred_t cred, int *aresid, proc_t p);
2033
2034/*!
2035 @function vnode_getname
2036 @abstract Get the name of a vnode from the VFS namecache.
2037 @discussion Not all vnodes have names, and vnode names can change (notably, hardlinks). Use this routine at your own risk.
2038 The string is returned with a refcount incremented in the cache; callers must call vnode_putname() to release that reference.
2039 @param vp The vnode whose name to grab.
2040 @return The name, or NULL if unavailable.
2041 */
2042const char *vnode_getname(vnode_t vp);
2043
2044/*!
2045 @function vnode_putname
2046 @abstract Release a reference on a name from the VFS cache.
2047 @discussion Should be called on a string obtained with vnode_getname().
2048 @param name String to release.
2049 */
2050void vnode_putname(const char *name);
2051
2052/*!
2053 @function vnode_getparent
2054 @abstract Get an iocount on the parent of a vnode.
2055 @discussion A vnode's parent may change over time or be reclaimed, so vnode_getparent() may return different
2056 results at different times (e.g. a multiple-hardlink file). The parent is returned with an iocount which must
2057 subsequently be dropped with vnode_put().
2058 @param vp The vnode whose parent to grab.
2059 @return Parent if available, else NULL.
2060 */
2061vnode_t vnode_getparent(vnode_t vp);
2062
2063/*!
2064 @function vnode_setdirty
2065 @abstract Mark the vnode as having data or metadata that needs to be written out during reclaim
2066 @discussion The vnode should be marked as dirty anytime a file system defers flushing of data or meta-data associated with it.
2067 @param vp the vnode to mark as dirty
2068 @return 0 if successful else an error code.
2069 */
2070int vnode_setdirty(vnode_t vp);
2071
2072/*!
2073 @function vnode_cleardirty
2074 @abstract Mark the vnode as clean i.e. all its data or metadata has been flushed
2075 @discussion The vnode should be marked as clean whenever the file system is done flushing data or meta-data associated with it.
2076 @param vp the vnode to clear as being dirty
2077 @return 0 if successful else an error code.
2078 */
2079int vnode_cleardirty(vnode_t vp);
2080
2081/*!
2082 @function vnode_isdirty
2083 @abstract Determine if a vnode is marked dirty.
2084 @discussion The vnode should be marked as clean whenever the file system is done flushing data or meta-data associated with it.
2085 @param vp the vnode to test.
2086 @return Non-zero if the vnode is dirty, 0 otherwise.
2087 */
2088int vnode_isdirty(vnode_t vp);
2089
2090#ifdef KERNEL_PRIVATE
2091/*!
2092 @function vnode_lookup_continue_needed
2093 @abstract Determine whether vnode needs additional processing in VFS before being opened.
2094 @discussion If result is zero, filesystem can open this vnode. If result is nonzero,
2095 additional processing is needed in VFS (e.g. symlink, mountpoint). Nonzero results should
2096 be passed up to VFS.
2097 @param vp Vnode to consider opening (found by filesystem).
2098 @param cnp Componentname as passed to filesystem from VFS.
2099 @result 0 to indicate that a vnode can be opened, or an error that should be passed up to VFS.
2100 */
2101int vnode_lookup_continue_needed(vnode_t vp, struct componentname *cnp);
2102
2103/*!
2104 @function vnode_istty
2105 @abstract Determine if the given vnode represents a tty device.
2106 @param vp Vnode to examine.
2107 @result Non-zero to indicate that the vnode represents a tty device. Zero otherwise.
2108 */
2109int vnode_istty(vnode_t vp);
2110
2111/*!
2112 @function bdevvp
2113 @abstract create a vnode for a given dev_t
2114 @result non-zero to indicate failure, vnode provided in *vpp arg
2115 */
2116int bdevvp (dev_t dev, struct vnode **vpp);
2117
2118/*
2119 @function vnode_getfromfd
2120 @abstract get a vnode from a file descriptor
2121 @result non-zero to indicate failure, vnode provided in *vpp arg
2122 */
2123int vnode_getfromfd (vfs_context_t ctx, int fd, vnode_t *vpp);
2124
2125#endif /* KERNEL_PRIVATE */
2126
2127#ifdef BSD_KERNEL_PRIVATE
2128/* Not in export list so can be private */
2129struct stat;
2130int vn_stat(struct vnode *vp, void * sb, kauth_filesec_t *xsec, int isstat64,
2131 vfs_context_t ctx);
2132int vn_stat_noauth(struct vnode *vp, void * sb, kauth_filesec_t *xsec, int isstat64,
2133 vfs_context_t ctx, struct ucred *file_cred);
2134int vaccess(mode_t file_mode, uid_t uid, gid_t gid,
2135 mode_t acc_mode, kauth_cred_t cred);
2136int check_mountedon(dev_t dev, enum vtype type, int *errorp);
2137int vn_getcdhash(struct vnode *vp, off_t offset, unsigned char *cdhash);
2138void vnode_reclaim(vnode_t);
2139vnode_t current_rootdir(void);
2140vnode_t current_workingdir(void);
2141void *vnode_vfsfsprivate(vnode_t);
2142struct vfsstatfs *vnode_vfsstatfs(vnode_t);
2143uint32_t vnode_vfsvisflags(vnode_t);
2144uint32_t vnode_vfscmdflags(vnode_t);
2145int vnode_is_openevt(vnode_t);
2146void vnode_set_openevt(vnode_t);
2147void vnode_clear_openevt(vnode_t);
2148int vnode_isstandard(vnode_t);
2149int vnode_makeimode(int, int);
2150enum vtype vnode_iftovt(int);
2151int vnode_vttoif(enum vtype);
2152int vnode_isshadow(vnode_t);
2153boolean_t vnode_on_reliable_media(vnode_t);
2154/*
2155 * Indicate that a file has multiple hard links. VFS will always call
2156 * VNOP_LOOKUP on this vnode. Volfs will always ask for it's parent
2157 * object ID (instead of using the v_parent pointer).
2158 */
2159vnode_t vnode_parent(vnode_t);
2160void vnode_setparent(vnode_t, vnode_t);
2161void vnode_setname(vnode_t, char *);
2162/* XXX temporary until we can arrive at a KPI for NFS, Seatbelt */
2163thread_t vfs_context_thread(vfs_context_t);
2164#if CONFIG_IOSCHED
2165vnode_t vnode_mountdevvp(vnode_t);
2166#endif
2167#endif /* BSD_KERNEL_PRIVATE */
2168
2169#ifdef KERNEL_PRIVATE
2170/*!
2171 @function vnode_getname_printable
2172 @abstract Get a non-null printable name of a vnode.
2173 @Used to make sure a printable name is returned for all vnodes. If a name exists or can be artificially created, the routine creates a new entry in the VFS namecache. Otherwise, the function returns an artificially created vnode name which is safer and easier to use. vnode_putname_printable() should be used to release names obtained by this routine.
2174 @param vp The vnode whose name to grab.
2175 @return The printable name.
2176 */
2177const char *vnode_getname_printable(vnode_t vp);
2178/*!
2179 @function vnode_putname_printable
2180 @abstract Release a reference on a name from the VFS cache if it was added by the matching vnode_getname_printable() call.
2181 @param name String to release.
2182 */
2183void vnode_putname_printable(const char *name);
2184#endif // KERNEL_PRIVATE
2185
2186/*!
2187 @function vnode_getbackingvnode
2188 @abstract If the input vnode is a NULLFS mirrored vnode, then return the vnode it wraps.
2189 @Used to un-mirror files, primarily for security purposes. On success, out_vp is always set to a vp with an iocount. The caller must release the iocount.
2190 @param in_vp The vnode being asked about
2191 @param out_vpp A pointer to the output vnode, unchanged on error
2192 @return 0 on Success, ENOENT if in_vp doesn't mirror anything, EINVAL on parameter errors.
2193 */
2194int vnode_getbackingvnode(vnode_t in_vp, vnode_t* out_vpp);
2195
2196/*
2197 * Helper functions for implementing VNOP_GETATTRLISTBULK for a filesystem
2198 */
2199
2200/*!
2201 @function vfs_setup_vattr_from_attrlist
2202 @abstract Setup a vnode_attr structure given an attrlist structure.
2203 @Used by a VNOP_GETATTRLISTBULK implementation to setup a vnode_attr structure from a attribute list. It also returns the fixed size of the attribute buffer required.
2204 @warning this forces new fork attr behavior, i.e. reinterpret forkattr bits as ATTR_CMNEXT
2205 @param alp Pointer to attribute list structure.
2206 @param vap Pointer to vnode_attr structure.
2207 @param obj_vtype Type of object - If VNON is passed, then the type is ignored and common, file and dir attrs are used to initialise the vattrs. If set to VDIR, only common and directory attributes are used. For all other types, only common and file attrbutes are used.
2208 @param attr_fixed_sizep Returns the fixed length required in the attrbute buffer for the object. NULL should be passed if it is not required.
2209 @param ctx vfs context of caller.
2210 @return error.
2211 */
2212errno_t vfs_setup_vattr_from_attrlist(struct attrlist *alp, struct vnode_attr *vap, enum vtype obj_vtype, ssize_t *attr_fixed_sizep, vfs_context_t ctx);
2213
2214/*!
2215 @function vfs_attr_pack
2216 @abstract Pack a vnode_attr structure into a buffer in the same format as getattrlist(2).
2217 @Used by a VNOP_GETATTRLISTBULK implementation to pack data provided into a vnode_attr structure into a buffer the way getattrlist(2) does.
2218 @param vp If available, the vnode for which the attributes are being given, NULL if vnode is not available (which will usually be the case for a VNOP_GETATTRLISTBULK implementation.
2219 @param uio - a uio_t initialised with one iovec..
2220 @param alp - Pointer to an attrlist structure.
2221 @param options - options for call (same as options for getattrlistbulk(2)).
2222 @param vap Pointer to a filled in vnode_attr structure. Data from the vnode_attr structure will be used to copy and lay out the data in the required format for getatrlistbulk(2) by this function.
2223 @param fndesc Currently unused
2224 @param ctx vfs context of caller.
2225 @return error.
2226 */
2227errno_t vfs_attr_pack(vnode_t vp, uio_t uio, struct attrlist *alp, uint64_t options, struct vnode_attr *vap, void *fndesc, vfs_context_t ctx);
2228
2229#ifdef KERNEL_PRIVATE
2230
2231// Returns a value suitable, safe and consistent for tracing and logging
2232vm_offset_t kdebug_vnode(vnode_t vp);
2233int vn_pathconf(vnode_t, int, int32_t *, vfs_context_t);
2234int vnode_should_flush_after_write(vnode_t vp, int ioflag);
2235void vfs_setowner(mount_t mp, uid_t uid, gid_t gid);
2236uint64_t vfs_idle_time(mount_t mp);
2237// Required until XsanFS is fixed...
2238#ifndef vnode_usecount
2239int vnode_usecount(vnode_t vp);
2240#endif
2241int vnode_iocount(vnode_t vp);
2242void vnode_rele_ext(vnode_t, int, int);
2243int is_package_name(const char *name, int len);
2244int vfs_context_issuser(vfs_context_t);
2245int vfs_context_iskernel(vfs_context_t);
2246vfs_context_t vfs_context_kernel(void); /* get from 1st kernel thread */
2247vnode_t vfs_context_cwd(vfs_context_t);
2248int vnode_isnoflush(vnode_t);
2249void vnode_setnoflush(vnode_t);
2250void vnode_clearnoflush(vnode_t);
2251
2252#define BUILDPATH_NO_FS_ENTER 0x1 /* Use cache values, do not enter file system */
2253#define BUILDPATH_CHECKACCESS 0x2 /* Check if parents have search rights */
2254#define BUILDPATH_CHECK_MOVED 0x4 /* Return EAGAIN if the parent hierarchy is modified */
2255#define BUILDPATH_VOLUME_RELATIVE 0x8 /* Return path relative to the nearest mount point */
2256
2257int build_path(vnode_t first_vp, char *buff, int buflen, int *outlen, int flags, vfs_context_t ctx);
2258
2259int vnode_issubdir(vnode_t vp, vnode_t dvp, int *is_subdir, vfs_context_t ctx);
2260
2261#endif // KERNEL_PRIVATE
2262
2263__END_DECLS
2264
2265#endif /* KERNEL */
2266
2267#endif /* !_VNODE_H_ */
2268