Skip to content

Commit

Permalink
allow command line argument order used by mount(8)
Browse files Browse the repository at this point in the history
The mount spec and directory are passed as the first and second
arguments to the helper, followed by the options.

The current implementation works on glibc but fails on POSIX-conforming
C libraries such as musl.
  • Loading branch information
kunkku committed Sep 29, 2018
1 parent 2ce337d commit 49f3e46
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions fuse/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,17 @@ static int fuse_exfat_main(char* mount_options, char* mount_point)
&fuse_exfat_ops, NULL);
}

static void read_arg(char **param, int *argc, char ***argv) {
if (!*param && *argc > optind && (*argv)[optind][0] != '-') {
*param = (*argv)[optind];
((*argv)++)[1] = (*argv)[0];
(*argc)--;
}
}

int main(int argc, char* argv[])
{
const char* spec = NULL;
char* spec = NULL;
char* mount_point = NULL;
char* fuse_options;
char* exfat_options;
Expand All @@ -523,6 +531,9 @@ int main(int argc, char* argv[])

printf("FUSE exfat %s\n", VERSION);

read_arg(&spec, &argc, &argv);
read_arg(&mount_point, &argc, &argv);

fuse_options = strdup("allow_other,"
#if defined(__linux__) || defined(__FreeBSD__)
"big_writes,"
Expand Down Expand Up @@ -573,15 +584,16 @@ int main(int argc, char* argv[])
usage(argv[0]);
break;
}

read_arg(&spec, &argc, &argv);
read_arg(&mount_point, &argc, &argv);
}
if (argc - optind != 2)
if (!mount_point || argc > optind)
{
free(exfat_options);
free(fuse_options);
usage(argv[0]);
}
spec = argv[optind];
mount_point = argv[optind + 1];

if (exfat_mount(&ef, spec, exfat_options) != 0)
{
Expand Down

0 comments on commit 49f3e46

Please sign in to comment.