🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #272

Re: Is a floppy formatted ?

#272
From: phys169
Date: Fri, 07 Aug 1992 00:00
50 lines
3653 bytes
In article <1992Aug6.093943.196@mble.philips.be>, stern@mble.philips.be writes:
> Could anybody explain me how to detect if a floppy is already formatted 
> or not? And also if it is simple to program a 'quick format' like in 
> DOS 5.0 format. 
>  

Use interrupt 0x13 to read sectors 1 and 2 from track 0, head 0. If the read
fails (carry flag set) then the diskette is either not formatted or has a fault
(bad block or you're looking at a non-DOS diskette or a 1.2Mb diskette in a
360Kb drive, or something like that).

Then look at the data you got - if the first byte of the second sector is less
than 0xF0 then it isn't a DOS-formatted disk (I could explain how to work out
if it is CPM, Macintosh, etc if you need to). If it is at least F0 then you
need to also look at sector 1 to be sure it is a good DOS disk - sector 1 must
not be a single byte repeated (if it is then you either have CPM or Macintosh
or some other system, or someone hit ^C during the format process). Ideally,
sector 1 will have a valid Bios Parameter Block - but it might not.. old DOS 1
diskettes don't have a valid BPB, some virus-infected diskettes don't, and some
diskettes created on non-DOS systems (like Amiga and Sun) for transfer of data
to PC's don't always have valid BPB structures.  This structure, if it exists
on the first sector, will be staright after the first 11 bytes (3 for a jump
instruction and 8 for the manufacturer's ID).  The following is the important
part of the BPB (enough to test for validity - try BytesPerSector!=512, and
understand that the TotalSectors can be zero on modern disks to indicate a
number greater than 65535.

type  BiosParameterBlock = record {should be found in boot sector, also found i
                     BytesPerSector  : word; {should be 512}
                     SectorsPerCluster:byte; {a power of two, depends on capa
                     ReservedSectors : word; {1, the boot sector. Any more is
                     NumberOfFATs    : byte; {2, some RAM drives have 1. Dos
                     RootEntries     : word; {a power of 16, can be varied}
                     TotalSectors    : word; {e.g. 720 for a 360K disk; inclu
                     IDbyte          : byte; {F0 to FF; see first byte in FAT
                     SectorsPerFAT   : word; {how many sectors does each FAT
                     SectorsPerTrack : word; {e.g. 8,9,15,18 for diskettes. "
                     NumberOfSides   : word; {1 or two for diskettes}

You can "quickly" format a diskette by writing the first few sectors - the boot
sector (sector 1), the two copies of the FAT (NumberOfFATs * SectorsPerFat),
which will be the IDbyte followed by a couple of 0xFF's, followed by lots of
zeros), followed by a root directory full of zeros - or, at least starting
with some zeros. You might like to see what various UNFORMAT commands expect 
to enable recovery after accidental formatting. I'm not a great fan of quick
formatting of old diskettes, since I've come across too many faulty ones. The
quick formatting method here ignores any bad block that were previously marked,
which is a bad thing (but too involved to easily explain here).

Mark Aitchison, University of Canterbury.
Technical Details
Message-ID: <1992Aug7.120034.215@csc.canterbury.ac.nz>
Path: arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!waikato.ac.nz!canterbury.ac.nz!phys169
References: <1992Aug6.093943.196@mble.philips.be>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!waikato.ac.nz!canterbury.ac.nz!phys169
Newsgroups: comp.os.msdos.programmer
Subject: Re: Is a floppy formatted ?
Message-ID: <1992Aug7.120034.215@csc.canterbury.ac.nz>
From: phys169@csc.canterbury.ac.nz
Date: 7 Aug 92 12:00:34 +1200
References: <1992Aug6.093943.196@mble.philips.be>
Organization: University of Canterbury, Christchurch, New Zealand
Lines: 50