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