Remapping MDL with different access

Hi,

I have a need to write to an MDL returned by the cache manager
via IRP_MJ_READ/IRP_MN_MDL call.
Now the question is how do I do that?
Would this work:
lpBuffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
LowPagePriority);
lpWriteMdl = IoAllocateMdl(lpBuffer, dwLength, FALSE, FALSE,
NULL);
// Now what to call - MmProbeAndLockPages or
MmBuildMdlForNonPagedPool?
// simple debugging of CcMdlRead suggests that it uses paged
pool - but maybe this would changed in the next OS build…

Now the same but reverse question. I’ve an MDL returned from
IRP_MJ_WRITE/IRP_MN_MDL, and when it is returned to the Cc
(IRP_MJ_WRITE/IRP_MN_COMPLETE_MDL), I need to have both read and write
access - CcPrepareMdlWrite uses IoWriteAccess, so I guess that means no
read access.


Kind regards, Dejan M. MVP for DDK
http://www.alfasp.com E-mail: xxxxx@alfasp.com
Alfa Transparent File Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa File Monitor - File monitoring library for Win32 developers.

Dejan,

That unfortunately does not fit into the interface. I’m not sure in what
context you are performing this operation - if you are in a filter driver,
the only *safe* way is to make two calls and then use the MDLs separately.
Unfortunately, you get two separate system mappings.

I can say that we’ve exploited this specific interface in the past - we’ve
implemented the IRP_MJ_READ/IRP_MN_MDL interface so that it does NOT use the
cache manager. Thus, I would not recommend trying to use the Cache Manager
APIs directly (via BCBs you could gain greater control within the file
system itself.)

I can think of plenty of UNSAFE ways to do this - like the manner you
suggested. Yes, it will work *at present* but there is no guarantee that
you won’t be handed a chunk of read-only device memory which will die
horribly if/when you attempt to write to that memory. Or vice-versa.

And I have seen (and debugged) situations where a file system was using
device memory, so it can happen.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: Dejan Maksimovic [mailto:xxxxx@alfasp.com]
Sent: Wednesday, April 09, 2003 11:21 AM
To: File Systems Developers
Subject: [ntfsd] Remapping MDL with different access

Hi,

I have a need to write to an MDL returned by the cache manager
via IRP_MJ_READ/IRP_MN_MDL call.
Now the question is how do I do that?
Would this work:
lpBuffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
LowPagePriority);
lpWriteMdl = IoAllocateMdl(lpBuffer, dwLength, FALSE, FALSE,
NULL);
// Now what to call - MmProbeAndLockPages or
MmBuildMdlForNonPagedPool?
// simple debugging of CcMdlRead suggests that it uses paged
pool - but maybe this would changed in the next OS build…

Now the same but reverse question. I’ve an MDL returned from
IRP_MJ_WRITE/IRP_MN_MDL, and when it is returned to the Cc
(IRP_MJ_WRITE/IRP_MN_COMPLETE_MDL), I need to have both read and write
access - CcPrepareMdlWrite uses IoWriteAccess, so I guess that means no
read access.


Kind regards, Dejan M. MVP for DDK
http://www.alfasp.com E-mail: xxxxx@alfasp.com
Alfa Transparent File Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa File Monitor - File monitoring library for Win32 developers.


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

> That unfortunately does not fit into the interface. I’m not sure in what

context you are performing this operation - if you are in a filter driver,
the only *safe* way is to make two calls and then use the MDLs separately.
Unfortunately, you get two separate system mappings.

What do you mean by this - do MmGetSystemAddressForMdlSafe to get the
original access, the make an MDL over it and use that MDL’s system address for
the other access? (If so, that’s fine)


Kind regards, Dejan M. MVP for DDK
http://www.alfasp.com E-mail: xxxxx@alfasp.com
Alfa Transparent File Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32 developers.
Alfa File Monitor - File monitoring library for Win32 developers.

Dejan,

No, what I mean is to send an IRP_MJ_READ/IRP_MN_MDL and then again send
IRP_MJ_WRITE/IRP_MN_MDL (or the fast I/O equivalents). They will PROBABLY
describe the same physical memory, unless the underlying file system is very
weird.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: Dejan Maksimovic [mailto:xxxxx@alfasp.com]
Sent: Wednesday, April 09, 2003 3:31 PM
To: File Systems Developers
Subject: [ntfsd] RE: Remapping MDL with different access

That unfortunately does not fit into the interface. I’m not sure in what
context you are performing this operation - if you are in a filter driver,
the only *safe* way is to make two calls and then use the MDLs separately.
Unfortunately, you get two separate system mappings.

What do you mean by this - do MmGetSystemAddressForMdlSafe to get
the
original access, the make an MDL over it and use that MDL’s system address
for
the other access? (If so, that’s fine)


Kind regards, Dejan M. MVP for DDK
http://www.alfasp.com E-mail: xxxxx@alfasp.com
Alfa Transparent File Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa File Monitor - File monitoring library for Win32 developers.


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

Well, whatever works for FAT and NTFS is sufficient - for now.
I found that using my approach works for FAT, and I will test for NTFS.

Deja.

No, what I mean is to send an IRP_MJ_READ/IRP_MN_MDL and then again send
IRP_MJ_WRITE/IRP_MN_MDL (or the fast I/O equivalents). They will PROBABLY
describe the same physical memory, unless the underlying file system is very
weird.


Kind regards, Dejan M. MVP for DDK
http://www.alfasp.com E-mail: xxxxx@alfasp.com
Alfa Transparent File Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32 developers.
Alfa File Monitor - File monitoring library for Win32 developers.