source: rtems/cpukit/libmisc/shell/main_mount.c @ 7e9765d

4.104.115
Last change on this file since 7e9765d was f379d80, checked in by Joel Sherrill <joel.sherrill@…>, on 07/22/09 at 15:21:08

2009-07-22 Joel Sherrill <joel.sherrill@…>

  • libmisc/shell/main_mount.c: Eliminate warning.
  • Property mode set to 100644
File size: 4.4 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/dosfs.h>
28#include <rtems/fsmount.h>
29#include "internal.h"
30
31static rtems_chain_control filesystems;
32static bool                fs_init;
33
34static void rtems_shell_mount_fsys_init(void)
35{
36  if (!fs_init)
37  {
38    rtems_chain_initialize_empty (&filesystems);
39    fs_init = true;
40  }
41}
42
43void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t* fs)
44{
45  rtems_shell_mount_fsys_init();
46  rtems_chain_append (&filesystems, &fs->link);
47}
48
49void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t* fs)
50{
51  if (fs_init)
52    rtems_chain_extract (&fs->link);
53}
54
55int rtems_shell_libc_mounter(
56  const char*                driver,
57  const char*                path,
58  rtems_shell_filesystems_t* fs,
59  rtems_filesystem_options_t options)
60{
61  rtems_filesystem_mount_table_entry_t* mt_entry;
62  /*
63   * Mount the disk.
64   */
65 
66  if (mount (&mt_entry, fs->fs_ops, options, (char*) driver, (char*) path) < 0)
67  {
68    fprintf (stderr, "mount: mount failed: %s\n", strerror (errno));
69    return 1;
70  }
71 
72  return 0;
73}
74
75#define NUMOF(_i) (sizeof (_i) / sizeof (_i[0]))
76
77int rtems_shell_main_mount(
78  int   argc,
79  char *argv[]
80)
81{
82  rtems_filesystem_options_t options = RTEMS_FILESYSTEM_READ_WRITE;
83  rtems_shell_filesystems_t* fs = NULL;
84  char*                      driver = NULL;
85  char*                      mount_point = NULL;
86  int                        arg;
87
88  rtems_shell_mount_fsys_init();
89 
90  for (arg = 1; arg < argc; arg++) {
91    if (argv[arg][0] == '-') {
92      if (argv[arg][1] == 't') {
93        rtems_shell_filesystems_t** a;
94
95        arg++;
96        if (arg == argc) {
97          fprintf(
98            stderr,
99            "%s: -t needs a type of file-system;; see -L.\n",
100            argv[0]
101          );
102          return 1;
103        }
104
105        for (a = rtems_shell_Mount_filesystems; *a; a++) {
106          if (strcmp (argv[arg], (*a)->name) == 0) {
107            fs = *a;
108            break;
109          }
110        }
111
112        if (!fs && !rtems_chain_is_empty(&filesystems)) {
113          rtems_chain_node* node = filesystems.first;
114          while (!rtems_chain_is_tail (&filesystems, node)) {
115            rtems_shell_filesystems_t* f = (rtems_shell_filesystems_t*)node;
116            if (strcmp (argv[arg], f->name) == 0) {
117              fs = f;
118              break;
119            }
120            node = node->next;
121          }
122        }
123      } else if (argv[arg][1] == 'r') {
124        options = RTEMS_FILESYSTEM_READ_ONLY;
125      } else if (argv[arg][1] == 'L') {
126        rtems_shell_filesystems_t** a;
127        fprintf (stderr, "File systems: ");
128        for (a = rtems_shell_Mount_filesystems; *a; a++)
129          if (*a)
130            fprintf (stderr, "%s ", (*a)->name);
131        fprintf (stderr, "\n");
132        return 1;
133      } else {
134        fprintf (stderr, "unknown option: %s\n", argv[arg]);
135        return 1;
136      }
137    } else {
138      if (!driver)
139        driver = argv[arg];
140      else if (!mount_point)
141        mount_point = argv[arg];
142      else {
143        fprintf (
144          stderr, "mount: driver and mount only require: %s\n", argv[arg]);
145        return 1;
146      }
147    }
148  }
149
150  if (fs == NULL) {
151    fprintf (stderr, "mount: no file-system; see the -L option\n");
152    return 1;
153  }
154 
155  if (fs->driver_needed && !driver) {
156    fprintf (stderr, "mount: no driver\n");
157    return 1;
158  }
159 
160  if (!mount_point) {
161    fprintf (stderr, "mount: no mount point\n");
162    return 1;
163  }
164 
165  /*
166   * Mount the disk.
167   */
168 
169  if (fs->mounter (driver, mount_point, fs, options))
170    return 1;
171
172  printf ("mounted %s -> %s\n", driver, mount_point);
173 
174  return 0;
175}
176
177rtems_shell_cmd_t rtems_shell_MOUNT_Command = {
178  "mount",                                                /* name */
179  "mount [-t fstype] [-r] [-L] device path # mount disk", /* usage */
180  "files",                                                /* topic */
181  rtems_shell_main_mount,                                 /* command */
182  NULL,                                                   /* alias */
183  NULL                                                    /* next */
184};
Note: See TracBrowser for help on using the repository browser.