ZFMAT: Diskette Formatting Program
Copyright 1988 by Edward V. Dong, All Rights Reserved.
Edward V Dong's Floppy Formattor is a Turbo C program to format floppy
diskettes, based on earlier work by Frank Nystrom (COPYIT.C;CIS
71631,355), Kim Kokkonen (FMAT.PAS; Compuserve 72457,2131), and Peter
Norton (BOOT.ASM). This programs formats, accurately, 360K diskettes
in either standard 360K drives or 1.2M drives; and has been tested on
an XT clone with a 360K drive and an AT clone with a 1.2M drive. This
has not been tested on an AT with a 360K drive, and the program assumes
that 1.2M drives are used only with AT class machines.
Essentially, formatting is all performed by the BIOS, through calls to
Turbo C's biosdisk() routine. To format a disk, the tracks are first
formatted, then boot record, two copies of the file allocation table
(FAT), and the root directory are written to the diskette. This
program then verifies each track, again via the BIOS. The basic
formatting and verification routines are derived from Nystrom's
COPYIT.C; the boot record used is a custom one, based on Norton's
BOOT.ASM. The FAT and root directory routines are rehosted versions
based on Kokkonen's FMAT.PAS.
To format 360K diskettes in 1.2 megabyte drives, the DASD must be set -
this is only possible for DOS 3.0 or higher and for AT class machines.
The routines here are based on Kokkonen's Turbo Pascal work, ported to
Turbo C. Through some experimentation and analysis, the only
difference with running on an AT machine is to use a delay of about 0.3
seconds between biosdisk calls to allow the disk heads to settle.
Quick disk reformat is here done as a rewrite of the diskette's boot
sector, FAT, and root directory. A "quick" reformat ASSUMES that the
diskette has no bad sectors at all. Depending on configuration, DOS
retains a copy of the old FAT which shows the old free space, even
though the directory has been cleared. This is only true for AT's and
1.2 meg drives; as a workaround, one track is formatted, which seem to
force AT floppy disk controller to recognize that the disk has been
changed; and therefore DOS will read the diskette to acquire the new
FAT and directory information.
This source code is placed into the public domain. However,
contributions are always welcome. This is a modified form of the
source code used in the author's ZIP program. Written for Turbo C 1.5,
it should compile under Turbo C 1.0 as well, and should be portable to
other C compilers (notably MicroSoft). The included C source is well
annotated, so you should have no problem understanding it (I assume
some knowledge of BIOS, DOS, and diskette organization).
ZFMAT.C Turbo C source code
Files Not Included
FMAT.PAS Original disk formatting code by Kim Kokkonen
BOOTREC.ASM Peter Norton's BOOT record source code
Programming Note: Character bytes MUST BE set as unsigned. (If not,
you will get some nasty 'out of range' warnings.) This was
compiled using the Large Model, but is essentially independent of C
Edward V. Dong, 12205 Alexandria Pl, Chino, CA 91710.
08 Jun 88 - Add check for type of drive (360K or 1.2Meg)
04 Jun 88 - set up logical disk sectoring -
01 Jun 88 - fix message on disk space -
18 May 88 - original issue