source: rtems/cpukit/libmisc/shell/main_mount.c @ 00bf6744

4.10
Last change on this file since 00bf6744 was 00bf6744, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 1, 2010 at 2:10:54 PM

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

  • libcsupport/include/rtems/libio_.h: Declare rtems_filesystem_mount_table_control.
  • libcsupport/include/rtems/libio.h: Removed rtems_filesystem_table_first(), rtems_filesystem_table_next() and rtems_filesystem_table_node_t declarations. Declare rtems_per_filesystem_routine, rtems_filesystem_iterate() and rtems_filesystem_get_mount_handler().
  • libcsupport/src/mount.c: Added rtems_filesystem_mounts_first() and rtems_filesystem_mounts_next(). Simplify mount(). Removed rtems_filesystem_mount_table_control_init. Use rtems_filesystem_get_mount_handler().
  • libcsupport/src/mount-mgr.c: Removed rtems_filesystem_mounts_first() and rtems_filesystem_mounts_next(). Added rtems_filesystem_iterate() and rtems_filesystem_get_mount_handler(). Use rtems_libio_lock() and rtems_libio_unlock();
  • sapi/include/confdefs.h, libmisc/shell/main_mount.c: Update for mount API changes.

2010-06-07 Bharath Suri <bharath.s.jois@…>

  • libcsupport/include/rtems/libio_.h: Removed macros rtems_filesystem_is_separator rtems_filesystem_get_start_loc rtems_filesystem_get_sym_start_loc and added them as files under libcsupport/src/
  • libcsupport/src/: Added new files libcsupport/src/sup_fs_get_start_loc.c libcsupport/src/sup_fs_get_sym_start_loc.c libcsupport/src/sup_fs_is_separator.c
  • libcsupport/Makefile.am: Changes to accommodate new files under libcsupport/src/
  • 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 true;
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.