Vartika,
First, my apologies for guessing your gender incorrectly (alas, e-mail
does not give us much in the way of hints).
Some question:
(1) Why do you specify KernelMode for access? I’d instead suggest
using Irp->PreviousMode (so you do user mode probe for user buffers)
(2) What are you doing with the existing contents of
Irp->MdlAddress? It does not appear to be preserved in this case and
that could lead to memory leaks
(3) Where do you clear Irp->MdlAddress after you free the MDL? Not
doing so will lead the I/O Manager to clean up the MDL and that might
lead to PFN_LIST_CORRUPT
I’d suggest chaining the MDL onto the IRP and allowing the I/O Manager
to tear it down - that’s far less error prone than trying to do this
yourself (you should be able to make it work, but PFN_LIST_CORRUPT is
the way MM tells you that you didn’t do it correctly this time around.)
Regards,
Tony
Tony Mason
Consulting Partner
OSR Open Systems Resources Inc.
http://www.osr.com http:</http:>
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of vartika singh
Sent: Tuesday, April 20, 2004 10:18 AM
To: ntfsd redirect
Subject: Re: RE: [ntfsd] I/O calls in Create/Open
Hi all!
First of all im not ‘he’ im ‘she’.
Im sorry i didn’t mention the windows explorer clearly.
Secondly i had sent my code some time back,but as an attachment,and
consequently it got rejected.
Well here is how im manipulating the MDLs…
NTSTATUS
dispatchRead (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
PFILE_OBJECT fileObject = pThisIrp->FileObject;//defined in ntddk.h
16885
readContext->offset = fileObject->CurrentByteOffset.LowPart;
PAGED_CODE();
**********This is where i allocate the MDL*************
if( ! ( Irp->Flags & IRP_PAGING_IO ) ) {
readContext->pMdl = IoAllocateMdl
(
Irp->UserBuffer,
pThisIrp->Parameters.Read.Length,
FALSE,
FALSE,
NULL
);
__try {
MmProbeAndLockPages( readContext->pMdl, KernelMode,
IoModifyAccess );
}
__except( EXCEPTION_EXECUTE_HANDLER) {
IoFreeMdl( readContext->pMdl );
return GetExceptionCode();
}
}
else {
//cannot Probe and Lock on a PAGING_IO request, just pass the
MDL
readContext->pMdl = Irp->MdlAddress;
}
//setting the completion routine
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine
(
Irp,
ReadCompletion,
readContext,
TRUE,
TRUE,
TRUE
);
lowerStatus = IoCallDriver(
((PFILESPY_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->AttachedToDe
viceObject, Irp );
return lowerStatus;
}
NTSTATUS
ReadCompletion (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
{
PCHAR buf;
ULONG i;
PREAD_CONTEXT pReadCtx = (PREAD_CONTEXT)Context;
ULONG len = Irp->IoStatus.Information;
if( Irp->IoStatus.Status == STATUS_SUCCESS ) {
if( len > 0 ) {
buf = (PCHAR)MmGetSystemAddressForMdlSafe(
pReadCtx->pMdl,HighPagePriority );
************************************************************************
****This is where im replacing the data in the test files of mine.Please
note that all these files contain only few words as data.As to begin
with the data with which im replacing it with is also only a
sentence.***************************************************************
********
RtlInitUnicodeString(&readIoBuf,L"This is a test file!")
RtlCopyMemory(MmGetSystemAddressForMdlSafe(pReadCtx->pMdl,HighPagePriori
ty),readIoBuf.Buffer,len);
}
else {
DbgPrint ( “Not reading: non positive length from FSD” );
}
}
else {
DbgPrint ( “Not reading : non-zero rc from FSD: %08x \n”,
Irp->IoStatus.Status );
}
if( Irp->Flags & IRP_PAGING_IO ) {
;
}
else {
MmUnlockPages( pReadCtx->pMdl );
IoFreeMdl( pReadCtx->pMdl);
}
if(Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}
ExFreePoolWithTag( pReadCtx, SPY_READ_TAG );
return STATUS_SUCCESS;
}
Im using the filespy program provided with the IFS kit.Platform is
windows 2k pro.and im using the IFS kit’s Windows 2k checked build
environment for the x86 architecture.
This is my first shot at writing any sort of device driver and im really
confused.
regards
Vartika