MDL Address

How do we change the virtual address in MDL to non paged pool allocated by
the filter driver in the IRP_MJ_WRITE. so that i can write my own data
instead of original file data?

In IFS documention it is mentioned that it is usually done using
MmGetMdlVirtualAddress. Can any one help on this?

Regards,
VC

Change the whole MDL pointer at Irp->MdlAddress, this works. Do not forget
to change back to original MDL on any completion path.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Vishnu P”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Tuesday, June 14, 2005 7:41 PM
Subject: [ntfsd] MDL Address

>
> How do we change the virtual address in MDL to non paged pool allocated by
> the filter driver in the IRP_MJ_WRITE. so that i can write my own data
> instead of original file data?
>
> In IFS documention it is mentioned that it is usually done using
> MmGetMdlVirtualAddress. Can any one help on this?
>
> Regards,
> VC
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

thanx for the reply

i tried to create MDL and assign it to Irp->MdlAddress field but it is not
working.

see the code below

if(FlagOn(Irp->Flags,IRP_PAGING_IO) &&
FlagOn(Irp->Flags,IRP_NOCACHE))
{
syncToDispatch = TRUE;
bIsWriteFromVM = TRUE;

// Create MDL and assign it to Irp->MdlAddress

// 1. Allocate memory from non paged pool.
pModifiedData = ExAllocatePoolWithTag(NonPagedPool,
pIrpSp->Parameters.Write.Length,
FILESPY_MDLADDRESS_TAG);
ASSERT(NULL != pModifiedData);

RtlZeroMemory(pModifiedData,pIrpSp->Parameters.Write.Length);

// 2. Create Mdl
pNewMdl = IoAllocateMdl( pModifiedData,
pIrpSp->Parameters.Write.Length,
FALSE,
FALSE,
NULL);

ASSERT(NULL != pNewMdl);
pOriginalData = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
NormalPagePriority);

// 3. Modify the data
if(NULL != pOriginalData)
for(index = 0; index < pIrpSp->Parameters.Write.Length; index++)
pModifiedData[index] = pOriginalData[index]+1;

// 4. change the MdlAddress
pOriginalMdl = Irp->MdlAddress;
Irp->MdlAddress = pNewMdl;

}

later im restoring the original MdlAddress
if(bIsWriteFromVM)
Irp->MdlAddress = pOriginalMdl;

With this code system gets hang.
Is there any thing i should do to make it work?

Well you are missing something kind of important here! There is no call
to MmBuildMdlForNonPagedPool for a start.

You are also not updating the UserBuffer pointer:

Irp->UserBuffer = MmGetMdlVirtualAddress( pNewMdl );

Also, be careful when replacing the buffer for an irp with the
IRP_NOCACHE flag set. The allocation size of the MDL should be aligned
to the sector size of the disk AFAIK.

You also do not show the cleanup code, so I will assume you are not
calling IoFreeMdl and the buffer you allocated for your modified code.

I may have missed something else but that should get on the right track

Regards

Ben Curley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Vishnu P
Sent: 15 June 2005 10:29
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] MDL Address

thanx for the reply

i tried to create MDL and assign it to Irp->MdlAddress field but it is
not working.

see the code below

if(FlagOn(Irp->Flags,IRP_PAGING_IO) &&
FlagOn(Irp->Flags,IRP_NOCACHE))
{
syncToDispatch = TRUE;
bIsWriteFromVM = TRUE;

// Create MDL and assign it to Irp->MdlAddress

// 1. Allocate memory from non paged pool.
pModifiedData = ExAllocatePoolWithTag(NonPagedPool,
pIrpSp->Parameters.Write.Length,
FILESPY_MDLADDRESS_TAG);
ASSERT(NULL != pModifiedData);

RtlZeroMemory(pModifiedData,pIrpSp->Parameters.Write.Length);

// 2. Create Mdl
pNewMdl = IoAllocateMdl( pModifiedData,
pIrpSp->Parameters.Write.Length,
FALSE,
FALSE,
NULL);

ASSERT(NULL != pNewMdl);
pOriginalData = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
NormalPagePriority);

// 3. Modify the data
if(NULL != pOriginalData)
for(index = 0; index < pIrpSp->Parameters.Write.Length;
index++)
pModifiedData[index] = pOriginalData[index]+1;

// 4. change the MdlAddress
pOriginalMdl = Irp->MdlAddress;
Irp->MdlAddress = pNewMdl;

}

