Skip to content

Commit 49f3e46

Browse files
committed
allow command line argument order used by mount(8)
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.
1 parent 2ce337d commit 49f3e46

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

fuse/main.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,17 @@ static int fuse_exfat_main(char* mount_options, char* mount_point)
512512
&fuse_exfat_ops, NULL);
513513
}
514514

515+
static void read_arg(char **param, int *argc, char ***argv) {
516+
if (!*param && *argc > optind && (*argv)[optind][0] != '-') {
517+
*param = (*argv)[optind];
518+
((*argv)++)[1] = (*argv)[0];
519+
(*argc)--;
520+
}
521+
}
522+
515523
int main(int argc, char* argv[])
516524
{
517-
const char* spec = NULL;
525+
char* spec = NULL;
518526
char* mount_point = NULL;
519527
char* fuse_options;
520528
char* exfat_options;
@@ -523,6 +531,9 @@ int main(int argc, char* argv[])
523531

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

534+
read_arg(&spec, &argc, &argv);
535+
read_arg(&mount_point, &argc, &argv);
536+
526537
fuse_options = strdup("allow_other,"
527538
#if defined(__linux__) || defined(__FreeBSD__)
528539
"big_writes,"
@@ -573,15 +584,16 @@ int main(int argc, char* argv[])
573584
usage(argv[0]);
574585
break;
575586
}
587+
588+
read_arg(&spec, &argc, &argv);
589+
read_arg(&mount_point, &argc, &argv);
576590
}
577-
if (argc - optind != 2)
591+
if (!mount_point || argc > optind)
578592
{
579593
free(exfat_options);
580594
free(fuse_options);
581595
usage(argv[0]);
582596
}
583-
spec = argv[optind];
584-
mount_point = argv[optind + 1];
585597

586598
if (exfat_mount(&ef, spec, exfat_options) != 0)
587599
{

0 commit comments

Comments
 (0)