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