From: Jens Buechner on
Hi,

currently i try to call the DeviceIoControl Method with the
ATA_PASS_THROUGH_DIRETC IOCTL. I don't know much about the IOCTL but i
used an example from the DDK (spti example) to write my own code. My
problem is, that DeviceIoControl returns true, but i only get trash.
Here a snippet from my code:
---Definitions
#define METHOD_BUFFERED 0
#define METHOD_IN_DIRECT 1
#define METHOD_OUT_DIRECT 2
#define METHOD_NEITHER 3

#define CTL_CODE(DeviceType, Function, Method, Access) (((DeviceType)
<< 16) | ((Access) << 14) | ((Function) << 2) | (Method))
#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_DIRECT {
USHORT Length;
USHORT AtaFlags;
UCHAR PathId;
UCHAR TargetId;
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;
---
int iBufferLen = 256, iATARegsSize;
DWORD dwReturned;
bool bRet;

ATA_PASS_THROUGH_DIRECT* ATARegs;

ATARegs->Length = sizeof(ATA_PASS_THROUGH_DIRECT);
ATARegs->ReservedAsUchar= 0;
ATARegs->DataTransferLength = ATARegs->Length + iBufferLen;
ATARegs->TimeOutValue = 3;
ATARegs->ReservedAsUlong = 0;
ATARegs->DataBuffer = new WORD[iBufferLen];
memset(&ATARegs->PreviousTaskFile,0,sizeof(ATARegs->PreviousTaskFile));
memset(&ATARegs->CurrentTaskFile,0,sizeof(ATARegs->CurrentTaskFile));
ATARegs->CurrentTaskFile[6] = 0xEC; // Identify Device
iATARegsSize = sizeof(ATA_PASS_THROUGH_DIRECT) +
ATARegs->DataTransferLength;

bRet = DeviceIoControl(m_oDev->GetDevHandle(),
IOCTL_ATA_PASS_THROUGH_DIRECT, ATARegs, iATARegsSize, ATARegs,
iATARegsSize, &dwReturned, FALSE);
---

As an example i want to read the model number of my hdd from the
returned data.
The data looks something like this:
x\68;":CW\NIODSWs\syet3m;2:CW\NIODSWC;\:

While an another call with the IOCTL_IDE_PASS_THROUGH returns MAXTOR
6L040J2.

I think my structure is wrong and contains an error. But i don't know
what to do. It would be nice if someone could help me.

with greetings
Jens Buechner

From: Gary G. Little on
You don't mention the target OS or the DDK. IOCTL_ATA_PASS_THROUGH only
works on XP SP2, Server 2003, and VISTA. In XP SP1 and 2000, ATA pass
through is broken. The DDK for IOCTL_ATA_PASS_THROUGH is either 3790.1830,
or WDK 6000.

--
The personal opinion of
Gary G. Little


"Jens Buechner" <Maenchen(a)gmx.de> wrote in message
news:1168428832.091450.319940(a)i56g2000hsf.googlegroups.com...
> Hi,
>
> currently i try to call the DeviceIoControl Method with the
> ATA_PASS_THROUGH_DIRETC IOCTL. I don't know much about the IOCTL but i
> used an example from the DDK (spti example) to write my own code. My
> problem is, that DeviceIoControl returns true, but i only get trash.
> Here a snippet from my code:
> ---Definitions
> #define METHOD_BUFFERED 0
> #define METHOD_IN_DIRECT 1
> #define METHOD_OUT_DIRECT 2
> #define METHOD_NEITHER 3
>
> #define CTL_CODE(DeviceType, Function, Method, Access) (((DeviceType)
> << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
> #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_DIRECT {
> USHORT Length;
> USHORT AtaFlags;
> UCHAR PathId;
> UCHAR TargetId;
> 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;
> ---
> int iBufferLen = 256, iATARegsSize;
> DWORD dwReturned;
> bool bRet;
>
> ATA_PASS_THROUGH_DIRECT* ATARegs;
>
> ATARegs->Length = sizeof(ATA_PASS_THROUGH_DIRECT);
> ATARegs->ReservedAsUchar= 0;
> ATARegs->DataTransferLength = ATARegs->Length + iBufferLen;
> ATARegs->TimeOutValue = 3;
> ATARegs->ReservedAsUlong = 0;
> ATARegs->DataBuffer = new WORD[iBufferLen];
> memset(&ATARegs->PreviousTaskFile,0,sizeof(ATARegs->PreviousTaskFile));
> memset(&ATARegs->CurrentTaskFile,0,sizeof(ATARegs->CurrentTaskFile));
> ATARegs->CurrentTaskFile[6] = 0xEC; // Identify Device
> iATARegsSize = sizeof(ATA_PASS_THROUGH_DIRECT) +
> ATARegs->DataTransferLength;
>
> bRet = DeviceIoControl(m_oDev->GetDevHandle(),
> IOCTL_ATA_PASS_THROUGH_DIRECT, ATARegs, iATARegsSize, ATARegs,
> iATARegsSize, &dwReturned, FALSE);
> ---
>
> As an example i want to read the model number of my hdd from the
> returned data.
> The data looks something like this:
> x\68;":CW\NIODSWs\syet3m;2:CW\NIODSWC;\:
>
> While an another call with the IOCTL_IDE_PASS_THROUGH returns MAXTOR
> 6L040J2.
>
> I think my structure is wrong and contains an error. But i don't know
> what to do. It would be nice if someone could help me.
>
> with greetings
> Jens Buechner
>


 | 
Pages: 1
Prev: Selective suspend & stand by
Next: WDK and bscmake