Hello All,
Thanks for the reply. The problem is that we are creating a virtual device aganist our original drive. For example we have
created X: (virtual device) aganist F: (actual hard disk partition). Now we want to redirect every device control request for
X: to F: That is we want to write a function aganist IRP_MJ_DEVICE_CONTROL that will redirect the control requests for X: to
F:
Below is some portion of the code:
// Driver Entry
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = SampleDeviceControl;
NTSTATUS
SampleDeviceControl(
PDEVICE_OBJECT DeviceObject,
PIRP Irp
)
{
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIO_STACK_LOCATION currentIrpStack = IoGetCurrentIrpStackLocation(Irp);
ULONG command = currentIrpStack->Parameters.DeviceIoControl.IoControlCode;
NTSTATUS status = STATUS_SUCCESS;
KEVENT event;
PIRP OwnIoctlIrp;
PVOID InputBuffer, OutputBuffer;
status = IoAcquireRemoveLock(&deviceExtension->RemoveLock, (PVOID)42);
if (!NT_SUCCESS(status)) {
DbgPrint(“=== DTSC4DeviceControl FAILURE(1) ===\n”);
DbgPrint(“Acquire RemoveLock failed\n”);
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp,IO_NO_INCREMENT);
return status;
}
if(currentIrpStack->Parameters.DeviceIoControl.InputBufferLength){
InputBuffer = Irp->AssociatedIrp.SystemBuffer;
OutputBuffer = NULL;
}
else{
InputBuffer = NULL;
OutputBuffer = Irp->AssociatedIrp.SystemBuffer;
}
KeInitializeEvent(&event, /*SynchronizationEvent*/NotificationEvent, FALSE);
OwnIoctlIrp = IoBuildDeviceIoControlRequest (
command,
deviceExtension->StoragetDeviceObject,
InputBuffer,
currentIrpStack->Parameters.DeviceIoControl.InputBufferLength,
OutputBuffer,
currentIrpStack->Parameters.DeviceIoControl.OutputBufferLength,
FALSE, // External
&event,
&Irp->IoStatus);
if (NULL == OwnIoctlIrp) {
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp,IO_NO_INCREMENT);
IoReleaseRemoveLock(&deviceExtension->RemoveLock, (PVOID)42);
return STATUS_INSUFFICIENT_RESOURCES;
}
status = IoCallDriver(deviceExtension->StoragetDeviceObject, OwnIoctlIrp);
if (status == STATUS_PENDING){
DbgPrint(“=== DTSC4DeviceControl FAILURE(3) ===\n”);
KeWaitForSingleObject(
&event,
Executive,
KernelMode,
FALSE,
NULL);
}
IoCompleteRequest(Irp,IO_NO_INCREMENT);
IoReleaseRemoveLock(&deviceExtension->RemoveLock, (PVOID)42);
return STATUS_SUCCESS;
}
Thanks