none
using DeviceIOControl in Windows7 RRS feed

  • Question

  • I have written a benchmark tool that performs lba based read and write to a secondary device[ ata or usb device ].

    I used DeviceIOControl for sending IOCTLs to the device. The tool works fine in XP.

    However in Windows7, the tool fails when write commands are sent to the ata device.

    Making the device 'offline' using disk management[diskpart], enables to execute write commands [ ata commands].

    In Windows 8 also i observe the same behaviour.

    Should i re-write my application for Windows7 using a different API.

    Please suggest which APIs to use.

    • Moved by Jie Bao Wednesday, October 10, 2012 3:00 AM (From:Application Compatibility for Windows Desktop Development)
    Monday, October 8, 2012 4:36 AM

Answers

  • what is the specific devpath? are you opening the drive by volume (ie "D:") or by file name ("D:\foo.txt"). if by volume, the behavior you are seeing is by design since there is an active FS attached to the volume unless you mark it as offline.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, October 10, 2012 3:10 AM

All replies

  • Hi,

    Could you please share some code or a sample that I can reproduce it in my side?  


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, October 9, 2012 4:52 AM
  • HDD device is opened as 'hd'

    hd = CreateFileA( devPath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,  NULL,
                              OPEN_EXISTING,  0,  NULL);

    The following line of code is where i find problem.

    DeviceIoControl( hd, IOCTL_ATA_PASS_THROUGH_DIRECT , &onBoardATACmd, sizeof (ATA_PASS_THROUGH_DIRECT),                        &onBoardATACmd, sizeof (ATA_PASS_THROUGH_DIRECT),  &dwReturned, 0)

    The DeviceIoControl returns error when ATA write commands are used in cdb [onBoardATACmd], which i found using GetLastError(), which gave the hex value 0x04.

    When i put the HDD device in 'offline' mode using diskpart/disk management, then the DeviceIOControl() does not throw any error.

    In XP the same code works without any problem.

    Tuesday, October 9, 2012 8:24 AM
  • I think I should help to move it to WDK forum, I found there are many similar threads on that forum, and may get helps from there.

    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 10, 2012 3:00 AM
  • what is the specific devpath? are you opening the drive by volume (ie "D:") or by file name ("D:\foo.txt"). if by volume, the behavior you are seeing is by design since there is an active FS attached to the volume unless you mark it as offline.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, October 10, 2012 3:10 AM
  • what is the specific devpath? are you opening the drive by volume (ie "D:") or by file name ("D:\foo.txt"). if by volume, the behavior you are seeing is by design since there is an active FS attached to the volume unless you mark it as offline.

    the devpath is "\\.\Physicaldrive1".

    yes you are right. When i mark the drive as 'offline' the  DeviceIOControl() succeeds.

    I would like to perform DeviceIOControl() without turning device to 'offline'.

    Is it Ok to perform diskpart operations in the program to turn the device to 'offline' and then to 'online'.

    Wednesday, October 10, 2012 1:03 PM
  • OK depends on your customer requirements. from an OS POV, clearly you need to do this for you to get your IOCTL call to work

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, October 10, 2012 4:21 PM