I think it probably does something similar to: http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx
Except instead of mapping a drive to usb device, it does it the other way around.
After looking more into it it really looks like this is the thing it does. (I need a bunch of hacks for it to work, but alas.) However it doesn't get me much further since our IOCTL_STORAGE_GET_DEVICE_NUMBER ioctl is a stub. I would need something that can at least guarantee uniqueness per volume for it, perhaps a conversion of drive letter to integer. Now I just need to figure that one out.
Cheers, Maarten.
I do not believe the device number matching is the problem, I have been
exploring this problem a little with RemoveDriveByLetter and I believe that it is not working because the SymbolicLink entry is not added as a "real" thing in Wine. Performing an experiment with accessing the same drive letter in three different ways (results below, last parameter is "hDrive") I see that only the call with the registry-returned value for the drive fails (even if it is added to "HKLM/System/MountedDevices"). I believe that a call to IoCreateSymbolicLink must be made in order for the name returned by the registry to be recognized as an alias for the drive. I think iTunes is probably going through the device tree looking for its vendor and product code. It should get this back from CM_Get_Device_ID, but I do not have Windows so I cannot fake iTunes out to confirm this.
SetupDiGetDeviceInterfaceDetail '\?\USBSTOR#Disk&Ven_Apple&Prod_iPod&Rev_1.62#000A27001420C124&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}': -1 SetupDiGetDeviceInterfaceDetail '\?\Volume{00000000-0000-0000-0000-000000000048}': 60 SetupDiGetDeviceInterfaceDetail '\.\H:': 64 Device number comparison: 1 1