patch by Filip Navara:
[reactos.git] / reactos / ntoskrnl / io / pnpmgr.c
index 13bb59a..d706ba0 100644 (file)
@@ -11,6 +11,7 @@
 /* INCLUDES ******************************************************************/
 
 #include <ntoskrnl.h>
+#include <ddk/wdmguid.h>
 
 #define NDEBUG
 #include <internal/debug.h>
@@ -434,7 +435,7 @@ IoRequestDeviceEject(
 
 BOOLEAN
 IopCreateUnicodeString(
-  PUNICODE_STRING      Destination,
+  PUNICODE_STRING Destination,
   PWSTR Source,
   POOL_TYPE PoolType)
 {
@@ -507,7 +508,7 @@ IopCreateDeviceNode(PDEVICE_NODE ParentNode,
   DPRINT("ParentNode %x PhysicalDeviceObject %x\n",
     ParentNode, PhysicalDeviceObject);
 
-  Node = (PDEVICE_NODE)ExAllocatePool(PagedPool, sizeof(DEVICE_NODE));
+  Node = (PDEVICE_NODE)ExAllocatePool(NonPagedPool, sizeof(DEVICE_NODE));
   if (!Node)
     {
       return STATUS_INSUFFICIENT_RESOURCES;
@@ -763,16 +764,15 @@ IopCreateDeviceKeyPath(PWSTR Path,
     }
 
   wcsncpy (KeyBuffer, Path, MAX_PATH-1);
-  RtlInitUnicodeString (&KeyName, KeyBuffer);
 
   /* Skip \\Registry\\ */
-  Current = KeyName.Buffer;
-  Current = wcschr (Current, '\\') + 1;
-  Current = wcschr (Current, '\\') + 1;
+  Current = KeyBuffer;
+  Current = wcschr (Current, L'\\') + 1;
+  Current = wcschr (Current, L'\\') + 1;
 
   while (TRUE)
     {
-      Next = wcschr (Current, '\\');
+      Next = wcschr (Current, L'\\');
       if (Next == NULL)
        {
          /* The end */
@@ -782,6 +782,7 @@ IopCreateDeviceKeyPath(PWSTR Path,
          *Next = 0;
        }
 
+      RtlInitUnicodeString (&KeyName, KeyBuffer);
       InitializeObjectAttributes (&ObjectAttributes,
                                  &KeyName,
                                  OBJ_CASE_INSENSITIVE,
@@ -790,7 +791,7 @@ IopCreateDeviceKeyPath(PWSTR Path,
 
       DPRINT("Create '%S'\n", KeyName.Buffer);
 
-      Status = NtCreateKey (&KeyHandle,
+      Status = ZwCreateKey (&KeyHandle,
                            KEY_ALL_ACCESS,
                            &ObjectAttributes,
                            0,
@@ -799,7 +800,7 @@ IopCreateDeviceKeyPath(PWSTR Path,
                            NULL);
       if (!NT_SUCCESS (Status))
        {
-         DPRINT ("NtCreateKey() failed with status %x\n", Status);
+         DPRINT ("ZwCreateKey() failed with status %x\n", Status);
          return Status;
        }
 
@@ -810,7 +811,7 @@ IopCreateDeviceKeyPath(PWSTR Path,
        }
       else
        {
-         NtClose (KeyHandle);
+         ZwClose (KeyHandle);
          *Next = L'\\';
        }
 
@@ -842,7 +843,7 @@ IopSetDeviceInstanceData(HANDLE InstanceKey,
                             OBJ_CASE_INSENSITIVE,
                             InstanceKey,
                             NULL);
-  Status = NtCreateKey(&LogConfKey,
+  Status = ZwCreateKey(&LogConfKey,
                       KEY_ALL_ACCESS,
                       &ObjectAttributes,
                       0,
@@ -861,7 +862,7 @@ IopSetDeviceInstanceData(HANDLE InstanceKey,
 
        RtlInitUnicodeString(&KeyName,
                             L"BootConfig");
-       Status = NtSetValueKey(LogConfKey,
+       Status = ZwSetValueKey(LogConfKey,
                               &KeyName,
                               0,
                               REG_RESOURCE_LIST,
@@ -876,7 +877,7 @@ IopSetDeviceInstanceData(HANDLE InstanceKey,
     {
       RtlInitUnicodeString(&KeyName,
                           L"BasicConfigVector");
-      Status = NtSetValueKey(LogConfKey,
+      Status = ZwSetValueKey(LogConfKey,
                             &KeyName,
                             0,
                             REG_RESOURCE_REQUIREMENTS_LIST,
@@ -884,7 +885,7 @@ IopSetDeviceInstanceData(HANDLE InstanceKey,
                             DeviceNode->ResourceRequirements->ListSize);
     }
 
-    NtClose(LogConfKey);
+    ZwClose(LogConfKey);
   }
 
   DPRINT("IopSetDeviceInstanceData() done\n");
@@ -1068,7 +1069,7 @@ IopActionInterrogateDeviceStack(
       /* Set 'Capabilities' value */
       RtlInitUnicodeString(&ValueName,
                           L"Capabilities");
-      Status = NtSetValueKey(InstanceKey,
+      Status = ZwSetValueKey(InstanceKey,
                             &ValueName,
                             0,
                             REG_DWORD,
@@ -1080,7 +1081,7 @@ IopActionInterrogateDeviceStack(
       {
          RtlInitUnicodeString(&ValueName,
                              L"UINumber");
-         Status = NtSetValueKey(InstanceKey,
+         Status = ZwSetValueKey(InstanceKey,
                                &ValueName,
                                0,
                                REG_DWORD,
@@ -1119,7 +1120,7 @@ IopActionInterrogateDeviceStack(
 
       RtlInitUnicodeString(&ValueName,
                           L"HardwareID");
-      Status = NtSetValueKey(InstanceKey,
+      Status = ZwSetValueKey(InstanceKey,
                             &ValueName,
                             0,
                             REG_MULTI_SZ,
@@ -1127,7 +1128,7 @@ IopActionInterrogateDeviceStack(
                             (TotalLength + 1) * sizeof(WCHAR));
       if (!NT_SUCCESS(Status))
        {
-          DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
+          DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
        }
    }
    else
@@ -1165,7 +1166,7 @@ IopActionInterrogateDeviceStack(
 
       RtlInitUnicodeString(&ValueName,
                           L"CompatibleIDs");
-      Status = NtSetValueKey(InstanceKey,
+      Status = ZwSetValueKey(InstanceKey,
                             &ValueName,
                             0,
                             REG_MULTI_SZ,
@@ -1173,7 +1174,7 @@ IopActionInterrogateDeviceStack(
                             (TotalLength + 1) * sizeof(WCHAR));
       if (!NT_SUCCESS(Status))
        {
-          DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
+          DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
        }
    }
    else
@@ -1195,7 +1196,7 @@ IopActionInterrogateDeviceStack(
    {
       RtlInitUnicodeString(&ValueName,
                           L"DeviceDesc");
-      Status = NtSetValueKey(InstanceKey,
+      Status = ZwSetValueKey(InstanceKey,
                             &ValueName,
                             0,
                             REG_SZ,
@@ -1203,7 +1204,7 @@ IopActionInterrogateDeviceStack(
                             (wcslen((PWSTR)IoStatusBlock.Information) + 1) * sizeof(WCHAR));
       if (!NT_SUCCESS(Status))
        {
-          DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
+          DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
        }
    }
    else
@@ -1225,7 +1226,7 @@ IopActionInterrogateDeviceStack(
       DPRINT("LocationInformation: %S\n", (PWSTR)IoStatusBlock.Information);
       RtlInitUnicodeString(&ValueName,
                           L"LocationInformation");
-      Status = NtSetValueKey(InstanceKey,
+      Status = ZwSetValueKey(InstanceKey,
                             &ValueName,
                             0,
                             REG_SZ,
@@ -1233,7 +1234,7 @@ IopActionInterrogateDeviceStack(
                             (wcslen((PWSTR)IoStatusBlock.Information) + 1) * sizeof(WCHAR));
       if (!NT_SUCCESS(Status))
        {
-          DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
+          DPRINT1("ZwSetValueKey() failed (Status %lx)\n", Status);
        }
    }
    else
@@ -1314,10 +1315,14 @@ IopActionInterrogateDeviceStack(
       IopSetDeviceInstanceData(InstanceKey, DeviceNode);
    }
 
-   NtClose(InstanceKey);
+   ZwClose(InstanceKey);
 
    DeviceNode->Flags |= DNF_PROCESSED;
 
+   /* Report the device to the user-mode pnp manager */
+   IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
+                             &DeviceNode->InstancePath);
+
    return STATUS_SUCCESS;
 }
 
@@ -1728,17 +1733,20 @@ IopInvalidateDeviceRelations(
       NULL,
       NULL);
 
-   Status = NtOpenFile(
+   Status = ZwOpenFile(
       &Handle,
       FILE_ALL_ACCESS,
       &ObjectAttributes,
       &IoStatusBlock,
       0,
       0);
-   BootDrivers = NT_SUCCESS(Status) ? FALSE : TRUE;
-
-   NtClose(Handle);
+   if(NT_SUCCESS(Status))
+   {
+     BootDrivers = FALSE;
+     ZwClose(Handle);
+   }
+   else
+     BootDrivers = TRUE;
 
    /*
     * Initialize services for discovered children. Only boot drivers will
@@ -1800,6 +1808,18 @@ PnpInit(VOID)
       KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
    }
 
+   if (!IopCreateUnicodeString(&IopRootDeviceNode->InstancePath,
+       L"HTREE\\Root\\0",
+       PagedPool))
+   {
+     CPRINT("Failed to create the instance path!\n");
+     KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, STATUS_UNSUCCESSFUL, 0, 0, 0);
+   }
+
+   /* Report the device to the user-mode pnp manager */
+   IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL,
+                             &IopRootDeviceNode->InstancePath);
+
    IopRootDeviceNode->PhysicalDeviceObject->Flags |= DO_BUS_ENUMERATED_DEVICE;
    PnpRootDriverEntry(IopRootDriverObject, NULL);
    IopRootDriverObject->DriverExtension->AddDevice(