🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8316

Re: floppy disk bad sectors

#8316
From: Andrue Cope [TeamB]
Date: Thu, 11 Nov 2004 16:46
65 lines
3587 bytes
Andrue Cope [TeamB] wrote:

> // Experimental, didn't work. I'm looking into this now.
>   DWORD blockTotal=GetFileSize( fileHandle, NULL );

Lol. Hmmm. Doesn't seem to be an easy answer to this.

One option would be to check the return error code from SetFilePointer
and if it fails at 360kB, 720kB, 1.2MB or 1.4MB then you've reached the
end. The code we're using is:

      if( DeviceIoControl( MyHandle,
                           IOCTL_DISK_GET_DRIVE_GEOMETRY,
                           NULL,
                           0,
                           &geom,
                           sizeof( geom ),
                           &returned,
                           NULL ) )
      {
        MyBlockSize=WORD( geom.BytesPerSector );
        QWORD tmpQ=0;

        PARTITION_INFORMATION partnInfo;

        if( DeviceIoControl( MyHandle,
                             IOCTL_DISK_GET_PARTITION_INFO,
                             NULL,
                             0,
                             &partnInfo,
                             sizeof( partnInfo ),
                             &returned,
                             NULL ) )
        {
          tmpQ=partnInfo.PartitionLength.QuadPart/MyBlockSize;
        }
        else
        {
          PARTITION_INFORMATION_EX partnInfoEx;

          if( DeviceIoControl( MyHandle,
                               IOCTL_DISK_GET_PARTITION_INFO_EX,
                               NULL,
                               0,
                               &partnInfo,
                               sizeof( partnInfoEx ),
                               &returned,
                               NULL ) )
          {
            tmpQ=partnInfoEx.PartitionLength.QuadPart/MyBlockSize;
          }
          else
            tmpQ=geom.Cylinders.QuadPart*
                 geom.TracksPerCylinder*
                 geom.SectorsPerTrack;
        }

But this is designed to handle any block access device (floppy, hard
disk, card reader, memory stick) so you might not need the whole
shebang. We have just found that some devices respond to one inquiry,
others to another.
-- 
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID: <41939810@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.com!newsfeed00.sul.t-online.de!t-online.de!news.zanker.org!news.cambrium.nl!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
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> <419394a0$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> <419394a0$1@newsgroups.borland.com>
Date: Thu, 11 Nov 2004 16:46:02 +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: <41939810@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1100191760 217.207.223.34 (11 Nov 2004 08:49:20 -0700)
Lines: 65
X-Authenticated-User: acope
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.com!newsfeed00.sul.t-online.de!t-online.de!news.zanker.org!news.cambrium.nl!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