1.\" $NetBSD: vfssubr.9,v 1.14 2007/01/21 15:42:36 hannken 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.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd January 21, 2007 38.Dt VFSSUBR 9 39.Os 40.Sh NAME 41.Nm vfssubr , 42.Nm vfs_getnewfsid , 43.Nm vfs_getvfs , 44.Nm vfs_export , 45.Nm vfs_showexport , 46.Nm vfs_export_lookup , 47.Nm vfs_setpublicfs , 48.Nm vfs_mountedon , 49.Nm vfs_mountroot , 50.Nm vfs_unmountall , 51.Nm vfs_busy , 52.Nm vfs_unbusy , 53.Nm vfs_rootmountalloc , 54.Nm vfs_shutdown , 55.Nm vfs_attach , 56.Nm vfs_detach , 57.Nm vfs_reinit , 58.Nm vfs_getopsbyname , 59.Nm vfs_suspend , 60.Nm vfs_resume 61.Nd high-level interface to kernel file system interface 62.Sh SYNOPSIS 63.In sys/param.h 64.In sys/mount.h 65.In sys/vnode.h 66.Ft void 67.Fn vfs_getnewfsid "struct mount *mp" 68.Ft struct mount * 69.Fn vfs_getvfs "fsid_t *fsid" 70.Ft int 71.Fn vfs_export_lookup "struct mount *mp" "struct netexport *nep" \ 72"struct export_args *argp" 73.Ft int 74.Fn vfs_setpublicfs "struct mount *mp" "struct netexport *nep" \ 75"struct export_args *argp" 76.Ft int 77.Fn vfs_mountedon "struct vnode *vp" 78.Ft int 79.Fn vfs_mountroot "void" 80.Ft void 81.Fn vfs_unmountall "struct lwp *l" 82.Ft int 83.Fn vfs_busy "struct mount *mp" "int flags" "struct simplelock *interlkp" 84.Ft void 85.Fn vfs_unbusy "struct mount *mp" 86.Ft int 87.Fn vfs_rootmountalloc "char *fstypename" "char *devname" \ 88"struct mount **mpp" 89.Ft void 90.Fn vfs_shutdown "void" 91.Ft int 92.Fn vfs_attach "struct vfsops *vfs" 93.Ft int 94.Fn vfs_detach "struct vfsops *vfs" 95.Ft void 96.Fn vfs_reinit "void" 97.Ft struct vfsops * 98.Fn vfs_getopsbyname "const char *name" 99.Ft int 100.Fn vfs_suspend "struct mount *mp" "int nowait" 101.Ft void 102.Fn vfs_resume "struct mount *mp" 103.Sh DESCRIPTION 104The high-level functions described in this page are the interface to 105the kernel file system interface (VFS). 106.Sh FUNCTIONS 107.Bl -tag -width compact 108.It Fn vfs_getnewfsid "mp" 109Get a new unique file system id type for the file system specified by 110the mount structure 111.Fa mp . 112The file system id type is stored in 113.Em mp-\*[Gt]mnt_stat.f_fsidx . 114.It Fn vfs_getvfs "fsid" 115Lookup a mount point with the file system identifier 116.Fa fsid . 117.It Fn vfs_export_lookup "mp" "nep" "argp" 118Check client permission on the exportable file system specified by the 119mount structure 120.Fa mp . 121The argument 122.Fa nam 123is the address of the networked client. 124This function is used by file system type specific functions to verify 125that the client can access the file system. 126.It Fn vfs_setpublicfs "mp" "nep" "argp" 127Set the publicly exported file system specified by the mount structure 128.Fa mp . 129.It Fn vfs_mountedon "vp" 130Check to see if a file system is mounted on a block device specified 131by the vnode 132.Fa vp . 133.It Fn vfs_mountroot "void" 134Mount the root file system. 135.It Fn vfs_unmountall "l" 136Unmount all file systems. 137.It Fn vfs_busy "mp" "flags" "interlkp" 138Mark the mount point specified by 139.Fa mp 140as busy. 141This function is used to synchronize access and to delay unmounting. 142The interlock specified by argument 143.Fa interlkp 144is not released on failure. 145.It Fn vfs_unbusy "mp" 146Free the busy file system specified by the mount structure 147.Fa mp . 148.It Fn vfs_rootmountalloc "fstypename" "devname" "mpp" 149Lookup a file system type specified by the name 150.Fa fstypename 151and if found allocate and initialise a mount structure for it. 152The allocated mount structure is returned in the address specified by 153.Fa mpp . 154The device the root file system was mounted from is specified by the 155argument 156.Fa devname 157and is recorded in the new mount structure. 158.It Fn vfs_shutdown 159Sync and unmount all file systems before shutting down. 160Invoked by 161.Xr cpu_reboot 9 . 162.It Fn vfs_attach "vfs" 163Establish file system 164.Fa vfs 165and initialise it. 166.It Fn vfs_detach "vfs" 167Remove file system 168.Fa vfs 169from the kernel. 170.It Fn vfs_reinit "void" 171Reinitialises all file systems within the kernel through file 172system-specific vfs operation (see 173.Xr vfsops 9 ) . 174.It Fn vfs_getopsbyname "name" 175Given a file system name specified by 176.Fa name , 177look up the vfs operations for that file system (see 178.Xr vfsops 9 ) , 179or return 180.Dv NULL 181if file system isn't present in the kernel. 182.It Fn vfs_suspend "mp" "nowait" 183Request a mounted file system to suspend all operations. 184All new operations to the file system are stopped. 185After all operations in progress have completed, the 186file system is synced to disk and the function returns. 187If a file system suspension is currently in progress and 188.Fa nowait 189is set 190.Er EWOULDBLOCK 191is returned. 192If the operation is successful, zero is returned, otherwise an 193appropriate error code is returned. 194.It Fn vfs_resume "mp" 195Request a mounted file system to resume operations. 196.El 197.Sh CODE REFERENCES 198This section describes places within the 199.Nx 200source tree where actual code implementing or using the vfs 201operations can be found. 202All pathnames are relative to 203.Pa /usr/src . 204.Pp 205The vfs interface functions are implemented within the files 206.Pa sys/kern/vfs_subr.c 207and 208.Pa sys/kern/vfs_init.c . 209.Sh SEE ALSO 210.Xr intro 9 , 211.Xr namei 9 , 212.Xr vfs 9 , 213.Xr vfsops 9 , 214.Xr vnode 9 , 215.Xr vnodeops 9 216