I am trying to read directly from a disk in my driver. I open a handle to the disk with:
OBJECT_ATTRIBUTES Disk0;
IO_STATUS_BLOCK Disk0Comp;
UNICODE_STRING Disk0Path;
RtlInitUnicodeString(&Disk0Path, PConnectInfo->Disk0Path);
InitializeObjectAttributes(&Disk0, &Disk0Path, OBJ_OPENIF, NULL, NULL);
status = ZwCreateFile(
&(pEntry->Disk0BaseAddress), //File HANDLE
GENERIC_READ, //Desired Access
&Disk0, //Object Attributes
&Disk0Comp, //IO_STATUS_BLOCK
NULL, //Allocation Size
FILE_ATTRIBUTE_NORMAL, //File Attributes
FILE_SHARE_READ, //Share Access
FILE_OPEN, //Create Disposition
FILE_NON_DIRECTORY_FILE | FILE_RANDOM_ACCESS, //Create Options
NULL, //EABuffer
0 //EALength
);
Where the Disk Path is \??\PhysicalDrive1\0. This returns STATUS_SUCCESS and then in my read function I attempt to do this:
PVOID buffer = ExAllocatePoolWithTag(NonPagedPool, ReadLength, ‘buf’);
IO_STATUS_BLOCK pSrc;
LARGE_INTEGER Read;
NTSTATUS status;
Read.LowPart = StartingLbn.LowPart;
Read.HighPart = StartingLbn.HighPart;
Read.QuadPart += pConnectionInformation->ConnectionInfo.Disk0Start;
status = ZwReadFile(
pConnectionInformation->Disk0BaseAddress, //HANDLE
NULL, //EVENT HANDLE
NULL, //PIO_APC_ROUTINE
NULL, //PVOID ApcContext
&pSrc, //PIO_STATUS_BLOCK
buffer, //PVOID buffer
ReadLength, //ULONG Length
&Read, //PLARGE_INTEGER ByteOffset
NULL //PULONG Key
);
This returns STATUS_OBJECT_TYPE_MISMATCH.
Everything looks correct to me so if someone could point out what I am doing wrong it would be appreciated.
Are you doing CreateFile in one thread and Reading in some other thread?
If handle has to be used in kernel mode, use OBJ_KERNEL_HANDLE flag in
*Attributes
*parameter of InitializeObjectAttributes.
* InitializeObjectAttributes(&Disk0, &Disk0Path, OBJ_OPENIF |
OBJ_KERNEL_HANDLE, NULL, NULL);*
Regards
Deepak
On Thu, Jan 6, 2011 at 2:13 AM, wrote:
> I am trying to read directly from a disk in my driver. I open a handle to
> the disk with:
>
> OBJECT_ATTRIBUTES Disk0;
> IO_STATUS_BLOCK Disk0Comp;
> UNICODE_STRING Disk0Path;
> RtlInitUnicodeString(&Disk0Path, PConnectInfo->Disk0Path);
> InitializeObjectAttributes(&Disk0, &Disk0Path, OBJ_OPENIF, NULL, NULL);
> status = ZwCreateFile(
> &(pEntry->Disk0BaseAddress), //File HANDLE
> GENERIC_READ, //Desired Access
> &Disk0, //Object Attributes
> &Disk0Comp, //IO_STATUS_BLOCK
> NULL, //Allocation Size
> FILE_ATTRIBUTE_NORMAL, //File Attributes
> FILE_SHARE_READ, //Share Access
> FILE_OPEN, //Create Disposition
> FILE_NON_DIRECTORY_FILE | FILE_RANDOM_ACCESS, //Create Options
> NULL, //EABuffer
> 0 //EALength
> );
>
> Where the Disk Path is \??\PhysicalDrive1\0. This returns STATUS_SUCCESS
> and then in my read function I attempt to do this:
>
> PVOID buffer = ExAllocatePoolWithTag(NonPagedPool, ReadLength, ‘buf’);
> IO_STATUS_BLOCK pSrc;
> LARGE_INTEGER Read;
> NTSTATUS status;
> Read.LowPart = StartingLbn.LowPart;
> Read.HighPart = StartingLbn.HighPart;
> Read.QuadPart += pConnectionInformation->ConnectionInfo.Disk0Start;
> status = ZwReadFile(
> pConnectionInformation->Disk0BaseAddress, //HANDLE
> NULL,
> //EVENT HANDLE
> NULL,
> //PIO_APC_ROUTINE
> NULL,
> //PVOID ApcContext
> &pSrc,
> //PIO_STATUS_BLOCK
> buffer,
> //PVOID buffer
> ReadLength,
> //ULONG Length
> &Read,
> //PLARGE_INTEGER ByteOffset
> NULL
> //PULONG Key
> );
>
> This returns STATUS_OBJECT_TYPE_MISMATCH.
>
> Everything looks correct to me so if someone could point out what I am
> doing wrong it would be appreciated.
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>