Files
rtems/cpukit/libmisc/shell/main_msdosfmt.c
Ralf Corsepius 3421e5201f * libmisc/shell/main_help.c: Make rtems_shell_help_cmd,
rtems_shell_help static.
	* libmisc/shell/main_hexdump.c: Make main_hexdump static.
	* libmisc/shell/main_id.c: Make rtems_shell_main_id static.
	* libmisc/shell/main_ifconfig.c: Make rtems_shell_main_ifconfig static.
	* libmisc/shell/main_ln.c: Make rtems_shell_main_ln static.
	* libmisc/shell/main_logoff.c: Make rtems_shell_main_logoff static.
	* libmisc/shell/main_ls.c: Make rtems_shell_main_ls static.
	* libmisc/shell/main_mallocinfo.c: Include <rtems/libcsupport.h>.
	Remove private decls of malloc_info,
	rtems_shell_print_unified_work_area_message.
	Make rtems_shell_main_malloc_info static.
	* libmisc/shell/main_medit.c: Remove private decl of
	rtems_shell_main_mdump.
	Make rtems_shell_main_medit static.
	* libmisc/shell/main_mfill.c: Make rtems_shell_main_mfill static.
	* libmisc/shell/main_mkdir.c: Make rtems_shell_main_mkdir static.
	* libmisc/shell/main_mknod.c: Make rtems_shell_main_mknod static.
	* libmisc/shell/main_mmove.c: Remove private decl of
	rtems_shell_main_mdump.
	Make rtems_shell_main_mmove static.
	* libmisc/shell/main_mount.c: Make rtems_shell_main_mount static.
	* libmisc/shell/main_msdosfmt.c: Make rtems_shell_main_msdos_format
	static.
	* libmisc/shell/main_mv.c: Include "internal.h".
	Make rtems_shell_mv_exit, rtems_shell_main_mv static.
	Remove private decls of strmode rtems_shell_main_cp,
	rtems_shell_main_rm.
	* libmisc/shell/main_mwdump.c: Make rtems_shell_main_mwdump static.
	* libmisc/shell/main_netstats.c: Make rtems_shell_main_netstats
	static.
	* libmisc/shell/main_perioduse.c: Make rtems_shell_main_perioduse
	static.
	* libmisc/shell/main_pwd.c: Make rtems_shell_main_pwd static.
	* libmisc/shell/main_rm.c: Include "internal.h".
	Make rtems_shell_rm_exit static.
	Remove private decl of strmode.
	* libmisc/shell/main_rmdir.c: Make rtems_shell_main_rmdir static.
	libmisc/shell/main_route.c: Make rtems_shell_main_route static.
	* libmisc/shell/main_setenv.c: Make rtems_shell_main_setenv static.
	* libmisc/shell/main_sleep.c: Make rtems_shell_main_sleep static.
	* libmisc/shell/main_stackuse.c: Make rtems_shell_main_stackuse static.
	* libmisc/shell/main_time.c: Make rtems_shell_main_time static.
	* libmisc/shell/main_tty.c: Make rtems_shell_main_tty static.
	* libmisc/shell/main_umask.c: Make rtems_shell_main_umask static.
	* libmisc/shell/main_unmount.c: Make rtems_shell_main_unmount
	static.
	* libmisc/shell/main_unsetenv.c: Make rtems_shell_main_unsetenv
	static.
	* libmisc/shell/main_whoami.c: Make rtems_shell_main_whoami static.
	* libmisc/shell/main_wkspaceinfo.c: Make
	rtems_shell_main_wkspace_info static.
2011-12-04 10:22:51 +00:00

186 lines
5.0 KiB
C

