/core/10.4/fusefs/fuse_main.c
C | 167 lines | 128 code | 35 blank | 4 comment | 30 complexity | 599fbb664f1a93c93e1d39378480ea9d MD5 | raw file
1/* 2 * Copyright (C) 2006-2008 Google. All Rights Reserved. 3 * Amit Singh <singh@> 4 */ 5 6#include <sys/param.h> 7#include <sys/systm.h> 8#include <sys/conf.h> 9#include <mach/mach_types.h> 10#include <miscfs/devfs/devfs.h> 11 12#include <libkern/libkern.h> 13#include <libkern/OSMalloc.h> 14#include <libkern/locks.h> 15 16#include "fuse.h" 17#include "fuse_device.h" 18#include "fuse_ipc.h" 19#include "fuse_locking.h" 20#include "fuse_node.h" 21#include "fuse_nodehash.h" 22#include "fuse_sysctl.h" 23#include <fuse_mount.h> 24 25OSMallocTag fuse_malloc_tag = NULL; 26 27extern struct vfs_fsentry fuse_vfs_entry; 28extern vfstable_t fuse_vfs_table_ref; 29 30kern_return_t fusefs_start(kmod_info_t *ki, void *d); 31kern_return_t fusefs_stop(kmod_info_t *ki, void *d); 32 33static void 34fini_stuff(void) 35{ 36 if (fuse_device_mutex) { 37 lck_mtx_free(fuse_device_mutex, fuse_lock_group); 38 fuse_device_mutex = NULL; 39 } 40 41 if (fuse_lock_group) { 42 lck_grp_free(fuse_lock_group); 43 fuse_lock_group = NULL; 44 } 45 46 if (fuse_malloc_tag) { 47 OSMalloc_Tagfree(fuse_malloc_tag); 48 fuse_malloc_tag = NULL; 49 } 50 51 if (fuse_lock_attr) { 52 lck_attr_free(fuse_lock_attr); 53 fuse_lock_attr = NULL; 54 } 55 56 if (fuse_group_attr) { 57 lck_grp_attr_free(fuse_group_attr); 58 fuse_group_attr = NULL; 59 } 60} 61 62static kern_return_t 63init_stuff(void) 64{ 65 kern_return_t ret = KERN_SUCCESS; 66 67 fuse_malloc_tag = OSMalloc_Tagalloc(MACFUSE_BUNDLE_IDENTIFIER, 68 OSMT_DEFAULT); 69 if (fuse_malloc_tag == NULL) { 70 ret = KERN_FAILURE; 71 } 72 73 fuse_lock_attr = lck_attr_alloc_init(); 74 fuse_group_attr = lck_grp_attr_alloc_init(); 75 lck_attr_setdebug(fuse_lock_attr); 76 77 if (ret == KERN_SUCCESS) { 78 fuse_lock_group = lck_grp_alloc_init(MACFUSE_BUNDLE_IDENTIFIER, 79 fuse_group_attr); 80 if (fuse_lock_group == NULL) { 81 ret = KERN_FAILURE; 82 } 83 } 84 85 if (ret == KERN_SUCCESS) { 86 fuse_device_mutex = lck_mtx_alloc_init(fuse_lock_group, fuse_lock_attr); 87 if (fuse_device_mutex == NULL) { 88 ret = ENOMEM; 89 } 90 } 91 92 if (ret != KERN_SUCCESS) { 93 fini_stuff(); 94 } 95 96 return ret; 97} 98 99kern_return_t 100fusefs_start(__unused kmod_info_t *ki, __unused void *d) 101{ 102 int ret; 103 104 ret = init_stuff(); 105 if (ret != KERN_SUCCESS) { 106 return KERN_FAILURE; 107 } 108 109 ret = HNodeInit(fuse_lock_group, fuse_lock_attr, fuse_malloc_tag, 110 kHNodeMagic, sizeof(struct fuse_vnode_data)); 111 if (ret != KERN_SUCCESS) { 112 goto error; 113 } 114 115 ret = vfs_fsadd(&fuse_vfs_entry, &fuse_vfs_table_ref); 116 if (ret != 0) { 117 fuse_vfs_table_ref = NULL; 118 goto error; 119 } 120 121 ret = fuse_devices_start(); 122 if (ret != KERN_SUCCESS) { 123 goto error; 124 } 125 126 fuse_sysctl_start(); 127 128 IOLog("MacFUSE: starting (version %s, %s)\n", 129 MACFUSE_VERSION, MACFUSE_TIMESTAMP); 130 131 return KERN_SUCCESS; 132 133error: 134 if (fuse_vfs_table_ref) { 135 (void)vfs_fsremove(fuse_vfs_table_ref); 136 } 137 HNodeTerm(); 138 fini_stuff(); 139 140 return KERN_FAILURE; 141} 142 143kern_return_t 144fusefs_stop(__unused kmod_info_t *ki, __unused void *d) 145{ 146 int ret; 147 148 ret = fuse_devices_stop(); 149 if (ret != KERN_SUCCESS) { 150 return KERN_FAILURE; 151 } 152 153 ret = vfs_fsremove(fuse_vfs_table_ref); 154 if (ret != KERN_SUCCESS) { 155 return KERN_FAILURE; 156 } 157 158 HNodeTerm(); 159 fini_stuff(); 160 161 fuse_sysctl_stop(); 162 163 IOLog("MacFUSE: stopping (version %s, %s)\n", 164 MACFUSE_VERSION, MACFUSE_TIMESTAMP); 165 166 return KERN_SUCCESS; 167}