From cd157d41a902856046e2a6b0f64e76d839ddefec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 25 Jul 2002 02:56:47 +0000 Subject: [PATCH] Implemented the "mount" command. Added a missing newline at the end of alert.cpp. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@432 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/Jamfile | 1 + src/apps/bin/alert.cpp | 2 +- src/apps/bin/mount.c | 91 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/apps/bin/mount.c diff --git a/src/apps/bin/Jamfile b/src/apps/bin/Jamfile index df27bc6b3c..34fe0af12f 100644 --- a/src/apps/bin/Jamfile +++ b/src/apps/bin/Jamfile @@ -17,6 +17,7 @@ StdBinCommands listimage.c listport.c listsem.c + mount.c prio.c ps.c renice.c diff --git a/src/apps/bin/alert.cpp b/src/apps/bin/alert.cpp index 09cc26719f..586f38dd3e 100644 --- a/src/apps/bin/alert.cpp +++ b/src/apps/bin/alert.cpp @@ -225,4 +225,4 @@ int main( int argc, char ** argv ) } return errorlevel; -} \ No newline at end of file +} diff --git a/src/apps/bin/mount.c b/src/apps/bin/mount.c new file mode 100644 index 0000000000..88b3f54cf7 --- /dev/null +++ b/src/apps/bin/mount.c @@ -0,0 +1,91 @@ +/* +** 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 (axeld@users.sf.net) +** Description: mounts a volume with the specified file system +*/ + + +#include +#include +#include +#include +#include + + +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; +} +