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