1*433d6423SLionel Sambuc /* This file contains the implementation of the HGFS file system server.
2*433d6423SLionel Sambuc * The file system side is handled by libsffs, whereas the host communication
3*433d6423SLionel Sambuc * is handled by libhgfs. This file mainly contains the glue between them.
4*433d6423SLionel Sambuc *
5*433d6423SLionel Sambuc * The entry points into this file are:
6*433d6423SLionel Sambuc * main main program function
7*433d6423SLionel Sambuc *
8*433d6423SLionel Sambuc * Created:
9*433d6423SLionel Sambuc * April 2009 (D.C. van Moolenbroek)
10*433d6423SLionel Sambuc */
11*433d6423SLionel Sambuc
12*433d6423SLionel Sambuc #include <minix/drivers.h>
13*433d6423SLionel Sambuc #include <minix/sffs.h>
14*433d6423SLionel Sambuc #include <minix/hgfs.h>
15*433d6423SLionel Sambuc #include <minix/optset.h>
16*433d6423SLionel Sambuc
17*433d6423SLionel Sambuc static struct sffs_params params;
18*433d6423SLionel Sambuc
19*433d6423SLionel Sambuc static struct optset optset_table[] = {
20*433d6423SLionel Sambuc { "prefix", OPT_STRING, params.p_prefix, sizeof(params.p_prefix) },
21*433d6423SLionel Sambuc { "uid", OPT_INT, ¶ms.p_uid, 10 },
22*433d6423SLionel Sambuc { "gid", OPT_INT, ¶ms.p_gid, 10 },
23*433d6423SLionel Sambuc { "fmask", OPT_INT, ¶ms.p_file_mask, 8 },
24*433d6423SLionel Sambuc { "dmask", OPT_INT, ¶ms.p_dir_mask, 8 },
25*433d6423SLionel Sambuc { "icase", OPT_BOOL, ¶ms.p_case_insens, TRUE },
26*433d6423SLionel Sambuc { "noicase", OPT_BOOL, ¶ms.p_case_insens, FALSE },
27*433d6423SLionel Sambuc { NULL, 0, NULL, 0 }
28*433d6423SLionel Sambuc };
29*433d6423SLionel Sambuc
30*433d6423SLionel Sambuc /*===========================================================================*
31*433d6423SLionel Sambuc * sef_cb_init_fresh *
32*433d6423SLionel Sambuc *===========================================================================*/
sef_cb_init_fresh(int UNUSED (type),sef_init_info_t * UNUSED (info))33*433d6423SLionel Sambuc static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
34*433d6423SLionel Sambuc {
35*433d6423SLionel Sambuc /* Initialize this file server. Called at startup time.
36*433d6423SLionel Sambuc */
37*433d6423SLionel Sambuc const struct sffs_table *table;
38*433d6423SLionel Sambuc int i, r;
39*433d6423SLionel Sambuc
40*433d6423SLionel Sambuc /* Defaults */
41*433d6423SLionel Sambuc params.p_prefix[0] = 0;
42*433d6423SLionel Sambuc params.p_uid = 0;
43*433d6423SLionel Sambuc params.p_gid = 0;
44*433d6423SLionel Sambuc params.p_file_mask = 0755;
45*433d6423SLionel Sambuc params.p_dir_mask = 0755;
46*433d6423SLionel Sambuc params.p_case_insens = FALSE;
47*433d6423SLionel Sambuc
48*433d6423SLionel Sambuc /* If we have been given an options string, parse options from there. */
49*433d6423SLionel Sambuc for (i = 1; i < env_argc - 1; i++)
50*433d6423SLionel Sambuc if (!strcmp(env_argv[i], "-o"))
51*433d6423SLionel Sambuc optset_parse(optset_table, env_argv[++i]);
52*433d6423SLionel Sambuc
53*433d6423SLionel Sambuc /* Initialize the HGFS library. If this fails, exit immediately. */
54*433d6423SLionel Sambuc if ((r = hgfs_init(&table)) != OK) {
55*433d6423SLionel Sambuc if (r == EAGAIN)
56*433d6423SLionel Sambuc printf("HGFS: shared folders are disabled\n");
57*433d6423SLionel Sambuc else
58*433d6423SLionel Sambuc printf("HGFS: unable to initialize HGFS library (%d)\n", r);
59*433d6423SLionel Sambuc
60*433d6423SLionel Sambuc return r;
61*433d6423SLionel Sambuc }
62*433d6423SLionel Sambuc
63*433d6423SLionel Sambuc /* Now initialize the SFFS library. */
64*433d6423SLionel Sambuc if ((r = sffs_init("HGFS", table, ¶ms)) != OK) {
65*433d6423SLionel Sambuc hgfs_cleanup();
66*433d6423SLionel Sambuc
67*433d6423SLionel Sambuc return r;
68*433d6423SLionel Sambuc }
69*433d6423SLionel Sambuc
70*433d6423SLionel Sambuc return OK;
71*433d6423SLionel Sambuc }
72*433d6423SLionel Sambuc
73*433d6423SLionel Sambuc /*===========================================================================*
74*433d6423SLionel Sambuc * sef_local_startup *
75*433d6423SLionel Sambuc *===========================================================================*/
sef_local_startup(void)76*433d6423SLionel Sambuc static void sef_local_startup(void)
77*433d6423SLionel Sambuc {
78*433d6423SLionel Sambuc /* Local SEF initialization.
79*433d6423SLionel Sambuc */
80*433d6423SLionel Sambuc
81*433d6423SLionel Sambuc /* Register init callback. */
82*433d6423SLionel Sambuc sef_setcb_init_fresh(sef_cb_init_fresh);
83*433d6423SLionel Sambuc
84*433d6423SLionel Sambuc /* Register signal callback. SFFS handles this. */
85*433d6423SLionel Sambuc sef_setcb_signal_handler(sffs_signal);
86*433d6423SLionel Sambuc
87*433d6423SLionel Sambuc sef_startup();
88*433d6423SLionel Sambuc }
89*433d6423SLionel Sambuc
90*433d6423SLionel Sambuc /*===========================================================================*
91*433d6423SLionel Sambuc * main *
92*433d6423SLionel Sambuc *===========================================================================*/
main(int argc,char ** argv)93*433d6423SLionel Sambuc int main(int argc, char **argv)
94*433d6423SLionel Sambuc {
95*433d6423SLionel Sambuc /* The main function of this file server.
96*433d6423SLionel Sambuc */
97*433d6423SLionel Sambuc
98*433d6423SLionel Sambuc env_setargs(argc, argv);
99*433d6423SLionel Sambuc sef_local_startup();
100*433d6423SLionel Sambuc
101*433d6423SLionel Sambuc sffs_loop();
102*433d6423SLionel Sambuc
103*433d6423SLionel Sambuc hgfs_cleanup();
104*433d6423SLionel Sambuc
105*433d6423SLionel Sambuc return 0;
106*433d6423SLionel Sambuc }
107