File indexing completed on 2025-05-11 08:24:19
0001
0002
0003
0004
0005
0006
0007 #ifdef HAVE_CONFIG_H
0008 #include "config.h"
0009 #endif
0010
0011 #include <stdio.h>
0012 #include <unistd.h>
0013 #include <string.h>
0014 #include <errno.h>
0015 #include <inttypes.h>
0016
0017 #include <rtems.h>
0018 #include <rtems/shell.h>
0019 #include <rtems/stringto.h>
0020 #include <rtems/shellconfig.h>
0021 #include <rtems/dosfs.h>
0022 #include <rtems/fsmount.h>
0023 #include "internal.h"
0024
0025 static int rtems_shell_main_msdos_format(
0026 int argc,
0027 char *argv[]
0028 )
0029 {
0030 msdos_format_request_param_t rqdata = {
0031 .OEMName = "RTEMS",
0032 .VolLabel = "RTEMSDisk",
0033 .sectors_per_cluster = 0,
0034 .fat_num = 0,
0035 .files_per_root_dir = 0,
0036 .media = 0,
0037 .quick_format = TRUE,
0038 .skip_alignment = 0,
0039 .info_level = 0
0040 };
0041
0042 unsigned long tmp;
0043 const char* driver = NULL;
0044 int arg;
0045
0046 for (arg = 1; arg < argc; arg++) {
0047 if (argv[arg][0] == '-') {
0048 switch (argv[arg][1]) {
0049 case 'V':
0050 arg++;
0051 if (arg == argc) {
0052 fprintf (stderr, "error: no volume label.\n");
0053 return 1;
0054 }
0055 rqdata.VolLabel = argv[arg];
0056 break;
0057
0058 case 's':
0059 arg++;
0060 if (arg == argc) {
0061 fprintf (stderr, "error: sectors per cluster count.\n");
0062 return 1;
0063 }
0064
0065 if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
0066 printf(
0067 "sector per cluster argument (%s) is not a number\n",
0068 argv[arg]
0069 );
0070 return -1;
0071 }
0072
0073 rqdata.sectors_per_cluster = (uint32_t) tmp;
0074 break;
0075
0076 case 'r':
0077 arg++;
0078 if (arg == argc) {
0079 fprintf (stderr, "error: no root directory size.\n");
0080 return 1;
0081 }
0082
0083 if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
0084 printf(
0085 "root directory size argument (%s) is not a number\n",
0086 argv[arg]
0087 );
0088 return -1;
0089 }
0090
0091 rqdata.files_per_root_dir = (uint32_t) tmp;
0092 break;
0093
0094 case 'v':
0095 rqdata.info_level++;
0096 break;
0097
0098 default:
0099 fprintf (stderr, "error: invalid option: %s\n", argv[arg]);
0100 return 1;
0101
0102 }
0103 } else {
0104 if (!driver)
0105 driver = argv[arg];
0106 else {
0107 fprintf (stderr, "error: only one driver allowed: %s\n", argv[arg]);
0108 return 1;
0109 }
0110 }
0111 }
0112
0113 if (!driver) {
0114 fprintf (stderr, "error: no driver\n");
0115 return 1;
0116 }
0117
0118 printf ("msdos format: %s\n", driver);
0119
0120 if (rqdata.info_level)
0121 {
0122 printf (" %-20s: %s\n", "OEMName", "RTEMS");
0123 printf (" %-20s: %s\n", "VolLabel", "RTEMSDisk");
0124 printf (" %-20s: %" PRIu32 "\n", "sectors per cluster", rqdata.sectors_per_cluster);
0125 printf (" %-20s: %" PRIu32 "\n", "fats", rqdata.fat_num);
0126 printf (" %-20s: %" PRIu32 "\n", "files per root dir", rqdata.files_per_root_dir);
0127 printf (" %-20s: %d\n", "media", rqdata.media);
0128 printf (" %-20s: %d\n", "quick_format", rqdata.quick_format);
0129 printf (" %-20s: %s\n", "skip_alignment", (0 == rqdata.skip_alignment) ? "false" : "true");
0130 }
0131
0132 if (msdos_format (driver, &rqdata) < 0) {
0133 fprintf (stderr, "error: format failed: %s\n", strerror (errno));
0134 return 1;
0135 }
0136
0137 printf ("msdos format successful\n");
0138
0139 return 0;
0140 }
0141
0142 #define OPTIONS "[-V label] [-s sectors/cluster] [-r size] [-v]"
0143
0144 rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command = {
0145 "mkdos",
0146 "mkdos " OPTIONS " path # format disk",
0147 "files",
0148 rtems_shell_main_msdos_format,
0149 NULL,
0150 NULL
0151 };
0152
0153 rtems_shell_cmd_t rtems_shell_MSDOSFMT_Alias = {
0154 "msdosfmt",
0155 NULL,
0156 "files",
0157 rtems_shell_main_msdos_format,
0158 &rtems_shell_MSDOSFMT_Command,
0159 NULL
0160 };