RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / bin / mount.c
blobd0d7d06f96a7c6a02cdb8f12518e834045d5fa30
1 /*
2 * Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 /** Mounts a volume with the specified file system */
9 #include <fs_volume.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
18 static void
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);
27 exit(1);
31 int
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;
40 dev_t volume;
41 uint32 flags = 0;
43 /* prettify the program name */
45 if (strrchr(programName, '/'))
46 programName = strrchr(programName, '/') + 1;
48 /* get all options */
50 while (*++argv) {
51 char *arg = *argv;
52 argc--;
53 if (*arg != '-')
54 break;
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) {
59 if (argc <= 1)
60 break;
61 fs = *++argv;
62 argc--;
63 } else if ((!strcmp(arg, "p") || !strcmp(arg, "o")) && parameter == NULL) {
64 if (argc <= 1)
65 break;
66 parameter = *++argv;
67 argc--;
68 } else
69 usage(programName);
72 /* check the arguments */
74 if (argc > 1) {
75 device = argv[0];
76 argv++;
77 argc--;
79 mountPoint = argv[0];
81 if (mountPoint == NULL)
82 usage(programName);
84 if (stat(mountPoint, &mountStat) < 0) {
85 fprintf(stderr, "%s: The mount point '%s' is not accessible\n", programName, mountPoint);
86 return 1;
88 if (!S_ISDIR(mountStat.st_mode)) {
89 fprintf(stderr, "%s: The mount point '%s' is not a directory\n", programName, mountPoint);
90 return 1;
93 /* do the work */
95 volume = fs_mount_volume(mountPoint, device, fs, flags, parameter);
96 if (volume < B_OK) {
97 fprintf(stderr, "%s: %s\n", programName, strerror(volume));
98 return 1;
100 return 0;