[NTOS:PNP] IopInitializeDevice: Create a device, allocate a device node and attach it to the root node

This commit is contained in:
Eric Kohl 2022-04-27 21:52:21 +02:00
parent 03c8832a77
commit de316477b9

View 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);