1 | /* |
---|
2 | * The license and distribution terms for this file may be |
---|
3 | * found in the file LICENSE in this distribution or at |
---|
4 | * http://www.rtems.com/license/LICENSE. |
---|
5 | * |
---|
6 | * $Id$ |
---|
7 | */ |
---|
8 | |
---|
9 | #ifdef HAVE_CONFIG_H |
---|
10 | #include "config.h" |
---|
11 | #endif |
---|
12 | |
---|
13 | #include <stdio.h> |
---|
14 | #include <unistd.h> |
---|
15 | #include <string.h> |
---|
16 | #include <errno.h> |
---|
17 | #include <inttypes.h> |
---|
18 | |
---|
19 | #include <rtems.h> |
---|
20 | #include <rtems/shell.h> |
---|
21 | #include <rtems/stringto.h> |
---|
22 | #include <rtems/shellconfig.h> |
---|
23 | #include <rtems/dosfs.h> |
---|
24 | #include <rtems/fsmount.h> |
---|
25 | #include "internal.h" |
---|
26 | |
---|
27 | int rtems_shell_main_msdos_format( |
---|
28 | int argc, |
---|
29 | char *argv[] |
---|
30 | ) |
---|
31 | { |
---|
32 | msdos_format_request_param_t rqdata = { |
---|
33 | OEMName: "RTEMS", |
---|
34 | VolLabel: "RTEMSDisk", |
---|
35 | sectors_per_cluster: 0, |
---|
36 | fat_num: 0, |
---|
37 | files_per_root_dir: 0, |
---|
38 | fattype: MSDOS_FMT_FATANY, |
---|
39 | media: 0, |
---|
40 | quick_format: TRUE, |
---|
41 | cluster_align: 0, |
---|
42 | info_level: 0 |
---|
43 | }; |
---|
44 | |
---|
45 | unsigned long tmp; |
---|
46 | const char* driver = NULL; |
---|
47 | int arg; |
---|
48 | |
---|
49 | for (arg = 1; arg < argc; arg++) { |
---|
50 | if (argv[arg][0] == '-') { |
---|
51 | switch (argv[arg][1]) { |
---|
52 | case 'V': |
---|
53 | arg++; |
---|
54 | if (arg == argc) { |
---|
55 | fprintf (stderr, "error: no volume label.\n"); |
---|
56 | return 1; |
---|
57 | } |
---|
58 | rqdata.VolLabel = argv[arg]; |
---|
59 | break; |
---|
60 | |
---|
61 | case 's': |
---|
62 | arg++; |
---|
63 | if (arg == argc) { |
---|
64 | fprintf (stderr, "error: sectors per cluster count.\n"); |
---|
65 | return 1; |
---|
66 | } |
---|
67 | |
---|
68 | if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) { |
---|
69 | printf( |
---|
70 | "sector per cluster argument (%s) is not a number\n", |
---|
71 | argv[arg] |
---|
72 | ); |
---|
73 | return -1; |
---|
74 | } |
---|
75 | |
---|
76 | rqdata.sectors_per_cluster = (uint32_t) tmp; |
---|
77 | break; |
---|
78 | |
---|
79 | case 'r': |
---|
80 | arg++; |
---|
81 | if (arg == argc) { |
---|
82 | fprintf (stderr, "error: no root directory size.\n"); |
---|
83 | return 1; |
---|
84 | } |
---|
85 | |
---|
86 | if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) { |
---|
87 | printf( |
---|
88 | "root directory size argument (%s) is not a number\n", |
---|
89 | argv[arg] |
---|
90 | ); |
---|
91 | return -1; |
---|
92 | } |
---|
93 | |
---|
94 | rqdata.files_per_root_dir = (uint32_t) tmp; |
---|
95 | break; |
---|
96 | |
---|
97 | case 't': |
---|
98 | arg++; |
---|
99 | if (arg == argc) { |
---|
100 | fprintf (stderr, "error: no FAT type.\n"); |
---|
101 | return 1; |
---|
102 | } |
---|
103 | |
---|
104 | if (strcmp (argv[arg], "any") == 0) |
---|
105 | rqdata.fattype = MSDOS_FMT_FATANY; |
---|
106 | else if (strcmp (argv[arg], "12") == 0) |
---|
107 | rqdata.fattype = MSDOS_FMT_FAT12; |
---|
108 | else if (strcmp (argv[arg], "16") == 0) |
---|
109 | rqdata.fattype = MSDOS_FMT_FAT16; |
---|
110 | else if (strcmp (argv[arg], "32") == 0) |
---|
111 | rqdata.fattype = MSDOS_FMT_FAT32; |
---|
112 | else { |
---|
113 | fprintf (stderr, "error: invalid type, can any, 12, 16, or 32\n"); |
---|
114 | return 1; |
---|
115 | } |
---|
116 | break; |
---|
117 | |
---|
118 | case 'v': |
---|
119 | rqdata.info_level++; |
---|
120 | break; |
---|
121 | |
---|
122 | default: |
---|
123 | fprintf (stderr, "error: invalid option: %s\n", argv[arg]); |
---|
124 | return 1; |
---|
125 | |
---|
126 | } |
---|
127 | } else { |
---|
128 | if (!driver) |
---|
129 | driver = argv[arg]; |
---|
130 | else { |
---|
131 | fprintf (stderr, "error: only one driver allowed: %s\n", argv[arg]); |
---|
132 | return 1; |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | if (!driver) { |
---|
138 | fprintf (stderr, "error: no driver\n"); |
---|
139 | return 1; |
---|
140 | } |
---|
141 | |
---|
142 | printf ("msdos format: %s\n", driver); |
---|
143 | |
---|
144 | if (rqdata.info_level) |
---|
145 | { |
---|
146 | printf (" %-20s: %s\n", "OEMName", "RTEMS"); |
---|
147 | printf (" %-20s: %s\n", "VolLabel", "RTEMSDisk"); |
---|
148 | printf (" %-20s: %" PRIu32 "\n", "sectors per cluster", rqdata.sectors_per_cluster); |
---|
149 | printf (" %-20s: %" PRIu32 "\n", "fats", rqdata.fat_num); |
---|
150 | printf (" %-20s: %" PRIu32 "\n", "files per root dir", rqdata.files_per_root_dir); |
---|
151 | printf (" %-20s: %i\n", "fat type", rqdata.fattype); |
---|
152 | printf (" %-20s: %d\n", "media", rqdata.media); |
---|
153 | printf (" %-20s: %d\n", "quick_format", rqdata.quick_format); |
---|
154 | printf (" %-20s: %" PRIu32 "\n", "cluster align", rqdata.cluster_align); |
---|
155 | } |
---|
156 | |
---|
157 | if (msdos_format (driver, &rqdata) < 0) { |
---|
158 | fprintf (stderr, "error: format failed: %s\n", strerror (errno)); |
---|
159 | return 1; |
---|
160 | } |
---|
161 | |
---|
162 | printf ("msdos format successful\n"); |
---|
163 | |
---|
164 | return 0; |
---|
165 | } |
---|
166 | |
---|
167 | #define OPTIONS "[-v label] [-r size] [-t any/12/16/32]" |
---|
168 | |
---|
169 | rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command = { |
---|
170 | "mkdos", /* name */ |
---|
171 | "mkdos " OPTIONS " path # format disk", /* usage */ |
---|
172 | "files", /* topic */ |
---|
173 | rtems_shell_main_msdos_format, /* command */ |
---|
174 | NULL, /* alias */ |
---|
175 | NULL /* next */ |
---|
176 | }; |
---|
177 | |
---|
178 | rtems_shell_cmd_t rtems_shell_MSDOSFMT_Alias = { |
---|
179 | "msdosfmt", /* name */ |
---|
180 | NULL, /* usage */ |
---|
181 | "files", /* topic */ |
---|
182 | NULL, /* command */ |
---|
183 | &rtems_shell_MSDOSFMT_Command, /* alias */ |
---|
184 | NULL /* next */ |
---|
185 | }; |
---|