1433d6423SLionel Sambuc #include "fs.h"
2433d6423SLionel Sambuc #include "buf.h"
3433d6423SLionel Sambuc #include "inode.h"
4*970d95ecSDavid van Moolenbroek #include <string.h>
5*970d95ecSDavid van Moolenbroek #include <minix/optset.h>
6433d6423SLionel Sambuc
7433d6423SLionel Sambuc /* SEF functions and variables. */
8433d6423SLionel Sambuc static void sef_local_startup(void);
9433d6423SLionel Sambuc static int sef_cb_init_fresh(int type, sef_init_info_t *info);
10433d6423SLionel Sambuc static void sef_cb_signal_handler(int signo);
11433d6423SLionel Sambuc
12433d6423SLionel Sambuc EXTERN int env_argc;
13433d6423SLionel Sambuc EXTERN char **env_argv;
14433d6423SLionel Sambuc
15433d6423SLionel Sambuc static struct optset optset_table[] = {
16433d6423SLionel Sambuc { "sb", OPT_INT, &opt.block_with_super, 0 },
17433d6423SLionel Sambuc { "orlov", OPT_BOOL, &opt.use_orlov, TRUE },
18433d6423SLionel Sambuc { "oldalloc", OPT_BOOL, &opt.use_orlov, FALSE },
19433d6423SLionel Sambuc { "mfsalloc", OPT_BOOL, &opt.mfsalloc, TRUE },
20433d6423SLionel Sambuc { "reserved", OPT_BOOL, &opt.use_reserved_blocks, TRUE },
21433d6423SLionel Sambuc { "prealloc", OPT_BOOL, &opt.use_prealloc, TRUE },
22433d6423SLionel Sambuc { "noprealloc", OPT_BOOL, &opt.use_prealloc, FALSE },
23433d6423SLionel Sambuc { NULL, 0, NULL, 0 }
24433d6423SLionel Sambuc };
25433d6423SLionel Sambuc
26433d6423SLionel Sambuc /*===========================================================================*
27433d6423SLionel Sambuc * main *
28433d6423SLionel Sambuc *===========================================================================*/
main(int argc,char * argv[])29433d6423SLionel Sambuc int main(int argc, char *argv[])
30433d6423SLionel Sambuc {
31*970d95ecSDavid van Moolenbroek /* This is the main routine of this service. */
32433d6423SLionel Sambuc unsigned short test_endian = 1;
33433d6423SLionel Sambuc
34433d6423SLionel Sambuc /* SEF local startup. */
35433d6423SLionel Sambuc env_setargs(argc, argv);
36433d6423SLionel Sambuc sef_local_startup();
37433d6423SLionel Sambuc
38433d6423SLionel Sambuc le_CPU = (*(unsigned char *) &test_endian == 0 ? 0 : 1);
39433d6423SLionel Sambuc
40433d6423SLionel Sambuc /* Server isn't tested on big endian CPU */
41433d6423SLionel Sambuc ASSERT(le_CPU == 1);
42433d6423SLionel Sambuc
43*970d95ecSDavid van Moolenbroek /* The fsdriver library does the actual work here. */
44*970d95ecSDavid van Moolenbroek fsdriver_task(&ext2_table);
45433d6423SLionel Sambuc
46433d6423SLionel Sambuc return 0;
47433d6423SLionel Sambuc }
48433d6423SLionel Sambuc
49433d6423SLionel Sambuc /*===========================================================================*
50433d6423SLionel Sambuc * sef_local_startup *
51433d6423SLionel Sambuc *===========================================================================*/
sef_local_startup()52433d6423SLionel Sambuc static void sef_local_startup()
53433d6423SLionel Sambuc {
54433d6423SLionel Sambuc /* Register init callbacks. */
55433d6423SLionel Sambuc sef_setcb_init_fresh(sef_cb_init_fresh);
56433d6423SLionel Sambuc
57433d6423SLionel Sambuc /* Register signal callbacks. */
58433d6423SLionel Sambuc sef_setcb_signal_handler(sef_cb_signal_handler);
59433d6423SLionel Sambuc
60433d6423SLionel Sambuc /* Let SEF perform startup. */
61433d6423SLionel Sambuc sef_startup();
62433d6423SLionel Sambuc }
63433d6423SLionel Sambuc
64433d6423SLionel Sambuc /*===========================================================================*
65433d6423SLionel Sambuc * sef_cb_init_fresh *
66433d6423SLionel Sambuc *===========================================================================*/
sef_cb_init_fresh(int UNUSED (type),sef_init_info_t * UNUSED (info))67433d6423SLionel Sambuc static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
68433d6423SLionel Sambuc {
69433d6423SLionel Sambuc /* Initialize the Minix file server. */
70433d6423SLionel Sambuc int i;
71433d6423SLionel Sambuc
72433d6423SLionel Sambuc /* Defaults */
73433d6423SLionel Sambuc opt.use_orlov = TRUE;
74433d6423SLionel Sambuc opt.mfsalloc = FALSE;
75433d6423SLionel Sambuc opt.use_reserved_blocks = FALSE;
76433d6423SLionel Sambuc opt.block_with_super = 0;
77433d6423SLionel Sambuc opt.use_prealloc = FALSE;
78433d6423SLionel Sambuc
79433d6423SLionel Sambuc /* If we have been given an options string, parse options from there. */
80433d6423SLionel Sambuc for (i = 1; i < env_argc - 1; i++)
81433d6423SLionel Sambuc if (!strcmp(env_argv[i], "-o"))
82433d6423SLionel Sambuc optset_parse(optset_table, env_argv[++i]);
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc lmfs_may_use_vmcache(1);
85433d6423SLionel Sambuc
86433d6423SLionel Sambuc /* Init inode table */
87433d6423SLionel Sambuc for (i = 0; i < NR_INODES; ++i) {
88433d6423SLionel Sambuc inode[i].i_count = 0;
89433d6423SLionel Sambuc cch[i] = 0;
90433d6423SLionel Sambuc }
91433d6423SLionel Sambuc
92433d6423SLionel Sambuc init_inode_cache();
93433d6423SLionel Sambuc
94433d6423SLionel Sambuc /* just a small number before we find out the block size at mount time */
95433d6423SLionel Sambuc lmfs_buf_pool(10);
96433d6423SLionel Sambuc
97433d6423SLionel Sambuc return(OK);
98433d6423SLionel Sambuc }
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc /*===========================================================================*
101433d6423SLionel Sambuc * sef_cb_signal_handler *
102433d6423SLionel Sambuc *===========================================================================*/
sef_cb_signal_handler(int signo)103433d6423SLionel Sambuc static void sef_cb_signal_handler(int signo)
104433d6423SLionel Sambuc {
105433d6423SLionel Sambuc /* Only check for termination signal, ignore anything else. */
106433d6423SLionel Sambuc if (signo != SIGTERM) return;
107433d6423SLionel Sambuc
108*970d95ecSDavid van Moolenbroek fs_sync();
109433d6423SLionel Sambuc
110*970d95ecSDavid van Moolenbroek fsdriver_terminate();
111433d6423SLionel Sambuc }
112