xref: /minix/minix/fs/ext2/main.c (revision 0a6a1f1d)
1 #include "fs.h"
2 #include "buf.h"
3 #include "inode.h"
4 #include <string.h>
5 #include <minix/optset.h>
6 
7 /* SEF functions and variables. */
8 static void sef_local_startup(void);
9 static int sef_cb_init_fresh(int type, sef_init_info_t *info);
10 static void sef_cb_signal_handler(int signo);
11 
12 EXTERN int env_argc;
13 EXTERN char **env_argv;
14 
15 static struct optset optset_table[] = {
16   { "sb",		OPT_INT,    &opt.block_with_super,	0	},
17   { "orlov",		OPT_BOOL,   &opt.use_orlov,		TRUE    },
18   { "oldalloc",		OPT_BOOL,   &opt.use_orlov,		FALSE   },
19   { "mfsalloc",		OPT_BOOL,   &opt.mfsalloc,		TRUE    },
20   { "reserved",		OPT_BOOL,   &opt.use_reserved_blocks,	TRUE    },
21   { "prealloc",		OPT_BOOL,   &opt.use_prealloc, 		TRUE	},
22   { "noprealloc",	OPT_BOOL,   &opt.use_prealloc, 		FALSE	},
23   { NULL,		0,	    NULL,			0	}
24 };
25 
26 /*===========================================================================*
27  *				main                                         *
28  *===========================================================================*/
29 int main(int argc, char *argv[])
30 {
31 /* This is the main routine of this service. */
32   unsigned short test_endian = 1;
33 
34   /* SEF local startup. */
35   env_setargs(argc, argv);
36   sef_local_startup();
37 
38   le_CPU = (*(unsigned char *) &test_endian == 0 ? 0 : 1);
39 
40   /* Server isn't tested on big endian CPU */
41   ASSERT(le_CPU == 1);
42 
43   /* The fsdriver library does the actual work here. */
44   fsdriver_task(&ext2_table);
45 
46   return 0;
47 }
48 
49 /*===========================================================================*
50  *			       sef_local_startup			     *
51  *===========================================================================*/
52 static void sef_local_startup()
53 {
54   /* Register init callbacks. */
55   sef_setcb_init_fresh(sef_cb_init_fresh);
56 
57   /* Register signal callbacks. */
58   sef_setcb_signal_handler(sef_cb_signal_handler);
59 
60   /* Let SEF perform startup. */
61   sef_startup();
62 }
63 
64 /*===========================================================================*
65  *		            sef_cb_init_fresh                                *
66  *===========================================================================*/
67 static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
68 {
69 /* Initialize the Minix file server. */
70   int i;
71 
72   /* Defaults */
73   opt.use_orlov = TRUE;
74   opt.mfsalloc = FALSE;
75   opt.use_reserved_blocks = FALSE;
76   opt.block_with_super = 0;
77   opt.use_prealloc = FALSE;
78 
79   /* If we have been given an options string, parse options from there. */
80   for (i = 1; i < env_argc - 1; i++)
81 	if (!strcmp(env_argv[i], "-o"))
82 		optset_parse(optset_table, env_argv[++i]);
83 
84   lmfs_may_use_vmcache(1);
85 
86   /* Init inode table */
87   for (i = 0; i < NR_INODES; ++i) {
88 	inode[i].i_count = 0;
89 	cch[i] = 0;
90   }
91 
92   init_inode_cache();
93 
94   /* just a small number before we find out the block size at mount time */
95   lmfs_buf_pool(10);
96 
97   return(OK);
98 }
99 
100 /*===========================================================================*
101  *		           sef_cb_signal_handler                             *
102  *===========================================================================*/
103 static void sef_cb_signal_handler(int signo)
104 {
105   /* Only check for termination signal, ignore anything else. */
106   if (signo != SIGTERM) return;
107 
108   fs_sync();
109 
110   fsdriver_terminate();
111 }
112