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