[NTOS:PNP] IopInitializeDevice: Create a device, allocate a device node and attach...
authorEric Kohl <eric.kohl@reactos.org>
Wed, 27 Apr 2022 19:52:21 +0000 (21:52 +0200)
committerEric Kohl <eric.kohl@reactos.org>
Wed, 27 Apr 2022 19:52:21 +0000 (21:52 +0200)
ntoskrnl/io/pnpmgr/plugplay.c

index c1f108d..46093b2 100644 (file)
@@ -194,6 +194,7 @@ IopInitializeDevice(
 {
     UNICODE_STRING DeviceInstance;
     PDEVICE_OBJECT DeviceObject;
+    PDEVICE_NODE DeviceNode;
     NTSTATUS Status = STATUS_SUCCESS;
 
     DPRINT("IopInitializeDevice(%p)\n", ControlData);
@@ -210,7 +211,7 @@ IopInitializeDevice(
     DeviceObject = IopGetDeviceObjectFromDeviceInstance(&DeviceInstance);
     if (DeviceInstance.Buffer != NULL)
     {
-        DPRINT("Device %wZ already exists!\n", &DeviceInstance);
+        DPRINT1("Device %wZ already exists!\n", &DeviceInstance);
         Status = STATUS_SUCCESS;
         goto done;
     }
@@ -219,7 +220,36 @@ IopInitializeDevice(
 
     DPRINT("Device %wZ does not exist!\n", &DeviceInstance);
 
-    /* FIXME: Create a device node for the device instan*/
+    /* Create a device node for the device instance */
+    Status = IoCreateDevice(IopRootDriverObject,
+                            0,
+                            NULL,
+                            FILE_DEVICE_CONTROLLER,
+                            FILE_AUTOGENERATED_DEVICE_NAME,
+                            FALSE,
+                            &DeviceObject);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("IoCreateDevice() failed (Status 0x%08lx)\n", Status);
+        goto done;
+    }
+
+    /* Allocate a new device node */
+    DeviceNode = PipAllocateDeviceNode(DeviceObject);
+    if (DeviceNode == NULL)
+    {
+        DPRINT1("Failed to allocate a device node!\n");
+        IoDeleteDevice(DeviceObject);
+        Status = STATUS_INSUFFICIENT_RESOURCES;
+        goto done;
+    }
+
+    /* Set the device instance of the device node */
+    RtlDuplicateUnicodeString(0, &DeviceInstance, &DeviceNode->InstancePath);
+
+
+    /* Insert as a root enumerated device node */
+    PiInsertDevNode(DeviceNode, IopRootDeviceNode);
 
 done:
     ExFreePool(DeviceInstance.Buffer);