[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DeviceIoControl problems...

Posted on 2002-04-08
4
Medium Priority
?
689 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
3 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

872 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