Roll my IRP in filter,question about Allocate MDL.

Roll my IRP in filter,question about Allocate MDL.
In my filter,I want to Roll a IRP,IRP_MJ_Write IRP;
I want to Allocate MDL,So,Code:
//pBuffer is nonpagedpool;
pMdl = IoAllocateMdl(pBuffer, nReadLength, FALSE, TRUE, NULL);
MmProbeAndLockPages(pMdl, KernelMode, IoWriteAccess);
status = WriteData(…);//Build a IRP,then Call,then wait completion(free
irp),return;
MmUnlockPages(pMdl);
IoFreeMdl(pMdl);

Is right?If I want to use MmBuildMdlForNonPagedPool,what shall I do?Just
like kfc by osr,
but there isn’t IoFreeMDL;bug?
I think code is:
//pBuffer is nonpagedpool;
pMdl = IoAllocateMdl(pBuffer, nReadLength, FALSE, TRUE, NULL);
MmBuildMdlForNonPagedPool(mdl);
status = WriteData(…);//Build a IRP,then Call,then wait completion(free
Irp),return;
IoFreeMdl(pMdl);

Is right?

If you’re playing with a buffer allocated from non-paged code, your
second scenario is correct.

ecore wrote:

Roll my IRP in filter,question about Allocate MDL.
In my filter,I want to Roll a IRP,IRP_MJ_Write IRP;
I want to Allocate MDL,So,Code:
//pBuffer is nonpagedpool;
pMdl = IoAllocateMdl(pBuffer, nReadLength, FALSE, TRUE, NULL);
MmProbeAndLockPages(pMdl, KernelMode, IoWriteAccess);
status = WriteData(…);//Build a IRP,then Call,then wait completion(free
irp),return;
MmUnlockPages(pMdl);
IoFreeMdl(pMdl);

Is right?If I want to use MmBuildMdlForNonPagedPool,what shall I do?Just
like kfc by osr,
but there isn’t IoFreeMDL;bug?
I think code is:
//pBuffer is nonpagedpool;
pMdl = IoAllocateMdl(pBuffer, nReadLength, FALSE, TRUE, NULL);
MmBuildMdlForNonPagedPool(mdl);
status = WriteData(…);//Build a IRP,then Call,then wait completion(free
Irp),return;
IoFreeMdl(pMdl);

Is right?


You are currently subscribed to ntfsd as: xxxxx@nryan.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

  • Nick Ryan (MVP for DDK)

Why do you need to build a MDL?
IoBuildAsynchronousFdsRequest takes care of setting up buffer in IRP
accroding to requirements of underlying device.

Alexei.

“ecore” wrote in message news:xxxxx@ntfsd…
>
> Roll my IRP in filter,question about Allocate MDL.
> In my filter,I want to Roll a IRP,IRP_MJ_Write IRP;
> I want to Allocate MDL,So,Code:
> //pBuffer is nonpagedpool;
> pMdl = IoAllocateMdl(pBuffer, nReadLength, FALSE, TRUE, NULL);
> MmProbeAndLockPages(pMdl, KernelMode, IoWriteAccess);
> status = WriteData(…);//Build a IRP,then Call,then wait completion(free
> irp),return;
> MmUnlockPages(pMdl);
> IoFreeMdl(pMdl);
>
> Is right?If I want to use MmBuildMdlForNonPagedPool,what shall I do?Just
> like kfc by osr,
> but there isn’t IoFreeMDL;bug?
> I think code is:
> //pBuffer is nonpagedpool;
> pMdl = IoAllocateMdl(pBuffer, nReadLength, FALSE, TRUE, NULL);
> MmBuildMdlForNonPagedPool(mdl);
> status = WriteData(…);//Build a IRP,then Call,then wait completion(free
> Irp),return;
> IoFreeMdl(pMdl);
>
> Is right?
>
>

I want to build a Write IRP,and it must not be IRP_NOCACHE(including
PagingIO,of course).
IoBuildAsynchronousFdsRequest can complete it?
thanks.

Why do you need to build a MDL?
IoBuildAsynchronousFdsRequest takes care of setting up buffer in IRP
accroding to requirements of underlying device.

Alexei.

As far as I remember IoBuildAsynchronousFdsRequest doesn’t set IRP_NOCACHE
flag. But this doesn’t matter, you can clear this flag before invoking
IoCallDriver. If you are sending the IRP to a file system driver you
normally don’t need to set MDL - all file systems I know about use
METHOD_NEITHER for IO. File system driver will create an MDL if it choose to
do so; for Cached IO it usually unnesessary.

Alexei.

“ecore” wrote in message news:xxxxx@ntfsd…
>
> I want to build a Write IRP,and it must not be IRP_NOCACHE(including
> PagingIO,of course).
> IoBuildAsynchronousFdsRequest can complete it?
> thanks.
>
> > Why do you need to build a MDL?
> > IoBuildAsynchronousFdsRequest takes care of setting up buffer in IRP
> > accroding to requirements of underlying device.
> >
> > Alexei.
> >
>
>