2 Copyright © 2003-2007, The AROS Development Team. All rights reserved.
5 Desc: Format CLI command
8 /******************************************************************************
17 Format DRIVE=<Drive> [NAME=<name>] [OFS | FFS] [INTL | NOINTL] [FORCE] [QUIET]
21 DRIVE/K/A, NAME/K/A, OFS/S, FFS/S, INTL=INTERNTIONAL/S, NOINTL=NOINTERNATIONAL/S, FORCE/S, QUIET/S
29 Format will initialise a disk to be useable by the AROS.
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.
39 QUIET -- It will not display any output, ordinary or error messages.
45 This command only supports OFS and FFS filesystem.
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.)
63 ******************************************************************************/
66 #include <proto/dos.h>
68 #include <aros/debug.h>
69 #include <exec/types.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>
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
)
99 struct FileSysStartupMsg
*fssm
;
100 struct DosEnvec
*env
;
102 if (SHArg(QUIET
) && !SHArg(FORCE
))
104 PutStr("ERROR: Cannot specify QUIET without FORCE.\n");
107 if (SHArg(OFS
) && SHArg(FFS
))
109 PutStr("ERROR: Cannot specify OFS with FFS.\n");
112 if (SHArg(INTERNATIONAL
) && SHArg(NOINTERNATIONAL
))
114 PutStr("ERROR: Cannot specify INTL with NOINTL.\n");
117 dp
= GetDeviceProc(SHArg(DRIVE
), NULL
);
120 Printf("ERROR: Device %s not found.\n", SHArg(DRIVE
));
123 dl
= dp
->dvp_DevNode
;
125 if (dl
->dol_Type
!= DLT_DEVICE
)
127 Printf("ERROR: %s is not a physical device.\n", SHArg(DRIVE
));
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
));
143 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
));
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);
165 if (choice
== 'y' || choice
== 'Y')
169 Printf("Formatting...");
174 if (Inhibit(SHArg(DRIVE
), DOSTRUE
))
176 if (Format(SHArg(DRIVE
), SHArg(NAME
), dostype
))
178 if (!SHArg(QUIET
)) Printf("done\n");
184 Inhibit(SHArg(DRIVE
), DOSFALSE
);
195 if (!SHArg(QUIET
)) Printf("ERROR!\n");