15fe58019SAttilio Rao /* 25fe58019SAttilio Rao * Copyright (c) 2007-2009 Google Inc. 35fe58019SAttilio Rao * All rights reserved. 45fe58019SAttilio Rao * 55fe58019SAttilio Rao * Redistribution and use in source and binary forms, with or without 65fe58019SAttilio Rao * modification, are permitted provided that the following conditions are 75fe58019SAttilio Rao * met: 85fe58019SAttilio Rao * 95fe58019SAttilio Rao * * Redistributions of source code must retain the above copyright 105fe58019SAttilio Rao * notice, this list of conditions and the following disclaimer. 115fe58019SAttilio Rao * * Redistributions in binary form must reproduce the above 125fe58019SAttilio Rao * copyright notice, this list of conditions and the following disclaimer 135fe58019SAttilio Rao * in the documentation and/or other materials provided with the 145fe58019SAttilio Rao * distribution. 155fe58019SAttilio Rao * * Neither the name of Google Inc. nor the names of its 165fe58019SAttilio Rao * contributors may be used to endorse or promote products derived from 175fe58019SAttilio Rao * this software without specific prior written permission. 185fe58019SAttilio Rao * 195fe58019SAttilio Rao * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 205fe58019SAttilio Rao * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 215fe58019SAttilio Rao * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 225fe58019SAttilio Rao * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 235fe58019SAttilio Rao * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 245fe58019SAttilio Rao * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 255fe58019SAttilio Rao * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 265fe58019SAttilio Rao * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 275fe58019SAttilio Rao * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 285fe58019SAttilio Rao * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 295fe58019SAttilio Rao * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 305fe58019SAttilio Rao * 315fe58019SAttilio Rao * Copyright (C) 2005 Csaba Henk. 325fe58019SAttilio Rao * All rights reserved. 335fe58019SAttilio Rao * 345fe58019SAttilio Rao * Redistribution and use in source and binary forms, with or without 355fe58019SAttilio Rao * modification, are permitted provided that the following conditions 365fe58019SAttilio Rao * are met: 375fe58019SAttilio Rao * 1. Redistributions of source code must retain the above copyright 385fe58019SAttilio Rao * notice, this list of conditions and the following disclaimer. 395fe58019SAttilio Rao * 2. Redistributions in binary form must reproduce the above copyright 405fe58019SAttilio Rao * notice, this list of conditions and the following disclaimer in the 415fe58019SAttilio Rao * documentation and/or other materials provided with the distribution. 425fe58019SAttilio Rao * 435fe58019SAttilio Rao * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 445fe58019SAttilio Rao * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 455fe58019SAttilio Rao * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 465fe58019SAttilio Rao * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 475fe58019SAttilio Rao * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 485fe58019SAttilio Rao * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 495fe58019SAttilio Rao * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 505fe58019SAttilio Rao * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 515fe58019SAttilio Rao * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 525fe58019SAttilio Rao * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 535fe58019SAttilio Rao * SUCH DAMAGE. 545fe58019SAttilio Rao */ 555fe58019SAttilio Rao 565fe58019SAttilio Rao #include <sys/cdefs.h> 575fe58019SAttilio Rao __FBSDID("$FreeBSD$"); 585fe58019SAttilio Rao 595fe58019SAttilio Rao #include <sys/types.h> 605fe58019SAttilio Rao #include <sys/module.h> 615fe58019SAttilio Rao #include <sys/systm.h> 625fe58019SAttilio Rao #include <sys/errno.h> 635fe58019SAttilio Rao #include <sys/param.h> 645fe58019SAttilio Rao #include <sys/kernel.h> 655fe58019SAttilio Rao #include <sys/conf.h> 665fe58019SAttilio Rao #include <sys/mutex.h> 675fe58019SAttilio Rao #include <sys/proc.h> 685fe58019SAttilio Rao #include <sys/mount.h> 695fe58019SAttilio Rao #include <sys/vnode.h> 705fe58019SAttilio Rao #include <sys/stat.h> 715fe58019SAttilio Rao #include <sys/file.h> 725fe58019SAttilio Rao #include <sys/buf.h> 735fe58019SAttilio Rao #include <sys/sysctl.h> 745fe58019SAttilio Rao 755fe58019SAttilio Rao #include "fuse.h" 765fe58019SAttilio Rao 775fe58019SAttilio Rao static void fuse_bringdown(eventhandler_tag eh_tag); 785fe58019SAttilio Rao static int fuse_loader(struct module *m, int what, void *arg); 795fe58019SAttilio Rao 805fe58019SAttilio Rao struct mtx fuse_mtx; 815fe58019SAttilio Rao 825fe58019SAttilio Rao extern struct vfsops fuse_vfsops; 835fe58019SAttilio Rao extern struct cdevsw fuse_cdevsw; 845fe58019SAttilio Rao extern struct vop_vector fuse_vnops; 855fe58019SAttilio Rao extern int fuse_pbuf_freecnt; 865fe58019SAttilio Rao 875fe58019SAttilio Rao static struct vfsconf fuse_vfsconf = { 885fe58019SAttilio Rao .vfc_version = VFS_VERSION, 895fe58019SAttilio Rao .vfc_name = "fusefs", 905fe58019SAttilio Rao .vfc_vfsops = &fuse_vfsops, 915fe58019SAttilio Rao .vfc_typenum = -1, 925fe58019SAttilio Rao .vfc_flags = VFCF_SYNTHETIC 935fe58019SAttilio Rao }; 945fe58019SAttilio Rao 955fe58019SAttilio Rao SYSCTL_INT(_vfs_fuse, OID_AUTO, kernelabi_major, CTLFLAG_RD, 96*f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, FUSE_KERNEL_VERSION, "FUSE kernel abi major version"); 975fe58019SAttilio Rao SYSCTL_INT(_vfs_fuse, OID_AUTO, kernelabi_minor, CTLFLAG_RD, 98*f0188618SHans Petter Selasky SYSCTL_NULL_INT_PTR, FUSE_KERNEL_MINOR_VERSION, "FUSE kernel abi minor version"); 995fe58019SAttilio Rao 1005fe58019SAttilio Rao /****************************** 1015fe58019SAttilio Rao * 1025fe58019SAttilio Rao * >>> Module management stuff 1035fe58019SAttilio Rao * 1045fe58019SAttilio Rao ******************************/ 1055fe58019SAttilio Rao 1065fe58019SAttilio Rao static void 1075fe58019SAttilio Rao fuse_bringdown(eventhandler_tag eh_tag) 1085fe58019SAttilio Rao { 1095fe58019SAttilio Rao 1105fe58019SAttilio Rao fuse_ipc_destroy(); 1115fe58019SAttilio Rao fuse_device_destroy(); 1125fe58019SAttilio Rao mtx_destroy(&fuse_mtx); 1135fe58019SAttilio Rao } 1145fe58019SAttilio Rao 1155fe58019SAttilio Rao static int 1165fe58019SAttilio Rao fuse_loader(struct module *m, int what, void *arg) 1175fe58019SAttilio Rao { 1185fe58019SAttilio Rao static eventhandler_tag eh_tag = NULL; 1195fe58019SAttilio Rao int err = 0; 1205fe58019SAttilio Rao 1215fe58019SAttilio Rao switch (what) { 1225fe58019SAttilio Rao case MOD_LOAD: /* kldload */ 1235fe58019SAttilio Rao fuse_pbuf_freecnt = nswbuf / 2 + 1; 1245fe58019SAttilio Rao mtx_init(&fuse_mtx, "fuse_mtx", NULL, MTX_DEF); 1255fe58019SAttilio Rao err = fuse_device_init(); 1265fe58019SAttilio Rao if (err) { 1275fe58019SAttilio Rao mtx_destroy(&fuse_mtx); 1285fe58019SAttilio Rao return (err); 1295fe58019SAttilio Rao } 1305fe58019SAttilio Rao fuse_ipc_init(); 1315fe58019SAttilio Rao 1325fe58019SAttilio Rao /* vfs_modevent ignores its first arg */ 1335fe58019SAttilio Rao if ((err = vfs_modevent(NULL, what, &fuse_vfsconf))) 1345fe58019SAttilio Rao fuse_bringdown(eh_tag); 1355fe58019SAttilio Rao else 1365fe58019SAttilio Rao printf("fuse-freebsd: version %s, FUSE ABI %d.%d\n", 1375fe58019SAttilio Rao FUSE_FREEBSD_VERSION, 1385fe58019SAttilio Rao FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); 1395fe58019SAttilio Rao 1405fe58019SAttilio Rao break; 1415fe58019SAttilio Rao case MOD_UNLOAD: 1425fe58019SAttilio Rao if ((err = vfs_modevent(NULL, what, &fuse_vfsconf))) 1435fe58019SAttilio Rao return (err); 1445fe58019SAttilio Rao fuse_bringdown(eh_tag); 1455fe58019SAttilio Rao break; 1465fe58019SAttilio Rao default: 1475fe58019SAttilio Rao return (EINVAL); 1485fe58019SAttilio Rao } 1495fe58019SAttilio Rao 1505fe58019SAttilio Rao return (err); 1515fe58019SAttilio Rao } 1525fe58019SAttilio Rao 1535fe58019SAttilio Rao /* Registering the module */ 1545fe58019SAttilio Rao 1555fe58019SAttilio Rao static moduledata_t fuse_moddata = { 1565fe58019SAttilio Rao "fuse", 1575fe58019SAttilio Rao fuse_loader, 1585fe58019SAttilio Rao &fuse_vfsconf 1595fe58019SAttilio Rao }; 1605fe58019SAttilio Rao 1615fe58019SAttilio Rao DECLARE_MODULE(fuse, fuse_moddata, SI_SUB_VFS, SI_ORDER_MIDDLE); 1625fe58019SAttilio Rao MODULE_VERSION(fuse, 1); 163