Files
haiku-beta6/src/apps/bin/mount.c
T
Niels Sascha Reedijk b9a05f7f4c Summary: Fix a lot of warnings in apps (merge from fixes-branch)
Keywords:

Patches applied:

 * [email protected]/bin-applications--fixes--0.1--base-0
   tag of [email protected]/bin-applications--mainline--0.1--base-0

 * [email protected]/bin-applications--fixes--0.1--patch-1
   Fix warning

 * [email protected]/bin-applications--fixes--0.1--patch-2
   Fix warning in roster.cpp

 * [email protected]/bin-applications--fixes--0.1--patch-3
   Fix warning in clipboard.cpp

 * [email protected]/bin-applications--fixes--0.1--patch-4
   Fix warning in shutdown.cpp (trivial)

 * [email protected]/bin-applications--fixes--0.1--patch-5
   Fix warnings in chop.c (trivial)

 * [email protected]/bin-applications--fixes--0.1--patch-6
   Trivial warning fix in eject.c

 * [email protected]/bin-applications--fixes--0.1--patch-7
   Trivial warning fix in hd.c

 * [email protected]/bin-applications--fixes--0.1--patch-8
   Trivial warning fixes in listarea.c

 * [email protected]/bin-applications--fixes--0.1--patch-9
   TRIVIAL: Fix warning in listimage.c

 * [email protected]/bin-applications--fixes--0.1--patch-10
   TRIVIAL warning fix in listport.c

 * [email protected]/bin-applications--fixes--0.1--patch-11
   TRIVIAL fix in listsem.c

 * [email protected]/bin-applications--fixes--0.1--patch-12
   TRIVIAL fix in mount.c

 * [email protected]/bin-applications--fixes--0.1--patch-13
   Trivial fix in prio.c

 * [email protected]/bin-applications--fixes--0.1--patch-14
   TRIVIAL changes in ps.c

 * [email protected]/bin-applications--fixes--0.1--patch-15
   TRIVIAL fix in renice.c

 * [email protected]/bin-applications--fixes--0.1--patch-16
   TRIVIAL fix for rescan

 * [email protected]/bin-applications--fixes--0.1--patch-17
   TRIVIAL fix in sysinfo.c

 * [email protected]/bin-applications--fixes--0.1--patch-18
   TRIVIAL fix in unchop.c

 * [email protected]/bin-applications--fixes--0.1--patch-19
   TRIVIAL fix in chkbfs

 * [email protected]/bin-applications--fixes--0.1--patch-20
   TRIVIAL fixes for listdev

 * [email protected]/bin-applications--fixes--0.1--patch-21
   TRIVIAL fixes in pc


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5557 a95241bf-73f2-0310-859d-f6bbb57e9c96
2003-12-03 20:02:15 +00:00

92 lines
1.9 KiB
C

/*
** Copyright (c) 2001-2002, OpenBeOS
**
** This software is part of the OpenBeOS distribution and is covered
** by the OpenBeOS license.
**
** File: mount.c
** Author: Axel Dörfler ([email protected])
** Description: mounts a volume with the specified file system
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
static void
usage(const char *programName)
{
printf("usage: %s [-ro] [-t fstype] device directory\n"
"\t-ro\tmounts the volume read-only\n"
"\t-t\tspecifies the file system to use (defaults to \"bfs\")\n",programName);
exit(0);
}
int
main(int argc, char **argv)
{
const char *programName = argv[0];
const char *device, *mountPoint;
const char *parameter = NULL;
const char *fs = NULL;
struct stat mountStat;
int 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, "ro") && (flags & B_MOUNT_READ_ONLY) == 0)
flags |= B_MOUNT_READ_ONLY;
else if (!strcmp(arg, "t") && fs == NULL)
fs = *++argv;
else if (!strcmp(arg, "p") && parameter == NULL)
parameter = *++argv;
else
usage(programName);
}
/* check the arguments */
if (fs == NULL)
fs = "bfs";
device = argv[0];
mountPoint = argv[1];
if (device == NULL || mountPoint == NULL)
usage(programName);
if (stat(mountPoint, &mountStat) < 0) {
fprintf(stderr, "%s: The mount point '%s' is not accessible\n", programName, mountPoint);
return -1;
}
if (!S_ISDIR(mountStat.st_mode)) {
fprintf(stderr, "%s: The mount point '%s' is not a directory\n", programName, mountPoint);
return -1;
}
/* do the work */
if (mount(fs, mountPoint, device, flags, (void *)parameter, parameter ? strlen(parameter) : 0) < 0) {
fprintf(stderr, "%s: %s\n", programName, strerror(errno));
return -1;
}
return 0;
}