Article ID: 115828 - Last Review: November 21, 2006 - Revision: 3.2
How To Getting Floppy Drive Information This article was previously published under Q115828
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().
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.
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");
}
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 kbhowto kbkernbase kbfileio KB115828
Provide feedback on this information
Did this information solve your problem?
Was this information relevant?
What can we do to improve this information?
To protect your privacy, do not include contact information in your feedback.
Thank you! Your feedback is used to help us improve our support content. For more assistance options, please visit the
Help and Support Home Page .