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