xref: /netbsd-src/share/man/man9/vfs_hooks.9 (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1.\"     $NetBSD: vfs_hooks.9,v 1.3 2006/01/16 22:05:21 yamt Exp $
2.\"
3.\" Copyright (c) 2005 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Julio M. Merino Vidal.
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 September 23, 2005
38.Dt VFS_HOOKS 9
39.Os
40.Sh NAME
41.Nm vfs_hooks ,
42.Nm vfs_hooks_unmount
43.Nd VFS hooks interface
44.Sh SYNOPSIS
45.In sys/param.h
46.In sys/mount.h
47.Ft void
48.Fn vfs_hooks_unmount "struct mount *mp"
49.Sh DESCRIPTION
50The VFS hooks interface provides a way for different kernel subsystems to
51attach custom functions to specific VFS operations.
52This enforces code separation by keeping the VFS's core sources uncluttered
53and makes all subsystem functionality reside in a single place.
54As an example, this interface is used by the NFS server code to automatically
55handle the exports list for each mount point.
56.Pp
57Hooks are described by a
58.Ft struct vfs_hooks
59object, as seen below:
60.Bd -literal
61struct vfs_hooks {
62	int	(*vh_unmount)(struct mount *);
63};
64.Ed
65.Pp
66For simplicity, each field is named after the VFS operation it refers to.
67The purpose of each member function, alongside some important notes, is
68shown below:
69.Bl -tag -width compat
70.It Fn vh_unmount "mp"
71This hook is executed during the unmount process of a file system.
72.El
73.Pp
74For more information about the purpose of each operation, see
75.Xr vfsops 9 .
76Note that any of these fields may be a null pointer.
77.Pp
78After the definition of a
79.Ft struct vfs_hooks
80object, the kernel has to add it to the
81.Va vfs_hooks
82link set using the
83.Fn VFS_HOOKS_ATTACH "struct vfs_hooks *"
84macro.
85.Pp
86Please note that this interface is incomplete on purpose to keep it in its
87smallest possible size (i.e., do not provide a hook that is not used).
88If you feel the need to hook a routine to a VFS operation that is not yet
89supported by this interface, just add it to the files described in
90.Sx CODE REFERENCES .
91.Sh FUNCTIONS
92The following functions are provided to the VFS code to run the hooked
93functions:
94.Bl -tag -width compact
95.It Fn vfs_hooks_unmount "mp"
96Runs all hooks for the VFS unmount operation.
97Given that these operations shall not fail, it returns
98.Ft void .
99.El
100.Sh CODE REFERENCES
101The VFS hooks interface is implemented within the files
102.Pa sys/kern/vfs_hooks.c
103and
104.Pa sys/sys/mount.h .
105.Sh SEE ALSO
106.Xr intro 9 ,
107.Xr vfs 9 ,
108.Xr vfsops 9
109.Sh HISTORY
110The VFS hooks interface appeared in
111.Nx 4.0 .
112