/*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#include <rtems.h>
#include <rtems/shell.h>
#include <rtems/stringto.h>
#include <rtems/shellconfig.h>
#include <rtems/dosfs.h>
#include <rtems/fsmount.h>
#include "internal.h"
static int rtems_shell_main_msdos_format(
int argc,
char *argv[]
)
{
msdos_format_request_param_t rqdata = {
.OEMName = "RTEMS",
.VolLabel = "RTEMSDisk",
.sectors_per_cluster = 0,
.fat_num = 0,
.files_per_root_dir = 0,
.fattype = MSDOS_FMT_FATANY,
.media = 0,
.quick_format = TRUE,
.cluster_align = 0,
.info_level = 0
};
unsigned long tmp;
const char* driver = NULL;
int arg;
for (arg = 1; arg < argc; arg++) {
if (argv[arg][0] == '-') {
switch (argv[arg][1]) {
case 'V':
arg++;
if (arg == argc) {
fprintf (stderr, "error: no volume label.\n");
return 1;
}
rqdata.VolLabel = argv[arg];
break;
case 's':
arg++;
if (arg == argc) {
fprintf (stderr, "error: sectors per cluster count.\n");
return 1;
}
if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
printf(
"sector per cluster argument (%s) is not a number\n",
argv[arg]
);
return -1;
}
rqdata.sectors_per_cluster = (uint32_t) tmp;
break;
case 'r':
arg++;
if (arg == argc) {
fprintf (stderr, "error: no root directory size.\n");
return 1;
}
if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
printf(
"root directory size argument (%s) is not a number\n",
argv[arg]
);
return -1;
}
rqdata.files_per_root_dir = (uint32_t) tmp;
break;
case 't':
arg++;
if (arg == argc) {
fprintf (stderr, "error: no FAT type.\n");
return 1;
}
if (strcmp (argv[arg], "any") == 0)
rqdata.fattype = MSDOS_FMT_FATANY;
else if (strcmp (argv[arg], "12") == 0)
rqdata.fattype = MSDOS_FMT_FAT12;
else if (strcmp (argv[arg], "16") == 0)
rqdata.fattype = MSDOS_FMT_FAT16;
else if (strcmp (argv[arg], "32") == 0)
rqdata.fattype = MSDOS_FMT_FAT32;
else {
fprintf (stderr, "error: invalid type, can any, 12, 16, or 32\n");
return 1;
}
break;
case 'v':
rqdata.info_level++;
break;
default:
fprintf (stderr, "error: invalid option: %s\n", argv[arg]);
return 1;
}
} else {
if (!driver)
driver = argv[arg];
else {
fprintf (stderr, "error: only one driver allowed: %s\n", argv[arg]);
return 1;
}
}
}
if (!driver) {
fprintf (stderr, "error: no driver\n");
return 1;
}
printf ("msdos format: %s\n", driver);
if (rqdata.info_level)
{
printf (" %-20s: %s\n", "OEMName", "RTEMS");
printf (" %-20s: %s\n", "VolLabel", "RTEMSDisk");
printf (" %-20s: %" PRIu32 "\n", "sectors per cluster", rqdata.sectors_per_cluster);
printf (" %-20s: %" PRIu32 "\n", "fats", rqdata.fat_num);
printf (" %-20s: %" PRIu32 "\n", "files per root dir", rqdata.files_per_root_dir);
printf (" %-20s: %i\n", "fat type", rqdata.fattype);
printf (" %-20s: %d\n", "media", rqdata.media);
printf (" %-20s: %d\n", "quick_format", rqdata.quick_format);
printf (" %-20s: %" PRIu32 "\n", "cluster align", rqdata.cluster_align);
}
if (msdos_format (driver, &rqdata) < 0) {
fprintf (stderr, "error: format failed: %s\n", strerror (errno));
return 1;
}
printf ("msdos format successful\n");
return 0;
}
#define OPTIONS "[-v label] [-r size] [-t any/12/16/32]"
rtems_shell_cmd_t rtems_shell_MSDOSFMT_Command = {
"mkdos", /* name */
"mkdos " OPTIONS " path # format disk", /* usage */
"files", /* topic */
rtems_shell_main_msdos_format, /* command */
NULL, /* alias */
NULL /* next */
};
rtems_shell_cmd_t rtems_shell_MSDOSFMT_Alias = {
"msdosfmt", /* name */
NULL, /* usage */
"files", /* topic */
rtems_shell_main_msdos_format, /* command */
&rtems_shell_MSDOSFMT_Command, /* alias */
NULL /* next */
};