1.\" $NetBSD: vfssubr.9,v 1.16 2008/04/30 13:10:59 martin 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 January 21, 2007 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_rootmountalloc , 47.Nm vfs_shutdown , 48.Nm vfs_attach , 49.Nm vfs_detach , 50.Nm vfs_reinit , 51.Nm vfs_getopsbyname , 52.Nm vfs_suspend , 53.Nm vfs_resume 54.Nd high-level interface to kernel file system interface 55.Sh SYNOPSIS 56.In sys/param.h 57.In sys/mount.h 58.In sys/vnode.h 59.Ft void 60.Fn vfs_getnewfsid "struct mount *mp" 61.Ft struct mount * 62.Fn vfs_getvfs "fsid_t *fsid" 63.Ft int 64.Fn vfs_export_lookup "struct mount *mp" "struct netexport *nep" \ 65"struct export_args *argp" 66.Ft int 67.Fn vfs_setpublicfs "struct mount *mp" "struct netexport *nep" \ 68"struct export_args *argp" 69.Ft int 70.Fn vfs_mountedon "struct vnode *vp" 71.Ft int 72.Fn vfs_mountroot "void" 73.Ft void 74.Fn vfs_unmountall "struct lwp *l" 75.Ft int 76.Fn vfs_busy "struct mount *mp" "int flags" "struct simplelock *interlkp" 77.Ft void 78.Fn vfs_unbusy "struct mount *mp" 79.Ft int 80.Fn vfs_rootmountalloc "char *fstypename" "char *devname" \ 81"struct mount **mpp" 82.Ft void 83.Fn vfs_shutdown "void" 84.Ft int 85.Fn vfs_attach "struct vfsops *vfs" 86.Ft int 87.Fn vfs_detach "struct vfsops *vfs" 88.Ft void 89.Fn vfs_reinit "void" 90.Ft struct vfsops * 91.Fn vfs_getopsbyname "const char *name" 92.Ft int 93.Fn vfs_suspend "struct mount *mp" "int nowait" 94.Ft void 95.Fn vfs_resume "struct mount *mp" 96.Sh DESCRIPTION 97The high-level functions described in this page are the interface to 98the kernel file system interface (VFS). 99.Sh FUNCTIONS 100.Bl -tag -width compact 101.It Fn vfs_getnewfsid "mp" 102Get a new unique file system id type for the file system specified by 103the mount structure 104.Fa mp . 105The file system id type is stored in 106.Em mp-\*[Gt]mnt_stat.f_fsidx . 107.It Fn vfs_getvfs "fsid" 108Lookup a mount point with the file system identifier 109.Fa fsid . 110.It Fn vfs_export_lookup "mp" "nep" "argp" 111Check client permission on the exportable file system specified by the 112mount structure 113.Fa mp . 114The argument 115.Fa nam 116is the address of the networked client. 117This function is used by file system type specific functions to verify 118that the client can access the file system. 119.It Fn vfs_setpublicfs "mp" "nep" "argp" 120Set the publicly exported file system specified by the mount structure 121.Fa mp . 122.It Fn vfs_mountedon "vp" 123Check to see if a file system is mounted on a block device specified 124by the vnode 125.Fa vp . 126.It Fn vfs_mountroot "void" 127Mount the root file system. 128.It Fn vfs_unmountall "l" 129Unmount all file systems. 130.It Fn vfs_busy "mp" "flags" "interlkp" 131Mark the mount point specified by 132.Fa mp 133as busy. 134This function is used to synchronize access and to delay unmounting. 135The interlock specified by argument 136.Fa interlkp 137is not released on failure. 138.It Fn vfs_unbusy "mp" 139Free the busy file system specified by the mount structure 140.Fa mp . 141.It Fn vfs_rootmountalloc "fstypename" "devname" "mpp" 142Lookup a file system type specified by the name 143.Fa fstypename 144and if found allocate and initialise a mount structure for it. 145The allocated mount structure is returned in the address specified by 146.Fa mpp . 147The device the root file system was mounted from is specified by the 148argument 149.Fa devname 150and is recorded in the new mount structure. 151.It Fn vfs_shutdown 152Sync and unmount all file systems before shutting down. 153Invoked by 154.Xr cpu_reboot 9 . 155.It Fn vfs_attach "vfs" 156Establish file system 157.Fa vfs 158and initialise it. 159.It Fn vfs_detach "vfs" 160Remove file system 161.Fa vfs 162from the kernel. 163.It Fn vfs_reinit "void" 164Reinitialises all file systems within the kernel through file 165system-specific vfs operation (see 166.Xr vfsops 9 ) . 167.It Fn vfs_getopsbyname "name" 168Given a file system name specified by 169.Fa name , 170look up the vfs operations for that file system (see 171.Xr vfsops 9 ) , 172or return 173.Dv NULL 174if file system isn't present in the kernel. 175.It Fn vfs_suspend "mp" "nowait" 176Request a mounted file system to suspend all operations. 177All new operations to the file system are stopped. 178After all operations in progress have completed, the 179file system is synced to disk and the function returns. 180If a file system suspension is currently in progress and 181.Fa nowait 182is set 183.Er EWOULDBLOCK 184is returned. 185If the operation is successful, zero is returned, otherwise an 186appropriate error code is returned. 187.It Fn vfs_resume "mp" 188Request a mounted file system to resume operations. 189.El 190.Sh CODE REFERENCES 191This section describes places within the 192.Nx 193source tree where actual code implementing or using the vfs 194operations can be found. 195All pathnames are relative to 196.Pa /usr/src . 197.Pp 198The vfs interface functions are implemented within the files 199.Pa sys/kern/vfs_subr.c , 200.Pa sys/kern/vfs_subr2.c , 201and 202.Pa sys/kern/vfs_init.c . 203.Sh SEE ALSO 204.Xr intro 9 , 205.Xr namei 9 , 206.Xr vfs 9 , 207.Xr vfsops 9 , 208.Xr vnode 9 , 209.Xr vnodeops 9 210