xref: /netbsd-src/share/man/man9/vfssubr.9 (revision 01869ca4d24a86379a68731bf9706a9f0820fe4e)
1.\"     $NetBSD: vfssubr.9,v 1.28 2017/07/03 21:28:48 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 April 17, 2017
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"
81.Ft void
82.Fn vfs_unbusy "struct mount *mp"
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->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"
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.
148.It Fn vfs_unbusy "mp"
149Undo a
150.Fn vfs_busy
151on the mount point specified by
152.Fa mp .
153.It Fn vfs_mountalloc "vfsops" "vp"
154Allocate and initialise a mount structure, setting
155.Em mnt_vnodecovered
156to
157.Fa vp
158and
159.Em mnt_op
160to
161.Fa vfsops .
162On success return the address of the mount structure.
163Otherwise, return
164.Dv NULL .
165.It Fn vfs_rootmountalloc "fstypename" "devname" "mpp"
166Lookup a file system type specified by the name
167.Fa fstypename
168and if found allocate and initialise a mount structure for it.
169The allocated mount structure is marked as busy and returned in the
170address specified by
171.Fa mpp .
172The device the root file system was mounted from is specified by the
173argument
174.Fa devname
175and is recorded in the new mount structure.
176.It Fn vfs_shutdown
177Sync and unmount all file systems before shutting down.
178Invoked by
179.Xr cpu_reboot 9 .
180.It Fn vfs_attach "vfs"
181Establish file system
182.Fa vfs
183and initialise it.
184.It Fn vfs_detach "vfs"
185Remove file system
186.Fa vfs
187from the kernel.
188.It Fn vfs_reinit "void"
189Reinitialises all file systems within the kernel through file
190system-specific vfs operation (see
191.Xr vfsops 9 ) .
192.It Fn vfs_getopsbyname "name"
193Given a file system name specified by
194.Fa name ,
195look up the vfs operations for that file system (see
196.Xr vfsops 9 ) ,
197or return
198.Dv NULL
199if file system isn't present in the kernel.
200.It Fn vfs_suspend "mp" "nowait"
201Request a mounted file system to suspend all operations.
202All new operations to the file system are stopped.
203After all operations in progress have completed, the
204file system is synced to disk and the function returns.
205If a file system suspension is currently in progress and
206.Fa nowait
207is set
208.Er EWOULDBLOCK
209is returned.
210If the operation is successful, zero is returned, otherwise an
211appropriate error code is returned.
212.It Fn vfs_resume "mp"
213Request a mounted file system to resume operations.
214.It Fn vfs_vnode_iterator_init "mp" "vip"
215Allocate and initialize an iterator
216.Fa vip
217over all vnodes attached to mount point
218.Fa mp .
219.It Fn vfs_vnode_iterator_destroy "vi"
220Free all resources associated with an iterator
221.Fa vi .
222.It Fn vfs_vnode_iterator_next "vi" "selector" "context"
223Return the next vnode from iterator
224.Fa vi .
225If the operation is successful the vnode has a reference added to it
226and it is returned.
227If the iterator is exhausted the function returns
228.Dv NULL .
229If an optional
230.Fa selector
231function is provided, then this function is called with the
232.Fa context
233provided and the candidate vnode to be returned.
234If the
235.Fa selector
236returns
237.Dv false ,
238then the vnode is skipped; if it returns
239.Dv true ,
240the vnode is referenced and then returned.
241.El
242.Sh CODE REFERENCES
243The vfs interface functions are implemented within the files
244.Pa sys/kern/vfs_mount.c ,
245.Pa sys/kern/vfs_subr.c
246and
247.Pa sys/kern/vfs_init.c .
248.Sh SEE ALSO
249.Xr intro 9 ,
250.Xr namei 9 ,
251.Xr vfs 9 ,
252.Xr vfsops 9 ,
253.Xr vnode 9 ,
254.Xr vnodeops 9
255