source: rtems/cpukit/libmisc/shell/main_mount.c @ df719841

4.10
Last change on this file since df719841 was 955a34b5, checked in by Sebastian Huber <sebastian.huber@…>, on 07/01/10 at 15:18:06

2010-07-01 Sebastian Huber <sebastian.huber@…>

  • libcsupport/include/rtems/libio_.h: Removed rtems_filesystem_mount_table_control.
  • libcsupport/include/rtems/libio.h, libcsupport/src/mount-mgr.c, libcsupport/src/mount.c libcsupport/src/statvfs.c, libcsupport/src/unmount.c, libmisc/shell/main_mount.c: Documentation. Removed rtems_filesystem_mounts_first() and rtems_filesystem_mounts_next(). Added rtems_filesystem_mount_iterate(). Changed return type of rtems_filesystem_iterate(). Removed rtems_filesystem_nodes_equal().

2010-07-01 Sebastian Huber <sebastian.huber@…>

  • libfs/src/nfsclient/src/nfs.c, libfs/src/nfsclient/src/nfs.c, libfs/src/nfsclient/src/librtemsNfs.h: Renamed rtems_nfsfs_initialize() in rtems_nfs_initialize().
  • sapi/include/confdefs.h: Reflect changes above. Renamed *_miniIMFS in *_MINIIMFS. Renamed *_NFSFS in *_NFS.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *   Shell Command Implmentation
3 *
4 *  Author: Fernando RUIZ CASAS
5 *  Work: fernando.ruiz@ctv.es
6 *  Home: correo@fernando-ruiz.com
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <stdio.h>
20#include <unistd.h>
21#include <string.h>
22#include <errno.h>
23
24#include <rtems.h>
25#include <rtems/shell.h>
26#include <rtems/shellconfig.h>
27#include <rtems/libio.h>
28#include "internal.h"
29
30static bool print_filesystem(const rtems_filesystem_table_t *entry, void *arg)
31{
32  printf("%s ", entry->type);
33
34  return false;
35}
36
37int rtems_shell_main_mount(
38  int   argc,
39  char *argv[]
40)
41{
42  rtems_filesystem_options_t options = RTEMS_FILESYSTEM_READ_WRITE;
43  char*                      type = NULL;
44  char*                      source = NULL;
45  char*                      target = NULL;
46  char*                      fsoptions = NULL;
47  int                        arg;
48
49  for (arg = 1; arg < argc; arg++) {
50    if (argv[arg][0] == '-') {
51      if (argv[arg][1] == 't') {
52        arg++;
53        if (arg == argc) {
54          fprintf(
55            stderr,
56            "%s: -t needs a type of file-system;; see -L.\n",
57            argv[0]
58          );
59          return 1;
60        }
61        type = argv[arg];
62      } else if (argv[arg][1] == 'r') {
63        options = RTEMS_FILESYSTEM_READ_ONLY;
64      } else if (argv[arg][1] == 'L') {
65        printf ("File systems: ");
66        rtems_filesystem_iterate(print_filesystem, NULL);
67        printf ("\n");
68        return 0;
69      } else if (argv[arg][1] == 'o') {
70        arg++;
71        if (arg == argc) {
72          fprintf(
73            stderr,
74            "%s: -o needs a list if filesystem options.\n",
75            argv[0]
76          );
77          return 1;
78        }
79        fsoptions = argv[arg];
80      } else {
81        fprintf (stderr, "unknown option: %s\n", argv[arg]);
82        return 1;
83      }
84    } else {
85      if (!source)
86        source = argv[arg];
87      else if (!target)
88        target = argv[arg];
89      else {
90        fprintf (
91          stderr, "mount: source and mount only require: %s\n", argv[arg]);
92        return 1;
93      }
94    }
95  }
96
97  if (!type) {
98    fprintf (stderr, "mount: no file-system; see the -L option\n");
99    return 1;
100  }
101
102  if (!source) {
103    fprintf (stderr, "mount: no source\n");
104    return 1;
105  }
106
107  if (!target) {
108    fprintf (stderr, "mount: no mount point\n");
109    return 1;
110  }
111
112  /*
113   * Mount the disk.
114   */
115
116  if (mount (source, target, type, options, fsoptions) < 0) {
117    fprintf (stderr, "error: %s\n", strerror(errno));
118    return 1;
119  }
120
121  printf ("mounted %s -> %s\n", source, target);
122
123  return 0;
124}
125
126rtems_shell_cmd_t rtems_shell_MOUNT_Command = {
127  "mount",                                     /* name */
128  "mount [-t type] [-r] [-L] source target",   /* usage */
129  "files",                                     /* topic */
130  rtems_shell_main_mount,                      /* command */
131  NULL,                                        /* alias */
132  NULL                                         /* next */
133};
Note: See TracBrowser for help on using the repository browser.