1219820Sjeff/* 2219820Sjeff * Copyright (c) 2007-2009 Google Inc. 3219820Sjeff * All rights reserved. 4219820Sjeff * 5219820Sjeff * Redistribution and use in source and binary forms, with or without 6219820Sjeff * modification, are permitted provided that the following conditions are 7219820Sjeff * met: 8219820Sjeff * 9219820Sjeff * * Redistributions of source code must retain the above copyright 10219820Sjeff * notice, this list of conditions and the following disclaimer. 11219820Sjeff * * Redistributions in binary form must reproduce the above 12219820Sjeff * copyright notice, this list of conditions and the following disclaimer 13219820Sjeff * in the documentation and/or other materials provided with the 14219820Sjeff * distribution. 15219820Sjeff * * Neither the name of Google Inc. nor the names of its 16219820Sjeff * contributors may be used to endorse or promote products derived from 17219820Sjeff * this software without specific prior written permission. 18219820Sjeff * 19219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20219820Sjeff * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21219820Sjeff * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22219820Sjeff * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23219820Sjeff * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24219820Sjeff * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25219820Sjeff * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29219820Sjeff * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30219820Sjeff * 31219820Sjeff * Copyright (C) 2005 Csaba Henk. 32219820Sjeff * All rights reserved. 33219820Sjeff * 34219820Sjeff * Redistribution and use in source and binary forms, with or without 35219820Sjeff * modification, are permitted provided that the following conditions 36219820Sjeff * are met: 37219820Sjeff * 1. Redistributions of source code must retain the above copyright 38219820Sjeff * notice, this list of conditions and the following disclaimer. 39219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 40219820Sjeff * notice, this list of conditions and the following disclaimer in the 41 * documentation and/or other materials provided with the distribution. 42 * 43 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 46 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 53 * SUCH DAMAGE. 54 */ 55 56#include <sys/cdefs.h> 57__FBSDID("$FreeBSD: releng/11.0/sys/fs/fuse/fuse_main.c 273377 2014-10-21 07:31:21Z hselasky $"); 58 59#include <sys/types.h> 60#include <sys/module.h> 61#include <sys/systm.h> 62#include <sys/errno.h> 63#include <sys/param.h> 64#include <sys/kernel.h> 65#include <sys/conf.h> 66#include <sys/mutex.h> 67#include <sys/proc.h> 68#include <sys/mount.h> 69#include <sys/vnode.h> 70#include <sys/stat.h> 71#include <sys/file.h> 72#include <sys/buf.h> 73#include <sys/sysctl.h> 74 75#include "fuse.h" 76 77static void fuse_bringdown(eventhandler_tag eh_tag); 78static int fuse_loader(struct module *m, int what, void *arg); 79 80struct mtx fuse_mtx; 81 82extern struct vfsops fuse_vfsops; 83extern struct cdevsw fuse_cdevsw; 84extern struct vop_vector fuse_vnops; 85extern int fuse_pbuf_freecnt; 86 87static struct vfsconf fuse_vfsconf = { 88 .vfc_version = VFS_VERSION, 89 .vfc_name = "fusefs", 90 .vfc_vfsops = &fuse_vfsops, 91 .vfc_typenum = -1, 92 .vfc_flags = VFCF_SYNTHETIC 93}; 94 95SYSCTL_INT(_vfs_fuse, OID_AUTO, kernelabi_major, CTLFLAG_RD, 96 SYSCTL_NULL_INT_PTR, FUSE_KERNEL_VERSION, "FUSE kernel abi major version"); 97SYSCTL_INT(_vfs_fuse, OID_AUTO, kernelabi_minor, CTLFLAG_RD, 98 SYSCTL_NULL_INT_PTR, FUSE_KERNEL_MINOR_VERSION, "FUSE kernel abi minor version"); 99 100/****************************** 101 * 102 * >>> Module management stuff 103 * 104 ******************************/ 105 106static void 107fuse_bringdown(eventhandler_tag eh_tag) 108{ 109 110 fuse_ipc_destroy(); 111 fuse_device_destroy(); 112 mtx_destroy(&fuse_mtx); 113} 114 115static int 116fuse_loader(struct module *m, int what, void *arg) 117{ 118 static eventhandler_tag eh_tag = NULL; 119 int err = 0; 120 121 switch (what) { 122 case MOD_LOAD: /* kldload */ 123 fuse_pbuf_freecnt = nswbuf / 2 + 1; 124 mtx_init(&fuse_mtx, "fuse_mtx", NULL, MTX_DEF); 125 err = fuse_device_init(); 126 if (err) { 127 mtx_destroy(&fuse_mtx); 128 return (err); 129 } 130 fuse_ipc_init(); 131 132 /* vfs_modevent ignores its first arg */ 133 if ((err = vfs_modevent(NULL, what, &fuse_vfsconf))) 134 fuse_bringdown(eh_tag); 135 else 136 printf("fuse-freebsd: version %s, FUSE ABI %d.%d\n", 137 FUSE_FREEBSD_VERSION, 138 FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); 139 140 break; 141 case MOD_UNLOAD: 142 if ((err = vfs_modevent(NULL, what, &fuse_vfsconf))) 143 return (err); 144 fuse_bringdown(eh_tag); 145 break; 146 default: 147 return (EINVAL); 148 } 149 150 return (err); 151} 152 153/* Registering the module */ 154 155static moduledata_t fuse_moddata = { 156 "fuse", 157 fuse_loader, 158 &fuse_vfsconf 159}; 160 161DECLARE_MODULE(fuse, fuse_moddata, SI_SUB_VFS, SI_ORDER_MIDDLE); 162MODULE_VERSION(fuse, 1); 163