source: rtems/cpukit/libmisc/shell/main_msdosfmt.c @ 2649eef

4.104.115
Last change on this file since 2649eef was dfe0e58, checked in by Joel Sherrill <joel.sherrill@…>, on 02/27/08 at 21:52:16

2008-02-27 Joel Sherrill <joel.sherrill@…>

  • libmisc/shell/cat_file.c, libmisc/shell/main_alias.c, libmisc/shell/main_blksync.c, libmisc/shell/main_cat.c, libmisc/shell/main_chdir.c, libmisc/shell/main_chmod.c, libmisc/shell/main_chroot.c, libmisc/shell/main_cpuuse.c, libmisc/shell/main_date.c, libmisc/shell/main_help.c, libmisc/shell/main_id.c, libmisc/shell/main_logoff.c, libmisc/shell/main_ls.c, libmisc/shell/main_mallocinfo.c, libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c, libmisc/shell/main_mfill.c, libmisc/shell/main_mkdir.c, libmisc/shell/main_mmove.c, libmisc/shell/main_mount.c, libmisc/shell/main_mount_nfs.c, libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c, libmisc/shell/main_perioduse.c, libmisc/shell/main_pwd.c, libmisc/shell/main_rm.c, libmisc/shell/main_rmdir.c, libmisc/shell/main_stackuse.c, libmisc/shell/main_tty.c, libmisc/shell/main_umask.c, libmisc/shell/main_unmount.c, libmisc/shell/main_whoami.c, libmisc/shell/shell.h: Clean up done while writing documentation. Some command improvements such as date now allows setting of the current TOD. Often commands did not use stdout/stderr per expectations and did not return -1 on an error.
  • Property mode set to 100644
File size: 3.3 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  };
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
127rtems_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};
Note: See TracBrowser for help on using the repository browser.