[NTOS:PNP]
authorThomas Faber <thomas.faber@reactos.org>
Thu, 2 Mar 2017 13:42:04 +0000 (13:42 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Thu, 2 Mar 2017 13:42:04 +0000 (13:42 +0000)
- Move generation of the device instance path into its own function

svn path=/trunk/; revision=74024

reactos/ntoskrnl/io/pnpmgr/pnpmgr.c

index 8f79fc4..71e462f 100644 (file)
@@ -1847,86 +1847,18 @@ IopQueryCompatibleIds(PDEVICE_NODE DeviceNode,
    return Status;
 }
 
-
-/*
- * IopActionInterrogateDeviceStack
- *
- * Retrieve information for all (direct) child nodes of a parent node.
- *
- * Parameters
- *    DeviceNode
- *       Pointer to device node.
- *    Context
- *       Pointer to parent node to retrieve child node information for.
- *
- * Remarks
- *    Any errors that occur are logged instead so that all child services have a chance
- *    of being interrogated.
- */
-
 NTSTATUS
-IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
-                                PVOID Context)
+IopCreateDeviceInstancePath(
+    _In_ PDEVICE_NODE DeviceNode,
+    _Out_ PUNICODE_STRING InstancePathU)
 {
     IO_STATUS_BLOCK IoStatusBlock;
     PWSTR InformationString;
-    PDEVICE_NODE ParentDeviceNode;
     WCHAR InstancePath[MAX_PATH];
     IO_STACK_LOCATION Stack;
     NTSTATUS Status;
-    ULONG RequiredLength;
-    LCID LocaleId;
-    HANDLE InstanceKey = NULL;
-    UNICODE_STRING ValueName;
     UNICODE_STRING ParentIdPrefix = { 0, 0, NULL };
-    UNICODE_STRING InstancePathU;
     DEVICE_CAPABILITIES DeviceCapabilities;
-    PDEVICE_OBJECT OldDeviceObject;
-
-    DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
-    DPRINT("PDO 0x%p\n", DeviceNode->PhysicalDeviceObject);
-
-    ParentDeviceNode = (PDEVICE_NODE)Context;
-
-    /*
-     * We are called for the parent too, but we don't need to do special
-     * handling for this node
-     */
-    if (DeviceNode == ParentDeviceNode)
-    {
-        DPRINT("Success\n");
-        return STATUS_SUCCESS;
-    }
-
-    /*
-     * Make sure this device node is a direct child of the parent device node
-     * that is given as an argument
-     */
-    if (DeviceNode->Parent != ParentDeviceNode)
-    {
-        DPRINT("Skipping 2+ level child\n");
-        return STATUS_SUCCESS;
-    }
-
-    /* Skip processing if it was already completed before */
-    if (DeviceNode->Flags & DNF_PROCESSED)
-    {
-        /* Nothing to do */
-        return STATUS_SUCCESS;
-    }
-
-    /* Get Locale ID */
-    Status = ZwQueryDefaultLocale(FALSE, &LocaleId);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status);
-        return Status;
-    }
-
-    /*
-     * FIXME: For critical errors, cleanup and disable device, but always
-     * return STATUS_SUCCESS.
-     */
 
     DPRINT("Sending IRP_MN_QUERY_ID.BusQueryDeviceID to device stack\n");
 
@@ -1938,9 +1870,7 @@ IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("IopInitiatePnpIrp() failed (Status %x)\n", Status);
-
-        /* We have to return success otherwise we abort the traverse operation */
-        return STATUS_SUCCESS;
+        return Status;
     }
 
     /* Copy the device id string */
@@ -1960,9 +1890,7 @@ IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("IopInitiatePnpIrp() failed (Status 0x%08lx)\n", Status);
-
-        /* We have to return success otherwise we abort the traverse operation */
-        return STATUS_SUCCESS;
+        return Status;
     }
 
     /* This bit is only check after enumeration */
