source: rtems/cpukit/libmisc/shell/main_msdosfmt.c @ 07d6fd5

4.104.115
Last change on this file since 07d6fd5 was 07d6fd5, checked in by Chris Johns <chrisj@…>, on 04/29/09 at 08:31:27

2009-04-29 Chris Johns <chrisj@…>

  • libcsupport/include/rtems/libio.h: Add rtems_off64_t for internal use. Update the internal off_t to the 64bit offset.
  • libnetworking/lib/ftpfs.c, libnetworking/lib/tftpDriver.c, libfs/src/nfsclient/src/nfs.c, libfs/src/imfs/imfs_fifo.c, libfs/src/imfs/memfile.c, libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs.h, libfs/src/imfs/deviceio.c: Change off_t to rtems_off64_t.
  • libmisc/shell/main_msdosfmt.c: Add an info level so the format code can tell the user what is happening. Add more options to control the format configuration.
  • libfs/src/dosfs/msdos_format.c: Add a print function to display the format progress and print statements. Select a better default cluster size depending on the size of the disk. This lowers the size of the FAT on large disks. Read and maintain the MRB partition information.
  • libfs/src/dosfs/dosfs.h, libfs/src/dosfs/fat.h, libfs/src/dosfs/fat_file.c, libfs/src/dosfs/fat_file.h, libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_conv.c, libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_handlers_dir.c, libfs/src/dosfs/msdos_handlers_file.c, libfs/src/dosfs/msdos_init.c, libfs/src/dosfs/msdos_initsupp.c, libfs/src/dosfs/msdos_misc.c, libfs/src/dosfs/msdos_mknod.c: Add long file name support. Change off_t to rtems_off64_t.
  • Property mode set to 100644
File size: 4.2 KB
Line 
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
31int 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    info_level:          0
47  };
48 
49  const char* driver = NULL;
50  int         arg;
51 
52  for (arg = 1; arg < argc; arg++) {
53    if (argv[arg][0] == '-') {
54      switch (argv[arg][1]) {
55        case 'V':
56          arg++;
57          if (arg == argc) {
58            fprintf (stderr, "error: no volume label.\n");
59            return 1;
60          }
61          rqdata.VolLabel = argv[arg];
62          break;
63
64        case 's':
65          arg++;
66          if (arg == argc) {
67            fprintf (stderr, "error: sectors per cluster count.\n");
68            return 1;
69          }
70          rqdata.sectors_per_cluster = rtems_shell_str2int(argv[arg]);
71          break;
72         
73        case 'r':
74          arg++;
75          if (arg == argc) {
76            fprintf (stderr, "error: no root directory size.\n");
77            return 1;
78          }
79          rqdata.files_per_root_dir = rtems_shell_str2int(argv[arg]);
80          break;
81         
82        case 't':
83          arg++;
84          if (arg == argc) {
85            fprintf (stderr, "error: no FAT type.\n");
86            return 1;
87          }
88
89          if (strcmp (argv[arg], "any") == 0)
90            rqdata.fattype = MSDOS_FMT_FATANY;
91          else if (strcmp (argv[arg], "12") == 0)
92            rqdata.fattype = MSDOS_FMT_FAT12;
93          else if (strcmp (argv[arg], "16") == 0)
94            rqdata.fattype = MSDOS_FMT_FAT16;
95          else if (strcmp (argv[arg], "32") == 0)
96            rqdata.fattype = MSDOS_FMT_FAT32;
97          else {
98            fprintf (stderr, "error: invalid type, can any, 12, 16, or 32\n");
99            return 1;
100          }
101          break;
102
103        case 'v':
104          rqdata.info_level++;
105          break;
106         
107        default:
108          fprintf (stderr, "error: invalid option: %s\n", argv[arg]);
109          return 1;
110         
111      }
112    } else {
113      if (!driver)
114        driver = argv[arg];
115      else {
116        fprintf (stderr, "error: only one driver allowed: %s\n", argv[arg]);
117        return 1;
118      }
119    }
120  }
121
122  if (!driver) {
123    fprintf (stderr, "error: no driver\n");
124    return 1;
125  }
126 
127  printf ("msdos format: %s\n", driver);
128
129  if (rqdata.info_level)
130  {
131    printf (" %-20s: %s\n", "OEMName", "RTEMS");
132    printf (" %-20s: %s\n", "VolLabel", "RTEMSDisk");
133    printf (" %-20s: %i\n", "sectors per cluster", rqdata.sectors_per_cluster);
134    printf (" %-20s: %i\n", "fats", rqdata.fat_num);
135    printf (" %-20s: %i\n", "files per root dir", rqdata.files_per_root_dir);
136    printf (" %-20s: %i\n", "fat type", rqdata.fattype);
137    printf (" %-20s: %d\n", "media", rqdata.media);
138    printf (" %-20s: %d\n", "quick_format", rqdata.quick_format);
139    printf (" %-20s: %i\n", "cluster align", rqdata.cluster_align);
140  }
141 
142  if (msdos_format (driver, &rqdata) < 0) {
143    fprintf (stderr, "error: format failed: %s\n", strerror (errno));
144    return 1;
145  }
146
147  printf ("msdos format successful\n");
148
149  return 0;
150}
151
152#define OPTIONS "[-v label] [-r size] [-t any/12/16/32]"
153
154rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command = {
155  "msdosfmt",                                /* name */
156  "msdosfmt " OPTIONS " path # format disk", /* usage */
157  "files",                                   /* topic */
158  rtems_shell_main_msdos_format,             /* command */
159  NULL,                                      /* alias */
160  NULL                                       /* next */
161};
Note: See TracBrowser for help on using the repository browser.