1 /* 2 ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 ** Distributed under the terms of the MIT License. 4 */ 5 6 /** Unmounts a volume */ 7 8 9 #include <fs_volume.h> 10 11 #include <sys/stat.h> 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 #include <unistd.h> 16 17 18 static void 19 usage(const char *programName) 20 { 21 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); 25 } 26 27 28 int 29 main(int argc, char **argv) 30 { 31 const char *programName = argv[0]; 32 struct stat pathStat; 33 const char *path; 34 status_t status; 35 uint32 flags = 0; 36 37 /* prettify the program name */ 38 39 if (strrchr(programName, '/')) 40 programName = strrchr(programName, '/') + 1; 41 42 /* get all options */ 43 44 while (*++argv) { 45 char *arg = *argv; 46 if (*arg != '-') 47 break; 48 49 if (!strcmp(++arg, "f")) 50 flags |= B_FORCE_UNMOUNT; 51 else 52 usage(programName); 53 } 54 55 path = argv[0]; 56 57 /* check the arguments */ 58 59 if (path == NULL) 60 usage(programName); 61 62 if (stat(path, &pathStat) < 0) { 63 fprintf(stderr, "%s: The path \"%s\" is not accessible\n", programName, path); 64 return 1; 65 } 66 67 /* do the work */ 68 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; 73 } 74 75 return 0; 76 } 77 78