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