forget update de.rc
[reactos.git] / reactos / ntoskrnl / cm / import.c
index 9ce6fb7..a9da467 100644 (file)
@@ -1,25 +1,25 @@
-/* $Id: import.c,v 1.25 2003/11/27 00:48:11 gdalsnes Exp $
+/* $Id$
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/cm/import.c
  * PURPOSE:         Registry-Hive import functions
+ *
  * PROGRAMMERS:     Eric Kohl
  */
 
 /* INCLUDES *****************************************************************/
 
-
-#include <ddk/ntddk.h>
-#include <string.h>
-#include <ctype.h>
-#include <roscfg.h>
-
+#include <ntoskrnl.h>
 #define NDEBUG
 #include <internal/debug.h>
 
 #include "cm.h"
 
+#if defined (ALLOC_PRAGMA)
+#pragma alloc_text(INIT, CmImportHardwareHive)
+#endif
+
 /* GLOBALS ******************************************************************/
 
 static BOOLEAN CmiHardwareHiveImported = FALSE;
@@ -83,9 +83,9 @@ CmImportBinaryHive (PCHAR ChunkBase,
 
   /* Allocate block list */
   DPRINT("Space needed for block list describing hive: 0x%x\n",
-        Hive->BlockListSize * sizeof(PHBIN *));
+        Hive->BlockListSize * sizeof(BLOCK_LIST_ENTRY));
   Hive->BlockList = ExAllocatePool (NonPagedPool,
-                                   Hive->BlockListSize * sizeof(PHBIN *));
+                                   Hive->BlockListSize * sizeof(BLOCK_LIST_ENTRY));
   if (Hive->BlockList == NULL)
     {
       DPRINT1 ("Allocating block list failed\n");
@@ -94,7 +94,7 @@ CmImportBinaryHive (PCHAR ChunkBase,
       return FALSE;
     }
   RtlZeroMemory (Hive->BlockList,
-                Hive->BlockListSize * sizeof(PHBIN *));
+                Hive->BlockListSize * sizeof(BLOCK_LIST_ENTRY));
 
   /* Import the bins */
   Status = CmiImportHiveBins(Hive,
@@ -106,7 +106,7 @@ CmImportBinaryHive (PCHAR ChunkBase,
       ExFreePool (Hive->BlockList);
       ExFreePool (Hive->HiveHeader);
       ExFreePool (Hive);
-      return Status;
+      return (BOOLEAN)Status;
     }
 
   /* Initialize the free cell list */
@@ -119,7 +119,7 @@ CmImportBinaryHive (PCHAR ChunkBase,
       ExFreePool (Hive->HiveHeader);
       ExFreePool (Hive);
 
-      return Status;
+      return (BOOLEAN)Status;
     }
 
   if (!(Hive->Flags & HIVE_NO_FILE))
@@ -135,22 +135,19 @@ CmImportBinaryHive (PCHAR ChunkBase,
          ExFreePool (Hive->HiveHeader);
          ExFreePool (Hive);
 
-         return Status;
+         return (BOOLEAN)Status;
        }
     }
 
-  /* Initialize the hive's executive resource */
-  ExInitializeResourceLite(&Hive->HiveResource);
-
   /* Acquire hive list lock exclusively */
   KeEnterCriticalRegion();
-  ExAcquireResourceExclusiveLite(&CmiHiveListLock, TRUE);
+  ExAcquireResourceExclusiveLite(&CmiRegistryLock, TRUE);
 
   /* Add the new hive to the hive list */
   InsertTailList(&CmiHiveListHead, &Hive->HiveList);
 
   /* Release hive list lock */
-  ExReleaseResourceLite(&CmiHiveListLock);
+  ExReleaseResourceLite(&CmiRegistryLock);
   KeLeaveCriticalRegion();
 
   *RegistryHive = Hive;
@@ -181,13 +178,13 @@ CmImportSystemHive(PCHAR ChunkBase,
   /* Import the binary system hive (non-volatile, offset-based, permanent) */
   if (!CmImportBinaryHive (ChunkBase, ChunkSize, 0, &RegistryHive))
     {
-      DPRINT1 ("CmiImportBinaryHive() failed\n", Status);
+      DPRINT1 ("CmiImportBinaryHive() failed\n");
       return FALSE;
     }
 
   /* Attach it to the machine key */
   RtlInitUnicodeString (&KeyName,
-                       L"\\Registry\\Machine\\System");
+                       REG_SYSTEM_KEY_NAME);
   InitializeObjectAttributes (&ObjectAttributes,
                              &KeyName,
                              OBJ_CASE_INSENSITIVE,
@@ -197,18 +194,18 @@ CmImportSystemHive(PCHAR ChunkBase,
                           RegistryHive);
   if (!NT_SUCCESS(Status))
     {
-      DPRINT1 ("CmiConnectHive() failed (Status %lx)\n", Status);
+      DPRINT1 ("CmiConnectHive(%wZ) failed (Status %lx)\n", &KeyName, Status);
 //      CmiRemoveRegistryHive(RegistryHive);
       return FALSE;
     }
 
   /* Set the hive filename */
   RtlCreateUnicodeString (&RegistryHive->HiveFileName,
-                         SYSTEM_REG_FILE);
+                          SYSTEM_REG_FILE);
 
   /* Set the log filename */
   RtlCreateUnicodeString (&RegistryHive->LogFileName,
-                         SYSTEM_LOG_FILE);
+                          SYSTEM_LOG_FILE);
 
   return TRUE;
 }