later im restoring the original MdlAddress
if(bIsWriteFromVM)
Irp->MdlAddress = pOriginalMdl;

With this code system gets hang.
Is there any thing i should do to make it work?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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

Well thanx Curley. That really worked out for me.

here is the clean up code

Irp->MdlAddress = pOriginalMdl;

if(pNewMdl)
IoFreeMdl(pNewMdl);

if(pModifiedData)
ExFreePoolWithTag(pModifiedData,FILESPY_MDLADDRESS_TAG);

I hope that will be enough.

“Ben Curley” wrote in message news:xxxxx@ntfsd…

Well you are missing something kind of important here! There is no call
to MmBuildMdlForNonPagedPool for a start.

You are also not updating the UserBuffer pointer:

Irp->UserBuffer = MmGetMdlVirtualAddress( pNewMdl );

Also, be careful when replacing the buffer for an irp with the
IRP_NOCACHE flag set. The allocation size of the MDL should be aligned
to the sector size of the disk AFAIK.

You also do not show the cleanup code, so I will assume you are not
calling IoFreeMdl and the buffer you allocated for your modified code.

I may have missed something else but that should get on the right track

Regards

Ben Curley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Vishnu P
Sent: 15 June 2005 10:29
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] MDL Address

thanx for the reply

i tried to create MDL and assign it to Irp->MdlAddress field but it is
not working.

see the code below

if(FlagOn(Irp->Flags,IRP_PAGING_IO) &&
FlagOn(Irp->Flags,IRP_NOCACHE))
{
syncToDispatch = TRUE;
bIsWriteFromVM = TRUE;

// Create MDL and assign it to Irp->MdlAddress

// 1. Allocate memory from non paged pool.
pModifiedData = ExAllocatePoolWithTag(NonPagedPool,
pIrpSp->Parameters.Write.Length,
FILESPY_MDLADDRESS_TAG);
ASSERT(NULL != pModifiedData);

RtlZeroMemory(pModifiedData,pIrpSp->Parameters.Write.Length);

// 2. Create Mdl
pNewMdl = IoAllocateMdl( pModifiedData,
pIrpSp->Parameters.Write.Length,
FALSE,
FALSE,
NULL);

ASSERT(NULL != pNewMdl);
pOriginalData = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
NormalPagePriority);

// 3. Modify the data
if(NULL != pOriginalData)
for(index = 0; index < pIrpSp->Parameters.Write.Length;
index++)
pModifiedData[index] = pOriginalData[index]+1;

// 4. change the MdlAddress
pOriginalMdl = Irp->MdlAddress;
Irp->MdlAddress = pNewMdl;

}

later im restoring the original MdlAddress
if(bIsWriteFromVM)
Irp->MdlAddress = pOriginalMdl;

With this code system gets hang.
Is there any thing i should do to make it work?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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

Don’t forget to replace the original irp->UserBuffer value in your
completion because you have done

Irp->UserBuffer = MmGetMdlVirtualAddress( pNewMdl );

in the dispatch.

Other than that it looks ok.

Regards

Ben Curley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Vishnu P
Sent: 15 June 2005 13:09
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] MDL Address

Well thanx Curley. That really worked out for me.

here is the clean up code

Irp->MdlAddress = pOriginalMdl;

if(pNewMdl)
IoFreeMdl(pNewMdl);

if(pModifiedData)
ExFreePoolWithTag(pModifiedData,FILESPY_MDLADDRESS_TAG);

I hope that will be enough.

“Ben Curley” wrote in message news:xxxxx@ntfsd…

Well you are missing something kind of important here! There is no call
to MmBuildMdlForNonPagedPool for a start.

You are also not updating the UserBuffer pointer:

Irp->UserBuffer = MmGetMdlVirtualAddress( pNewMdl );

Also, be careful when replacing the buffer for an irp with the
IRP_NOCACHE flag set. The allocation size of the MDL should be aligned
to the sector size of the disk AFAIK.

You also do not show the cleanup code, so I will assume you are not
calling IoFreeMdl and the buffer you allocated for your modified code.

I may have missed something else but that should get on the right track

Regards

Ben Curley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Vishnu P
Sent: 15 June 2005 10:29
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] MDL Address

thanx for the reply

i tried to create MDL and assign it to Irp->MdlAddress field but it is
not working.

see the code below

