When IRP_MJ_CREATE is received, I want to read some more data first before
processing the request by creating an IRP using IoAllocateIrp(), but I got
the status c0000128 STATUS_FILE_CLOSED (An I/O request other than close
and several other special-case oeprations were attempted using a
FileObject that had already been closed. Why do I get such an error?
// Initialize the event
KeInitializeEvent(&event, SynchronizationEvent, FALSE);
// Allocate an irp for this request. This could also come from a
// private pool, for instance.
readIrp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
if (readIrp == NULL)
{
DbgPrint(“ERROR! IoAllocateIrp fail!\n”);
return FALSE;
}
// Build the IRP’s main body
readIrp->AssociatedIrp.SystemBuffer = NULL;
readIrp->UserEvent = &event;
readIrp->UserIosb = &IoStatusBlock;
readIrp->Tail.Overlay.Thread = PsGetCurrentThread();
readIrp->Tail.Overlay.OriginalFileObject = FileObject;
readIrp->RequestorMode = KernelMode;
readBuf = ExAllocatePool(NonPagedPool, 4096);
readIrp->UserBuffer = readBuf;
readIrp->MdlAddress = NULL;
readIrp->IoStatus.Information = 5; // Read 5 bytes.
// Set up the I/O stack location.
ioStackLocation = IoGetNextIrpStackLocation(readIrp);
ioStackLocation->MajorFunction = IRP_MJ_READ;
ioStackLocation->MinorFunction = 0;
ioStackLocation->DeviceObject = DeviceObject;
ioStackLocation->FileObject = FileObject;
ioStackLocation->Parameters.Read.ByteOffset.LowPart = 0;
// ioStackLocation->Parameters.Read.Key
ioStackLocation->Parameters.Read.Length = 4096;
DbgPrint(“IoCallDriver\n”);
// Send it to the FSD
ntStatus = IoCallDriver(DeviceObject, readIrp);
if (ntStatus != 0)
{
DbgPrint(“IoCallDriver - ntStatus=%x\n”, ntStatus);
}
// Wait for the I/O
KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);
ExFreePool(readBuf);
Am I missing something?