Hi,
I have the following scenario: In my incoming Read callback, I have an incoming MDL, but the data on the disk is supposed to be read in to different parts of the incoming MDL. Rather than creating a bunch of IoBuildPartialMdls and sending a bunch of individual reads to the disk, is it possible to create a new MDL and chaining a bunch of IoBuildPartialMdl’s of the original MDL and send it down to disk. Pseudo-code below:
NTSTATUS ReadWrite(_In_ PDEVICE_OBJECT deviceObject, PIRP irp)
{
PMDL incomingMdl = irp->MdlAddress;
PMDL toDiskMdl = NULL;
UINT32 toDiskLength = 0;
PMDL lastChainMdl = NULL;
PVOID virtualAddress = (INT_PTR)MmGetMdlVirtualAddress(incomingMdl);
for (int i = 0; i < count; ++i)
{
if (i == 0)
{
toDiskMdl = IoAllocateMdl(incomingMdl, incomingMdlLength, FALSE, FALSE, NULL);
latChainMdl = toDiskMdl;
}
partialBufferOffset = /* calculate offset based on i */;
partialBufferLength = /* calculate length based on i */;
PMDL partialMdl = NULL;
IoBuildPartialMdl(toDiskMdl, partialMdl, (INT_PTR)virtualAddress + partialBufferOffset, partialBufferLength);
lastChainMdl->Next = partialMdl;
lastChainMdl = partialMdl;
toDiskLength += partialBufferLength;
}
/* Now that toDiskMdl is created, send an IRP down to disk with toDiskMdl and toDiskLength */
/* Complete the incoming IRP in the completion routine */
}