etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libvtreefs / vtreefs.c
blob291649e0cc2802507c1f2310f66604f735fc53ce
1 /* VTreeFS - vtreefs.c - initialization and message loop */
3 #include "inc.h"
5 static unsigned int inodes;
6 static struct inode_stat *root_stat;
7 static index_t root_entries;
8 static size_t buf_size;
9 static size_t extra_size;
12 * Initialize internal state. This is the only place where dynamic memory
13 * allocation takes place.
15 static int
16 init_server(int __unused type, sef_init_info_t * __unused info)
18 int r;
20 /* Initialize the virtual tree. */
21 if ((r = init_inodes(inodes, root_stat, root_entries)) != OK)
22 panic("init_inodes failed: %d", r);
24 /* Initialize extra data. */
25 if ((r = init_extra(inodes, extra_size)) != OK)
26 panic("init_extra failed: %d", r);
28 /* Initialize the I/O buffer. */
29 if ((r = init_buf(buf_size)) != OK)
30 panic("init_buf failed: %d", r);
32 return OK;
36 * We received a signal.
38 static void
39 got_signal(int sig)
42 if (sig != SIGTERM)
43 return;
45 fsdriver_terminate();
49 * SEF initialization.
51 static void
52 sef_local_startup(void)
54 sef_setcb_init_fresh(init_server);
55 sef_setcb_init_restart(SEF_CB_INIT_RESTART_STATEFUL);
57 sef_setcb_signal_handler(got_signal);
59 sef_startup();
63 * We have received a message that is not a file system request from VFS.
64 * Call the message hook, if there is one.
66 void
67 fs_other(const message * m_ptr, int ipc_status)
69 message msg;
71 if (vtreefs_hooks->message_hook != NULL) {
73 * Not all of vtreefs's users play nice with the message, so
74 * make a copy to allow it to be modified.
76 msg = *m_ptr;
78 vtreefs_hooks->message_hook(&msg, ipc_status);
83 * This is the main routine of this service. It uses the main loop as provided
84 * by the fsdriver library. The routine returns once the file system has been
85 * unmounted and the process is signaled to exit.
87 void
88 run_vtreefs(struct fs_hooks * hooks, unsigned int nr_inodes,
89 size_t inode_extra, struct inode_stat * istat,
90 index_t nr_indexed_entries, size_t bufsize)
94 * Use global variables to work around the inability to pass parameters
95 * through SEF to the initialization function..
97 vtreefs_hooks = hooks;
98 inodes = nr_inodes;
99 extra_size = inode_extra;
100 root_stat = istat;
101 root_entries = nr_indexed_entries;
102 buf_size = bufsize;
104 sef_local_startup();
106 fsdriver_task(&vtreefs_table);
108 cleanup_buf();
109 cleanup_inodes();