2 * Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 /** Mounts a volume with the specified file system */
19 usage(const char *programName
)
22 printf("usage: %s [-ro] [-t fstype] [-p parameter] [device] directory\n"
23 "\t-ro\tmounts the volume read-only\n"
24 "\t-t\tspecifies the file system to use (defaults to automatic recognition)\n"
25 "\t-p\tspecifies parameters to pass to the file system (-o also accepted)\n"
26 "\tif device is not specified, NULL is passed (for in-memory filesystems)\n",programName
);
32 main(int argc
, char **argv
)
34 const char *programName
= argv
[0];
35 const char *device
= NULL
;
36 const char *mountPoint
;
37 const char *parameter
= NULL
;
38 const char *fs
= NULL
;
39 struct stat mountStat
;
43 /* prettify the program name */
45 if (strrchr(programName
, '/'))
46 programName
= strrchr(programName
, '/') + 1;
56 if (!strcmp(++arg
, "ro") && (flags
& B_MOUNT_READ_ONLY
) == 0)
57 flags
|= B_MOUNT_READ_ONLY
;
58 else if (!strcmp(arg
, "t") && fs
== NULL
) {
63 } else if ((!strcmp(arg
, "p") || !strcmp(arg
, "o")) && parameter
== NULL
) {
72 /* check the arguments */
81 if (mountPoint
== NULL
)
84 if (stat(mountPoint
, &mountStat
) < 0) {
85 fprintf(stderr
, "%s: The mount point '%s' is not accessible\n", programName
, mountPoint
);
88 if (!S_ISDIR(mountStat
.st_mode
)) {
89 fprintf(stderr
, "%s: The mount point '%s' is not a directory\n", programName
, mountPoint
);
95 volume
= fs_mount_volume(mountPoint
, device
, fs
, flags
, parameter
);
97 fprintf(stderr
, "%s: %s\n", programName
, strerror(volume
));