Programmatically differentiating between USB Floppy Drive and USB Flash Drive in Windows
Asked Answered
C

4

7

On Windows (XP-7), is there a reliable way of programatically differentiating between USB floppy drives and USB flash drives in C++?

At the moment, I'm using WMI to get updates when new Win32_LogicalDisk instances are detected, and then using the DriveType attribute of the LogicalDisk object to figure out a basic type. This works quite well, except that floppy drives and USB flash drives are both of DriveType DRIVE_REMOVABLE, so to differentiate between those (floppy vs. flash), I'm using the IOCTL_STORAGE_GET_HOTPLUG_INFO interface to figure out if the device is hotpluggable, and was working on the principal that that meant it was a flash drive and not a floppy. Again, I think this works quite well (if a little inefficient, using both the WDK API and WMI to get info ) in the case of internal floppy drives, but unfortunately USB Floppy drives are also hotpluggable a lot of the time, so there is no clear way to differentiate between flash and USB floppy drives, that I can see. I know there are properties that may work, like checking if its mapped to the reserved drives A: or B (edit: only relevant if the machine definitely has a floppy drive - see MS-KB: How to change drive letter assignments in Windows XP), or looking at the description, but I'd really like something a bit more reliable.

Sorry about the long explanation, but just wanted to be clear! Thanks

Cimbalom answered 25/11, 2009 at 14:7 Comment(3)
A: and B: are reserved for floppies? Source?Belgian
I got this from MS-KB:How to change drive letter assignments in Windows XP, and its the way they phrase it, but as it also points out, if the machine doesn't have a floppy drive, then they may be used for other drives, so arguably its a misnomer, and certainly not indicative of the drive being a floppy drive or not. I'll reword the question to make it a bit clearer.Cimbalom
Ah, that's from a user viewpoint, when you're manually changing driveletters. Makes sense then, I was thinking from a OS viewpoint.Belgian
R
5

Did you try Win32_LogicalDisk.MediaType? It has specific enumerations for floppy disks. Make sure you try it when there's no disk in the drive.

Retirement answered 25/11, 2009 at 15:44 Comment(3)
In case anyone else needs this, my testing found that it does correctly return an approximate media type (certainly good enough for USB floppy vs. flash drive) when there's no media present, but this isn't guaranteed - from the docs : "Win32_LogicalDisk.Media Type : Type of media currently present in the logical drive. This value will be one of the values of the MEDIA_TYPE enumeration defined in Winioctl.h. The value may not be exact for removable drives if currently there is no media in the drive."Cimbalom
Of course, the situation "no media in drive" implies that it's a media-loading drive, and therefore not a USB flash drive.Belgian
See my reply below. Also, many usb flash disk will start declare themselves as "removable media" and start with "no media in drive" (and will signal media inserted once they are ready to accept commands)Quack
Q
5

On the USB level, there is no way to differentiate between a conventional Disk on Key and a USB-Floppy. Which means windows itself, cannot tell reliably what is what.

There are a few hints that you can gather: Floppies should: a. Have mass-storage protocol CBI/CB b. SCSI UFI

BUT, in the world of USB devices, everyone does whatever they want. The only test is: "Does it work on windows". And Windows just checks the size, if its a USB device with removable-media set and with conventional floppy sizes, it will consider it to be a floppy.

Can't say about "real" floppy, but with the USB attached, there is no definite way.

Quack answered 26/11, 2009 at 8:49 Comment(0)
D
4

You can use the Size attribute (USB > 1.4MB), it's not like there is any chance of meeting 1.4MB flash drive any time soon.

Dobruja answered 25/11, 2009 at 14:47 Comment(2)
Better make that 2.88 MB, although I believe that floppy format was uncommon outside of Japan.Belgian
I don't if all the Zip drive (which support up to 750MB) are not consider to be floppy as well.Dobruja
B
4

The obvious property to check would be IOCTL_DISK_GET_DRIVE_GEOMETRY. This gets you (amongst other things) a MEDIA_TYPE. Anything but RemovableMedia and FixedMedia is a floppy.

Belgian answered 26/11, 2009 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.