Implement IoReportDetectedDevice
Modified: trunk/reactos/ntoskrnl/io/pnpreport.c

Modified: trunk/reactos/ntoskrnl/io/pnpreport.c
--- trunk/reactos/ntoskrnl/io/pnpreport.c	2005-03-20 12:04:30 UTC (rev 14214)
+++ trunk/reactos/ntoskrnl/io/pnpreport.c	2005-03-20 12:15:33 UTC (rev 14215)
@@ -10,14 +10,14 @@
 
 /* INCLUDES ******************************************************************/
 
-//#define NDEBUG
+#define NDEBUG
 #include <ntoskrnl.h>
 #include <internal/debug.h>
 
 /* FUNCTIONS *****************************************************************/
 
 /*
- * @unimplemented
+ * @implemented
  */
 NTSTATUS
 STDCALL
@@ -32,24 +32,38 @@
   IN OUT PDEVICE_OBJECT *DeviceObject)
 {
   PDEVICE_NODE DeviceNode;
-  NTSTATUS Status;
+  PDEVICE_OBJECT Pdo;
+  NTSTATUS Status = STATUS_SUCCESS;
   
-  DPRINT("IoReportDetectedDevice called (partly implemented)\n");
-  /* Use IopRootDeviceNode for now */
-  Status = IopCreateDeviceNode(IopRootDeviceNode, NULL, &DeviceNode);
-  if (!NT_SUCCESS(Status))
+  DPRINT("IoReportDetectedDevice (DeviceObject %p, *DeviceObject %p)\n",
+    DeviceObject, DeviceObject ? *DeviceObject : NULL);
+  
+  /* if *DeviceObject is not NULL, we must use it as a PDO,
+   * and don't create a new one.
+   */
+  if (DeviceObject && *DeviceObject)
+    Pdo = *DeviceObject;
+  else
   {
-    DPRINT("IopCreateDeviceNode() failed (Status 0x%08x)\n", Status);
-    return Status;
+    /* create a new PDO and return it in *DeviceObject */
+    Status = IopCreateDeviceNode(IopRootDeviceNode, NULL, &DeviceNode);
+    if (!NT_SUCCESS(Status))
+    {
+      DPRINT("IopCreateDeviceNode() failed (Status 0x%08lx)\n", Status);
+      return Status;
+    }
+    Pdo = DeviceNode->PhysicalDeviceObject;
+    if (DeviceObject)
+      *DeviceObject = Pdo;
   }
   
-  Status = IopInitializePnpServices(DeviceNode, FALSE);
-  if (!NT_SUCCESS(Status))
-  {
-    DPRINT("IopInitializePnpServices() failed (Status 0x%08x)\n", Status);
-    return Status;
-  }
-  return IopInitializeDevice(DeviceNode, DriverObject);
+  /* we don't need to call AddDevice and send IRP_MN_START_DEVICE */
+  
+  /* FIXME: save this device into the root-enumerated list, so this
+   * device would be detected as a PnP device during next startups.
+   */
+  
+  return Status;
 }
 
 /*
@@ -66,7 +80,7 @@
   IN ULONG DeviceListSize   OPTIONAL,
   OUT PBOOLEAN ConflictDetected)
 {
-  DPRINT("IoReportResourceForDetection UNIMPLEMENTED but returns success.\n");
+  DPRINT1("IoReportResourceForDetection UNIMPLEMENTED but returns success.\n");
   *ConflictDetected = FALSE;
   return STATUS_SUCCESS;
 }