vfs: check userland buffers before reading them.
[haiku.git] / src / bin / unmount.c
blob2b6fe20fd0e582fe0947556f6cd8099c985f0196
1 /*
2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
4 */
6 /** Unmounts a volume */
9 #include <fs_volume.h>
11 #include <sys/stat.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <unistd.h>
18 static void
19 usage(const char *programName)
22 printf("usage: %s [-f] <path to volume>\n"
23 "\t-f\tforces unmounting in case of open files left\n", programName);
24 exit(1);
28 int
29 main(int argc, char **argv)
31 const char *programName = argv[0];
32 struct stat pathStat;
33 const char *path;
34 status_t status;
35 uint32 flags = 0;
37 /* prettify the program name */
39 if (strrchr(programName, '/'))
40 programName = strrchr(programName, '/') + 1;
42 /* get all options */
44 while (*++argv) {
45 char *arg = *argv;
46 if (*arg != '-')
47 break;
49 if (!strcmp(++arg, "f"))
50 flags |= B_FORCE_UNMOUNT;
51 else
52 usage(programName);
55 path = argv[0];
57 /* check the arguments */
59 if (path == NULL)
60 usage(programName);
62 if (stat(path, &pathStat) < 0) {
63 fprintf(stderr, "%s: The path \"%s\" is not accessible\n", programName, path);
64 return 1;
67 /* do the work */
69 status = fs_unmount_volume(path, flags);
70 if (status != B_OK) {
71 fprintf(stderr, "%s: unmounting failed: %s\n", programName, strerror(status));
72 return 1;
75 return 0;