-
November 27th, 2013, 03:24 PM
#1
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,
-
November 27th, 2013, 03:41 PM
#2
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)
-
November 27th, 2013, 03:43 PM
#3
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,
-
November 28th, 2013, 08:44 AM
#4
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.
-
December 2nd, 2013, 02:50 PM
#5
Re: Ioctl_ide_pass_through
Thanks very much I will try this out.
Thanks,
Sonia
-
December 2nd, 2013, 07:21 PM
#6
Re: Ioctl_ide_pass_through
Originally Posted by sondeepa
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.
-
December 3rd, 2013, 02:24 AM
#7
Re: Ioctl_ide_pass_through
Originally Posted by STLDude
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|