00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <vfs/vfs.h>
00032 #include <errno.h>
00033 #include <getopt.h>
00034 #include "config.h"
00035 #include "util.h"
00036 #include "errors.h"
00037 #include "entry.h"
00038 #include "mount.h"
00039 #include "cmds.h"
00040
00041 static const char *cmdname = "mount";
00042
00043 static struct option const long_options[] = {
00044 { "help", no_argument, 0, 'h' },
00045 { 0, 0, 0, 0 }
00046 };
00047
00048
00049
00050 void help_cmd_mount(unsigned int level)
00051 {
00052 static char helpfmt[] =
00053 "Usage: %s <fstype> <mp> <dev> [<moptions>]\n";
00054 if (level == HELP_SHORT) {
00055 printf("'%s' mounts a file system.\n", cmdname);
00056 } else {
00057 help_cmd_mount(HELP_SHORT);
00058 printf(helpfmt, cmdname);
00059 }
00060 return;
00061 }
00062
00063
00064 int cmd_mount(char **argv)
00065 {
00066 unsigned int argc;
00067 const char *mopts = "";
00068 int rc, c, opt_ind;
00069
00070 argc = cli_count_args(argv);
00071
00072 for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
00073 c = getopt_long(argc, argv, "h", long_options, &opt_ind);
00074 switch (c) {
00075 case 'h':
00076 help_cmd_mount(HELP_LONG);
00077 return CMD_SUCCESS;
00078 }
00079 }
00080
00081 if ((argc < 4) || (argc > 5)) {
00082 printf("%s: invalid number of arguments. Try `mount --help'\n",
00083 cmdname);
00084 return CMD_FAILURE;
00085 }
00086 if (argc == 5)
00087 mopts = argv[4];
00088
00089 rc = mount(argv[1], argv[2], argv[3], mopts, 0);
00090 if (rc != EOK) {
00091 printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n",
00092 argv[1], argv[2], argv[3], rc);
00093 return CMD_FAILURE;
00094 }
00095
00096 return CMD_SUCCESS;
00097 }
00098