|
Can use DeviceIoControl for retriving data about an USB storage device (flash or hard drive) like: manufacturer, type, revision?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
For retrieving the manufacturer, type and revision... you can probably use the IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION and populate a USB_DEVICE_DESCRIPTOR struct.
Best Wishes,
-David Delaune
|
|
|
|
|
I found IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION and USB_DEVICE_DESCRIPTOR in WIN_DDK, but I don't work with that environment because I'm not so advanced. Is it possible in VC++ and/or MFC?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: Is it possible in VC++ and/or MFC?
Yes, Absolutely.
|
|
|
|
|
Thx 4 quoting me but I really need 2 know how to do it
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
Why do you need someone to show you how to do this? What have you tried so far? Did it succeed or fail?
It looks like all you need to do is create a USB_DEVICE_DESCRIPTOR structure and call DeviceIoControl with the IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION control code.
Best Wishes,
-David Delaune
|
|
|
|
|
I've tested in VC++10:
- declared locally the COMCTL for IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION
- declared locally the structure USB_NODE_CONNECTION_INFORMATION
and DeviceIoControl() returned NULL. GetLastError() returned ... 50 ERROR_NOT_SUPPORTED .
Can you tell me why? pls
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
With that error... it sounds like you are sending the control code to the wrong device. What handle are you passing to DeviceIoControl?
I would suggest that you use this sample:
www.intel.com/intelpress/usb/examples/DUSBVC.PDF[^]
I have compiled it and confirmed that it works with the 7600.16385.1 DDK. Just paste the code from the Intel PDF file into a Multi-Byte console application created from Visual Studio. You will need to add this #include path to the project:
\7600.16385.1\inc\api
Copy and paste programming at its best.
Best Wishes,
-Copy&Paste
|
|
|
|
|
My project is to make an app that erases media (HDD, USB flash, USB HDD, etc.) showing some information on them. I use \\.\PhysicalDriveX to access the media for details on the size and type (fixed, removable, etc.).
I found that the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\
keeps up-to-date the drives in order that they are attached.
First it comes the first HDD - subkey "0" something like IDE\DiskWDC_WD5000BEVT-0A0RT0__________________01.01A01\5&2c0d176e&0&0.0.0 , next, the next HDD ... .
Then follows the USB devices, in the order that they were attached.
Here comes trouble...
Consider you have 1 HDD and 2 USB devices A and B.
Subkey 0 holds data for the HDD.
Attach A, subkey 1 holds data for A.
Attach B, subkey 2 holds data for B.
Detach A, subkey 1 holds data for B.
Attach A, subkey 2 holds data for A.
... and all this time ...
A remained \\.\PhysicalDrive1
B remained \\.\PhysicalDrive2
I can`t count on registry for that information, so I have to obtain them - via DeviceIoControl with a handle for \\.\PhysicalDriveX so I can map the devices to the description, exactly.
I hope that is clear enough, now, what is my problem.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
Could you be a little more clear about the exact problem you are having? While I do understand the problem you mention in your last post... I fail to see how this relates to the original post where you stated that you need 'manufacturer, type, revision'
Someone asked me a similar question a few years ago. Maybe you will find something useful there. Here is the post[^].
If you need to know which physical drive such as \\.\PhysicalDrive1 then you should investigate the IOCTL_STORAGE_GET_DEVICE_NUMBER control code[^] and populate a STORAGE_DEVICE_NUMBER structure[^].
If you are having problems identifying the USB device after the user has moved the USB device... maybe you should investigate the IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER control code[^] and populate a MEDIA_SERIAL_NUMBER_DATA structure[^].
All of this info combined with the Intel sample should give you enough to uniquely identifying drives.
Best Wishes,
-David Delaune
|
|
|
|
|
In this App I use DeviceIoControl to accomplish the following tasks:
- enumerate the PhysicalDriveX devices
- determine nr. of bytes to be overwritten
- for ATA devices determine the Vendor, Product and Revision http://www.winsim.com/diskid32/diskid32.html[^] [http://www.winsim.com/diskid32/diskid32.html[^]] for the reason that the user not to erase a drive that is not intended to.
And all this via a HANDLE from CreateFile("\\\\.\\PhysicalDriveX", ...)
Everything goes OK for ATA , not for USB . In my previous post I have shown an example on how you can`t rely on
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\N because USB devices are presented in the order they were attached.
So, the question is: can I obtain with a HANDLE created by
CreateFile("\\\\.\\PhysicalDriveX", ...)
data reffering to manufacturer, type, revision for a USB attached storage device?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi,
I completely understand your problem now. You have a HANDLE to a physical drive and want to somehow associate that back to the USB device. I spent about 10 minutes looking into this... and I did not find any way to use DeviceIoControl because there are no documented IOCTL codes that will do this. I did not find any documented methods for using a HANDLE to a physical drive for obtaining information about the parent USB device.
However... you can absolutely do this using the Windows SetupAPI[^].
You could call the SetupDiGetClassDevs function[^] with the GUID_DEVINTERFACE_DISK class[^] and enumerate all of the storage devices using SetupDiEnumDeviceInterfaces[^] and call the SetupDiGetDeviceInterfaceDetail function[^] to get the drive path and serial. You can then call the CM_Get_Parent function[^] to get the parent USB device and retrieve these details.
Please spend some time researching this... if you cannot figure it out let me know and when I have more free time I may be able to write a sample function for you.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you!
I`ll do what you said.
Waiting for your answer I found this:
http://code.msdn.microsoft.com/CppStorageEnum-90ad5fa9[^]
I`ve tested a few, it seem to work, but it is to clean up a lot, maybe to include the dll code in the main.
I`ll keep you up to date with my progress.
Thanks again!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Happy 9 years and 2 days of CodeProject!
I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull...
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: Happy 9 years and 2 days of CodeProject!
Thanks!
I have actually been a member here on codeproject for around 11 years but I forgot the password to my first account and created this one to replace it.
RomTibi wrote: I worked a little around the example I found but I wasn`t able to port in VC++6.
If you can give me some advice I would be gratefull...
Almost everything can be ported to VC6 with the exception of some of the modern C++ templated code and C++11.
What version of the Platform SDK are you using with VC6?
|
|
|
|
|
|
|
Hi RomTibi,
No I don't mind at all. But I don't think anyone will be able to answer your question because to convert that project to VC6 takes alot of work and patience. You will just need to copy alot of Setup API structs and defines into a new header.
If I have some free time this weekend I'll investigate it.
Best Wishes,
-David Delaune
|
|
|
|
|
THX!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
Just wanted to drop in and let you know that I have not forgotten about your issue. Unfortunately I was out of town last weekend and did not write any code. I still have it on my TODO list so let me know if you have solved your problem.
|
|
|
|
|
Thanks! Wait ...
|
|
|
|
|
Hmmmm,
Who are you? Are you RomTibi?
|
|
|
|
|
Randor wrote: Hmmmm,
Who are you? Are you RomTibi?
yeap
if u don`t mind
|
|
|
|
|
Hi, I have a program, it should be possible to optimize. I need advice: what program or application will to monitor how much memory is allocated to a given block of objects.
Thanks
|
|
|
|
|
You can calculate it quite easily using the sizeof [^] operator.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|