1/* 2 * Copyright (c) 2000-2010 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, 1991, 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 * @(#)mount.h 8.21 (Berkeley) 5/20/95 62 */ 63/* 64 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce 65 * support for mandatory and extensible security protections. This notice 66 * is included in support of clause 2.2 (b) of the Apple Public License, 67 * Version 2.0. 68 */ 69 70 71#ifndef _SYS_MOUNT_H_ 72#define _SYS_MOUNT_H_ 73 74#include <sys/appleapiopts.h> 75#include <sys/cdefs.h> 76#include <sys/attr.h> /* needed for vol_capabilities_attr_t */ 77 78#ifndef KERNEL 79#include <stdint.h> 80#include <sys/ucred.h> 81#include <sys/queue.h> /* XXX needed for user builds */ 82#include <Availability.h> 83#else 84#include <sys/kernel_types.h> 85#include <uuid/uuid.h> 86#endif 87 88typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */ 89 90/* 91 * file system statistics 92 */ 93 94#define MFSNAMELEN 15 /* length of fs type name, not inc. null */ 95#define MFSTYPENAMELEN 16 /* length of fs type name including null */ 96 97#if __DARWIN_64_BIT_INO_T 98#define MNAMELEN MAXPATHLEN /* length of buffer for returned name */ 99#else /* ! __DARWIN_64_BIT_INO_T */ 100#define MNAMELEN 90 /* length of buffer for returned name */ 101#endif /* __DARWIN_64_BIT_INO_T */ 102 103#define __DARWIN_STRUCT_STATFS64 { \ 104 uint32_t f_bsize; /* fundamental file system block size */ \ 105 int32_t f_iosize; /* optimal transfer block size */ \ 106 uint64_t f_blocks; /* total data blocks in file system */ \ 107 uint64_t f_bfree; /* free blocks in fs */ \ 108 uint64_t f_bavail; /* free blocks avail to non-superuser */ \ 109 uint64_t f_files; /* total file nodes in file system */ \ 110 uint64_t f_ffree; /* free file nodes in fs */ \ 111 fsid_t f_fsid; /* file system id */ \ 112 uid_t f_owner; /* user that mounted the filesystem */ \ 113 uint32_t f_type; /* type of filesystem */ \ 114 uint32_t f_flags; /* copy of mount exported flags */ \ 115 uint32_t f_fssubtype; /* fs sub-type (flavor) */ \ 116 char f_fstypename[MFSTYPENAMELEN]; /* fs type name */ \ 117 char f_mntonname[MAXPATHLEN]; /* directory on which mounted */ \ 118 char f_mntfromname[MAXPATHLEN]; /* mounted filesystem */ \ 119 uint32_t f_reserved[8]; /* For future use */ \ 120} 121 122#if !__DARWIN_ONLY_64_BIT_INO_T 123 124struct statfs64 __DARWIN_STRUCT_STATFS64; 125 126#endif /* !__DARWIN_ONLY_64_BIT_INO_T */ 127 128#if __DARWIN_64_BIT_INO_T 129 130struct statfs __DARWIN_STRUCT_STATFS64; 131 132#else /* !__DARWIN_64_BIT_INO_T */ 133 134/* 135 * LP64 - WARNING - must be kept in sync with struct user_statfs in mount_internal.h. 136 */ 137struct statfs { 138 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */ 139 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */ 140 long f_bsize; /* fundamental file system block size */ 141 long f_iosize; /* optimal transfer block size */ 142 long f_blocks; /* total data blocks in file system */ 143 long f_bfree; /* free blocks in fs */ 144 long f_bavail; /* free blocks avail to non-superuser */ 145 long f_files; /* total file nodes in file system */ 146 long f_ffree; /* free file nodes in fs */ 147 fsid_t f_fsid; /* file system id */ 148 uid_t f_owner; /* user that mounted the filesystem */ 149 short f_reserved1; /* spare for later */ 150 short f_type; /* type of filesystem */ 151 long f_flags; /* copy of mount exported flags */ 152 long f_reserved2[2]; /* reserved for future use */ 153 char f_fstypename[MFSNAMELEN]; /* fs type name */ 154 char f_mntonname[MNAMELEN]; /* directory on which mounted */ 155 char f_mntfromname[MNAMELEN];/* mounted filesystem */ 156 char f_reserved3; /* For alignment */ 157 long f_reserved4[4]; /* For future use */ 158}; 159 160#endif /* __DARWIN_64_BIT_INO_T */ 161 162#pragma pack(4) 163 164struct vfsstatfs { 165 uint32_t f_bsize; /* fundamental file system block size */ 166 size_t f_iosize; /* optimal transfer block size */ 167 uint64_t f_blocks; /* total data blocks in file system */ 168 uint64_t f_bfree; /* free blocks in fs */ 169 uint64_t f_bavail; /* free blocks avail to non-superuser */ 170 uint64_t f_bused; /* free blocks avail to non-superuser */ 171 uint64_t f_files; /* total file nodes in file system */ 172 uint64_t f_ffree; /* free file nodes in fs */ 173 fsid_t f_fsid; /* file system id */ 174 uid_t f_owner; /* user that mounted the filesystem */ 175 uint64_t f_flags; /* copy of mount exported flags */ 176 char f_fstypename[MFSTYPENAMELEN];/* fs type name inclus */ 177 char f_mntonname[MAXPATHLEN];/* directory on which mounted */ 178 char f_mntfromname[MAXPATHLEN];/* mounted filesystem */ 179 uint32_t f_fssubtype; /* fs sub-type (flavor) */ 180 void *f_reserved[2]; /* For future use == 0 */ 181}; 182 183#pragma pack() 184 185#ifdef KERNEL 186/* 187 * Kernel level support for the VFS_GETATTR(), VFS_SETATTR() for use in 188 * implementation of filesystem KEXTs, and by the vfs_getattr() and 189 * vfs_setattr() KPIs. 190 */ 191 192#define VFSATTR_INIT(s) ((s)->f_supported = (s)->f_active = 0LL) 193#define VFSATTR_SET_SUPPORTED(s, a) ((s)->f_supported |= VFSATTR_ ## a) 194#define VFSATTR_IS_SUPPORTED(s, a) ((s)->f_supported & VFSATTR_ ## a) 195#define VFSATTR_CLEAR_ACTIVE(s, a) ((s)->f_active &= ~VFSATTR_ ## a) 196#define VFSATTR_IS_ACTIVE(s, a) ((s)->f_active & VFSATTR_ ## a) 197#define VFSATTR_ALL_SUPPORTED(s) (((s)->f_active & (s)->f_supported) == (s)->f_active) 198#define VFSATTR_WANTED(s, a) ((s)->f_active |= VFSATTR_ ## a) 199#define VFSATTR_RETURN(s, a, x) do { (s)-> a = (x); VFSATTR_SET_SUPPORTED(s, a);} while(0) 200 201#define VFSATTR_f_objcount (1LL<< 0) 202#define VFSATTR_f_filecount (1LL<< 1) 203#define VFSATTR_f_dircount (1LL<< 2) 204#define VFSATTR_f_maxobjcount (1LL<< 3) 205#define VFSATTR_f_bsize (1LL<< 4) 206#define VFSATTR_f_iosize (1LL<< 5) 207#define VFSATTR_f_blocks (1LL<< 6) 208#define VFSATTR_f_bfree (1LL<< 7) 209#define VFSATTR_f_bavail (1LL<< 8) 210#define VFSATTR_f_bused (1LL<< 9) 211#define VFSATTR_f_files (1LL<< 10) 212#define VFSATTR_f_ffree (1LL<< 11) 213#define VFSATTR_f_fsid (1LL<< 12) 214#define VFSATTR_f_owner (1LL<< 13) 215#define VFSATTR_f_capabilities (1LL<< 14) 216#define VFSATTR_f_attributes (1LL<< 15) 217#define VFSATTR_f_create_time (1LL<< 16) 218#define VFSATTR_f_modify_time (1LL<< 17) 219#define VFSATTR_f_access_time (1LL<< 18) 220#define VFSATTR_f_backup_time (1LL<< 19) 221#define VFSATTR_f_fssubtype (1LL<< 20) 222#define VFSATTR_f_vol_name (1LL<< 21) 223#define VFSATTR_f_signature (1LL<< 22) 224#define VFSATTR_f_carbon_fsid (1LL<< 23) 225#define VFSATTR_f_uuid (1LL<< 24) 226 227/* 228 * Argument structure. 229 */ 230#pragma pack(4) 231/* 232 * Note: the size of the vfs_attr structure can change. 233 * A kext should only reference the fields that are 234 * marked as active; it should not depend on the actual 235 * size of the structure or attempt to copy it. 236 */ 237struct vfs_attr { 238 uint64_t f_supported; 239 uint64_t f_active; 240 241 uint64_t f_objcount; /* number of filesystem objects in volume */ 242 uint64_t f_filecount; /* ... files */ 243 uint64_t f_dircount; /* ... directories */ 244 uint64_t f_maxobjcount; /* maximum number of filesystem objects */ 245 246 uint32_t f_bsize; /* block size for the below size values */ 247 size_t f_iosize; /* optimal transfer block size */ 248 uint64_t f_blocks; /* total data blocks in file system */ 249 uint64_t f_bfree; /* free blocks in fs */ 250 uint64_t f_bavail; /* free blocks avail to non-superuser */ 251 uint64_t f_bused; /* blocks in use */ 252 uint64_t f_files; /* total file nodes in file system */ 253 uint64_t f_ffree; /* free file nodes in fs */ 254 fsid_t f_fsid; /* file system id */ 255 uid_t f_owner; /* user that mounted the filesystem */ 256 257 vol_capabilities_attr_t f_capabilities; 258 vol_attributes_attr_t f_attributes; 259 260 struct timespec f_create_time; /* creation time */ 261 struct timespec f_modify_time; /* last modification time */ 262 struct timespec f_access_time; /* time of last access */ 263 struct timespec f_backup_time; /* last backup time */ 264 265 uint32_t f_fssubtype; /* filesystem subtype */ 266 267 char *f_vol_name; /* volume name */ 268 269 uint16_t f_signature; /* used for ATTR_VOL_SIGNATURE, Carbon's FSVolumeInfo.signature */ 270 uint16_t f_carbon_fsid; /* same as Carbon's FSVolumeInfo.filesystemID */ 271 uuid_t f_uuid; /* file system UUID (version 3 or 5), available in 10.6 and later */ 272}; 273 274#pragma pack() 275 276#endif /* KERNEL */ 277 278/* 279 * User specifiable flags. 280 * 281 * Unmount uses MNT_FORCE flag. 282 */ 283#define MNT_RDONLY 0x00000001 /* read only filesystem */ 284#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ 285#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ 286#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ 287#define MNT_NODEV 0x00000010 /* don't interpret special files */ 288#define MNT_UNION 0x00000020 /* union with underlying filesystem */ 289#define MNT_ASYNC 0x00000040 /* file system written asynchronously */ 290#define MNT_CPROTECT 0x00000080 /* file system supports content protection */ 291 292/* 293 * NFS export related mount flags. 294 */ 295#define MNT_EXPORTED 0x00000100 /* file system is exported */ 296 297/* 298 * MAC labeled / "quarantined" flag 299 */ 300#define MNT_QUARANTINE 0x00000400 /* file system is quarantined */ 301 302/* 303 * Flags set by internal operations. 304 */ 305#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ 306#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ 307#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ 308#define MNT_DOVOLFS 0x00008000 /* FS supports volfs (deprecated flag in Mac OS X 10.5) */ 309 310 311#define MNT_DONTBROWSE 0x00100000 /* file system is not appropriate path to user data */ 312#define MNT_IGNORE_OWNERSHIP 0x00200000 /* VFS will ignore ownership information on filesystem objects */ 313#define MNT_AUTOMOUNTED 0x00400000 /* filesystem was mounted by automounter */ 314#define MNT_JOURNALED 0x00800000 /* filesystem is journaled */ 315#define MNT_NOUSERXATTR 0x01000000 /* Don't allow user extended attributes */ 316#define MNT_DEFWRITE 0x02000000 /* filesystem should defer writes */ 317#define MNT_MULTILABEL 0x04000000 /* MAC support for individual labels */ 318#define MNT_NOATIME 0x10000000 /* disable update of file access time */ 319#ifdef BSD_KERNEL_PRIVATE 320/* #define MNT_IMGSRC_BY_INDEX 0x20000000 see sys/imgsrc.h */ 321#endif /* BSD_KERNEL_PRIVATE */ 322 323/* backwards compatibility only */ 324#define MNT_UNKNOWNPERMISSIONS MNT_IGNORE_OWNERSHIP 325 326 327/* 328 * XXX I think that this could now become (~(MNT_CMDFLAGS)) 329 * but the 'mount' program may need changing to handle this. 330 */ 331#define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \ 332 MNT_NOSUID | MNT_NODEV | MNT_UNION | \ 333 MNT_ASYNC | MNT_EXPORTED | MNT_QUARANTINE | \ 334 MNT_LOCAL | MNT_QUOTA | \ 335 MNT_ROOTFS | MNT_DOVOLFS | MNT_DONTBROWSE | \ 336 MNT_IGNORE_OWNERSHIP | MNT_AUTOMOUNTED | MNT_JOURNALED | \ 337 MNT_NOUSERXATTR | MNT_DEFWRITE | MNT_MULTILABEL | \ 338 MNT_NOATIME | MNT_CPROTECT) 339/* 340 * External filesystem command modifier flags. 341 * Unmount can use the MNT_FORCE flag. 342 * XXX These are not STATES and really should be somewhere else. 343 * External filesystem control flags. 344 */ 345#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ 346#define MNT_NOBLOCK 0x00020000 /* don't block unmount if not responding */ 347#define MNT_RELOAD 0x00040000 /* reload filesystem data */ 348#define MNT_FORCE 0x00080000 /* force unmount or readonly change */ 349#define MNT_CMDFLAGS (MNT_UPDATE|MNT_NOBLOCK|MNT_RELOAD|MNT_FORCE) 350 351 352 353/* 354 * Sysctl CTL_VFS definitions. 355 * 356 * Second level identifier specifies which filesystem. Second level 357 * identifier VFS_GENERIC returns information about all filesystems. 358 */ 359#define VFS_GENERIC 0 /* generic filesystem information */ 360#define VFS_NUMMNTOPS 1 /* int: total num of vfs mount/unmount operations */ 361/* 362 * Third level identifiers for VFS_GENERIC are given below; third 363 * level identifiers for specific filesystems are given in their 364 * mount specific header files. 365 */ 366#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ 367#define VFS_CONF 2 /* struct: vfsconf for filesystem given 368 as next argument */ 369#define VFS_SET_PACKAGE_EXTS 3 /* set package extension list */ 370 371/* 372 * Flags for various system call interfaces. 373 * 374 * waitfor flags to vfs_sync() and getfsstat() 375 */ 376#define MNT_WAIT 1 /* synchronized I/O file integrity completion */ 377#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */ 378#define MNT_DWAIT 4 /* synchronized I/O data integrity completion */ 379 380 381#ifndef KERNEL 382struct mount; 383typedef struct mount * mount_t; 384struct vnode; 385typedef struct vnode * vnode_t; 386#endif 387 388/* Reserved fields preserve binary compatibility */ 389struct vfsconf { 390 uint32_t vfc_reserved1; /* opaque */ 391 char vfc_name[MFSNAMELEN]; /* filesystem type name */ 392 int vfc_typenum; /* historic filesystem type number */ 393 int vfc_refcount; /* number mounted of this type */ 394 int vfc_flags; /* permanent flags */ 395 uint32_t vfc_reserved2; /* opaque */ 396 uint32_t vfc_reserved3; /* opaque */ 397}; 398 399struct vfsidctl { 400 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */ 401 fsid_t vc_fsid; /* fsid to operate on. */ 402 void *vc_ptr; /* pointer to data structure. */ 403 size_t vc_len; /* sizeof said structure. */ 404 u_int32_t vc_spare[12]; /* spare (must be zero). */ 405}; 406 407 408/* vfsidctl API version. */ 409#define VFS_CTL_VERS1 0x01 410 411#ifdef KERNEL 412struct user_vfsidctl { 413 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */ 414 fsid_t vc_fsid; /* fsid to operate on. */ 415 user_addr_t vc_ptr __attribute((aligned(8))); /* pointer to data structure. */ 416 user_size_t vc_len; /* sizeof said structure. */ 417 u_int32_t vc_spare[12]; /* spare (must be zero). */ 418}; 419 420struct user32_vfsidctl { 421 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */ 422 fsid_t vc_fsid; /* fsid to operate on. */ 423 user32_addr_t vc_ptr; /* pointer to data structure. */ 424 user32_size_t vc_len; /* sizeof said structure. */ 425 u_int32_t vc_spare[12]; /* spare (must be zero). */ 426}; 427 428union union_vfsidctl { /* the fields vc_vers and vc_fsid are compatible */ 429 struct user32_vfsidctl vc32; 430 struct user_vfsidctl vc64; 431}; 432 433#endif /* KERNEL */ 434 435/* 436 * New style VFS sysctls, do not reuse/conflict with the namespace for 437 * private sysctls. 438 */ 439#define VFS_CTL_STATFS 0x00010001 /* statfs */ 440#define VFS_CTL_UMOUNT 0x00010002 /* unmount */ 441#define VFS_CTL_QUERY 0x00010003 /* anything wrong? (vfsquery) */ 442#define VFS_CTL_NEWADDR 0x00010004 /* reconnect to new address */ 443#define VFS_CTL_TIMEO 0x00010005 /* set timeout for vfs notification */ 444#define VFS_CTL_NOLOCKS 0x00010006 /* disable file locking */ 445#define VFS_CTL_SADDR 0x00010007 /* get server address */ 446#define VFS_CTL_DISC 0x00010008 /* server disconnected */ 447 448struct vfsquery { 449 u_int32_t vq_flags; 450 u_int32_t vq_spare[31]; 451}; 452 453/* vfsquery flags */ 454#define VQ_NOTRESP 0x0001 /* server down */ 455#define VQ_NEEDAUTH 0x0002 /* server bad auth */ 456#define VQ_LOWDISK 0x0004 /* we're low on space */ 457#define VQ_MOUNT 0x0008 /* new filesystem arrived */ 458#define VQ_UNMOUNT 0x0010 /* filesystem has left */ 459#define VQ_DEAD 0x0020 /* filesystem is dead, needs force unmount */ 460#define VQ_ASSIST 0x0040 /* filesystem needs assistance from external program */ 461#define VQ_NOTRESPLOCK 0x0080 /* server lockd down */ 462#define VQ_UPDATE 0x0100 /* filesystem information has changed */ 463#define VQ_VERYLOWDISK 0x0200 /* file system has *very* little disk space left */ 464#define VQ_SYNCEVENT 0x0400 /* a sync just happened */ 465#define VQ_FLAG0800 0x0800 /* placeholder */ 466#define VQ_FLAG1000 0x1000 /* placeholder */ 467#define VQ_FLAG2000 0x2000 /* placeholder */ 468#define VQ_FLAG4000 0x4000 /* placeholder */ 469#define VQ_FLAG8000 0x8000 /* placeholder */ 470 471 472#ifdef KERNEL 473 474/* Structure for setting device IO parameters per mount point */ 475struct vfsioattr { 476 u_int32_t io_maxreadcnt; /* Max. byte count for read */ 477 u_int32_t io_maxwritecnt; /* Max. byte count for write */ 478 u_int32_t io_segreadcnt; /* Max. segment count for read */ 479 u_int32_t io_segwritecnt; /* Max. segment count for write */ 480 u_int32_t io_maxsegreadsize; /* Max. segment read size */ 481 u_int32_t io_maxsegwritesize; /* Max. segment write size */ 482 u_int32_t io_devblocksize; /* the underlying device block size */ 483 u_int32_t io_flags; /* flags for underlying device */ 484 void * io_reserved[2]; /* extended attribute information */ 485}; 486 487#define VFS_IOATTR_FLAGS_FUA 0x01 /* Write-through cache supported */ 488#define VFS_IOATTR_FLAGS_UNMAP 0x02 /* Unmap (trim) supported */ 489 490/* 491 * Filesystem Registration information 492 */ 493#define VFS_TBLTHREADSAFE 0x0001 494#define VFS_TBLFSNODELOCK 0x0002 495#define VFS_TBLNOTYPENUM 0x0008 496#define VFS_TBLLOCALVOL 0x0010 497#define VFS_TBL64BITREADY 0x0020 498#define VFS_TBLNATIVEXATTR 0x0040 499#define VFS_TBLDIRLINKS 0x0080 500#define VFS_TBLUNMOUNT_PREFLIGHT 0x0100 /* does a preflight check before unmounting */ 501#define VFS_TBLGENERICMNTARGS 0x0200 /* force generic mount args for local fs */ 502#define VFS_TBLREADDIR_EXTENDED 0x0400 /* fs supports VNODE_READDIR_EXTENDED */ 503#define VFS_TBLNOMACLABEL 0x1000 504#define VFS_TBLVNOP_PAGEINV2 0x2000 505#define VFS_TBLVNOP_PAGEOUTV2 0x4000 506 507 508struct vfs_fsentry { 509 struct vfsops * vfe_vfsops; /* vfs operations */ 510 int vfe_vopcnt; /* # of vnodeopv_desc being registered (reg, spec, fifo ...) */ 511 struct vnodeopv_desc ** vfe_opvdescs; /* null terminated; */ 512 int vfe_fstypenum; /* historic filesystem type number */ 513 char vfe_fsname[MFSNAMELEN]; /* filesystem type name */ 514 uint32_t vfe_flags; /* defines the FS capabilities */ 515 void * vfe_reserv[2]; /* reserved for future use; set this to zero*/ 516 }; 517 518 519 520struct vfsops { 521 /*! 522 @function vfs_mount 523 @abstract Perform filesystem-specific operations required for mounting. 524 @discussion Typical operations include setting the mount-specific data with vfs_setfsprivate(). 525 Note that if a mount call fails, the filesystem must clean up any state it has constructed, because 526 vfs-level mount code will not clean it up. 527 @param mp Mount structure for the newly mounted filesystem. 528 @param devvp Device that the filesystem is mounted from. 529 @param data Filesystem-specific data passed down from userspace. 530 @param context Context to authenticate for mount. 531 @return 0 for success, else an error code. Once success is returned, the filesystem should be ready to go active; 532 VFS will not ask again. 533 */ 534 int (*vfs_mount)(struct mount *mp, vnode_t devvp, user_addr_t data, vfs_context_t context); 535 536 /*! 537 @function vfs_start 538 @abstract Mark a mount as ready to be used. 539 @discussion After receiving this calldown, a filesystem will be hooked into the mount list and should expect 540 calls down from the VFS layer. 541 @param mp Mount structure being activated. 542 @param flags Unused. 543 @param context Context to authenticate for mount. 544 @return Return value is ignored. 545 */ 546 int (*vfs_start)(struct mount *mp, int flags, vfs_context_t context); 547 548 /*! 549 @function vfs_unmount 550 @abstract Perform filesystem-specific cleanup as part of unmount. 551 @discussion If the unmount downcall succeeds, VFS considers itself authorized to destroy all 552 state related to the mount. 553 @param mp Mount structure to unmount. 554 @param mntflags MNT_FORCE indicates that we wish to unmount even if there are active vnodes. 555 @param context Context to authenticate for unmount. 556 @return 0 for success, else an error code. 557 */ 558 int (*vfs_unmount)(struct mount *mp, int mntflags, vfs_context_t context); 559 560 /*! 561 @function vfs_root 562 @abstract Get the root vnode of a filesystem. 563 @discussion Upon success, should return with an iocount held on the root vnode which the caller will 564 drop with vnode_put(). 565 @param mp Mount for which to get the root. 566 @param vpp Destination for root vnode. 567 @param context Context to authenticate for getting the root. 568 @return 0 for success, else an error code. 569 */ 570 int (*vfs_root)(struct mount *mp, struct vnode **vpp, vfs_context_t context); 571 572 /*! 573 @function vfs_quotactl 574 @abstract Manipulate quotas for a volume. 575 @param mp Mount for which to manipulate quotas. 576 @param cmds Detailed in "quotactl" manual page. 577 @param uid Detailed in "quotactl" manual page. 578 @param arg Detailed in "quotactl" manual page. 579 @param context Context to authenticate for changing quotas. 580 @return 0 for success, else an error code. 581 */ 582 int (*vfs_quotactl)(struct mount *mp, int cmds, uid_t uid, caddr_t arg, vfs_context_t context); 583 584 /*! 585 @function vfs_getattr 586 @abstract Get filesystem attributes. 587 @discussion See VFSATTR_RETURN, VFSATTR_ACTIVE, VFSATTR_SET_SUPPORTED, VFSATTR_WANTED macros. 588 @param mp Mount for which to get parameters. 589 @param vfa Container for specifying which attributes are desired and which attributes the filesystem 590 supports, as well as for returning results. 591 @param ctx Context to authenticate for getting filesystem attributes. 592 @return 0 for success, else an error code. 593 */ 594 int (*vfs_getattr)(struct mount *mp, struct vfs_attr *, vfs_context_t context); 595/* int (*vfs_statfs)(struct mount *mp, struct vfsstatfs *sbp, vfs_context_t context);*/ 596 597 /*! 598 @function vfs_sync 599 @abstract Flush all filesystem data to backing store. 600 @discussion vfs_sync will be called as part of the sync() system call and during unmount. 601 @param mp Mountpoint to sync. 602 @param waitfor MNT_WAIT: flush synchronously, waiting for all data to be written before returning. MNT_NOWAIT: start I/O but do not wait for it. 603 @param ctx Context to authenticate for the sync. 604 @return 0 for success, else an error code. 605 */ 606 int (*vfs_sync)(struct mount *mp, int waitfor, vfs_context_t context); 607 608 /*! 609 @function vfs_vget 610 @abstract Get a vnode by file id (inode number). 611 @discussion This routine is chiefly used to build paths to vnodes. Result should be turned with an iocount that the 612 caller will drop with vnode_put(). 613 @param mp Mount against which to look up inode number. 614 @param ino File ID for desired file, as found through a readdir. 615 @param vpp Destination for vnode. 616 @return 0 for success, else an error code. 617 */ 618 int (*vfs_vget)(struct mount *mp, ino64_t ino, struct vnode **vpp, vfs_context_t context); 619 620 /*! 621 @function vfs_fhtovp 622 @abstract Get the vnode corresponding to a file handle. 623 @discussion Filesystems can return handles to files which are independent of their (transient) vnode identities. 624 vfs_thtovp converts that persistent handle back to a vnode. The vnode should be returned with an iocount which 625 the caller will drop with vnode_put(). 626 @param mp Mount against which to look up file handle. 627 @param fhlen Size of file handle structure, as returned by vfs_vptofh. 628 @param fhp Pointer to handle. 629 @param vpp Destination for vnode. 630 @param ctx Context against which to authenticate the file-handle conversion. 631 @return 0 for success, else an error code. 632 */ 633 int (*vfs_fhtovp)(struct mount *mp, int fhlen, unsigned char *fhp, struct vnode **vpp, 634 vfs_context_t context); 635 636 /*! 637 @function vfs_vptofh 638 @abstract Get a persistent handle corresponding to a vnode. 639 @param mp Mount against which to convert the vnode to a handle. 640 @param fhlen Size of buffer provided for handle; set to size of actual handle returned. 641 @param fhp Pointer to buffer in which to place handle data. 642 @param ctx Context against which to authenticate the file-handle request. 643 @return 0 for success, else an error code. 644 */ 645 int (*vfs_vptofh)(struct vnode *vp, int *fhlen, unsigned char *fhp, vfs_context_t context); 646 647 /*! 648 @function vfs_init 649 @abstract Prepare a filesystem for having instances mounted. 650 @discussion This routine is called once, before any particular instance of a filesystem 651 is mounted; it allows the filesystem to initialize whatever global data structures 652 are shared across all mounts. If this returns successfully, a filesystem should be ready to have 653 instances mounted. 654 @param vfsconf Configuration information. Currently, the only useful data are the filesystem name, 655 typenum, and flags. The flags field will be either 0 or MNT_LOCAL. Many filesystems ignore this 656 parameter. 657 @return 0 for success, else an error code. 658 */ 659 int (*vfs_init)(struct vfsconf *); 660 661 /*! 662 @function vfs_sysctl 663 @abstract Broad interface for querying and controlling filesystem. 664 @discussion VFS defines VFS_CTL_QUERY as a generic status request which is answered 665 with the VQ_* macros in a "struct vfsquery." 666 A filesystem may also define implementation-specific commands. See "man 3 sysctl" 667 for the meaning of sysctl parameters. 668 @param context Context against which to authenticate command. 669 @return 0 for success, else an error code. 670 */ 671 int (*vfs_sysctl)(int *, u_int, user_addr_t, size_t *, user_addr_t, size_t, vfs_context_t context); 672 673 /*! 674 @function vfs_setattr 675 @abstract Set filesystem attributes. 676 @discussion The other side of the vfs_getattr coin. Currently only called to set volume name. 677 @param mp Mount on which to set attributes. 678 @param vfa VFS attribute structure containing requested attributes to set and their values. Currently 679 will only be called with f_vol_name set. 680 @param context Context against which to authenticate attribute change. 681 @return 0 for success, else an error code. 682 */ 683 int (*vfs_setattr)(struct mount *mp, struct vfs_attr *, vfs_context_t context); 684 void *vfs_reserved[7]; 685}; 686 687 688/* 689 * flags passed into vfs_iterate 690 */ 691#ifdef PRIVATE 692#define VFS_ITERATE_TAIL_FIRST (1 << 0) 693#endif /* PRIVATE */ 694 695/* 696 * return values from callback 697 */ 698#define VFS_RETURNED 0 /* done with vnode, reference can be dropped */ 699#define VFS_RETURNED_DONE 1 /* done with vnode, reference can be dropped, terminate iteration */ 700#define VFS_CLAIMED 2 /* don't drop reference */ 701#define VFS_CLAIMED_DONE 3 /* don't drop reference, terminate iteration */ 702 703 704__BEGIN_DECLS 705#ifdef BSD_KERNEL_PRIVATE 706extern int VFS_MOUNT(mount_t, vnode_t, user_addr_t, vfs_context_t); 707extern int VFS_START(mount_t, int, vfs_context_t); 708extern int VFS_UNMOUNT(mount_t, int, vfs_context_t); 709extern int VFS_ROOT(mount_t, vnode_t *, vfs_context_t); 710extern int VFS_QUOTACTL(mount_t, int, uid_t, caddr_t, vfs_context_t); 711extern int VFS_GETATTR(mount_t, struct vfs_attr *, vfs_context_t); 712extern int VFS_SETATTR(mount_t, struct vfs_attr *, vfs_context_t); 713extern int VFS_SYNC(mount_t, int, vfs_context_t); 714extern int VFS_VGET(mount_t, ino64_t, vnode_t *, vfs_context_t); 715extern int VFS_FHTOVP(mount_t, int, unsigned char *, vnode_t *, vfs_context_t); 716extern int VFS_VPTOFH(vnode_t, int *, unsigned char *, vfs_context_t); 717#endif /* BSD_KERNEL_PRIVATE */ 718/* 719 * prototypes for exported VFS operations 720 */ 721 722/*! 723 @function vfs_fsadd 724 @abstract Register a filesystem with VFS. 725 @discussion Typically called by a filesystem Kernel Extension when it is loaded. 726 @param vfe Filesystem information: table of vfs operations, list of vnode operation tables, 727 filesystem type number (can be omitted with VFS_TBLNOTYPENUM flag), name, flags. 728 @param handle Opaque handle which will be passed to vfs_fsremove. 729 @return 0 for success, else an error code. 730 */ 731int vfs_fsadd(struct vfs_fsentry *, vfstable_t *); 732 733/*! 734 @function vfs_fsremove 735 @abstract Unregister a filesystem with VFS. 736 @discussion Typically called by a filesystem Kernel Extension when it is unloaded. 737 @param handle Handle which was returned by vfs_fsadd. 738 @return 0 for success, else an error code. 739 */ 740int vfs_fsremove(vfstable_t); 741 742/*! 743 @function vfs_iterate 744 @abstract Iterate over all mountpoints with a callback. Used, for example, by sync(). 745 @param flags Unused. 746 @param callback Function which takes a mount and arbitrary passed-in "arg," and returns one of VFS_RETURNED_DONE or VFS_CLAIMED_DONE: end 747 iteration and return success. VFS_RETURNED or VFS_CLAIMED: continue iterating. Anything else: continue iterating. 748 @param arg Arbitrary data to pass to callback. 749 @return 0 for success, else an error code. 750 */ 751int vfs_iterate(int, int (*)(struct mount *, void *), void *); 752 753/*! 754 @function vfs_init_io_attributes 755 @abstract Set I/O attributes on a mountpoint based on device properties. 756 @param devvp Block device vnode from which a filesystem is being mounted. 757 @param mp Mountpoint whose I/O parameters to initialize. 758 @return 0 for success, else an error code. 759 */ 760int vfs_init_io_attributes(vnode_t, mount_t); 761 762/*! 763 @function vfs_flags 764 @abstract Retrieve mount flags. 765 @discussion Results will be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS. 766 @param mp Mount whose flags to grab. 767 @return Flags. 768 */ 769uint64_t vfs_flags(mount_t); 770 771/*! 772 @function vfs_setflags 773 @abstract Set flags on a mount. 774 @discussion Sets mount flags to the bitwise "OR" of their current value and the specified bits. Often 775 used by a filesystem as part of the mount process. 776 @param mp Mount whose flags to set. 777 @param flags Flags to activate. Must be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS. 778 @return Flags. 779 */ 780void vfs_setflags(mount_t, uint64_t); 781 782/*! 783 @function vfs_clearflags 784 @abstract Clear flags on a mount. 785 @discussion Sets mount flags to the bitwise "AND" of their current value and the complement of the specified bits. 786 @param mp Mount whose flags to set. 787 @param flags Flags to deactivate. Must be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS. 788 @return void. 789 */ 790void vfs_clearflags(mount_t, uint64_t); 791 792/*! 793 @function vfs_issynchronous 794 @abstract Determine if writes to a filesystem occur synchronously. 795 @param mp Mount to test. 796 @return Nonzero if writes occur synchronously, else 0. 797 */ 798int vfs_issynchronous(mount_t); 799 800/*! 801 @function vfs_iswriteupgrade 802 @abstract Determine if a filesystem is mounted read-only but a request has been made to upgrade 803 to read-write. 804 @param mp Mount to test. 805 @return Nonzero if a request has been made to update from read-only to read-write, else 0. 806 */ 807int vfs_iswriteupgrade(mount_t); 808 809/*! 810 @function vfs_isupdate 811 @abstract Determine if a mount update is in progress. 812 @param mp Mount to test. 813 @return Nonzero if a mount update is in progress, 0 otherwise. 814 */ 815int vfs_isupdate(mount_t); 816 817/*! 818 @function vfs_isreload 819 @abstract Determine if a reload of filesystem data is in progress. This can only be the case 820 for a read-only filesystem; all data is brought in from secondary storage. 821 @param mp Mount to test. 822 @return Nonzero if a request has been made to reload data, else 0. 823 */ 824int vfs_isreload(mount_t); 825 826/*! 827 @function vfs_isforce 828 @abstract Determine if a forced unmount is in progress. 829 @discussion A forced unmount invalidates open files. 830 @param mp Mount to test. 831 @return Nonzero if a request has been made to forcibly unmount, else 0. 832 */ 833int vfs_isforce(mount_t); 834 835/*! 836 @function vfs_isunmount 837 @abstract Determine if an unmount is in progress. 838 @discussion This is an unsynchronized snapshot of the mount state. It should only be called 839 if the mount is known to be valid, e.g. there are known to be live files on that volume. 840 @param mp Mount to test. 841 @return Nonzero if an unmount is in progress, else zero. 842 */ 843int vfs_isunmount(mount_t mp); 844 845/*! 846 @function vfs_isrdonly 847 @abstract Determine if a filesystem is mounted read-only. 848 @param mp Mount to test. 849 @return Nonzero if filesystem is mounted read-only, else 0. 850 */ 851int vfs_isrdonly(mount_t); 852 853/*! 854 @function vfs_isrdwr 855 @abstract Determine if a filesystem is mounted with writes enabled. 856 @param mp Mount to test. 857 @return Nonzero if filesystem is mounted read-write, else 0. 858 */ 859int vfs_isrdwr(mount_t); 860 861/*! 862 @function vfs_authopaque 863 @abstract Determine if a filesystem's authorization decisions occur remotely. 864 @param mp Mount to test. 865 @return Nonzero if filesystem authorization is controlled remotely, else 0. 866 */ 867int vfs_authopaque(mount_t); 868 869/*! 870 @function vfs_authopaqueaccess 871 @abstract Check if a filesystem is marked as having reliable remote VNOP_ACCESS support. 872 @param mp Mount to test. 873 @return Nonzero if VNOP_ACCESS is supported remotely, else 0. 874 */ 875int vfs_authopaqueaccess(mount_t); 876 877/*! 878 @function vfs_setauthopaque 879 @abstract Mark a filesystem as having authorization decisions controlled remotely. 880 @param mp Mount to mark. 881 @return void. 882 */ 883void vfs_setauthopaque(mount_t); 884 885/*! 886 @function vfs_setauthopaqueaccess 887 @abstract Mark a filesystem as having remote VNOP_ACCESS support. 888 @param mp Mount to mark. 889 @return void. 890 */ 891void vfs_setauthopaqueaccess(mount_t); 892 893/*! 894 @function vfs_clearauthopaque 895 @abstract Mark a filesystem as not having remote authorization decisions. 896 @param mp Mount to mark. 897 @return void. 898 */ 899void vfs_clearauthopaque(mount_t); 900 901/*! 902 @function vfs_clearauthopaque 903 @abstract Mark a filesystem as not having remote VNOP_ACCESS support. 904 @param mp Mount to mark. 905 @return void. 906 */ 907void vfs_clearauthopaqueaccess(mount_t); 908 909/*! 910 @function vfs_setextendedsecurity 911 @abstract Mark a filesystem as supporting security controls beyond POSIX permissions. 912 @discussion Specific controls include ACLs, file owner UUIDs, and group UUIDs. 913 @param mp Mount to test. 914 @return void. 915 */ 916void vfs_setextendedsecurity(mount_t); 917 918/*! 919 @function vfs_clearextendedsecurity 920 @abstract Mark a filesystem as NOT supporting security controls beyond POSIX permissions. 921 @discussion Specific controls include ACLs, file owner UUIDs, and group UUIDs. 922 @param mp Mount to test. 923 @return void. 924 */ 925void vfs_clearextendedsecurity(mount_t); 926 927/*! 928 @function vfs_setlocklocal 929 @abstract Mark a filesystem as using VFS-level advisory locking support. 930 @discussion Advisory locking operations will not call down to the filesystem if this flag is set. 931 @param mp Mount to mark. 932 @return void. 933 */ 934void vfs_setlocklocal(mount_t); 935 936/*! 937 @function vfs_authcache_ttl 938 @abstract Determine the time-to-live of cached authorized credentials for files in this filesystem. 939 @discussion If a filesystem is set to allow caching credentials, the VFS layer can authorize 940 previously-authorized actions from the same vfs_context_t without calling down to the filesystem (though 941 it will not deny based on the cache). 942 @param mp Mount for which to check cache lifetime. 943 @return Cache lifetime in seconds. CACHED_RIGHT_INFINITE_TTL indicates that credentials never expire. 944 */ 945int vfs_authcache_ttl(mount_t); 946 947/*! 948 @function vfs_setauthcache_ttl 949 @abstract Enable credential caching and set time-to-live of cached authorized credentials for files in this filesystem. 950 @discussion If a filesystem is set to allow caching credentials, the VFS layer can authorize 951 previously-authorized actions from the same vfs_context_t without calling down to the filesystem (though 952 it will not deny based on the cache). 953 @param mp Mount for which to set cache lifetime. 954 @return void. 955 */ 956void vfs_setauthcache_ttl(mount_t, int); 957 958/*! 959 @function vfs_clearauthcache_ttl 960 @abstract Remove time-to-live controls for cached credentials on a filesytem. Filesystems with remote authorization 961 decisions (opaque) will still have KAUTH_VNODE_SEARCH rights cached for a default of CACHED_LOOKUP_RIGHT_TTL seconds. 962 @param mp Mount for which to clear cache lifetime. 963 @return void. 964 */ 965void vfs_clearauthcache_ttl(mount_t); 966 967/* 968 * return value from vfs_cachedrights_ttl if 969 * neither MNTK_AUTH_OPAQUE | MNTK_AUTH_CACHE_TTL 970 * is set in mnt_kern_flag.. it indicates 971 * that no TTL is being applied to the vnode rights cache 972 */ 973#define CACHED_RIGHT_INFINITE_TTL ~0 974 975/*! 976 @function vfs_maxsymlen 977 @abstract Get the maximum length of a symbolic link on a filesystem. 978 @param mp Mount from which to get symlink length cap. 979 @return Max symlink length. 980 */ 981uint32_t vfs_maxsymlen(mount_t); 982 983/*! 984 @function vfs_setmaxsymlen 985 @abstract Set the maximum length of a symbolic link on a filesystem. 986 @param mp Mount on which to set symlink length cap. 987 @param symlen Length to set. 988 @return Max symlink length. 989 */ 990void vfs_setmaxsymlen(mount_t, uint32_t); 991 992/*! 993 @function vfs_fsprivate 994 @abstract Get filesystem-private mount data. 995 @discussion A filesystem generally has an internal mount structure which it attaches to the VFS-level mount structure 996 as part of the mounting process. 997 @param mp Mount for which to get private data. 998 @return Private data. 999 */ 1000void * vfs_fsprivate(mount_t); 1001 1002/*! 1003 @function vfs_setfsprivate 1004 @abstract Set filesystem-private mount data. 1005 @discussion A filesystem generally has an internal mount structure which it attaches to the VFS-level mount structure 1006 as part of the mounting process. 1007 @param mp Mount for which to set private data. 1008 @return Void. 1009 */ 1010void vfs_setfsprivate(mount_t, void *mntdata); 1011 1012/*! 1013 @function vfs_statfs 1014 @abstract Get information about filesystem status. 1015 @discussion Each filesystem has a struct vfsstatfs associated with it which is updated as events occur; this function 1016 returns a pointer to it. Note that the data in the structure will continue to change over time and also that it may 1017 be quite stale of vfs_update_vfsstat has not been called recently. 1018 @param mp Mount for which to get vfsstatfs pointer. 1019 @return Pointer to vfsstatfs. 1020 */ 1021struct vfsstatfs * vfs_statfs(mount_t); 1022#define VFS_USER_EVENT 0 1023#define VFS_KERNEL_EVENT 1 1024 1025/*! 1026 @function vfs_update_vfsstat 1027 @abstract Update cached filesystem status information in the VFS mount structure. 1028 @discussion Each filesystem has a struct vfsstatfs associated with it which is updated as events occur; this function 1029 updates it so that the structure pointer returned by vfs_statfs() returns a pointer to fairly recent data. 1030 @param mp Mount for which to update cached status information. 1031 @param ctx Context to authenticate against for call down to filesystem. 1032 @param eventtype VFS_USER_EVENT: need for update is driven by user-level request; perform additional authentication. 1033 VFS_KERNEL_EVENT: need for update is driven by in-kernel events. Skip extra authentication. 1034 @return 0 for success, or an error code for authentication failure or problem with call to filesystem to 1035 request information. 1036 */ 1037int vfs_update_vfsstat(mount_t, vfs_context_t, int eventtype); 1038 1039/*! 1040 @function vfs_typenum 1041 @abstract Get (archaic) filesystem type number. 1042 @discussion Filesystem type numbers are an old construct; most filesystems just get a number assigned based on 1043 the order in which they are registered with the system. 1044 @param mp Mount for which to get type number. 1045 @return Type number. 1046 */ 1047int vfs_typenum(mount_t); 1048 1049/*! 1050 @function vfs_name 1051 @abstract Copy filesystem name into a buffer. 1052 @discussion Get filesystem name; this refers to the filesystem type of which a mount is an instantiation, 1053 rather than a name specific to the mountpoint. 1054 @param mp Mount for which to get name. 1055 @param buffer Destination for name; length should be at least MFSNAMELEN. 1056 @return void. 1057 */ 1058void vfs_name(mount_t, char *); 1059 1060/*! 1061 @function vfs_devblocksize 1062 @abstract Get the block size of the device underlying a mount. 1063 @param mp Mount for which to get block size. 1064 @return Block size. 1065 */ 1066int vfs_devblocksize(mount_t); 1067 1068/*! 1069 @function vfs_ioattr 1070 @abstract Get I/O attributes associated with a mounpoint. 1071 @param mp Mount for which to get attributes. If NULL, system defaults are filled into ioattrp. 1072 @param ioattrp Destination for results. 1073 @return void. 1074 */ 1075void vfs_ioattr(mount_t, struct vfsioattr *); 1076 1077/*! 1078 @function vfs_setioattr 1079 @abstract Set I/O attributes associated with a mounpoint. 1080 @param mp Mount for which to set attributes. 1081 @param ioattrp Structure containing I/O parameters; all fields must be filled in. 1082 @return void. 1083 */ 1084void vfs_setioattr(mount_t, struct vfsioattr *); 1085 1086/*! 1087 @function vfs_64bitready 1088 @abstract Check if the filesystem associated with a mountpoint is marked ready for interaction with 64-bit user processes. 1089 @param mp Mount to test. 1090 @return Nonzero if filesystem is ready for 64-bit; 0 otherwise. 1091 */ 1092int vfs_64bitready(mount_t); 1093 1094 1095#define LK_NOWAIT 1 1096/*! 1097 @function vfs_busy 1098 @abstract "Busy" a mountpoint. 1099 @discussion vfs_busy() will "busy" a mountpoint, preventing unmounts from taking off, by taking its reader-writer lock 1100 in a shared manner. If a mount is dead, 1101 it will fail; if an unmount is in progress, depending on flags, it will either fail immediately or block 1102 until the unmount completes (then failing if the unmount has succeeded, or potentially succeeding if unmounting failed). 1103 A successful vfs_busy() must be followed by a vfs_unbusy() to release the lock on the mount. 1104 @param mp Mount to busy. 1105 @param flags LK_NOWAIT: fail with ENOENT if an unmount is in progress. 1106 @return 0 for success, with a lock held; an error code otherwise, with no lock held. 1107 */ 1108int vfs_busy(mount_t, int); 1109 1110/*! 1111 @function vfs_unbusy 1112 @abstract "Unbusy" a mountpoint by releasing its read-write lock. 1113 @discussion A successful vfs_busy() must be followed by a vfs_unbusy() to release the lock on the mount. 1114 @param mp Mount to unbusy. 1115 @return void. 1116 */ 1117void vfs_unbusy(mount_t); 1118 1119/*! 1120 @function vfs_getnewfsid 1121 @abstract Generate a unique filesystem ID for a mount and store it in the mount structure. 1122 @discussion Filesystem IDs are returned as part of "struct statfs." This function is typically 1123 called as part of file-system specific mount code (i.e. through VFS_MOUNT). 1124 @param mp Mount to set an ID for. 1125 @return void. 1126 */ 1127void vfs_getnewfsid(struct mount *); 1128 1129/*! 1130 @function vfs_getvfs 1131 @abstract Given a filesystem ID, look up a mount structure. 1132 @param fsid Filesystem ID to look up. 1133 @return Mountpoint if found, else NULL. Note unmounting mountpoints can be returned. 1134 */ 1135mount_t vfs_getvfs(fsid_t *); 1136 1137/*! 1138 @function vfs_mountedon 1139 @abstract Check whether a given block device has a filesystem mounted on it. 1140 @discussion Note that this is NOT a check for a covered vnode (the directory upon which 1141 a filesystem is mounted)--it is a test for whether a block device is being used as the source 1142 of a filesystem. Note that a block device marked as being mounted on cannot be opened. 1143 @param vp The vnode to test. 1144 @return EBUSY if vnode is indeed the source of a filesystem; 0 if it is not. 1145 */ 1146int vfs_mountedon(struct vnode *); 1147 1148/*! 1149 @function vfs_unmountbyfsid 1150 @abstract Find a filesystem by ID and unmount it. 1151 @param fsid ID of filesystem to unmount, as found through (for example) statfs. 1152 @param flags MNT_FORCE: forcibly invalidate files open on the mount (though in-flight I/O operations 1153 will be allowed to complete). 1154 @param ctx Context against which to authenticate unmount operation. 1155 @return 0 for succcess, nonero for failure. 1156 */ 1157int vfs_unmountbyfsid(fsid_t *, int, vfs_context_t); 1158 1159/*! 1160 @function vfs_event_signal 1161 @abstract Post a kqueue-style event on a filesystem (EVFILT_FS). 1162 @param fsid Unused. 1163 @param event Events to post. 1164 @param data Unused. 1165 @return void. 1166 */ 1167void vfs_event_signal(fsid_t *, u_int32_t, intptr_t); 1168/*! 1169 @function vfs_event_init 1170 @abstract This function should not be called by kexts. 1171 */ 1172void vfs_event_init(void); /* XXX We should not export this */ 1173#ifdef KERNEL_PRIVATE 1174int vfs_getbyid(fsid_t *fsid, ino64_t ino, vnode_t *vpp, vfs_context_t ctx); 1175int vfs_getattr(mount_t mp, struct vfs_attr *vfa, vfs_context_t ctx); 1176int vfs_setattr(mount_t mp, struct vfs_attr *vfa, vfs_context_t ctx); 1177int vfs_extendedsecurity(mount_t); 1178mount_t vfs_getvfs_by_mntonname(char *); 1179void vfs_markdependency(mount_t); 1180vnode_t vfs_vnodecovered(mount_t mp); /* Returns vnode with an iocount that must be released with vnode_put() */ 1181vnode_t vfs_devvp(mount_t mp); /* Please see block comment with implementation */ 1182void * vfs_mntlabel(mount_t mp); /* Safe to cast to "struct label*"; returns "void*" to limit dependence of mount.h on security headers. */ 1183void vfs_setunmountpreflight(mount_t mp); 1184void vfs_setcompoundopen(mount_t mp); 1185uint64_t vfs_throttle_mask(mount_t mp); 1186 1187struct vnode_trigger_info; 1188 1189/*! 1190 @function vfs_addtrigger 1191 @abstract Create an "external" trigger vnode: look up a vnode and mark it as 1192 a trigger. Can only safely be called in the context of a callback set by 1193 vfs_settriggercallback(). May only be used on a file which is not already 1194 marked as a trigger. 1195 @param relpath Path relative to root of mountpoint at which to mark trigger. 1196 @param vtip Information about trigger; analogous to "vnode_trigger_param" 1197 argument to vnode_create. 1198 @param ctx Authorization context. 1199 */ 1200int vfs_addtrigger(mount_t mp, const char *relpath, struct vnode_trigger_info *vtip, vfs_context_t ctx); 1201 1202 1203/*! 1204 @enum vfs_trigger_callback_op_t 1205 @abstract Operation to perform after an attempted unmount (successful or otherwise). 1206 @constant VTC_REPLACE Unmount failed: attempt to replace triggers. Only valid 1207 VFS operation to perform in this context is vfs_addtrigger(). 1208 @constant VTC_RELEASE Unmount succeeded: release external triggering context. 1209 */ 1210typedef enum { 1211 VTC_REPLACE, 1212 VTC_RELEASE 1213} vfs_trigger_callback_op_t; 1214 1215/*! 1216 @typedef vfs_trigger_callback_t 1217 @abstract Callback to be passed to vfs_settriggercallback() and invoked from 1218 unmount context. 1219 @param mp Mountpoint on which unmount is occurring. 1220 @param op Operation (see vfs_trigger_callback_op_t) 1221 @param data Context passed to vfs_settriggercallback() 1222 @param ctx Authorization context in which unmount is occurring. 1223 */ 1224typedef void vfs_trigger_callback_t(mount_t mp, vfs_trigger_callback_op_t op, void *data, vfs_context_t ctx); 1225 1226/*! 1227 @function vfs_settriggercallback 1228 @abstract Install a callback to be called after unmount attempts on a volume, 1229 to restore triggers for failed unmounts and release state for successful ones. 1230 @discussion Installs a callback which will be called in two situations: a 1231 failed unmount where vnodes may have been reclaimed and a successful unmount. 1232 Gives an external trigger-marking entity an opportunity to replace triggers 1233 which may have been reclaimed. The callback can only be installed (not 1234 cleared), and only one callback can be installed. The callback will be called 1235 with a read-write lock held on the mount point; in the VTC_REPLACE case, the 1236 <em>only</em> valid VFS operation to perform in the context of the callback is 1237 vfs_addtrigger() on the mountpoint in question. This rwlock is held in order 1238 to attempt to provide some modicum of coverage from lookups which might find 1239 missing trigger vnodes and receive spurious ENOENTs. Note that this 1240 protection is incomplete--current working directories, or traversals up into a 1241 volume via ".." may still find missing triggers. As of this writing, no 1242 serialization mechanism exists to do better than this. 1243 When the "op" is VTC_RELEASE, the mountpoint is going away, and the only valid 1244 VFS operation is to free the private data pointer if needed. The callback 1245 will be called immediately, with VTC_REPLACE, from vfs_settriggercallback(), 1246 if installation is successful. 1247 @param fsid FSID for filesystem in question. 1248 @param vtc Callback pointer. 1249 @param data Context pointer to be passed to callback. 1250 @param flags Currently unused. 1251 @param ctx Authorization context. 1252 @return 0 for success. EBUSY if a trigger has already been installed. 1253 */ 1254int vfs_settriggercallback(fsid_t *fsid, vfs_trigger_callback_t vtc, void *data, uint32_t flags, vfs_context_t ctx); 1255 1256#endif /* KERNEL_PRIVATE */ 1257__END_DECLS 1258 1259#endif /* KERNEL */ 1260 1261#ifndef KERNEL 1262 1263/* 1264 * Generic file handle 1265 */ 1266#define NFS_MAX_FH_SIZE NFSV4_MAX_FH_SIZE 1267#define NFSV4_MAX_FH_SIZE 128 1268#define NFSV3_MAX_FH_SIZE 64 1269#define NFSV2_MAX_FH_SIZE 32 1270struct fhandle { 1271 int fh_len; /* length of file handle */ 1272 unsigned char fh_data[NFS_MAX_FH_SIZE]; /* file handle value */ 1273}; 1274typedef struct fhandle fhandle_t; 1275 1276 1277__BEGIN_DECLS 1278int fhopen(const struct fhandle *, int); 1279int fstatfs(int, struct statfs *) __DARWIN_INODE64(fstatfs); 1280#if !__DARWIN_ONLY_64_BIT_INO_T 1281int fstatfs64(int, struct statfs64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA); 1282#endif /* !__DARWIN_ONLY_64_BIT_INO_T */ 1283int getfh(const char *, fhandle_t *); 1284int getfsstat(struct statfs *, int, int) __DARWIN_INODE64(getfsstat); 1285#if !__DARWIN_ONLY_64_BIT_INO_T 1286int getfsstat64(struct statfs64 *, int, int) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA); 1287#endif /* !__DARWIN_ONLY_64_BIT_INO_T */ 1288int getmntinfo(struct statfs **, int) __DARWIN_INODE64(getmntinfo); 1289#if !__DARWIN_ONLY_64_BIT_INO_T 1290int getmntinfo64(struct statfs64 **, int) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA); 1291#endif /* !__DARWIN_ONLY_64_BIT_INO_T */ 1292int mount(const char *, const char *, int, void *); 1293int statfs(const char *, struct statfs *) __DARWIN_INODE64(statfs); 1294#if !__DARWIN_ONLY_64_BIT_INO_T 1295int statfs64(const char *, struct statfs64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA); 1296#endif /* !__DARWIN_ONLY_64_BIT_INO_T */ 1297int unmount(const char *, int); 1298int getvfsbyname(const char *, struct vfsconf *); 1299__END_DECLS 1300 1301#endif /* KERNEL */ 1302#endif /* !_SYS_MOUNT_H_ */ 1303