1.\" $NetBSD: vfssubr.9,v 1.25 2014/05/24 17:14:02 wiz Exp $ 2.\" 3.\" Copyright (c) 2003, 2005, 2006 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Gregory McGarry. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd May 24, 2014 31.Dt VFSSUBR 9 32.Os 33.Sh NAME 34.Nm vfssubr , 35.Nm vfs_getnewfsid , 36.Nm vfs_getvfs , 37.Nm vfs_export , 38.Nm vfs_showexport , 39.Nm vfs_export_lookup , 40.Nm vfs_setpublicfs , 41.Nm vfs_mountedon , 42.Nm vfs_mountroot , 43.Nm vfs_unmountall , 44.Nm vfs_busy , 45.Nm vfs_unbusy , 46.Nm vfs_mountalloc , 47.Nm vfs_rootmountalloc , 48.Nm vfs_shutdown , 49.Nm vfs_attach , 50.Nm vfs_detach , 51.Nm vfs_reinit , 52.Nm vfs_getopsbyname , 53.Nm vfs_suspend , 54.Nm vfs_resume , 55.Nm vfs_vnode_iterator_init , 56.Nm vfs_vnode_iterator_destroy , 57.Nm vfs_vnode_iterator_next 58.Nd high-level interface to kernel file system interface 59.Sh SYNOPSIS 60.In sys/param.h 61.In sys/mount.h 62.In sys/vnode.h 63.Ft void 64.Fn vfs_getnewfsid "struct mount *mp" 65.Ft struct mount * 66.Fn vfs_getvfs "fsid_t *fsid" 67.Ft int 68.Fn vfs_export_lookup "struct mount *mp" "struct netexport *nep" \ 69"struct export_args *argp" 70.Ft int 71.Fn vfs_setpublicfs "struct mount *mp" "struct netexport *nep" \ 72"struct export_args *argp" 73.Ft int 74.Fn vfs_mountedon "struct vnode *vp" 75.Ft int 76.Fn vfs_mountroot "void" 77.Ft void 78.Fn vfs_unmountall "struct lwp *l" 79.Ft int 80.Fn vfs_busy "struct mount *mp" "struct mount **nextp" 81.Ft void 82.Fn vfs_unbusy "struct mount *mp" "bool keepref" "struct mount **nextp" 83.Ft struct mount * 84.Fn vfs_mountalloc "struct vfsops *vfs" "struct vnode *vp" 85.Ft int 86.Fn vfs_rootmountalloc "char *fstypename" "char *devname" \ 87"struct mount **mpp" 88.Ft void 89.Fn vfs_shutdown "void" 90.Ft int 91.Fn vfs_attach "struct vfsops *vfs" 92.Ft int 93.Fn vfs_detach "struct vfsops *vfs" 94.Ft void 95.Fn vfs_reinit "void" 96.Ft struct vfsops * 97.Fn vfs_getopsbyname "const char *name" 98.Ft int 99.Fn vfs_suspend "struct mount *mp" "int nowait" 100.Ft void 101.Fn vfs_resume "struct mount *mp" 102.Ft void 103.Fn vfs_vnode_iterator_init "struct mount *mp" "struct vnode_iterator **vip" 104.Ft void 105.Fn vfs_vnode_iterator_destroy "struct vnode_iterator *vi" 106.Ft struct vnode * 107.Fn vfs_vnode_iterator_next "struct vnode_iterator *vi" "bool (*selector)(void *context, struct vnode *vpp)" "void *context" 108.Sh DESCRIPTION 109The high-level functions described in this page are the interface to 110the kernel file system interface (VFS). 111.Sh FUNCTIONS 112.Bl -tag -width compact 113.It Fn vfs_getnewfsid "mp" 114Get a new unique file system id type for the file system specified by 115the mount structure 116.Fa mp . 117The file system id type is stored in 118.Em mp-\*[Gt]mnt_stat.f_fsidx . 119.It Fn vfs_getvfs "fsid" 120Lookup a mount point with the file system identifier 121.Fa fsid . 122.It Fn vfs_export_lookup "mp" "nep" "argp" 123Check client permission on the exportable file system specified by the 124mount structure 125.Fa mp . 126The argument 127.Fa nam 128is the address of the networked client. 129This function is used by file system type specific functions to verify 130that the client can access the file system. 131.It Fn vfs_setpublicfs "mp" "nep" "argp" 132Set the publicly exported file system specified by the mount structure 133.Fa mp . 134.It Fn vfs_mountedon "vp" 135Check to see if a file system is mounted on a block device specified 136by the vnode 137.Fa vp . 138.It Fn vfs_mountroot "void" 139Mount the root file system. 140.It Fn vfs_unmountall "l" 141Unmount all file systems. 142.It Fn vfs_busy "mp" "nextp" 143Mark the mount point specified by 144.Fa mp 145as busy and get a reference to it. 146This function is used to synchronize access and to delay unmounting. 147The caller must hold a pre-existing reference to the mount. 148If 149.Fa nextp 150is not 151.Dv NULL , 152the caller must hold the 153.Em mountlist_lock 154and 155.Fa nextp 156will receive the next mount from mount list on error. 157The 158.Em mountlist_lock 159is released on return. 160.It Fn vfs_unbusy "mp" "keepref" "nextp" 161Undo a 162.Fn vfs_busy 163on the mount point specified by 164.Fa mp . 165If 166.Fa keepref 167is true, preserve the reference added by 168.Fn vfs_busy . 169If 170.Fa nextp 171is not 172.Dv NULL , 173the 174.Em mountlist_lock 175will be aquired and 176.Fa nextp 177will receive the next mount from mount list. 178.It Fn vfs_mountalloc "vfsops" "vp" 179Allocate and initialise a mount structure, setting 180.Em mnt_vnodecovered 181to 182.Fa vp 183and 184.Em mnt_op 185to 186.Fa vfsops . 187On success, mark the mount structure as busy and return its address. 188Otherwise, return 189.Dv NULL . 190.It Fn vfs_rootmountalloc "fstypename" "devname" "mpp" 191Lookup a file system type specified by the name 192.Fa fstypename 193and if found allocate and initialise a mount structure for it. 194The allocated mount structure is returned in the address specified by 195.Fa mpp . 196The device the root file system was mounted from is specified by the 197argument 198.Fa devname 199and is recorded in the new mount structure. 200.It Fn vfs_shutdown 201Sync and unmount all file systems before shutting down. 202Invoked by 203.Xr cpu_reboot 9 . 204.It Fn vfs_attach "vfs" 205Establish file system 206.Fa vfs 207and initialise it. 208.It Fn vfs_detach "vfs" 209Remove file system 210.Fa vfs 211from the kernel. 212.It Fn vfs_reinit "void" 213Reinitialises all file systems within the kernel through file 214system-specific vfs operation (see 215.Xr vfsops 9 ) . 216.It Fn vfs_getopsbyname "name" 217Given a file system name specified by 218.Fa name , 219look up the vfs operations for that file system (see 220.Xr vfsops 9 ) , 221or return 222.Dv NULL 223if file system isn't present in the kernel. 224.It Fn vfs_suspend "mp" "nowait" 225Request a mounted file system to suspend all operations. 226All new operations to the file system are stopped. 227After all operations in progress have completed, the 228file system is synced to disk and the function returns. 229If a file system suspension is currently in progress and 230.Fa nowait 231is set 232.Er EWOULDBLOCK 233is returned. 234If the operation is successful, zero is returned, otherwise an 235appropriate error code is returned. 236.It Fn vfs_resume "mp" 237Request a mounted file system to resume operations. 238.It Fn vfs_vnode_iterator_init "mp" "vip" 239Allocate and initialize an iterator 240.Fa vip 241over all vnodes attached to mount point 242.Fa mp . 243.It Fn vfs_vnode_iterator_destroy "vi" 244Free all resources associated with an iterator 245.Fa vi . 246.It Fn vfs_vnode_iterator_next "vi" "selector" "context" 247Return the next vnode from iterator 248.Fa vi . 249If the operation is successful the vnode has a reference added to it 250and it is returned. 251If the iterator is exhausted the function returns 252.Dv NULL . 253If an optional 254.Fa selector 255function is provided, then this function is called with the 256.Fa context 257provided and the candidate vnode to be returned. 258If the 259.Fa selector 260returns 261.Dv false , 262then the vnode is skipped; if it returns 263.Dv true , 264the vnode is referenced and then returned. 265.El 266.Sh CODE REFERENCES 267The vfs interface functions are implemented within the files 268.Pa sys/kern/vfs_mount.c , 269.Pa sys/kern/vfs_subr.c 270and 271.Pa sys/kern/vfs_init.c . 272.Sh SEE ALSO 273.Xr intro 9 , 274.Xr namei 9 , 275.Xr vfs 9 , 276.Xr vfsops 9 , 277.Xr vnode 9 , 278.Xr vnodeops 9 279