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 | |
---|
30 | static bool print_filesystem(const rtems_filesystem_table_t *entry, void *arg) |
---|
31 | { |
---|
32 | printf("%s ", entry->type); |
---|
33 | |
---|
34 | return false; |
---|
35 | } |
---|
36 | |
---|
37 | int 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 | |
---|
126 | rtems_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 | }; |
---|