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 | |
---|
31 | int rtems_shell_main_msdos_format( |
---|
32 | int argc, |
---|
33 | char *argv[] |
---|
34 | ) |
---|
35 | { |
---|
36 | msdos_format_request_param_t rqdata = { |
---|
37 | OEMName: "RTEMS", |
---|
38 | VolLabel: "RTEMSDisk", |
---|
39 | sectors_per_cluster: 0, |
---|
40 | fat_num: 0, |
---|
41 | files_per_root_dir: 0, |
---|
42 | fattype: MSDOS_FMT_FATANY, |
---|
43 | media: 0, |
---|
44 | quick_format: TRUE, |
---|
45 | cluster_align: 0 |
---|
46 | }; |
---|
47 | |
---|
48 | const char* driver = NULL; |
---|
49 | int arg; |
---|
50 | |
---|
51 | for (arg = 1; arg < argc; arg++) { |
---|
52 | if (argv[arg][0] == '-') { |
---|
53 | switch (argv[arg][1]) { |
---|
54 | case 'v': |
---|
55 | arg++; |
---|
56 | if (arg == argc) { |
---|
57 | fprintf (stderr, "error: no volume label.\n"); |
---|
58 | return 1; |
---|
59 | } |
---|
60 | rqdata.VolLabel = argv[arg]; |
---|
61 | break; |
---|
62 | |
---|
63 | case 'r': |
---|
64 | arg++; |
---|
65 | if (arg == argc) { |
---|
66 | fprintf (stderr, "error: no root directory size.\n"); |
---|
67 | return 1; |
---|
68 | } |
---|
69 | rqdata.files_per_root_dir = rtems_shell_str2int(argv[arg]); |
---|
70 | break; |
---|
71 | |
---|
72 | case 't': |
---|
73 | arg++; |
---|
74 | if (arg == argc) { |
---|
75 | fprintf (stderr, "error: no FAT type.\n"); |
---|
76 | return 1; |
---|
77 | } |
---|
78 | |
---|
79 | if (strcmp (argv[arg], "any") == 0) |
---|
80 | rqdata.fattype = MSDOS_FMT_FATANY; |
---|
81 | else if (strcmp (argv[arg], "12") == 0) |
---|
82 | rqdata.fattype = MSDOS_FMT_FAT12; |
---|
83 | else if (strcmp (argv[arg], "16") == 0) |
---|
84 | rqdata.fattype = MSDOS_FMT_FAT16; |
---|
85 | else if (strcmp (argv[arg], "32") == 0) |
---|
86 | rqdata.fattype = MSDOS_FMT_FAT32; |
---|
87 | else { |
---|
88 | fprintf (stderr, "error: invalid type, can any, 12, 16, or 32\n"); |
---|
89 | return 1; |
---|
90 | } |
---|
91 | break; |
---|
92 | |
---|
93 | default: |
---|
94 | fprintf (stderr, "error: invalid option: %s\n", argv[arg]); |
---|
95 | return 1; |
---|
96 | |
---|
97 | } |
---|
98 | } else { |
---|
99 | if (!driver) |
---|
100 | driver = argv[arg]; |
---|
101 | else { |
---|
102 | fprintf (stderr, "error: only one driver allowed: %s\n", argv[arg]); |
---|
103 | return 1; |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | if (!driver) { |
---|
109 | fprintf (stderr, "error: no driver\n"); |
---|
110 | return 1; |
---|
111 | } |
---|
112 | |
---|
113 | printf ("msdos format: %s\n", driver); |
---|
114 | |
---|
115 | if (msdos_format (driver, &rqdata) < 0) { |
---|
116 | fprintf (stderr, "error: format failed: %s\n", strerror (errno)); |
---|
117 | return 1; |
---|
118 | } |
---|
119 | |
---|
120 | printf ("msdos format successful\n"); |
---|
121 | |
---|
122 | return 0; |
---|
123 | } |
---|
124 | |
---|
125 | #define OPTIONS "[-v label] [-r size] [-t any/12/16/32]" |
---|
126 | |
---|
127 | rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command = { |
---|
128 | "msdosfmt", /* name */ |
---|
129 | "msdosfmt " OPTIONS " path # format disk", /* usage */ |
---|
130 | "files", /* topic */ |
---|
131 | rtems_shell_main_msdos_format, /* command */ |
---|
132 | NULL, /* alias */ |
---|
133 | NULL /* next */ |
---|
134 | }; |
---|