1 /* VTreeFS - vtreefs.c - by Alen Stojanov and David van Moolenbroek */ 2 3 #include "inc.h" 4 5 static unsigned int inodes; 6 static struct inode_stat *root_stat; 7 static index_t root_entries; 8 9 /*===========================================================================* 10 * init_server * 11 *===========================================================================*/ 12 static int init_server(int UNUSED(type), sef_init_info_t *UNUSED(info)) 13 { 14 /* Initialize internal state, and register with VFS. 15 */ 16 17 /* Initialize the virtual tree. */ 18 init_inodes(inodes, root_stat, root_entries); 19 20 return OK; 21 } 22 23 /*===========================================================================* 24 * got_signal * 25 *===========================================================================*/ 26 static void got_signal(int signal) 27 { 28 /* We received a signal. 29 */ 30 31 if (signal != SIGTERM) 32 return; 33 34 fsdriver_terminate(); 35 } 36 37 /*===========================================================================* 38 * sef_local_startup * 39 *===========================================================================*/ 40 static void sef_local_startup(void) 41 { 42 sef_setcb_init_fresh(init_server); 43 sef_setcb_init_restart(init_server); 44 45 sef_setcb_signal_handler(got_signal); 46 47 /* No support for live update yet. */ 48 49 sef_startup(); 50 } 51 52 /*===========================================================================* 53 * fs_other * 54 *===========================================================================*/ 55 void fs_other(const message *m_ptr, int __unused ipc_status) 56 { 57 /* We received a message that is not among the recognized file system 58 * requests. Call the message hook, if there is one. 59 */ 60 message msg; 61 62 if (vtreefs_hooks->message_hook != NULL) { 63 /* Not all of vtreefs's users play nice with the message, so 64 * make a copy to allow it to be modified. 65 */ 66 msg = *m_ptr; 67 68 vtreefs_hooks->message_hook(&msg); 69 } 70 } 71 72 /*===========================================================================* 73 * start_vtreefs * 74 *===========================================================================*/ 75 void start_vtreefs(struct fs_hooks *hooks, unsigned int nr_inodes, 76 struct inode_stat *stat, index_t nr_indexed_entries) 77 { 78 /* This is the main routine of this service. It uses the main loop as 79 * provided by the fsdriver library. The routine returns once the file 80 * system has been unmounted and the process is signaled to exit. 81 */ 82 83 /* Use global variables to work around the inability to pass parameters 84 * through SEF to the initialization function.. 85 */ 86 vtreefs_hooks = hooks; 87 inodes = nr_inodes; 88 root_stat = stat; 89 root_entries = nr_indexed_entries; 90 91 sef_local_startup(); 92 93 fsdriver_task(&vtreefs_table); 94 95 cleanup_inodes(); 96 } 97