diff --git a/reactos/ntoskrnl/io/plugplay.c b/reactos/ntoskrnl/io/plugplay.c index a6d2218f6eb..71f11ba42b6 100644 --- a/reactos/ntoskrnl/io/plugplay.c +++ b/reactos/ntoskrnl/io/plugplay.c @@ -223,9 +223,36 @@ NtGetPlugPlayEvent(IN ULONG Reserved1, } +static PDEVICE_OBJECT +IopTraverseDeviceNode(PDEVICE_NODE Node, PUNICODE_STRING DeviceInstance) +{ + PDEVICE_OBJECT DeviceObject; + PDEVICE_NODE ChildNode; + + if (RtlEqualUnicodeString(&Node->InstancePath, + DeviceInstance, TRUE)) + return Node->PhysicalDeviceObject; + + /* Traversal of all children nodes */ + for (ChildNode = Node->Child; + ChildNode != NULL; + ChildNode = ChildNode->NextSibling) + { + DeviceObject = IopTraverseDeviceNode(ChildNode, DeviceInstance); + if (DeviceObject != NULL) + { + return DeviceObject; + } + } + + return NULL; +} + + static PDEVICE_OBJECT IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance) { +#if 0 OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName, ValueName; LPWSTR KeyNameBuffer; @@ -308,7 +335,7 @@ IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance) ZwClose(ControlKeyHandle); if (!NT_SUCCESS(Status)) { - DPRINT1("Failed to open the 'Control' key (Status %lx)\n", Status); + DPRINT1("Failed to query the 'DeviceReference' value (Status %lx)\n", Status); return NULL; } @@ -336,9 +363,30 @@ IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance) DPRINT("IopGetDeviceObjectFromDeviceInstance() done\n"); return DeviceObject; +#endif + + if (IopRootDeviceNode == NULL) + return NULL; + + if (DeviceInstance == NULL || + DeviceInstance->Length == 0 + ) + { + if (IopRootDeviceNode->PhysicalDeviceObject) + { + ObReferenceObject(IopRootDeviceNode->PhysicalDeviceObject); + return IopRootDeviceNode->PhysicalDeviceObject; + } + else + return NULL; + } + + return IopTraverseDeviceNode(IopRootDeviceNode, DeviceInstance); + } + static NTSTATUS IopGetDeviceProperty(PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData) {