1 #include "fs.h"
2 #include "buf.h"
3 #include "inode.h"
4
5
6 /* SEF functions and variables. */
7 static void sef_local_startup(void);
8 static int sef_cb_init_fresh(int type, sef_init_info_t *info);
9 static void sef_cb_signal_handler(int signo);
10
11 /*===========================================================================*
12 * main *
13 *===========================================================================*/
main(int argc,char * argv[])14 int main(int argc, char *argv[])
15 {
16 /* This is the main routine of this service. */
17
18 /* SEF local startup. */
19 env_setargs(argc, argv);
20 sef_local_startup();
21
22 /* The fsdriver library does the actual work here. */
23 fsdriver_task(&mfs_table);
24
25 return(0);
26 }
27
28 /*===========================================================================*
29 * sef_local_startup *
30 *===========================================================================*/
sef_local_startup()31 static void sef_local_startup()
32 {
33 /* Register init callbacks. */
34 sef_setcb_init_fresh(sef_cb_init_fresh);
35 sef_setcb_init_restart(SEF_CB_INIT_RESTART_STATEFUL);
36
37 /* Register signal callbacks. */
38 sef_setcb_signal_handler(sef_cb_signal_handler);
39
40 /* Let SEF perform startup. */
41 sef_startup();
42 }
43
44 /*===========================================================================*
45 * sef_cb_init_fresh *
46 *===========================================================================*/
sef_cb_init_fresh(int UNUSED (type),sef_init_info_t * UNUSED (info))47 static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
48 {
49 /* Initialize the Minix file server. */
50 int i;
51
52 lmfs_may_use_vmcache(1);
53
54 /* Init inode table */
55 for (i = 0; i < NR_INODES; ++i) {
56 inode[i].i_count = 0;
57 cch[i] = 0;
58 }
59
60 init_inode_cache();
61
62 lmfs_buf_pool(DEFAULT_NR_BUFS);
63
64 return(OK);
65 }
66
67 /*===========================================================================*
68 * sef_cb_signal_handler *
69 *===========================================================================*/
sef_cb_signal_handler(int signo)70 static void sef_cb_signal_handler(int signo)
71 {
72 /* Only check for termination signal, ignore anything else. */
73 if (signo != SIGTERM) return;
74
75 fs_sync();
76
77 fsdriver_terminate();
78 }
79
80
81 #if 0
82 /*===========================================================================*
83 * cch_check *
84 *===========================================================================*/
85 static void cch_check(void)
86 {
87 int i;
88
89 for (i = 0; i < NR_INODES; ++i) {
90 if (inode[i].i_count != cch[i] && req_nr != REQ_GETNODE &&
91 req_nr != REQ_PUTNODE && req_nr != REQ_READSUPER &&
92 req_nr != REQ_MOUNTPOINT && req_nr != REQ_UNMOUNT &&
93 req_nr != REQ_SYNC && req_nr != REQ_LOOKUP) {
94 printf("MFS(%d) inode(%lu) cc: %d req_nr: %d\n", sef_self(),
95 inode[i].i_num, inode[i].i_count - cch[i], req_nr);
96 }
97
98 cch[i] = inode[i].i_count;
99 }
100 }
101 #endif
102
103