Files
haiku-beta6/src/bin/unmount.c
T
Jérôme Duval 15e29cfa03 fix exit codes (1 on error, 0 on success)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18705 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-08-30 09:46:42 +00:00

77 lines
1.3 KiB
C

/*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
/** Unmounts a volume */
#include <fs_volume.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
static void
usage(const char *programName)
{
printf("usage: %s [-f] <path to volume>\n"
"\t-f\tforces unmounting in case of open files left\n", programName);
exit(1);
}
int
main(int argc, char **argv)
{
const char *programName = argv[0];
struct stat pathStat;
const char *path;
status_t status;
uint32 flags = 0;
/* prettify the program name */
if (strrchr(programName, '/'))
programName = strrchr(programName, '/') + 1;
/* get all options */
while (*++argv) {
char *arg = *argv;
if (*arg != '-')
break;
if (!strcmp(++arg, "f"))
flags |= B_FORCE_UNMOUNT;
else
usage(programName);
}
path = argv[0];
/* check the arguments */
if (path == NULL)
usage(programName);
if (stat(path, &pathStat) < 0) {
fprintf(stderr, "%s: The path \"%s\" is not accessible\n", programName, path);
return 1;
}
/* do the work */
status = fs_unmount_volume(path, flags);
if (status != B_OK) {
fprintf(stderr, "%s: unmounting failed: %s\n", programName, strerror(status));
return 1;
}
return 0;
}