none
My ATA command cant access RRS feed

  • Question

  • Hi,

     I tried to send ATA command to my device but always failed, my source code as below, anyone can help me to check? tks

     ATA_PASS_THROUGH_EX inputBuffer;
    	memset(&inputBuffer, 0, sizeof(ATA_PASS_THROUGH_DIRECT)) ;
        	inputBuffer.Length = sizeof (ATA_PASS_THROUGH_EX);
       	 inputBuffer.AtaFlags = ATA_FLAGS_DATA_IN | ATA_FLAGS_DRDY_REQUIRED;
        	inputBuffer.DataTransferLength = sizeof(inputBuffer);;
       	 inputBuffer.DataBufferOffset = sizeof(ATA_PASS_THROUGH_EX);
    	inputBuffer.TimeOutValue = 10;
    	memset(inputBuffer.CurrentTaskFile , 0x00 , 8);
    	inputBuffer.CurrentTaskFile[1] = 1;
    	inputBuffer.CurrentTaskFile[3] = 0;
    	inputBuffer.CurrentTaskFile[4] = 0;
    	inputBuffer.CurrentTaskFile[6] = 0xEC;
        	unsigned int inputBufferSize = 1024;
        	UINT8 outputBuffer[1024];
        	UINT32 outputBufferSize = 1024;
        	DWORD bytesReturned;
    	
        if(!(DeviceIoControl( DeviceHandle,IOCTL_ATA_PASS_THROUGH_DIRECT, &inputBuffer,inputBufferSize, &outputBuffer, 	outputBufferSize, &bytesReturned, NULL)))
    		printf("GetLastError %u\n", GetLastError());		
    
        std::cout << outputBuffer << std::endl;


       
    • Edited by Eden Huang Wednesday, September 24, 2014 9:32 AM
    • Moved by May Wang - MSFT Thursday, September 25, 2014 6:55 AM WDK issue related
    Wednesday, September 24, 2014 9:31 AM

All replies

  • Try to run your application elevated. From what I remember this particular IOCTLs need administrative privileges.

    What value are you receiving by GetLastError?


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.



    • Edited by Bordon Wednesday, September 24, 2014 10:25 AM
    Wednesday, September 24, 2014 10:24 AM
  • Hi Bordon,

    thanks for your reply, my GetLastError is 24 (The program issued a command but the command length is incorrect.) and I am checked the VC does work by administrative privileges.


    • Edited by Eden Huang Wednesday, September 24, 2014 11:01 AM
    Wednesday, September 24, 2014 11:00 AM
  • It seems the parameters of the command are not correct. You  should check the documentation of this particular IOCTL. Maybe this helps:

    http://www.tomshardware.co.uk/forum/37446-45-send-command-buffer-deivice

    further questions are better in the WDK section since your problem is more WDK related not SDK.


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

    Wednesday, September 24, 2014 11:09 AM
  • Hi Bordon 

    I tried to follow the website and set the parameters, return value change to error 24, my struct as below, please help me to check thanks 

    PS:my OS is Windows 7 64bits

    from ntddscsi.h
    
    #define IOCTL_ATA_PASS_THROUGH          CTL_CODE(IOCTL_SCSI_BASE, 0x040b, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
    #define IOCTL_ATA_PASS_THROUGH_DIRECT   CTL_CODE(IOCTL_SCSI_BASE, 0x040c, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
    
    typedef struct _ATA_PASS_THROUGH_EX {
        USHORT Length;
        USHORT AtaFlags;
        UCHAR PathId;
        UCHAR TargetId;
        UCHAR Lun;
        UCHAR ReservedAsUchar;
        ULONG DataTransferLength;
        ULONG TimeOutValue;
        ULONG ReservedAsUlong;
        ULONG_PTR DataBufferOffset;
        UCHAR PreviousTaskFile[8];
        UCHAR CurrentTaskFile[8];
    } ATA_PASS_THROUGH_EX, *PATA_PASS_THROUGH_EX;
    
    typedef struct _ATA_PASS_THROUGH_DIRECT {
        USHORT Length;
        USHORT AtaFlags;
        UCHAR PathId;
        UCHAR TargetId;ATA_PASS_THROUGH_EX
        UCHAR Lun;
        UCHAR ReservedAsUchar;
        ULONG DataTransferLength;
        ULONG TimeOutValue;
        ULONG ReservedAsUlong;
        PVOID DataBuffer;
        UCHAR PreviousTaskFile[8];
        UCHAR CurrentTaskFile[8];
    } ATA_PASS_THROUGH_DIRECT, *PATA_PASS_THROUGH_DIRECT;





    • Edited by Eden Huang Thursday, September 25, 2014 10:25 AM
    Thursday, September 25, 2014 1:25 AM