Hello Everybody,
I’m working on a module for mounting a virtual disk, i’m using the
filedisk code provided in bosse’s site as a template. Since there is no
provision in the filedisk template for mounting the virtual disk from
kernel mode only; which is essential after restart(as the virtual drive is
lost with every shutdown). I’m trying to roll my own IRP for device
control and getting KMODE_EXCEPTION with
0xC0000005(STATUS_ACCESS_VIOLATION). Am i doing something terribly
incorrect???
Please help…
My code is as follows:
static VOID MyOwnIRP(PDEVICE_OBJECT DeviceObject)
{
PIRP irp;
KEVENT event;
PIO_STACK_LOCATION ioStackLocation;
POPEN_FILE_INFORMATION OpenFileInformation; // contains the file info
IO_STATUS_BLOCK ioStatus;
PIO_STATUS_BLOCK IoStatusBlock = NULL;
NTSTATUS status;
irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
if (!irp) {
//
// Failure!
//
return;
}
irp->AssociatedIrp.SystemBuffer = OpenFileInformation;
irp->UserEvent = &event;
irp->UserIosb = IoStatusBlock;
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->RequestorMode = KernelMode;
KeInitializeEvent(&event, SynchronizationEvent, FALSE);
ioStackLocation = IoGetNextIrpStackLocation(irp);
ioStackLocation->MajorFunction = IRP_MJ_DEVICE_CONTROL;
ioStackLocation->Parameters.DeviceIoControl.IoControlCode =
IOCTL_DISK_OPEN_FILE;
ioStackLocation->DeviceObject = DeviceObject;
ioStackLocation->Parameters.DeviceIoControl.InputBufferLength =
sizeof(OPEN_FILE_INFORMATION) + OpenFileInformation->FileNameLength;
//
// Set the completion routine.
//
IoSetCompletionRoutine(irp, MyOwnIoCompletion, 0, TRUE, TRUE, TRUE);
//
// Send it to the FSD
//
(void) IoCallDriver(DeviceObject, irp);
KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);
//
// Done!
//
return;
}
static NTSTATUS MyOwnIoCompletion(PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context)
{
//
// Copy the status information back into the “user” IOSB.
//
PDEVICE_OBJECT myDeviceObject;
myDeviceObject = DeviceObject;
Context = NULL;
*Irp->UserIosb = Irp->IoStatus;
//
// Set the user event - wakes up the mainline code doing this.
//
KeSetEvent(Irp->UserEvent, 0, FALSE);
//
// Free the IRP now that we are done with it.
//
IoFreeIrp(Irp);
return STATUS_MORE_PROCESSING_REQUIRED;
}