+#define VFS_RETURNED 0 /* done with vnode, reference can be dropped */
+#define VFS_RETURNED_DONE 1 /* done with vnode, reference can be dropped, terminate iteration */
+#define VFS_CLAIMED 2 /* don't drop reference */
+#define VFS_CLAIMED_DONE 3 /* don't drop reference, terminate iteration */
+
+
+__BEGIN_DECLS
+#ifdef BSD_KERNEL_PRIVATE
+extern int VFS_MOUNT(mount_t, vnode_t, user_addr_t, vfs_context_t);
+extern int VFS_START(mount_t, int, vfs_context_t);
+extern int VFS_UNMOUNT(mount_t, int, vfs_context_t);
+extern int VFS_ROOT(mount_t, vnode_t *, vfs_context_t);
+extern int VFS_QUOTACTL(mount_t, int, uid_t, caddr_t, vfs_context_t);
+extern int VFS_GETATTR(mount_t, struct vfs_attr *, vfs_context_t);
+extern int VFS_SETATTR(mount_t, struct vfs_attr *, vfs_context_t);
+extern int VFS_SYNC(mount_t, int, vfs_context_t);
+extern int VFS_VGET(mount_t, ino64_t, vnode_t *, vfs_context_t);
+extern int VFS_FHTOVP(mount_t, int, unsigned char *, vnode_t *, vfs_context_t);
+extern int VFS_VPTOFH(vnode_t, int *, unsigned char *, vfs_context_t);
+#endif /* BSD_KERNEL_PRIVATE */
+/*
+ * prototypes for exported VFS operations
+ */
+
+/*!
+ @function vfs_fsadd
+ @abstract Register a filesystem with VFS.
+ @discussion Typically called by a filesystem Kernel Extension when it is loaded.
+ @param vfe Filesystem information: table of vfs operations, list of vnode operation tables,
+ filesystem type number (can be omitted with VFS_TBLNOTYPENUM flag), name, flags.
+ @param handle Opaque handle which will be passed to vfs_fsremove.
+ @return 0 for success, else an error code.
+ */
+int vfs_fsadd(struct vfs_fsentry *, vfstable_t *);
+
+/*!
+ @function vfs_fsremove
+ @abstract Unregister a filesystem with VFS.
+ @discussion Typically called by a filesystem Kernel Extension when it is unloaded.
+ @param handle Handle which was returned by vfs_fsadd.
+ @return 0 for success, else an error code.
+ */
+int vfs_fsremove(vfstable_t);
+
+/*!
+ @function vfs_iterate
+ @abstract Iterate over all mountpoints with a callback. Used, for example, by sync().
+ @param flags Unused.
+ @param callback Function which takes a mount and arbitrary passed-in "arg," and returns one of VFS_RETURNED_DONE or VFS_CLAIMED_DONE: end
+ iteration and return success. VFS_RETURNED or VFS_CLAIMED: continue iterating. Anything else: continue iterating.
+ @param arg Arbitrary data to pass to callback.
+ @return 0 for success, else an error code.
+ */
+int vfs_iterate(int, int (*)(struct mount *, void *), void *);
+
+/*!
+ @function vfs_init_io_attributes
+ @abstract Set I/O attributes on a mountpoint based on device properties.
+ @param devvp Block device vnode from which a filesystem is being mounted.
+ @param mp Mountpoint whose I/O parameters to initialize.
+ @return 0 for success, else an error code.
+ */
+int vfs_init_io_attributes(vnode_t, mount_t);
+
+/*!
+ @function vfs_flags
+ @abstract Retrieve mount flags.
+ @discussion Results will be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS.
+ @param mp Mount whose flags to grab.
+ @return Flags.
+ */
+uint64_t vfs_flags(mount_t);
+
+/*!
+ @function vfs_setflags
+ @abstract Set flags on a mount.
+ @discussion Sets mount flags to the bitwise "OR" of their current value and the specified bits. Often
+ used by a filesystem as part of the mount process.
+ @param mp Mount whose flags to set.
+ @param flags Flags to activate. Must be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS.
+ @return Flags.
+ */
+void vfs_setflags(mount_t, uint64_t);
+
+/*!
+ @function vfs_clearflags
+ @abstract Clear flags on a mount.
+ @discussion Sets mount flags to the bitwise "AND" of their current value and the complement of the specified bits.
+ @param mp Mount whose flags to set.
+ @param flags Flags to deactivate. Must be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS.
+ @return void.
+ */
+void vfs_clearflags(mount_t, uint64_t);
+
+/*!
+ @function vfs_issynchronous
+ @abstract Determine if writes to a filesystem occur synchronously.
+ @param mp Mount to test.
+ @return Nonzero if writes occur synchronously, else 0.
+ */
+int vfs_issynchronous(mount_t);
+
+/*!
+ @function vfs_iswriteupgrade
+ @abstract Determine if a filesystem is mounted read-only but a request has been made to upgrade
+ to read-write.
+ @param mp Mount to test.
+ @return Nonzero if a request has been made to update from read-only to read-write, else 0.
+ */
+int vfs_iswriteupgrade(mount_t);
+
+/*!
+ @function vfs_isupdate
+ @abstract Determine if a mount update is in progress.
+ @param mp Mount to test.
+ @return Nonzero if a mount update is in progress, 0 otherwise.
+ */
+int vfs_isupdate(mount_t);
+
+/*!
+ @function vfs_isreload
+ @abstract Determine if a reload of filesystem data is in progress. This can only be the case
+ for a read-only filesystem; all data is brought in from secondary storage.
+ @param mp Mount to test.
+ @return Nonzero if a request has been made to reload data, else 0.
+ */
+int vfs_isreload(mount_t);
+
+/*!
+ @function vfs_isforce
+ @abstract Determine if a forced unmount is in progress.
+ @discussion A forced unmount invalidates open files.
+ @param mp Mount to test.
+ @return Nonzero if a request has been made to forcibly unmount, else 0.
+ */
+int vfs_isforce(mount_t);
+
+/*!
+ @function vfs_isunmount
+ @abstract Determine if an unmount is in progress.
+ @discussion This is an unsynchronized snapshot of the mount state. It should only be called
+ if the mount is known to be valid, e.g. there are known to be live files on that volume.
+ @param mp Mount to test.
+ @return Nonzero if an unmount is in progress, else zero.
+ */
+int vfs_isunmount(mount_t mp);
+
+/*!
+ @function vfs_isrdonly
+ @abstract Determine if a filesystem is mounted read-only.
+ @param mp Mount to test.
+ @return Nonzero if filesystem is mounted read-only, else 0.
+ */
+int vfs_isrdonly(mount_t);
+
+/*!
+ @function vfs_isrdwr
+ @abstract Determine if a filesystem is mounted with writes enabled.
+ @param mp Mount to test.
+ @return Nonzero if filesystem is mounted read-write, else 0.
+ */
+int vfs_isrdwr(mount_t);
+
+/*!
+ @function vfs_authopaque
+ @abstract Determine if a filesystem's authorization decisions occur remotely.
+ @param mp Mount to test.
+ @return Nonzero if filesystem authorization is controlled remotely, else 0.
+ */
+int vfs_authopaque(mount_t);
+
+/*!
+ @function vfs_authopaqueaccess
+ @abstract Check if a filesystem is marked as having reliable remote VNOP_ACCESS support.
+ @param mp Mount to test.
+ @return Nonzero if VNOP_ACCESS is supported remotely, else 0.
+ */
+int vfs_authopaqueaccess(mount_t);
+
+/*!
+ @function vfs_setauthopaque
+ @abstract Mark a filesystem as having authorization decisions controlled remotely.
+ @param mp Mount to mark.
+ @return void.
+ */
+void vfs_setauthopaque(mount_t);
+
+/*!
+ @function vfs_setauthopaqueaccess
+ @abstract Mark a filesystem as having remote VNOP_ACCESS support.
+ @param mp Mount to mark.
+ @return void.
+ */
+void vfs_setauthopaqueaccess(mount_t);
+
+/*!
+ @function vfs_clearauthopaque
+ @abstract Mark a filesystem as not having remote authorization decisions.
+ @param mp Mount to mark.
+ @return void.
+ */
+void vfs_clearauthopaque(mount_t);
+
+/*!
+ @function vfs_clearauthopaque
+ @abstract Mark a filesystem as not having remote VNOP_ACCESS support.
+ @param mp Mount to mark.
+ @return void.
+ */
+void vfs_clearauthopaqueaccess(mount_t);
+
+/*!
+ @function vfs_setextendedsecurity
+ @abstract Mark a filesystem as supporting security controls beyond POSIX permissions.
+ @discussion Specific controls include ACLs, file owner UUIDs, and group UUIDs.
+ @param mp Mount to test.
+ @return void.
+ */
+void vfs_setextendedsecurity(mount_t);
+
+/*!
+ @function vfs_clearextendedsecurity
+ @abstract Mark a filesystem as NOT supporting security controls beyond POSIX permissions.
+ @discussion Specific controls include ACLs, file owner UUIDs, and group UUIDs.
+ @param mp Mount to test.
+ @return void.
+ */
+void vfs_clearextendedsecurity(mount_t);
+
+/*!
+ @function vfs_setlocklocal
+ @abstract Mark a filesystem as using VFS-level advisory locking support.
+ @discussion Advisory locking operations will not call down to the filesystem if this flag is set.
+ @param mp Mount to mark.
+ @return void.
+ */
+void vfs_setlocklocal(mount_t);
+
+/*!
+ @function vfs_authcache_ttl
+ @abstract Determine the time-to-live of cached authorized credentials for files in this filesystem.
+ @discussion If a filesystem is set to allow caching credentials, the VFS layer can authorize
+ previously-authorized actions from the same vfs_context_t without calling down to the filesystem (though
+ it will not deny based on the cache).
+ @param mp Mount for which to check cache lifetime.
+ @return Cache lifetime in seconds. CACHED_RIGHT_INFINITE_TTL indicates that credentials never expire.
+ */
+int vfs_authcache_ttl(mount_t);
+
+/*!
+ @function vfs_setauthcache_ttl
+ @abstract Enable credential caching and set time-to-live of cached authorized credentials for files in this filesystem.
+ @discussion If a filesystem is set to allow caching credentials, the VFS layer can authorize
+ previously-authorized actions from the same vfs_context_t without calling down to the filesystem (though
+ it will not deny based on the cache).
+ @param mp Mount for which to set cache lifetime.
+ @return void.
+ */
+void vfs_setauthcache_ttl(mount_t, int);
+
+/*!
+ @function vfs_clearauthcache_ttl
+ @abstract Remove time-to-live controls for cached credentials on a filesytem. Filesystems with remote authorization
+ decisions (opaque) will still have KAUTH_VNODE_SEARCH rights cached for a default of CACHED_LOOKUP_RIGHT_TTL seconds.
+ @param mp Mount for which to clear cache lifetime.
+ @return void.
+ */
+void vfs_clearauthcache_ttl(mount_t);
+
+/*
+ * return value from vfs_cachedrights_ttl if
+ * neither MNTK_AUTH_OPAQUE | MNTK_AUTH_CACHE_TTL
+ * is set in mnt_kern_flag.. it indicates
+ * that no TTL is being applied to the vnode rights cache
+ */
+#define CACHED_RIGHT_INFINITE_TTL ~0
+
+/*!
+ @function vfs_maxsymlen
+ @abstract Get the maximum length of a symbolic link on a filesystem.
+ @param mp Mount from which to get symlink length cap.
+ @return Max symlink length.
+ */
+uint32_t vfs_maxsymlen(mount_t);
+
+/*!
+ @function vfs_setmaxsymlen
+ @abstract Set the maximum length of a symbolic link on a filesystem.
+ @param mp Mount on which to set symlink length cap.
+ @param symlen Length to set.
+ @return Max symlink length.
+ */
+void vfs_setmaxsymlen(mount_t, uint32_t);
+
+/*!
+ @function vfs_fsprivate
+ @abstract Get filesystem-private mount data.
+ @discussion A filesystem generally has an internal mount structure which it attaches to the VFS-level mount structure
+ as part of the mounting process.
+ @param mp Mount for which to get private data.
+ @return Private data.
+ */
+void * vfs_fsprivate(mount_t);
+
+/*!
+ @function vfs_setfsprivate
+ @abstract Set filesystem-private mount data.
+ @discussion A filesystem generally has an internal mount structure which it attaches to the VFS-level mount structure
+ as part of the mounting process.
+ @param mp Mount for which to set private data.
+ @return Void.
+ */
+void vfs_setfsprivate(mount_t, void *mntdata);
+
+/*!
+ @function vfs_statfs
+ @abstract Get information about filesystem status.
+ @discussion Each filesystem has a struct vfsstatfs associated with it which is updated as events occur; this function
+ returns a pointer to it. Note that the data in the structure will continue to change over time and also that it may
+ be quite stale of vfs_update_vfsstat has not been called recently.
+ @param mp Mount for which to get vfsstatfs pointer.
+ @return Pointer to vfsstatfs.
+ */
+struct vfsstatfs * vfs_statfs(mount_t);
+#define VFS_USER_EVENT 0
+#define VFS_KERNEL_EVENT 1
+
+/*!
+ @function vfs_update_vfsstat
+ @abstract Update cached filesystem status information in the VFS mount structure.
+ @discussion Each filesystem has a struct vfsstatfs associated with it which is updated as events occur; this function
+ updates it so that the structure pointer returned by vfs_statfs() returns a pointer to fairly recent data.
+ @param mp Mount for which to update cached status information.
+ @param ctx Context to authenticate against for call down to filesystem.
+ @param eventtype VFS_USER_EVENT: need for update is driven by user-level request; perform additional authentication.
+ VFS_KERNEL_EVENT: need for update is driven by in-kernel events. Skip extra authentication.
+ @return 0 for success, or an error code for authentication failure or problem with call to filesystem to
+ request information.
+ */
+int vfs_update_vfsstat(mount_t, vfs_context_t, int eventtype);
+
+/*!
+ @function vfs_typenum
+ @abstract Get (archaic) filesystem type number.
+ @discussion Filesystem type numbers are an old construct; most filesystems just get a number assigned based on
+ the order in which they are registered with the system.
+ @param mp Mount for which to get type number.
+ @return Type number.
+ */
+int vfs_typenum(mount_t);
+
+/*!
+ @function vfs_name
+ @abstract Copy filesystem name into a buffer.
+ @discussion Get filesystem name; this refers to the filesystem type of which a mount is an instantiation,
+ rather than a name specific to the mountpoint.
+ @param mp Mount for which to get name.
+ @param buffer Destination for name; length should be at least MFSNAMELEN.
+ @return void.
+ */
+void vfs_name(mount_t, char *);
+
+/*!
+ @function vfs_devblocksize
+ @abstract Get the block size of the device underlying a mount.
+ @param mp Mount for which to get block size.
+ @return Block size.
+ */
+int vfs_devblocksize(mount_t);
+
+/*!
+ @function vfs_ioattr
+ @abstract Get I/O attributes associated with a mounpoint.
+ @param mp Mount for which to get attributes. If NULL, system defaults are filled into ioattrp.
+ @param ioattrp Destination for results.
+ @return void.
+ */
+void vfs_ioattr(mount_t, struct vfsioattr *);
+
+/*!
+ @function vfs_setioattr
+ @abstract Set I/O attributes associated with a mounpoint.
+ @param mp Mount for which to set attributes.
+ @param ioattrp Structure containing I/O parameters; all fields must be filled in.
+ @return void.
+ */
+void vfs_setioattr(mount_t, struct vfsioattr *);
+
+/*!
+ @function vfs_64bitready
+ @abstract Check if the filesystem associated with a mountpoint is marked ready for interaction with 64-bit user processes.
+ @param mp Mount to test.
+ @return Nonzero if filesystem is ready for 64-bit; 0 otherwise.
+ */
+int vfs_64bitready(mount_t);
+
+
+#define LK_NOWAIT 1
+/*!
+ @function vfs_busy
+ @abstract "Busy" a mountpoint.
+ @discussion vfs_busy() will "busy" a mountpoint, preventing unmounts from taking off, by taking its reader-writer lock
+ in a shared manner. If a mount is dead,
+ it will fail; if an unmount is in progress, depending on flags, it will either fail immediately or block
+ until the unmount completes (then failing if the unmount has succeeded, or potentially succeeding if unmounting failed).
+ A successful vfs_busy() must be followed by a vfs_unbusy() to release the lock on the mount.
+ @param mp Mount to busy.
+ @param flags LK_NOWAIT: fail with ENOENT if an unmount is in progress.
+ @return 0 for success, with a lock held; an error code otherwise, with no lock held.
+ */
+int vfs_busy(mount_t, int);
+
+/*!
+ @function vfs_unbusy
+ @abstract "Unbusy" a mountpoint by releasing its read-write lock.
+ @discussion A successful vfs_busy() must be followed by a vfs_unbusy() to release the lock on the mount.
+ @param mp Mount to unbusy.
+ @return void.
+ */
+void vfs_unbusy(mount_t);
+
+/*!
+ @function vfs_getnewfsid
+ @abstract Generate a unique filesystem ID for a mount and store it in the mount structure.
+ @discussion Filesystem IDs are returned as part of "struct statfs." This function is typically
+ called as part of file-system specific mount code (i.e. through VFS_MOUNT).
+ @param mp Mount to set an ID for.
+ @return void.
+ */
+void vfs_getnewfsid(struct mount *);
+
+/*!
+ @function vfs_getvfs
+ @abstract Given a filesystem ID, look up a mount structure.
+ @param fsid Filesystem ID to look up.
+ @return Mountpoint if found, else NULL. Note unmounting mountpoints can be returned.
+ */
+mount_t vfs_getvfs(fsid_t *);
+
+/*!
+ @function vfs_mountedon
+ @abstract Check whether a given block device has a filesystem mounted on it.
+ @discussion Note that this is NOT a check for a covered vnode (the directory upon which
+ a filesystem is mounted)--it is a test for whether a block device is being used as the source
+ of a filesystem. Note that a block device marked as being mounted on cannot be opened.
+ @param vp The vnode to test.
+ @return EBUSY if vnode is indeed the source of a filesystem; 0 if it is not.
+ */
+int vfs_mountedon(struct vnode *);
+
+/*!
+ @function vfs_unmountbyfsid
+ @abstract Find a filesystem by ID and unmount it.
+ @param fsid ID of filesystem to unmount, as found through (for example) statfs.
+ @param flags MNT_FORCE: forcibly invalidate files open on the mount (though in-flight I/O operations
+ will be allowed to complete).
+ @param ctx Context against which to authenticate unmount operation.
+ @return 0 for succcess, nonero for failure.
+ */
+int vfs_unmountbyfsid(fsid_t *, int, vfs_context_t);
+
+/*!
+ @function vfs_event_signal
+ @abstract Post a kqueue-style event on a filesystem (EVFILT_FS).
+ @param fsid Unused.
+ @param event Events to post.
+ @param data Unused.
+ @return void.
+ */
+void vfs_event_signal(fsid_t *, u_int32_t, intptr_t);
+/*!
+ @function vfs_event_init
+ @abstract This function should not be called by kexts.
+ */
+void vfs_event_init(void); /* XXX We should not export this */
+#ifdef KERNEL_PRIVATE
+int vfs_getattr(mount_t mp, struct vfs_attr *vfa, vfs_context_t ctx);
+int vfs_setattr(mount_t mp, struct vfs_attr *vfa, vfs_context_t ctx);
+int vfs_extendedsecurity(mount_t);
+mount_t vfs_getvfs_by_mntonname(char *);
+void vfs_markdependency(mount_t);
+vnode_t vfs_vnodecovered(mount_t mp); /* Returns vnode with an iocount that must be released with vnode_put() */
+void * vfs_mntlabel(mount_t mp); /* Safe to cast to "struct label*"; returns "void*" to limit dependence of mount.h on security headers. */
+void vfs_setunmountpreflight(mount_t mp);
+#endif /* KERNEL_PRIVATE */
+__END_DECLS
+
+#endif /* KERNEL */
+
+#ifndef KERNEL
+
+/*
+ * Generic file handle
+ */
+#define NFS_MAX_FH_SIZE NFSV4_MAX_FH_SIZE
+#define NFSV4_MAX_FH_SIZE 128
+#define NFSV3_MAX_FH_SIZE 64
+#define NFSV2_MAX_FH_SIZE 32
+struct fhandle {
+ int fh_len; /* length of file handle */
+ unsigned char fh_data[NFS_MAX_FH_SIZE]; /* file handle value */
+};
+typedef struct fhandle fhandle_t;