1 /* $NetBSD: vfs_hooks.c,v 1.3 2008/04/28 20:24:05 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Julio M. Merino Vidal. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * VFS hooks. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: vfs_hooks.c,v 1.3 2008/04/28 20:24:05 martin Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/mount.h> 41 42 /* 43 * Static list of file system specific hook sets supported by the kernel. 44 */ 45 __link_set_decl(vfs_hooks, struct vfs_hooks); 46 47 /* 48 * Initialize a VFS hook set that does nothing. This is to ensure that 49 * we have, at the very least, one item in the link set. Otherwise, 50 * ld(1) will complain. 51 */ 52 static struct vfs_hooks null_hooks = { 53 NULL /* vh_unmount */ 54 }; 55 VFS_HOOKS_ATTACH(null_hooks); 56 57 /* 58 * Macro to be used in one of the vfs_hooks_* function for hooks that 59 * return an error code. Calls will stop as soon as one of the hooks 60 * fails. 61 */ 62 #define VFS_HOOKS_W_ERROR(func, args) \ 63 int error; \ 64 struct vfs_hooks * const *hp; \ 65 \ 66 error = 0; \ 67 \ 68 __link_set_foreach(hp, vfs_hooks) { \ 69 if ((*hp)-> func != NULL) { \ 70 error = (*hp)-> func args; \ 71 if (error != 0) \ 72 break; \ 73 } \ 74 } \ 75 \ 76 return error; 77 78 /* 79 * Macro to be used in one of the vfs_hooks_* function for hooks that 80 * do not return any error code. All hooks will be executed 81 * unconditionally. 82 */ 83 #define VFS_HOOKS_WO_ERROR(func, fargs, hook, hargs) \ 84 void \ 85 func fargs \ 86 { \ 87 struct vfs_hooks * const *hp; \ 88 \ 89 __link_set_foreach(hp, vfs_hooks) { \ 90 if ((*hp)-> hook != NULL) \ 91 (*hp)-> hook hargs; \ 92 } \ 93 } 94 95 /* 96 * Routines to iterate over VFS hooks lists and execute them. 97 */ 98 99 VFS_HOOKS_WO_ERROR(vfs_hooks_unmount, (struct mount *mp), vh_unmount, (mp)); 100 101 /* 102 void 103 vfs_hooks_unmount(struct mount *mp) 104 { 105 106 VFS_HOOKS_WO_ERROR(vh_unmount, (mp)); 107 } 108 */ 109