Hi,
I will be very appreciated for any help.
I would like to issue a normal read/write/directory control irps to the file
object.
Seems, I do not understand the mechanism well enough, because
the system crashes with DRIVER_LEFT_LOCKED_PAGES_IN_PROGRESS
in the NTFS.SYS.
I am allocating a read buffer from the non-paged pool and
calling the following routine for synchronous read:
NTSTATUS
ReadFile (
IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN PIO_STATUS_BLOCK IoStatusBlock,
IN PVOID Buffer,
IN ULONG Length,
IN PLARGE_INTEGER ByteOffset
)
{
PIRP Irp;
PIO_STACK_LOCATION IrpSp;
KEVENT Event;
NTSTATUS Status;
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
if (Irp == NULL) {
return(STATUS_INSUFFICIENT_RESOURCES);
}
Irp->UserBuffer = Buffer;
Irp->UserEvent = &Event;
Irp->UserIosb = IoStatusBlock;
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
Irp->Tail.Overlay.OriginalFileObject = FileObject;
Irp->RequestorMode = KernelMode;
Irp->Flags = IRP_READ_OPERATION;
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->MajorFunction = IRP_MJ_READ;
IrpSp->MinorFunction = 0;
IrpSp->DeviceObject = DeviceObject;
IrpSp->FileObject = FileObject;
IrpSp->Parameters.Read.Length = Length;
IrpSp->Parameters.Read.ByteOffset = *ByteOffset;
IoSetCompletionRoutine(Irp, IrpComplete, 0, TRUE, TRUE, TRUE);
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING) {
KeWaitForSingleObject(&Event, Executive, KernelMode, TRUE, 0);
Status = IoStatusBlock->Status;
}
return(Status);
}
And the completion routine looks like
NTSTATUS
IrpComplete (
PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context
)
{
*Irp->UserIosb = Irp->IoStatus;
KeSetEvent(Irp->UserEvent, 0, FALSE);
IoFreeIrp(Irp);
return(STATUS_MORE_PROCESSING_REQUIRED);
}
What am I doing wrong in this code?
If I will use MDL, instead of raw buffer who is responsible for freeing it?
Thank you very much in advance.
Regards,
Leonid.