Help and Support
 

powered byLive Search

How To Getting Floppy Drive Information

Article ID:115828
Last Review:November 21, 2006
Revision:3.2
This article was previously published under Q115828
On This Page

SUMMARY

To get the media type(s) supported by a floppy drive, it is necessary to call CreateFile() to get a handle to the drive and then DeviceIoControl() to get the information. However, if there is no floppy disk in the floppy drive, the following message box may appear when CreateFile() is called for drive A (\\.\a:):
There is no disk in the drive. Please insert a disk into drive A:
When calling CreateFile(), be sure to use 0 for the access mode and FILE_SHARE_READ for the share mode so that the user will not be prompted to insert a floppy disk:
   CreateFile(
      szFileName,
      0,
      FILE_SHARE_READ,
      NULL,
      OPEN_ALWAYS,
      0,
      NULL
   );
				
Another way to avoid the message box prompt is to put
SetErrorMode( SEM_FAILCRITICALERRORS );
before the call to CreateFile().

Back to the top

MORE INFORMATION

The following sample code is based on the code in the FLOPPY SDK sample, but it simply displays the media type(s) supported by floppy drive A. The code demonstrates one way to retrieve the supported media without requiring you to insert a floppy disk in the drive.

Back to the top

Sample Code

   #include <windows.h>
   #include <stdio.h>
   #include <winioctl.h>

   DISK_GEOMETRY SupportedGeometry[20];
   DWORD SupportedGeometryCount;

   VOID
   GetSupportedGeometrys( HANDLE hDisk )
   {
      DWORD ReturnedByteCount;

      if( DeviceIoControl(
             hDisk,
             IOCTL_DISK_GET_MEDIA_TYPES,
             NULL,
             0,
             SupportedGeometry,
             sizeof(SupportedGeometry),
             &ReturnedByteCount,
             NULL
         ))
         SupportedGeometryCount = ReturnedByteCount / 
                                  sizeof(DISK_GEOMETRY);

      else SupportedGeometryCount = 0;
   }

   VOID
   PrintGeometry( PDISK_GEOMETRY lpGeometry )
   {
      LPSTR MediaType;

      switch ( lpGeometry->MediaType ) {
         case F5_1Pt2_512:
            MediaType = "5.25, 1.2MB,  512 bytes/sector";
            break;
         case F3_1Pt44_512:
            MediaType = "3.5,  1.44MB, 512 bytes/sector";
            break;
         case F3_2Pt88_512:
            MediaType = "3.5,  2.88MB, 512 bytes/sector";
            break;
         case F3_20Pt8_512:
            MediaType = "3.5,  20.8MB, 512   bytes/sector";
            break;
         case F3_720_512:
            MediaType = "3.5,  720KB,  512 bytes/sector";
            break;
         case F5_360_512:
            MediaType = "5.25, 360KB,  512 bytes/sector";
            break;
         case F5_320_512:
            MediaType = "5.25, 320KB,  512 bytes/sector";
            break;
         case F5_320_1024:
            MediaType = "5.25, 320KB,  1024 bytes/sector";
            break;
         case F5_180_512:
            MediaType = "5.25, 180KB,  512 bytes/sector";
            break;
         case F5_160_512:
            MediaType = "5.25, 160KB,  512  bytes/sector";
            break;
         case RemovableMedia:
            MediaType = "Removable media other than floppy";
            break;
         case FixedMedia:
            MediaType = "Fixed hard disk media";
            break;
         default:
            MediaType = "Unknown";
            break;
      }
      printf("    Media Type %s\n", MediaType );
      printf("    Cylinders %d, Tracks/Cylinder %d, Sectors/Track %d\n",
             lpGeometry->Cylinders.LowPart, lpGeometry->TracksPerCylinder,
             lpGeometry->SectorsPerTrack
            );
   }

   void main( int argc, char *argv[], char *envp[] )
   {
      HANDLE hDrive;
      UINT i;

      hDrive = CreateFile(
                      "\\\\.\\a:",
                      0,
                      FILE_SHARE_READ,
                      NULL,
                      OPEN_ALWAYS,
                      0,
                      NULL
                      );
      if ( hDrive == INVALID_HANDLE_VALUE )
      {
         printf( "Open failed: %d\n", GetLastError() );
         ExitProcess(1);
      }

      GetSupportedGeometrys( hDrive );

      printf( "\nDrive A supports the following disk geometries\n" );
      for( i=0; i<SupportedGeometryCount; i++ )
      {
          printf("\n");
          PrintGeometry( &SupportedGeometry[i] );
      }
      printf("\n");
   }
				

Back to the top


APPLIES TO
Microsoft Win32 Application Programming Interface, when used with:
  Microsoft Windows NT Advanced Server 3.1
  Microsoft Windows NT 4.0
  Microsoft Windows NT 4.0
  Microsoft Windows 2000 Standard Edition
   the operating system: Microsoft Windows XP

Back to the top

Keywords: 
kbhowto kbkernbase kbfileio KB115828

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.