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