I got a delicate problem with an USB device (and stackoverflow is not an option here...) and hope to get help here eventually.

I got a delicate problem with an USB device (and stackoverflow is not an option here...) and hope to get help here eventually.

We have a device that emulates an USB Massstorage device. That device registers the drive as "read only" but with a special USB command we can disable the read only flag so one can write to the drive.

That actually works well but.... I cannot convince Windows to properly
update the flag. I use DeviceIOControl on a handle that belongs to the registered drive to check the "IsWritable Flag" by issuing IOCTL_DISK_IS_WRITABLE and windows reports that the disk is actually writable. The thing is that the first attempt on CreateFile (createing a new file on that drive) atctually fails but a second one immediatly after the first one works!

Anyone has an idea on how I can tell windows to update that info before
I create the file.

I already tried the following IO codes:

IOCTL_DISK_UPDATE_PROPERTIES
IOCTL_DISK_VERIFY
IOCTL_STORAGE_CHECK_VERIFY2

I also tried to dismount the volume but had some issues with that.

Comments

  1. Updated information: GetVolumeInformation actually returns FILE_READ_ONLY_VOLUME but after the failed CreateFile call it reports as it should not to be locked read only

    ReplyDelete
  2. Alright... seems to be solved now:
    1.) I opened the drive handle not with GENERIC_READ or GENERIC_WRITE but rather with the SYNCHRONIZED flag which actually speeds up the detection. With this flag only the FAT is not read from the slow device but the lower level read and write operations work (DeviceIOControl 's).
    2.) -> So I needed to close the original drive handle - reopen it with generic read/write access and I needed to issue a dismount / mount command via DeviceIOControl.

    that did the trick.

    ReplyDelete

Post a Comment