2 * Format -- disk formatting and file-system creation program
3 * Copyright (C) 1999 Ben Hutchings <womble@zzumbouk.demon.co.uk>
4 * Copyright (C) 2008 Pavel Fedin <sonic_amiga@rambler.ru>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <dos/dosasl.h> /* for ERROR_BREAK definition */
24 #include <dos/dosextens.h>
25 #include <dos/filehandler.h>
26 #include <dos/rdargs.h>
27 #include <proto/dos.h>
28 #include <proto/exec.h>
55 #define ARGS_TEMPLATE "DEVICE=DRIVE/K/A,NAME/K/A,OFS/S,FFS/S," \
56 "INTL=INTERNATIONAL/S,NOINTL=NOINTERNATIONAL/S," \
57 "NOICONS/S,DISKICON/S," \
58 "QUICK/S,NOVERIFY/S,TYPE=DOSTYPE/K,FLAGS/K"
60 #define ARGS_TEMPLATE "DEVICE=DRIVE/K/A,NAME/K/A,OFS/S,FFS/S," \
61 "INTL=INTERNATIONAL/S,NOINTL=NOINTERNATIONAL/S," \
62 "DIRCACHE/S,NODIRCACHE/S,NOICONS/S,DISKICON/S," \
63 "QUICK/S,NOVERIFY/S,TYPE=DOSTYPE/K,FLAGS/K"
69 BOOL bCloseStdErr
= FALSE
;
70 LONG rc
= RETURN_FAIL
;
71 BPTR bpfhStdIn
, bpfhStdOut
;
72 BOOL DirCache
= FALSE
;
73 BOOL NoDirCache
= TRUE
;
76 prda
= ReadArgs(ARGS_TEMPLATE
, (IPTR
*)&args
, 0 );
79 PrintFault( IoErr(), 0 );
84 struct Process
* pprSelf
= (struct Process
*)FindTask(0);
85 bpfhStdIn
= pprSelf
->pr_CIS
;
86 bpfhStdOut
= pprSelf
->pr_COS
;
87 bpfhStdErr
= pprSelf
->pr_CES
;
88 /* CES is allowed to be 0; in that case the best behaviour is to
89 try opening the console, or as a last resort sending errors to
93 if( (bpfhStdErr
= Open( "*", MODE_NEWFILE
)) == 0 )
94 bpfhStdErr
= bpfhStdOut
;
100 if( !bSetSzDosDeviceFromSz(args
.pszDevice
)
101 || !bSetSzVolumeFromSz(args
.pszName
)
102 || (args
.pszType
&& !bSetFstFromSz(args
.pszType
))
103 || (args
.pszFlags
&& !bSetDevfFromSz(args
.pszFlags
))
104 || !bGetDosDevice(NULL
, 0) )
110 /* Get confirmation before we start the process */
111 *pchDosDeviceColon
= 0;
112 Printf( _(MSG_INSERT_DISK
),
115 SetMode( bpfhStdIn
, 1 ); /* raw input */
119 cch
= Read( bpfhStdIn
, &ch
, 1 );
120 D(Printf("Character code: %lu\n", ch
));
121 } while( cch
== 1 && ch
!= 3 && ch
!= 13 );
123 SetMode( bpfhStdIn
, 0 ); /* cooked input */
127 PrintFault( ERROR_BREAK
, 0 );
132 /* Do (low-level) format unless the "QUICK" switch was used */
133 BOOL formatOk
= TRUE
;
138 if(!bGetExecDevice(!args
.bNoVerify
))
141 PutStr("\033[0 p"); /* turn cursor off */
142 /* TODO: arrange for cursor to be turned back on in case of error */
148 /* Allow the user to break */
149 if(CheckSignal(SIGBREAKF_CTRL_C
))
152 D(Printf("Cancelled by user\n"));
153 PrintFault( ERROR_BREAK
, 0 );
158 Printf( _(MSG_FORMATTING
), icyl
, HighCyl
-icyl
);
161 if(!bFormatCylinder(icyl
))
169 PutStr( _(MSG_VERIFYING
) );
172 if(!bVerifyCylinder(icyl
))
180 PutStr("\033[ p\n"); /* turn cursor on and go to next line */
187 PutStr( _(MSG_INITIALIZING
) );
190 DirCache
= args
.bDirCache
;
191 NoDirCache
= args
.bNoDirCache
;
193 if( bMakeFileSys( args
.bFFS
, args
.bOFS
, args
.bIntl
, args
.bNoIntl
,
194 DirCache
, NoDirCache
)
195 && (args
.bNoIcons
|| bMakeFiles(args
.bDiskIcon
)) )
201 (void) Close(bpfhStdErr
);