Article View: borland.public.cppbuilder.nativeapi
Article #8314Re: floppy disk bad sectors
From: Andrue Cope [TeamB]
Date: Thu, 11 Nov 2004 16:19
Date: Thu, 11 Nov 2004 16:19
66 lines
3280 bytes
3280 bytes
Don Locke wrote:
> I'm gaining on it!! From what I gathered from your other replies, I
> need to read the entire disk & check for error codes to determine if
> the disk is good or not.
Yes.
The following should test a 1.4MB floppy disk:
// This would need to change according to capacity
DWORD totalBlocks=2880;
// This will be fixed for floppy disks
DWORD blockSize=512; // DWORD avoids casting issues later on.
bool DiskIsGood( diskHandle )
{
boost::scoped_array<BYTE> buffer( new BYTE[ blockSize ] );
for( DWORD blockNumber=0;
blockNumber<totalBlocks;
++blockNumber )
{
Seek( diskHandle,
blockNumber*blockSize );
DWORD bytesRead=0;
if( ReadFile( diskHandle,
buffer.get(),
blockSize,
&bytesRead,
NULL ) )
return false;
}
}
But might be a bit slow depending on whether your floppy driver
implements readahead or not. It looks like GetFileSize might work so
you could have:
DWORD totalBlocks=GetFileSize( diskHandle )/blockSize;
It should be obvious if the loop is working because you'll hear the
rythmic clunk-clunk-clunk of the disk head moving (80 times for a 1.4M
floppy). In any case I'm going to mock up this code now that I have a
spare few minutes just to be sure I haven't missed something, lol.
To really verify this you could write the data in 'buffer' to a file.
You'd then have written a one way disk imager. If you then wrote the
reverse code to put the file back on a disk you'd have written DiskCopy.
Easy, huh?
Lol, you'd be amazed how complicated a disk imager can get when you
have to deal with bad sectors. Hard disks can pull some really dirty
tricks on you like rearranging the block order, returning any old block
instead of the (bad) one you asked for.
None of this should bother you, luckily, but I thought I'd share my
pain :)
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<419391cc$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed.freenet.de!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<419121f3$1@newsgroups.borland.com> <41921bba$1@newsgroups.borland.com> <41922983$1@newsgroups.borland.com> <4192311f$1@newsgroups.borland.com> <41923ebd@newsgroups.borland.com> <41937d68@newsgroups.borland.com> <4193841f@newsgroups.borland.com> <419387ad$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2aacc4eb93e0b7a0 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address> Subject: Re: floppy disk bad sectors Newsgroups: borland.public.cppbuilder.nativeapi References: <419121f3$1@newsgroups.borland.com> <41921bba$1@newsgroups.borland.com> <41922983$1@newsgroups.borland.com> <4192311f$1@newsgroups.borland.com> <41923ebd@newsgroups.borland.com> <41937d68@newsgroups.borland.com> <4193841f@newsgroups.borland.com> <419387ad$1@newsgroups.borland.com> Date: Thu, 11 Nov 2004 16:19:21 +0000 User-Agent: XanaNews/1.16.4.6 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 217.207.223.34 Message-ID: <419391cc$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1100190156 217.207.223.34 (11 Nov 2004 08:22:36 -0700) Lines: 66 X-Authenticated-User: acope Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed.freenet.de!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail