How do I split an IO request in KMDF? In my test driver, when my app reads 8 sectors starting at 0, the first sector will come from a file and the rest from a block device. Here is my code to handle the Read operation (assume all calls return successfully).
WDF_REQUEST_PARAMETERS_INIT(¶meters);
WdfRequestGetParameters(Request, ¶meters);
status = WdfRequestRetrieveOutputMemory(Request, &hMemory);
fileOffset.QuadPart = parameters.Parameters.Read.DeviceOffset;
if(fileOffset.QuadPart >= 0 && fileOffset.QuadPart <= 512)
{
curLen = (size_t) (512 - fileOffset.QuadPart + 1);
buf = (PUCHAR) ExAllocatePoolWithTag(NonPagedPool, curLen, MYTESTDEV_TAG);
// Read from file
status = ZwReadFile(pDevContext->fileHandle,// File handle
NULL,// handle to event obj for completion
NULL,// reserved
NULL,// reserved
&ioStatusBlock,// Completion status
buf,// buf for read data
curLen,// bytes to read
&fileOffset,// read offset
NULL);// key, should be NULL
status = WdfMemoryCopyFromBuffer(hMemory, 0, buf, curLen);
status = WdfMemoryCopyFromBuffer(hMemory,
/* I tried to use the same hMemory object to read from the block device. And it doesn’t work */
totalLen = parameters.Parameters.Read.Length;
if(totalLen > curLen)
{
memOffset.BufferOffset = curLen;
memOffset.BufferLength = totalLen - curLen;
// Use an offset to skip the part that already read
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&memDescriptor, hMemory, &memOffset);
byteOffset = parameters.Parameters.Read.DeviceOffset + curLen;
// Read from block dev
status = WdfIoTargetSendReadSynchronously(pDevContext->ioTarget,
NULL,
&memDescriptor,
&byteOffset,
NULL,
&information);
information += (ULONG_PTR) curLen;
}
}
// Complete the request here.
I got an Assertion @ WdfIoTargetSendReadSynchronously
*** Assertion failed: pBuf != NULL
*** Source File: d:\vistartm\drivers\wdf\kmdf\src\support\fxrequestbuffer.cpp, line 369
Why can I reuse the hMem with an offset? TIA.
Chu Bun