@@ -235,13 +232,13 @@ CmImportHardwareHive(PCHAR ChunkBase,
     {
       /* Create '\Registry\Machine\HARDWARE' key. */
       RtlInitUnicodeString (&KeyName,
-                           L"\\Registry\\Machine\\HARDWARE");
+                           REG_HARDWARE_KEY_NAME);
       InitializeObjectAttributes (&ObjectAttributes,
                                  &KeyName,
                                  OBJ_CASE_INSENSITIVE,
                                  NULL,
                                  NULL);
-      Status = NtCreateKey (&HardwareKey,
+      Status = ZwCreateKey (&HardwareKey,
                            KEY_ALL_ACCESS,
                            &ObjectAttributes,
                            0,
@@ -250,19 +247,20 @@ CmImportHardwareHive(PCHAR ChunkBase,
                            &Disposition);
       if (!NT_SUCCESS(Status))
        {
-         return FALSE;
+          DPRINT1("NtCreateKey() failed, status: 0x%x\n", Status);
+          return FALSE;
        }
-      NtClose (HardwareKey);
+      ZwClose (HardwareKey);
 
       /* Create '\Registry\Machine\HARDWARE\DESCRIPTION' key. */
       RtlInitUnicodeString(&KeyName,
-                          L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION");
+                          REG_DESCRIPTION_KEY_NAME);
       InitializeObjectAttributes (&ObjectAttributes,
                                  &KeyName,
                                  OBJ_CASE_INSENSITIVE,
                                  NULL,
                                  NULL);
-      Status = NtCreateKey (&HardwareKey,
+      Status = ZwCreateKey (&HardwareKey,
                            KEY_ALL_ACCESS,
                            &ObjectAttributes,
                            0,
@@ -271,19 +269,20 @@ CmImportHardwareHive(PCHAR ChunkBase,
                            &Disposition);
       if (!NT_SUCCESS(Status))
        {
-         return FALSE;
+          DPRINT1("NtCreateKey() failed, status: 0x%x\n", Status);
+          return FALSE;
        }
-      NtClose (HardwareKey);
+      ZwClose (HardwareKey);
 
       /* Create '\Registry\Machine\HARDWARE\DEVICEMAP' key. */
       RtlInitUnicodeString (&KeyName,
-                           L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP");
+                           REG_DEVICEMAP_KEY_NAME);
       InitializeObjectAttributes (&ObjectAttributes,
                                  &KeyName,
                                  OBJ_CASE_INSENSITIVE,
                                  NULL,
                                  NULL);
-      Status = NtCreateKey (&HardwareKey,
+      Status = ZwCreateKey (&HardwareKey,
                            KEY_ALL_ACCESS,
                            &ObjectAttributes,
                            0,
@@ -292,19 +291,20 @@ CmImportHardwareHive(PCHAR ChunkBase,
                            &Disposition);
       if (!NT_SUCCESS(Status))
        {
-         return FALSE;
+          DPRINT1("NtCreateKey() failed, status: 0x%x\n", Status);
+          return FALSE;
        }
-      NtClose (HardwareKey);
+      ZwClose (HardwareKey);
 
       /* Create '\Registry\Machine\HARDWARE\RESOURCEMAP' key. */
       RtlInitUnicodeString(&KeyName,
-                          L"\\Registry\\Machine\\HARDWARE\\RESOURCEMAP");
+                          REG_RESOURCEMAP_KEY_NAME);
       InitializeObjectAttributes (&ObjectAttributes,
                                  &KeyName,
                                  OBJ_CASE_INSENSITIVE,
                                  NULL,
                                  NULL);
-      Status = NtCreateKey (&HardwareKey,
+      Status = ZwCreateKey (&HardwareKey,
                            KEY_ALL_ACCESS,
                            &ObjectAttributes,
                            0,
@@ -313,9 +313,10 @@ CmImportHardwareHive(PCHAR ChunkBase,
                            &Disposition);
       if (!NT_SUCCESS(Status))
        {
-         return FALSE;
+          DPRINT1("NtCreateKey() failed, status: 0x%x\n", Status);
+          return FALSE;
        }
-      NtClose (HardwareKey);
+      ZwClose (HardwareKey);
 
       return TRUE;
     }
@@ -333,13 +334,13 @@ CmImportHardwareHive(PCHAR ChunkBase,
   /* Import the binary system hive (volatile, offset-based, permanent) */
   if (!CmImportBinaryHive (ChunkBase, ChunkSize, HIVE_NO_FILE, &RegistryHive))
     {
-      DPRINT1 ("CmiImportBinaryHive() failed\n", Status);
+      DPRINT1 ("CmiImportBinaryHive() failed\n");
       return FALSE;
     }
 
   /* Attach it to the machine key */
   RtlInitUnicodeString (&KeyName,
-                       L"\\Registry\\Machine\\HARDWARE");
+                       REG_HARDWARE_KEY_NAME);
   InitializeObjectAttributes (&ObjectAttributes,
                              &KeyName,
                              OBJ_CASE_INSENSITIVE,
@@ -349,7 +350,7 @@ CmImportHardwareHive(PCHAR ChunkBase,
                           RegistryHive);
   if (!NT_SUCCESS(Status))
     {
-      DPRINT1 ("CmiConnectHive() failed (Status %lx)\n", Status);
+      DPRINT1 ("CmiConnectHive(%wZ) failed (Status %lx)\n", &KeyName, Status);
 //      CmiRemoveRegistryHive(RegistryHive);
       return FALSE;
     }