Skip to content

Commit

Permalink
FilterDevice: Extend IRP post processing logic
Browse files Browse the repository at this point in the history
This patch adds support for IRP post processing
on failure and in all cases.

New logic will be used by following commits to
implement device text patching.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
  • Loading branch information
Dmitry Fleytman committed Jul 4, 2016
1 parent e0c4356 commit 8c7edd9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
5 changes: 3 additions & 2 deletions UsbDk/FilterDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ NTSTATUS CUsbDkHubFilterStrategy::PNPPreProcess(PIRP Irp)
(BusRelations == irpStack->Parameters.QueryDeviceRelations.Type))
{
return PostProcessOnSuccess(Irp,
[this](PIRP Irp)
[this](PIRP Irp) -> NTSTATUS
{
CNonPagedDeviceRelations Relations;
auto status = Relations.Create((PDEVICE_RELATIONS)Irp->IoStatus.Information);

if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Failed to create device relations object: %!STATUS!", status);
return;
return STATUS_SUCCESS;
}

TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Starting relations array processing:");
Expand All @@ -261,6 +261,7 @@ NTSTATUS CUsbDkHubFilterStrategy::PNPPreProcess(PIRP Irp)
DropRemovedDevices(Relations);
AddNewDevices(Relations);
TraceEvents(TRACE_LEVEL_ERROR, TRACE_FILTERDEVICE, "%!FUNC! Finished relations array processing");
return STATUS_SUCCESS;
});
}

Expand Down
22 changes: 17 additions & 5 deletions UsbDk/FilterStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,29 @@ class CUsbDkFilterStrategy

template<typename PostProcessFuncT>
NTSTATUS PostProcessOnSuccess(PIRP Irp, PostProcessFuncT PostProcessFunc)
{
return PostProcess(Irp, [PostProcessFunc](PIRP Irp, NTSTATUS Status) -> NTSTATUS
{ return NT_SUCCESS(Status) ? PostProcessFunc(Irp) : Status; });
}

template<typename PostProcessFuncT>
NTSTATUS PostProcessOnFailure(PIRP Irp, PostProcessFuncT PostProcessFunc)
{
return PostProcess(Irp, [PostProcessFunc](PIRP Irp, NTSTATUS Status) -> NTSTATUS
{ return !NT_SUCCESS(Status) ? PostProcessFunc(Irp, Status) : Status; });
}

template<typename PostProcessFuncT>
NTSTATUS PostProcess(PIRP Irp, PostProcessFuncT PostProcessFunc)
{
IoCopyCurrentIrpStackLocationToNext(Irp);

auto status = CIrp::ForwardAndWait(Irp, [this, Irp]()
{ return WdfDeviceWdmDispatchPreprocessedIrp(m_Owner->WdfObject(), Irp); });
{ return WdfDeviceWdmDispatchPreprocessedIrp(m_Owner->WdfObject(), Irp); });

if (NT_SUCCESS(status))
{
PostProcessFunc(Irp);
}
status = PostProcessFunc(Irp, status);

Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
Expand Down
8 changes: 5 additions & 3 deletions UsbDk/HiderStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,24 @@ NTSTATUS CUsbDkHiderStrategy::PNPPreProcess(PIRP Irp)
{
case IRP_MN_QUERY_ID:
return PostProcessOnSuccess(Irp,
[this](PIRP Irp)
[this](PIRP Irp) -> NTSTATUS
{
PatchDeviceID(Irp);
return STATUS_SUCCESS;
});

case IRP_MN_QUERY_CAPABILITIES:
return PostProcessOnSuccess(Irp,
[](PIRP Irp)
[](PIRP Irp) -> NTSTATUS
{
auto irpStack = IoGetCurrentIrpStackLocation(Irp);
irpStack->Parameters.DeviceCapabilities.Capabilities->RawDeviceOK = 1;
irpStack->Parameters.DeviceCapabilities.Capabilities->NoDisplayInUI = 1;
irpStack->Parameters.DeviceCapabilities.Capabilities->Removable = 0;
irpStack->Parameters.DeviceCapabilities.Capabilities->EjectSupported = 0;
irpStack->Parameters.DeviceCapabilities.Capabilities->SilentInstall = 1;
});
return STATUS_SUCCESS;
});
default:
return CUsbDkNullFilterStrategy::PNPPreProcess(Irp);
}
Expand Down

0 comments on commit 8c7edd9

Please sign in to comment.