Solved

DeviceIoControl problems...

Posted on 2002-04-08
4
651 Views
Last Modified: 2013-11-20
I have 2 problems... first I am trying to format a disk using DeviceIoControl (*code below*) but it is only working on floppy disks.  I need to format CompactFlash memory cards in a memory card reader not floppy disks.  Does this method only support floppies??  If so ignore the second part of this question and if you have any ideas how to accomplish this please lend some help.  

Second problem is when formatting floppies it just makes like 200+ directories with no size and all named: "++++++++.+++" (but the plus signs are divide symbols).  

Here is the code I am using:

HANDLE hDrive;
DISK_GEOMETRY OutBuffer;
DWORD BytesReturned;
FORMAT_PARAMETERS FormatParameters;
PBAD_TRACK_NUMBER lpBadTrack;
UINT i;
BOOL b;
DWORD ReturnedByteCount;

 hDrive = CreateFile(
          "\\\\.\\a:",
          GENERIC_READ | GENERIC_WRITE,
          FILE_SHARE_READ|FILE_SHARE_WRITE,
          NULL,
          OPEN_EXISTING,
          0,
          NULL
          );

 if ( hDrive == INVALID_HANDLE_VALUE )
  {
    ExitProcess(1);
  }

 BOOL mybool = DeviceIoControl(
               hDrive,
               FSCTL_LOCK_VOLUME,
               NULL,
               0,
               NULL,
               0,
               &BytesReturned,
               NULL
               );

mybool = DeviceIoControl(
         hDrive,              
         IOCTL_DISK_GET_DRIVE_GEOMETRY,
         NULL,                          
         0,                            
         &OutBuffer,          
         sizeof(DISK_GEOMETRY),      
         &BytesReturned,    
         NULL
         );

  FormatParameters.MediaType = OutBuffer->MediaType;
  FormatParameters.StartHeadNumber = 0;
  FormatParameters.EndHeadNumber = OutBuffer->TracksPerCylinder - 1;
  lpBadTrack = (PBAD_TRACK_NUMBER) LocalAlloc(LMEM_ZEROINIT,OutBuffer->TracksPerCylinder*sizeof(*lpBadTrack));

  for (i = 0; i < OutBuffer->Cylinders.LowPart; i++) {

      FormatParameters.StartCylinderNumber = i;
      FormatParameters.EndCylinderNumber = i;

      b = DeviceIoControl(
              hDrive,
              IOCTL_DISK_FORMAT_TRACKS,
              &FormatParameters,
              sizeof(FormatParameters),
              lpBadTrack,
              NULL,
              &ReturnedByteCount,
              NULL
              );

      if (!b ) {
          LocalFree(lpBadTrack);
          return b;
          }
      }

  LocalFree(lpBadTrack);

  DWORD BytesReturned;

  BOOL mybool = DeviceIoControl(
              hDrive,
              FSCTL_UNLOCK_VOLUME,
              NULL,
              0,
              NULL,
              0,
              &BytesReturned,
              NULL
              );


0
Comment
Question by:Jedimaster
4 Comments
 

Author Comment

by:Jedimaster
ID: 6926111
Figures... as soon as I post my question I find in the MSDN that the IOCTL_DISK_FORMAT_TRACKS is for floppy disks only.  I guess since it sees a CompactFlash memory card as a "Removable Media" instead of a floppy disk it just will not work.  Does anyone know how I can do this without using SHFormatDrive??

I would still like to know why I was getting those funky folders on a floppy disk when I tried this method though.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8441628
Hi Jedimaster,
<Edited by SpideyMod>
An erroneous auto-delete was posted, we have corrected the problem.  Please indicate recommendations and these will not be scheduled for auto-delete, but will be finalized within the standard week notice.

A recommendation of "PAQ with refund" has already been proposed.

CleanupGuy -- EE database cleanup volunteer
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 11417166
PAQed, with points refunded (200)

Netminder
EE Admin
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now