xref: /minix3/minix/fs/vbfs/vbfs.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /* This file contains the implementation of the VBFS file system server. */
2*433d6423SLionel Sambuc /*
3*433d6423SLionel Sambuc  * The architecture of VBFS can be sketched as follows:
4*433d6423SLionel Sambuc  *
5*433d6423SLionel Sambuc  *     +-------------+
6*433d6423SLionel Sambuc  *     |    VBFS     |		This file
7*433d6423SLionel Sambuc  *     +-------------+
8*433d6423SLionel Sambuc  *            |
9*433d6423SLionel Sambuc  *     +-------------+
10*433d6423SLionel Sambuc  *     |   libsffs   |		Shared Folder File System library
11*433d6423SLionel Sambuc  *     +-------------+
12*433d6423SLionel Sambuc  *            |
13*433d6423SLionel Sambuc  *     +-------------+
14*433d6423SLionel Sambuc  *     |  libvboxfs  |		VirtualBox File System library
15*433d6423SLionel Sambuc  *     +-------------+
16*433d6423SLionel Sambuc  *            |
17*433d6423SLionel Sambuc  *     +-------------+
18*433d6423SLionel Sambuc  *     | libsys/vbox |		VBOX driver interfacing library
19*433d6423SLionel Sambuc  *     +-------------+
20*433d6423SLionel Sambuc  *  --------  |  -------- 		(process boundary)
21*433d6423SLionel Sambuc  *     +-------------+
22*433d6423SLionel Sambuc  *     | VBOX driver |		VirtualBox backdoor driver
23*433d6423SLionel Sambuc  *     +-------------+
24*433d6423SLionel Sambuc  *  ========  |  ======== 		(system boundary)
25*433d6423SLionel Sambuc  *     +-------------+
26*433d6423SLionel Sambuc  *     | VirtualBox  |		The host system
27*433d6423SLionel Sambuc  *     +-------------+
28*433d6423SLionel Sambuc  *
29*433d6423SLionel Sambuc  * The interfaces between the layers are defined in the following header files:
30*433d6423SLionel Sambuc  *   minix/sffs.h:	shared between VBFS, libsffs, and libvboxfs
31*433d6423SLionel Sambuc  *   minix/vboxfs.h:	shared between VBFS and libvboxfs
32*433d6423SLionel Sambuc  *   minix/vbox.h:	shared between libvboxfs and libsys/vbox
33*433d6423SLionel Sambuc  *   minix/vboxtype.h:	shared between libvboxfs, libsys/vbox, and VBOX
34*433d6423SLionel Sambuc  *   minix/vboxif.h:	shared between libsys/vbox and VBOX
35*433d6423SLionel Sambuc  */
36*433d6423SLionel Sambuc 
37*433d6423SLionel Sambuc #include <minix/drivers.h>
38*433d6423SLionel Sambuc #include <minix/sffs.h>
39*433d6423SLionel Sambuc #include <minix/vboxfs.h>
40*433d6423SLionel Sambuc #include <minix/optset.h>
41*433d6423SLionel Sambuc 
42*433d6423SLionel Sambuc static char share[PATH_MAX];
43*433d6423SLionel Sambuc static struct sffs_params params;
44*433d6423SLionel Sambuc 
45*433d6423SLionel Sambuc static struct optset optset_table[] = {
46*433d6423SLionel Sambuc 	{ "share",  OPT_STRING, share,               sizeof(share)           },
47*433d6423SLionel Sambuc 	{ "prefix", OPT_STRING, params.p_prefix,     sizeof(params.p_prefix) },
48*433d6423SLionel Sambuc 	{ "uid",    OPT_INT,    &params.p_uid,       10                      },
49*433d6423SLionel Sambuc 	{ "gid",    OPT_INT,    &params.p_gid,       10                      },
50*433d6423SLionel Sambuc 	{ "fmask",  OPT_INT,    &params.p_file_mask, 8                       },
51*433d6423SLionel Sambuc 	{ "dmask",  OPT_INT,    &params.p_dir_mask,  8                       },
52*433d6423SLionel Sambuc 	{ NULL,     0,          NULL,                0                       }
53*433d6423SLionel Sambuc };
54*433d6423SLionel Sambuc 
55*433d6423SLionel Sambuc /*
56*433d6423SLionel Sambuc  * Initialize this file server. Called at startup time.
57*433d6423SLionel Sambuc  */
58*433d6423SLionel Sambuc static int
init(int UNUSED (type),sef_init_info_t * UNUSED (info))59*433d6423SLionel Sambuc init(int UNUSED(type), sef_init_info_t *UNUSED(info))
60*433d6423SLionel Sambuc {
61*433d6423SLionel Sambuc 	const struct sffs_table *table;
62*433d6423SLionel Sambuc 	int i, r, roflag;
63*433d6423SLionel Sambuc 
64*433d6423SLionel Sambuc 	/* Set defaults. */
65*433d6423SLionel Sambuc 	share[0] = 0;
66*433d6423SLionel Sambuc 	params.p_prefix[0] = 0;
67*433d6423SLionel Sambuc 	params.p_uid = 0;
68*433d6423SLionel Sambuc 	params.p_gid = 0;
69*433d6423SLionel Sambuc 	params.p_file_mask = 0755;
70*433d6423SLionel Sambuc 	params.p_dir_mask = 0755;
71*433d6423SLionel Sambuc 	params.p_case_insens = FALSE;
72*433d6423SLionel Sambuc 
73*433d6423SLionel Sambuc 	/* We must have been given an options string. Parse the options. */
74*433d6423SLionel Sambuc 	for (i = 1; i < env_argc - 1; i++)
75*433d6423SLionel Sambuc 		if (!strcmp(env_argv[i], "-o"))
76*433d6423SLionel Sambuc 			optset_parse(optset_table, env_argv[++i]);
77*433d6423SLionel Sambuc 
78*433d6423SLionel Sambuc 	/* A share name is required. */
79*433d6423SLionel Sambuc 	if (!share[0]) {
80*433d6423SLionel Sambuc 		printf("VBFS: no shared folder share name specified\n");
81*433d6423SLionel Sambuc 
82*433d6423SLionel Sambuc 		return EINVAL;
83*433d6423SLionel Sambuc 	}
84*433d6423SLionel Sambuc 
85*433d6423SLionel Sambuc 	/* Initialize the VBOXFS library. If this fails, exit immediately. */
86*433d6423SLionel Sambuc 	r = vboxfs_init(share, &table, &params.p_case_insens, &roflag);
87*433d6423SLionel Sambuc 
88*433d6423SLionel Sambuc 	if (r != OK) {
89*433d6423SLionel Sambuc 		if (r == ENOENT)
90*433d6423SLionel Sambuc 			printf("VBFS: the given share does not exist\n");
91*433d6423SLionel Sambuc 		else
92*433d6423SLionel Sambuc 			printf("VBFS: unable to initialize VBOXFS (%d)\n", r);
93*433d6423SLionel Sambuc 
94*433d6423SLionel Sambuc 		return r;
95*433d6423SLionel Sambuc 	}
96*433d6423SLionel Sambuc 
97*433d6423SLionel Sambuc 	/* Now initialize the SFFS library. */
98*433d6423SLionel Sambuc 	if ((r = sffs_init("VBFS", table, &params)) != OK) {
99*433d6423SLionel Sambuc 		vboxfs_cleanup();
100*433d6423SLionel Sambuc 
101*433d6423SLionel Sambuc 		return r;
102*433d6423SLionel Sambuc 	}
103*433d6423SLionel Sambuc 
104*433d6423SLionel Sambuc 	return OK;
105*433d6423SLionel Sambuc }
106*433d6423SLionel Sambuc 
107*433d6423SLionel Sambuc /*
108*433d6423SLionel Sambuc  * Local SEF initialization.
109*433d6423SLionel Sambuc  */
110*433d6423SLionel Sambuc static void
sef_local_startup(void)111*433d6423SLionel Sambuc sef_local_startup(void)
112*433d6423SLionel Sambuc {
113*433d6423SLionel Sambuc 
114*433d6423SLionel Sambuc 	/* Register initialization callback. */
115*433d6423SLionel Sambuc 	sef_setcb_init_fresh(init);
116*433d6423SLionel Sambuc 
117*433d6423SLionel Sambuc 	/* Register signal callback. SFFS handles this. */
118*433d6423SLionel Sambuc 	sef_setcb_signal_handler(sffs_signal);
119*433d6423SLionel Sambuc 
120*433d6423SLionel Sambuc 	sef_startup();
121*433d6423SLionel Sambuc }
122*433d6423SLionel Sambuc 
123*433d6423SLionel Sambuc /*
124*433d6423SLionel Sambuc  * The main function of this file server.
125*433d6423SLionel Sambuc  */
126*433d6423SLionel Sambuc int
main(int argc,char ** argv)127*433d6423SLionel Sambuc main(int argc, char **argv)
128*433d6423SLionel Sambuc {
129*433d6423SLionel Sambuc 
130*433d6423SLionel Sambuc 	/* Start up. */
131*433d6423SLionel Sambuc 	env_setargs(argc, argv);
132*433d6423SLionel Sambuc 	sef_local_startup();
133*433d6423SLionel Sambuc 
134*433d6423SLionel Sambuc 	/* Let SFFS do the actual work. */
135*433d6423SLionel Sambuc 	sffs_loop();
136*433d6423SLionel Sambuc 
137*433d6423SLionel Sambuc 	/* Clean up. */
138*433d6423SLionel Sambuc 	vboxfs_cleanup();
139*433d6423SLionel Sambuc 
140*433d6423SLionel Sambuc 	return EXIT_SUCCESS;
141*433d6423SLionel Sambuc }
142