https://git.reactos.org/?p=reactos.git;a=commitdiff;h=de316477b9aaaf830d1e9…
commit de316477b9aaaf830d1e9802bc5fec1800140461
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Wed Apr 27 21:52:21 2022 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Wed Apr 27 21:52:21 2022 +0200
[NTOS:PNP] IopInitializeDevice: Create a device, allocate a device node and attach it
to the root node
---
ntoskrnl/io/pnpmgr/plugplay.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/ntoskrnl/io/pnpmgr/plugplay.c b/ntoskrnl/io/pnpmgr/plugplay.c
index c1f108da332..46093b252b5 100644
--- a/ntoskrnl/io/pnpmgr/plugplay.c
+++ b/ntoskrnl/io/pnpmgr/plugplay.c
@@ -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);