4

I wonder if there is an API to distinguish floppy and flash disk in windows, C++ And is it possible to link a flash disk to A:\? Many Thanks!

user25749
  • 4,825
  • 14
  • 61
  • 83
  • See here: http://stackoverflow.com/questions/1797128/programmatically-differentiating-between-usb-floppy-drive-and-usb-flash-drive-in – stephan Feb 01 '10 at 09:42

3 Answers3

2

First, you need to get the drive's type (GetDriveTypeA). If the result is equal to DRIVE_REMOVABLE, the letter drive will point either to a floppy of a removable flash drive (or maybe other type of removable disk). If the result is not DRIVE_REMOVABLE, there is no chance that this is a removable flash drive. However, beware from the point of view Window has, there is little difference between an external USB harddrive and a removable flash disk (I think the only difference is that a removable flash disk does not have a partition table, so it will have only one partition - though I'm not very sure).

Anyway, for DRIVE_REMOVABLE type, you need to query for more advanced properties of the device. In order to do this, first you need to open the physical device with somethink like this:


hDevice = CreateFileA("\\\\?\\X:", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL)

If the open succeeds, you need to issue a DeviceIoControl command to this device:


STORAGE_PROPERTY_QUERY Query;
Query.PropertyId = StorageDeviceProperty;
Query.QueryType = PropertyStandardQuery;

bResult = DeviceIoControl(
    hDevice, // device handle
    IOCTL_STORAGE_QUERY_PROPERTY, // info of device property
    &Query, sizeof(STORAGE_PROPERTY_QUERY), // input data buffer
    pDevDesc, pDevDesc->Size, // output data buffer
    &dwOutBytes, // out's length
    (LPOVERLAPPED)NULL
    );


If pDevDesc->BusType == BusTypeUsb, then X: points to a removable flash drive. The code works, however you need to read the documentation for DeviceIoControl in order to setup the pDevDesc parameter. If you have problems with it, I can give you the whole code.

botismarius
  • 2,977
  • 2
  • 30
  • 29
0

You can change the letters assigned to your drives somewhere in System Control, so the flash disk can be A:.

Use the OS API to query eg. the size of the disk, that should be enough to distinguish floppy and flash disk.

user231967
  • 1,935
  • 11
  • 9
0

It is possible to link a flash disk to A:, but only if you have no floppy drives.
See Defining an MS-DOS Device Name for information about how to do this in a program.

You can determine whether a drive letter maps to a floppy device by using QueryDosDevice on the drive letter. Floppy drives will return "\Device\Floppy0" or "\Device\Floppy1"

John Knoeller
  • 33,512
  • 4
  • 61
  • 92