[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / io / pnpmgr / pnproot.c
index c4b5965..cbe802a 100644 (file)
@@ -126,6 +126,61 @@ LocateChildDevice(
     return STATUS_NO_SUCH_DEVICE;
 }
 
+NTSTATUS
+PnpRootRegisterDevice(
+    IN PDEVICE_OBJECT DeviceObject)
+{
+    PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension = PnpRootDeviceObject->DeviceExtension;
+    PPNPROOT_DEVICE Device;
+    PDEVICE_NODE DeviceNode;
+    PWSTR InstancePath;
+    UNICODE_STRING InstancePathCopy;
+
+    Device = ExAllocatePoolWithTag(PagedPool, sizeof(PNPROOT_DEVICE), TAG_PNP_ROOT);
+    if (!Device) return STATUS_NO_MEMORY;
+
+    DeviceNode = IopGetDeviceNode(DeviceObject);
+    if (!RtlCreateUnicodeString(&InstancePathCopy, DeviceNode->InstancePath.Buffer))
+    {
+        ExFreePoolWithTag(Device, TAG_PNP_ROOT);
+        return STATUS_NO_MEMORY;
+    }
+
+    InstancePath = wcsrchr(InstancePathCopy.Buffer, L'\\');
+    ASSERT(InstancePath);
+
+    if (!RtlCreateUnicodeString(&Device->InstanceID, InstancePath + 1))
+    {
+        RtlFreeUnicodeString(&InstancePathCopy);
+        ExFreePoolWithTag(Device, TAG_PNP_ROOT);
+        return STATUS_NO_MEMORY;
+    }
+
+    InstancePath[0] = UNICODE_NULL;
+
+    if (!RtlCreateUnicodeString(&Device->DeviceID, InstancePathCopy.Buffer))
+    {
+        RtlFreeUnicodeString(&InstancePathCopy);
+        RtlFreeUnicodeString(&Device->InstanceID);
+        ExFreePoolWithTag(Device, TAG_PNP_ROOT);
+        return STATUS_NO_MEMORY;
+    }
+
+    InstancePath[0] = L'\\';
+
+    Device->Pdo = DeviceObject;
+
+    KeAcquireGuardedMutex(&DeviceExtension->DeviceListLock);
+    InsertTailList(&DeviceExtension->DeviceListHead,
+                   &Device->ListEntry);
+    DeviceExtension->DeviceListCount++;
+    KeReleaseGuardedMutex(&DeviceExtension->DeviceListLock);
+
+    RtlFreeUnicodeString(&InstancePathCopy);
+
+    return STATUS_SUCCESS;
+}
+
 /* Creates a new PnP device for a legacy driver */
 NTSTATUS
 PnpRootCreateDevice(
@@ -488,10 +543,8 @@ EnumerateDevices(
             /* Terminate the string */
             SubKeyInfo->Name[SubKeyInfo->NameLength / sizeof(WCHAR)] = 0;
 
-            _snwprintf(
-                DevicePath,
-                sizeof(DevicePath) / sizeof(WCHAR),
-                L"%s\\%s", REGSTR_KEY_ROOTENUM, KeyInfo->Name);
+            _snwprintf(DevicePath, sizeof(DevicePath) / sizeof(WCHAR),
+                       L"%s\\%s", REGSTR_KEY_ROOTENUM, KeyInfo->Name);
             DPRINT("Found device %S\\%s!\n", DevicePath, SubKeyInfo->Name);
             if (LocateChildDevice(DeviceExtension, DevicePath, SubKeyInfo->Name, &Device) == STATUS_NO_SUCH_DEVICE)
             {