source: rtems/cpukit/libmisc/shell/main_msdosfmt.c @ 48751ab

4.104.115
Last change on this file since 48751ab was 48751ab, checked in by Joel Sherrill <joel.sherrill@…>, on 07/23/09 at 14:32:34

2009-07-23 Joel Sherrill <joel.sherrill@…>

  • libmisc/Makefile.am, libmisc/shell/main_chmod.c, libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c, libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c, libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c, libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c, libmisc/shell/shell_script.c, libmisc/stringto/stringto.h, libmisc/stringto/stringto_template.h: Convert return type from bool to rtems_status_code and add rtems_string_to_pointer. Perform associated clean up and changes for return type change.
  • libmisc/stringto/stringtopointer.c: New file.
  • Property mode set to 100644
File size: 4.6 KB
Line 
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
18#include <rtems.h>
19#include <rtems/shell.h>
20#include <rtems/stringto.h>
21#include <rtems/shellconfig.h>
22#include <rtems/dosfs.h>
23#include <rtems/fsmount.h>
24#include "internal.h"
25
26int rtems_shell_main_msdos_format(
27  int   argc,
28  char *argv[]
29)
30{
31  msdos_format_request_param_t rqdata = {
32    OEMName:             "RTEMS",
33    VolLabel:            "RTEMSDisk",
34    sectors_per_cluster: 0,
35    fat_num:             0,
36    files_per_root_dir:  0,
37    fattype:             MSDOS_FMT_FATANY,
38    media:               0,
39    quick_format:        TRUE,
40    cluster_align:       0,
41    info_level:          0
42  };
43 
44  unsigned long tmp;
45  const char*   driver = NULL;
46  int           arg;
47 
48  for (arg = 1; arg < argc; arg++) {
49    if (argv[arg][0] == '-') {
50      switch (argv[arg][1]) {
51        case 'V':
52          arg++;
53          if (arg == argc) {
54            fprintf (stderr, "error: no volume label.\n");
55            return 1;
56          }
57          rqdata.VolLabel = argv[arg];
58          break;
59
60        case 's':
61          arg++;
62          if (arg == argc) {
63            fprintf (stderr, "error: sectors per cluster count.\n");
64            return 1;
65          }
66
67          if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
68            printf(
69              "sector per cluster argument (%s) is not a number\n",
70               argv[arg]
71            );
72            return -1;
73          }
74
75          rqdata.sectors_per_cluster = (uint32_t) tmp;
76          break;
77         
78        case 'r':
79          arg++;
80          if (arg == argc) {
81            fprintf (stderr, "error: no root directory size.\n");
82            return 1;
83          }
84
85          if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
86            printf(
87              "root directory size argument (%s) is not a number\n",
88               argv[arg]
89            );
90            return -1;
91          }
92
93          rqdata.files_per_root_dir = (uint32_t) tmp;
94          break;
95         
96        case 't':
97          arg++;
98          if (arg == argc) {
99            fprintf (stderr, "error: no FAT type.\n");
100            return 1;
101          }
102
103          if (strcmp (argv[arg], "any") == 0)
104            rqdata.fattype = MSDOS_FMT_FATANY;
105          else if (strcmp (argv[arg], "12") == 0)
106            rqdata.fattype = MSDOS_FMT_FAT12;
107          else if (strcmp (argv[arg], "16") == 0)
108            rqdata.fattype = MSDOS_FMT_FAT16;
109          else if (strcmp (argv[arg], "32") == 0)
110            rqdata.fattype = MSDOS_FMT_FAT32;
111          else {
112            fprintf (stderr, "error: invalid type, can any, 12, 16, or 32\n");
113            return 1;
114          }
115          break;
116
117        case 'v':
118          rqdata.info_level++;
119          break;
120         
121        default:
122          fprintf (stderr, "error: invalid option: %s\n", argv[arg]);
123          return 1;
124         
125      }
126    } else {
127      if (!driver)
128        driver = argv[arg];
129      else {
130        fprintf (stderr, "error: only one driver allowed: %s\n", argv[arg]);
131        return 1;
132      }
133    }
134  }
135
136  if (!driver) {
137    fprintf (stderr, "error: no driver\n");
138    return 1;
139  }
140 
141  printf ("msdos format: %s\n", driver);
142
143  if (rqdata.info_level)
144  {
145    printf (" %-20s: %s\n", "OEMName", "RTEMS");
146    printf (" %-20s: %s\n", "VolLabel", "RTEMSDisk");
147    printf (" %-20s: %lu\n", "sectors per cluster", rqdata.sectors_per_cluster);
148    printf (" %-20s: %lu\n", "fats", rqdata.fat_num);
149    printf (" %-20s: %lu\n", "files per root dir", rqdata.files_per_root_dir);
150    printf (" %-20s: %i\n", "fat type", rqdata.fattype);
151    printf (" %-20s: %d\n", "media", rqdata.media);
152    printf (" %-20s: %d\n", "quick_format", rqdata.quick_format);
153    printf (" %-20s: %lu\n", "cluster align", rqdata.cluster_align);
154  }
155 
156  if (msdos_format (driver, &rqdata) < 0) {
157    fprintf (stderr, "error: format failed: %s\n", strerror (errno));
158    return 1;
159  }
160
161  printf ("msdos format successful\n");
162
163  return 0;
164}
165
166#define OPTIONS "[-v label] [-r size] [-t any/12/16/32]"
167
168rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command = {
169  "msdosfmt",                                /* name */
170  "msdosfmt " OPTIONS " path # format disk", /* usage */
171  "files",                                   /* topic */
172  rtems_shell_main_msdos_format,             /* command */
173  NULL,                                      /* alias */
174  NULL                                       /* next */
175};
Note: See TracBrowser for help on using the repository browser.