1 /* usmb - mount SMB shares via FUSE and Samba
2 * Copyright (C) 2006-2013 Geoff Johnstone
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 static gboolean version
= FALSE
;
29 static gchar
*conffile
= NULL
;
30 static gboolean debug
= FALSE
;
31 static gboolean nofork
= FALSE
;
32 static gboolean umount
= FALSE
;
33 static gchar
**remaining
= NULL
;
36 static GOptionEntry entries
[] = {
37 { .long_name
= "version",
40 .arg
= G_OPTION_ARG_NONE
,
42 .description
= "Show usmb, FUSE and Samba versions" },
44 { .long_name
= "version",
46 .flags
= G_OPTION_FLAG_HIDDEN
,
47 .arg
= G_OPTION_ARG_NONE
,
49 .description
= NULL
},
51 { .long_name
= "config",
54 .arg
= G_OPTION_ARG_FILENAME
,
55 .arg_data
= &conffile
,
56 .description
= "usmb configuration file" },
58 { .long_name
= "debug",
60 .arg
= G_OPTION_ARG_NONE
,
62 .description
= "Debug mode" },
64 { .long_name
= "nofork",
66 .arg
= G_OPTION_ARG_NONE
,
68 .description
= "Foreground operation" },
70 { .long_name
= "unmount",
72 .arg
= G_OPTION_ARG_NONE
,
74 .description
= "Unmount the given filesystem" },
76 { .long_name
= G_OPTION_REMAINING
,
78 .arg
= G_OPTION_ARG_STRING_ARRAY
,
79 .arg_data
= &remaining
,
80 .description
= NULL
},
86 bool parse_args (int *argc
, char ***argv
,
87 const char **mountid
, const char **out_conffile
,
92 GOptionContext
*context
=
93 g_option_context_new ("- mount SMB shares via FUSE and Samba");
94 g_option_context_add_main_entries (context
, entries
, NULL
);
95 bool ret
= g_option_context_parse (context
, argc
, argv
, &error
);
96 g_option_context_free (context
);
100 fprintf (stderr
, "Try `%s --help' for more information\n", (*argv
)[0]);
106 show_version (stdout
);
110 if ((NULL
== remaining
) || (NULL
== remaining
[0]))
112 fputs ("No share ID given.\n", stderr
);
116 if (NULL
!= remaining
[1])
118 fputs ("Too many arguments.\n", stderr
);
122 *out_umount
= umount
;
123 *mountid
= remaining
[0];
125 DEBUG (fprintf (stderr
, "Mount ID: %s\n", *mountid
));
127 if (NULL
!= conffile
)
128 *out_conffile
= conffile
;
138 * -d -- if debug mode requested
139 * -f -- if foreground mode requested
140 * -o ... -- if any mount options in the config file
144 void build_fuse_args (const char *options
, const char *mountpoint
,
145 int *out_argc
, char ***out_argv
)
147 static char USMB
[] = "usmb";
148 static char MINUS_S
[] = "-s";
149 static char MINUS_D
[] = "-d";
150 static char MINUS_F
[] = "-f";
151 static char MINUS_O
[] = "-o";
152 static char MAX_READ
[] = "max_read=32768";
154 assert (NULL
!= mountpoint
);
155 static char *argv
[MAXARGS
];
160 argv
[argc
++] = MINUS_S
;
163 argv
[argc
++] = MINUS_D
;
165 // force -f in debug mode
169 argv
[argc
++] = MINUS_F
;
171 argv
[argc
++] = MINUS_O
;
172 argv
[argc
++] = MAX_READ
;
174 if ((NULL
!= options
) && ('\0' != options
[0]))
176 argv
[argc
++] = MINUS_O
;
177 argv
[argc
++] = (char *)options
;
180 argv
[argc
++] = (char *)mountpoint
;
181 argv
[argc
] = NULL
; // for good measure...
183 assert (argc
< MAXARGS
);
188 for (int i
= 0; i
< argc
; ++i
)
189 fprintf (stderr
, "%d: %s\n", i
, argv
[i
]);