Solved

DeviceIoControl problems...

Posted on 2002-04-08
4
654 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 66
maxBlock challenge 30 111
modThree challenge 4 77
scoreUp challenge 14 56
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

21 Experts available now in Live!

Get 1:1 Help Now