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

4.104.115
Last change on this file since 7baa484 was 7baa484, checked in by Chris Johns <chrisj@…>, on Jun 12, 2009 at 1:53:33 AM

2009-06-12 Chris Johns <chrisj@…>

  • libblock/src/bdbuf.c: Update comments.
  • libblock/src/bdpart.c, libblock/src/ide_part_table.c: Get the device from the rdev field of the stat buf.
  • libcsupport/include/rtems/libio.h: Add a path length to evalpath handler. Add parent locations to rmmod and unlink handlers.
  • libcsupport/include/rtems/libio_.h: Add a path length to rtems_filesystem_evaluate_path. Add rtems_filesystem_evaluate_relative_path, rtems_filesystem_dirname, and rtems_filesystem_prefix_separators. Remove rtems_filesystem_evaluate_parent.
  • libcsupport/src/base_fs.c, libcsupport/src/chdir.c, libcsupport/src/chmod.c, libcsupport/src/chown.c, libcsupport/src/chroot.c, libcsupport/src/fchdir.c, libcsupport/src/link.c, libcsupport/src/mount.c, libcsupport/src/open.c, libcsupport/src/privateenv.c, libcsupport/src/readlink.c, libcsupport/src/unmount.c, libcsupport/src/utime.c, libcsupport/src/unmount.c, libcsupport/src/utime.c, libfs/src/devfs/devfs.h, libfs/src/devfs/devfs_eval.c, libfs/src/devfs/devstat.c, libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_misc.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_eval.c, libfs/src/imfs/imfs_load_tar.c, libfs/src/imfs/ioman.c, libfs/src/pipe/pipe.c, libmisc/fsmount/fsmount.c, libnetworking/lib/ftpfs.c: Add the length parameter to the eval call.
  • libcsupport/src/eval.c: Add rtems_filesystem_prefix_separators, rtems_filesystem_dirname, rtems_filesystem_evaluate_relative_path. Add the length parameter to the eval call.
  • libcsupport/src/rmdir.c: Find the parent pathloc then the node pathloc from that node. Remove the call to find the parent given the node pathloc.
  • libcsupport/src/stat.c: Add the length parameter to the eval call. Set the device into the rdev field.
  • libcsupport/src/unlink.c: Find the parent pathloc then the node pathloc from that node. Remove the call to find the parent given the node pathloc.
  • libfs/src/dosfs/fat.c, libfs/src/dosfs/msdos_format.c: Get the disk device number from the stat rdev field.
  • libfs/src/dosfs/msdos.h: Add the length parameter to the eval call. Add the parent pathloc to the rmnod handler.
  • libfs/src/dosfs/msdos_dir.c: Add the parent pathloc to the rmnod handler.
  • libfs/src/dosfs/msdos_eval.c: Add the length parameter to the eval and token call.
  • libfs/src/imfs/imfs_directory.c: Add the parent pathloc to the rmnod handler.
  • libfs/src/imfs/imfs_fchmod.c: Do not test the mode flags for only the allowed flags. Add the missing flags spec'ed in the POSIX standard.
  • libfs/src/imfs/imfs_fsunmount.c, libfs/src/imfs/imfs_rmnod.c, libfs/src/imfs/imfs_unlink.c, libfs/src/imfs/memfile.c: Add the parent node. Currently ignored in the IMFS.
  • libfs/src/imfs/imfs_stat.c: Return the device number in the rdev field.
  • libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/imfs_symlink.c : Add the length parameter to the token call.
  • libfs/src/nfsclient/src/nfs.c: Add the length parameter to the eval call and parent node to the rmnod and unlink command.
  • libmisc/shell/internal.h: Remove the libc mounter decl to make public.
  • libmisc/shell/main_mount.c: Add support for hooking external mount support for new file systems.
  • libmisc/shell/shell.h: Add helper functions for the mount command.
  • 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()
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.