added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / c / Format / main.c
blob69782c1ce5e6965a1708f9873465fea5a5fe7fb8
1 /*
2 Copyright © 2003-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Format CLI command
6 Lang: English
7 */
8 /******************************************************************************
11 NAME
13 Format
15 USAGE
17 Format DRIVE=<Drive> [NAME=<name>] [OFS | FFS] [INTL | NOINTL] [FORCE] [QUIET]
19 SYNOPSIS
21 DRIVE/K/A, NAME/K/A, OFS/S, FFS/S, INTL=INTERNTIONAL/S, NOINTL=NOINTERNATIONAL/S, FORCE/S, QUIET/S
23 LOCATION
25 Sys:C
27 FUNCTION
29 Format will initialise a disk to be useable by the AROS.
31 INPUTS
33 DRIVE -- The device disk unit designation
34 NAME -- Sets the volume name
35 OFS -- Formats the drive withe the Old File system (not recommended for HDs)
36 FFS -- Formats the drive withe the Fast File system.
37 INTL -- Enables the FFS support of international characters.
38 FORCE
39 QUIET -- It will not display any output, ordinary or error messages.
41 RESULT
43 NOTES
45 This command only supports OFS and FFS filesystem.
47 EXAMPLE
49 Format DRIVE=DF0: NAME="MyDisk" FFS
50 (This will format a disk present in the internal floppy drive with the
51 name 'Mydisk' and with Fast File System.)
53 BUGS
55 SEE ALSO
57 SFSformat, Info
59 INTERNALS
61 HISTORY
63 ******************************************************************************/
64 #define DEBUG 0
66 #include <proto/dos.h>
68 #include <aros/debug.h>
69 #include <exec/types.h>
70 #include <dos/dos.h>
71 #include <dos/filehandler.h>
73 #define MASK_FFS AROS_MAKE_ID(0x00, 0x00, 0x00, 1)
74 #define MASK_INTL AROS_MAKE_ID(0x00, 0x00, 0x00, 2)
75 #define MASK_DOS AROS_MAKE_ID(0xFF, 0xFF, 0xFF, 0)
77 #define SH_GLOBAL_DOSBASE TRUE
78 #include <aros/shcommands.h>
80 AROS_SH8
82 Format, 41.1,
83 AROS_SHA(STRPTR, , DRIVE, /K/A, NULL),
84 AROS_SHA(STRPTR, , NAME, /K/A, NULL),
85 AROS_SHA(BOOL, , OFS, /S, FALSE),
86 AROS_SHA(BOOL, , FFS, /S, FALSE),
87 AROS_SHA(BOOL, INTL=, INTERNATIONAL, /S, FALSE),
88 AROS_SHA(BOOL, NOINTL=, NOINTERNATIONAL, /S, FALSE),
89 AROS_SHA(BOOL, , FORCE, /S, FALSE),
90 AROS_SHA(BOOL, , QUIET, /S, FALSE)
93 AROS_SHCOMMAND_INIT
95 TEXT choice = 'N';
96 ULONG dostype;
97 struct DevProc *dp;
98 struct DosList *dl;
99 struct FileSysStartupMsg *fssm;
100 struct DosEnvec *env;
102 if (SHArg(QUIET) && !SHArg(FORCE))
104 PutStr("ERROR: Cannot specify QUIET without FORCE.\n");
105 return RETURN_FAIL;
107 if (SHArg(OFS) && SHArg(FFS))
109 PutStr("ERROR: Cannot specify OFS with FFS.\n");
110 return RETURN_FAIL;
112 if (SHArg(INTERNATIONAL) && SHArg(NOINTERNATIONAL))
114 PutStr("ERROR: Cannot specify INTL with NOINTL.\n");
115 return RETURN_FAIL;
117 dp = GetDeviceProc(SHArg(DRIVE), NULL);
118 if (!dp)
120 Printf("ERROR: Device %s not found.\n", SHArg(DRIVE));
121 return RETURN_FAIL;
123 dl = dp->dvp_DevNode;
124 FreeDeviceProc(dp);
125 if (dl->dol_Type != DLT_DEVICE)
127 Printf("ERROR: %s is not a physical device.\n", SHArg(DRIVE));
128 return RETURN_FAIL;
131 fssm = (struct FileSysStartupMsg *)BADDR(dp->dvp_DevNode->dol_misc.dol_handler.dol_Startup);
132 env = (struct DosEnvec *)BADDR(fssm->fssm_Environ);
133 dostype = env->de_DosType;
134 D(Printf("DOS type queried: 0x%08lX\n", dostype));
135 if (((dostype & MASK_DOS) != ID_DOS_DISK) &&
136 (SHArg(OFS) || SHArg(FFS) || SHArg(INTERNATIONAL) || SHArg(NOINTERNATIONAL)))
138 Printf("ERROR: OFS, FFS, INTL and NOINTL can't be used on device %s./n", SHArg(DRIVE));
139 return RETURN_FAIL;
142 if (SHArg(OFS))
143 dostype &= ~MASK_FFS;
144 if (SHArg(FFS))
145 dostype |= MASK_FFS;
146 if (SHArg(INTERNATIONAL))
147 dostype |= MASK_INTL;
148 if (SHArg(NOINTERNATIONAL))
149 dostype &= ~MASK_INTL;
150 D(Printf("Resulting DOS type: 0x%08lX\n", dostype));
152 if (!SHArg(FORCE))
154 Printf("About to format drive %s. ", SHArg(DRIVE));
155 Printf("This will destroy all data on the drive!\n");
156 Printf("Are you sure? (y/N)"); Flush(Output());
158 Read(Input(), &choice, 1);
160 else
162 choice = 'y';
165 if (choice == 'y' || choice == 'Y')
167 if (!SHArg(QUIET))
169 Printf("Formatting...");
170 Flush(Output());
174 if (Inhibit(SHArg(DRIVE), DOSTRUE))
176 if (Format(SHArg(DRIVE), SHArg(NAME), dostype))
178 if (!SHArg(QUIET)) Printf("done\n");
180 else
182 goto error;
184 Inhibit(SHArg(DRIVE), DOSFALSE);
186 else
188 goto error;
192 return RETURN_OK;
194 error:
195 if (!SHArg(QUIET)) Printf("ERROR!\n");
197 return RETURN_FAIL;
199 AROS_SHCOMMAND_EXIT