Amy
Amy

Reputation: 1914

How to determine the type of a drive?

I am trying to figure out the device type for a particular drive. I'd like to know how to do it on Mac OS X and Linux as well, but for now if that's too much a Windows solution would suffice.

so, let's say I have a drive H. I can determine if the device is a removable drive through the Win32 API function GetDriveType(). I can find that out on Mac OS X as well.

But what I can't seem to find, in a reliable way, is the device type. Like, is it a USB Flash Drive, portable hard drive (PHD) etc.

Digging through the registries in Windows, I can't seem to find much info as well. Although I'd prefer to use some API for that if possible, I'll use the registry if required.

For now, what I'm interested in is.. is the drive a flash drive (so I can show a Usb flash drive icon in my program) or a portable hard drive (so, a PHD icon will be displayed).

Upvotes: 5

Views: 4481

Answers (4)

Andrew Lambert
Andrew Lambert

Reputation: 1909

Use the previously mentioned IOCTL_STORAGE_QUERY_PROPERTY control code to retrieve a STORAGE_DEVICE_DESCRIPTOR structure. Part of the structure is a STORAGE_BUS_TYPE enum, which will tell you the bus that the drive is on (USB, 1394, RAID, ATAPI, SCSI, etc.)

Upvotes: 1

Yuras
Yuras

Reputation: 13876

Is the device class what you want? If so you can try libusb (available for win32). Use libusb_get_device_descriptor function.

Upvotes: 1

asveikau
asveikau

Reputation: 40264

You might want to look at DeviceIoControl and IOCTL_STORAGE_QUERY_PROPERTY. For example, you can tell if a device is USB by specifying StorageDeviceProperty and looking at the BusType member. The "device type" member is also interesting.

If you don't mind forgoing XP support, there is the Virtual Disk Service which I believe provides this sort of information.

Upvotes: 1

please delete me
please delete me

Reputation:

For Windows it looks like SHGetFileInfo might do the trick. Perhaps you can call it on the root folder of a drive? See http://msdn.microsoft.com/en-us/library/bb762179(VS.85).aspx.

The SH... functions are generally the ones that Explorer uses so (assuming it works) this should give you the exact icon you see in Windows Explorer...

Upvotes: 3

Related Questions