CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2013
    Posts
    6

    Ioctl_ide_pass_through

    Hi,

    Would anyone know why

    HANDLE handle;

    UCHAR buffer[sizeof(ATA_PASS_THROUGH)-1 + 512];

    memset(&buffer,0,sizeof(ATA_PASS_THROUGH)-1 + 512);

    ATA_PASS_THROUGH *buf = reinterpret_cast<ATA_PASS_THROUGH*>(&buffer);

    DWORD num_out;

    const unsigned char magic = 0xcf;

    buf->IdeReg.bFeaturesReg = 0;

    buf->IdeReg.bSectorCountReg= 0x01;

    buf->IdeReg.bSectorNumberReg= 0x01;

    buf->IdeReg.bDriveHeadReg = 0xE0;

    buf->IdeReg.bCommandReg = 0x20;

    buf->DataBufferSize = 512;

    //buf->DataBuffer[0] = magic;



    int ioControlCode = IOCTL_IDE_PASS_THROUGH;

    handle= CreateFile(L"\\\\.\\PhysicalDrive0",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);







    printf("\n Error = %d", GetLastError());



    DWORD bytescopied = 0;



    if(handle)



    {



    if( DeviceIoControl(



    handle,



    ioControlCode,



    buffer,



    sizeof(ATA_PASS_THROUGH)-1 + 512 ,



    buffer,



    sizeof(ATA_PASS_THROUGH)-1 + 512 ,



    &bytescopied,



    NULL //not an overlapped operation



    ) )

    {









    printf("\n status is %d",buf->IdeReg.bCommandReg);



    printf("\n Error = %d", GetLastError());

    PrintDataBuffer(buf->DataBuffer, 512);

    }











    }

    CloseHandle(handle);

    Does not give any error and does not do a read on WIn 7?

    Are there any paramters I am missing. The struct is
    typedef struct {
    IDEREGS IdeReg;
    ULONG DataBufferSize;
    UCHAR DataBuffer[1];
    } ATA_PASS_THROUGH;


    Thanks,

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Ioctl_ide_pass_through

    When posting code, please format properly before posting and use code tags. Go advanced, select the code and click '#'.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Nov 2013
    Posts
    6

    Re: Ioctl_ide_pass_through

    Hi,

    Thanks, and sorry about that. I tried pasting directly but for some reason there were a lot of lines getting added. I will definitely do so in future.

    Thanks,

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Ioctl_ide_pass_through

    This is a rather old (and broken) relic IOCTL call, there's better ways to do this. In particular don't use it for writes.
    Or did you mean to use IOCTL_ATA_PASS_THROUGH ? (slightly less broken, but still, don't use it for multisector access)

    it could be related to the GENERIC_WRITE option (try without).

    My guess is either alignment or memory location, direct access tends to work with DMA so your buffers would need to be compatible with the DMA architecture if these are of that kind.
    You probably need the buffer to be page aligned (address multiple of 512 bytes)
    You may also need to provide memory that is kernel locked (doesn't have MEM_MOVE style)

    It may also be related to PhysicalDisk0 and the OS denying access to (part of) the boot volume for security reasons.

  5. #5
    Join Date
    Nov 2013
    Posts
    6

    Re: Ioctl_ide_pass_through

    Thanks very much I will try this out.

    Thanks,
    Sonia

  6. #6
    Join Date
    May 2007
    Posts
    811

    Re: Ioctl_ide_pass_through

    Quote Originally Posted by sondeepa View Post
    Hi,
    ... I will definitely do so in future.
    Thanks,
    You could edit your original post and fix up code tags, so it will be easier to read for future readers.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Ioctl_ide_pass_through

    Quote Originally Posted by STLDude View Post
    You could edit your original post and fix up code tags, so it will be easier to read for future readers.
    OP could not edit because it is only possible after at least 5 or more posts.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured