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