@@ -1970,7 +1898,7 @@ IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
     {
         /* FIXME: Cleanup device */
         DeviceNode->Flags |= DNF_DISABLED;
-        return STATUS_SUCCESS;
+        return STATUS_PLUGPLAY_NO_DEVICE;
     }
     else
     {
@@ -1985,9 +1913,7 @@ IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
         if (!NT_SUCCESS(Status))
         {
             DPRINT1("IopGetParentIdPrefix() failed (Status 0x%08lx)\n", Status);
-
-            /* We have to return success otherwise we abort the traverse operation */
-            return STATUS_SUCCESS;
+            return Status;
         }
     }
 
@@ -2034,10 +1960,103 @@ IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
     }
     RtlFreeUnicodeString(&ParentIdPrefix);
 
-    if (!RtlCreateUnicodeString(&InstancePathU, InstancePath))
+    if (!RtlCreateUnicodeString(InstancePathU, InstancePath))
     {
-        DPRINT("No resources\n");
-        /* FIXME: Cleanup and disable device */
+        DPRINT1("RtlCreateUnicodeString failed\n");
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    return STATUS_SUCCESS;
+}
+
+
+/*
+ * IopActionInterrogateDeviceStack
+ *
+ * Retrieve information for all (direct) child nodes of a parent node.
+ *
+ * Parameters
+ *    DeviceNode
+ *       Pointer to device node.
+ *    Context
+ *       Pointer to parent node to retrieve child node information for.
+ *
+ * Remarks
+ *    Any errors that occur are logged instead so that all child services have a chance
+ *    of being interrogated.
+ */
+
+NTSTATUS
+IopActionInterrogateDeviceStack(PDEVICE_NODE DeviceNode,
+                                PVOID Context)
+{
+    IO_STATUS_BLOCK IoStatusBlock;
+    PWSTR InformationString;
+    PDEVICE_NODE ParentDeviceNode;
+    IO_STACK_LOCATION Stack;
+    NTSTATUS Status;
+    ULONG RequiredLength;
+    LCID LocaleId;
+    HANDLE InstanceKey = NULL;
+    UNICODE_STRING ValueName;
+    UNICODE_STRING InstancePathU;
+    PDEVICE_OBJECT OldDeviceObject;
+
+    DPRINT("IopActionInterrogateDeviceStack(%p, %p)\n", DeviceNode, Context);
+    DPRINT("PDO 0x%p\n", DeviceNode->PhysicalDeviceObject);
+
+    ParentDeviceNode = (PDEVICE_NODE)Context;
+
+    /*
+     * We are called for the parent too, but we don't need to do special
+     * handling for this node
+     */
+    if (DeviceNode == ParentDeviceNode)
+    {
+        DPRINT("Success\n");
+        return STATUS_SUCCESS;
+    }
+
+    /*
+     * Make sure this device node is a direct child of the parent device node
+     * that is given as an argument
+     */
+    if (DeviceNode->Parent != ParentDeviceNode)
+    {
+        DPRINT("Skipping 2+ level child\n");
+        return STATUS_SUCCESS;
+    }
+
+    /* Skip processing if it was already completed before */
+    if (DeviceNode->Flags & DNF_PROCESSED)
+    {
+        /* Nothing to do */
+        return STATUS_SUCCESS;
+    }
+
+    /* Get Locale ID */
+    Status = ZwQueryDefaultLocale(FALSE, &LocaleId);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("ZwQueryDefaultLocale() failed with status 0x%lx\n", Status);
+        return Status;
+    }
+
+    /*
+     * FIXME: For critical errors, cleanup and disable device, but always
+     * return STATUS_SUCCESS.
+     */
+
+    Status = IopCreateDeviceInstancePath(DeviceNode, &InstancePathU);
+    if (!NT_SUCCESS(Status))
+    {
+        if (Status != STATUS_PLUGPLAY_NO_DEVICE)
+        {
+            DPRINT1("IopCreateDeviceInstancePath() failed with status 0x%lx\n", Status);
+        }
+
+        /* We have to return success otherwise we abort the traverse operation */
+        return STATUS_SUCCESS;
     }
 
     /* Verify that this is not a duplicate */