if(FlagOn(Irp->Flags,IRP_PAGING_IO) &&
FlagOn(Irp->Flags,IRP_NOCACHE))
{
syncToDispatch = TRUE;
bIsWriteFromVM = TRUE;

// Create MDL and assign it to Irp->MdlAddress

// 1. Allocate memory from non paged pool.
pModifiedData = ExAllocatePoolWithTag(NonPagedPool,
pIrpSp->Parameters.Write.Length,
FILESPY_MDLADDRESS_TAG);
ASSERT(NULL != pModifiedData);

RtlZeroMemory(pModifiedData,pIrpSp->Parameters.Write.Length);

// 2. Create Mdl
pNewMdl = IoAllocateMdl( pModifiedData,
pIrpSp->Parameters.Write.Length,
FALSE,
FALSE,
NULL);

ASSERT(NULL != pNewMdl);
pOriginalData = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
NormalPagePriority);

// 3. Modify the data
if(NULL != pOriginalData)
for(index = 0; index < pIrpSp->Parameters.Write.Length;
index++)
pModifiedData[index] = pOriginalData[index]+1;

// 4. change the MdlAddress
pOriginalMdl = Irp->MdlAddress;
Irp->MdlAddress = pNewMdl;

}

later im restoring the original MdlAddress
if(bIsWriteFromVM)
Irp->MdlAddress = pOriginalMdl;

With this code system gets hang.
Is there any thing i should do to make it work?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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

ya i have done that.
do i need to change back the Irp->UserBuffer to original value after

Irp->MdlAddress = pOriginalMdl;

on completion path

“Ben Curley” wrote in message news:xxxxx@ntfsd…

Don’t forget to replace the original irp->UserBuffer value in your
completion because you have done

Irp->UserBuffer = MmGetMdlVirtualAddress( pNewMdl );

in the dispatch.

Other than that it looks ok.

Regards

Ben Curley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Vishnu P
Sent: 15 June 2005 13:09
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] MDL Address

Well thanx Curley. That really worked out for me.

here is the clean up code

Irp->MdlAddress = pOriginalMdl;

if(pNewMdl)
IoFreeMdl(pNewMdl);

if(pModifiedData)
ExFreePoolWithTag(pModifiedData,FILESPY_MDLADDRESS_TAG);

I hope that will be enough.

“Ben Curley” wrote in message news:xxxxx@ntfsd…

Well you are missing something kind of important here! There is no call
to MmBuildMdlForNonPagedPool for a start.

You are also not updating the UserBuffer pointer:

Irp->UserBuffer = MmGetMdlVirtualAddress( pNewMdl );

Also, be careful when replacing the buffer for an irp with the
IRP_NOCACHE flag set. The allocation size of the MDL should be aligned
to the sector size of the disk AFAIK.

You also do not show the cleanup code, so I will assume you are not
calling IoFreeMdl and the buffer you allocated for your modified code.

I may have missed something else but that should get on the right track

Regards

Ben Curley

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Vishnu P
Sent: 15 June 2005 10:29
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] MDL Address

thanx for the reply

i tried to create MDL and assign it to Irp->MdlAddress field but it is
not working.

see the code below

if(FlagOn(Irp->Flags,IRP_PAGING_IO) &&
FlagOn(Irp->Flags,IRP_NOCACHE))
{
syncToDispatch = TRUE;
bIsWriteFromVM = TRUE;

// Create MDL and assign it to Irp->MdlAddress

// 1. Allocate memory from non paged pool.
pModifiedData = ExAllocatePoolWithTag(NonPagedPool,
pIrpSp->Parameters.Write.Length,
FILESPY_MDLADDRESS_TAG);
ASSERT(NULL != pModifiedData);

RtlZeroMemory(pModifiedData,pIrpSp->Parameters.Write.Length);

// 2. Create Mdl
pNewMdl = IoAllocateMdl( pModifiedData,
pIrpSp->Parameters.Write.Length,
FALSE,
FALSE,
NULL);

ASSERT(NULL != pNewMdl);
pOriginalData = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
NormalPagePriority);

// 3. Modify the data
if(NULL != pOriginalData)
for(index = 0; index < pIrpSp->Parameters.Write.Length;
index++)
pModifiedData[index] = pOriginalData[index]+1;

// 4. change the MdlAddress
pOriginalMdl = Irp->MdlAddress;
Irp->MdlAddress = pNewMdl;

}

later im restoring the original MdlAddress
if(bIsWriteFromVM)
Irp->MdlAddress = pOriginalMdl;

With this code system gets hang.
Is there any thing i should do to make it work?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

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