From c85a086e9eb8fbf3ea19fb3e28de1ffdfd3f8e2e Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Thu, 21 Jul 2005 20:30:55 +0000 Subject: [PATCH] Make IoGetDeviceObjectFromDeviceInstance work without using the Registry. (experimental) svn path=/trunk/; revision=16686 --- reactos/ntoskrnl/io/plugplay.c | 50 +++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) 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) {