[ros-diffs] [fireball] 30695: - Remove hack in CmpLinkHiveToMaster and make it support the "Allocate" boolean parameter. - Enable code in CmiInitHives to take advantage of the new link code when using the SYSTEM hive on the bootcd/setup. - Don't skip CmpCreateControlSet anymore, just add a simple hack to hard-code Current to 001. - Remove CmiInitControlSetLink since CmpCrateControlSet now does the work - Enable code in CmpInitializeSystemHive to use CmpInitializeHive(HINIT_CREATE) when creating a new SYSTEM hive, since we now have new link code that supports the "Allocate" flag. - This means we now have a working SYSTEM hive on the Boot CD as well since early bootup, and not only when NtInitializeRegistry is called - Do bootcd vs hard-disk boot registry path setup in CmpGetRegistryPath instead of in-line.

fireball at svn.reactos.org fireball at svn.reactos.org
Fri Nov 23 16:26:27 CET 2007


Author: fireball
Date: Fri Nov 23 18:26:27 2007
New Revision: 30695

URL: http://svn.reactos.org/svn/reactos?rev=30695&view=rev
Log:
- Remove hack in CmpLinkHiveToMaster and make it support the "Allocate" boolean parameter.
- Enable code in CmiInitHives to take advantage of the new link code when using the SYSTEM hive on the bootcd/setup.
- Don't skip CmpCreateControlSet anymore, just add a simple hack to hard-code Current to 001.
- Remove CmiInitControlSetLink since CmpCrateControlSet now does the work
- Enable code in CmpInitializeSystemHive to use CmpInitializeHive(HINIT_CREATE) when creating a new SYSTEM hive, since we now have new link code that supports the "Allocate" flag.
- This means we now have a working SYSTEM hive on the Boot CD as well since early bootup, and not only when NtInitializeRegistry is called
- Do bootcd vs hard-disk boot registry path setup in CmpGetRegistryPath instead of in-line.

Modified:
    trunk/reactos/ntoskrnl/cm/registry.c
    trunk/reactos/ntoskrnl/config/cmsysini.c

Modified: trunk/reactos/ntoskrnl/cm/registry.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cm/registry.c?rev=30695&r1=30694&r2=30695&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/cm/registry.c (original)
+++ trunk/reactos/ntoskrnl/cm/registry.c Fri Nov 23 18:26:27 2007
@@ -115,9 +115,6 @@
     CM_PARSE_CONTEXT ParseContext = {0};
     PAGED_CODE();
 
-    /* TEMPHACK: Don't do anything if we don't actually have a hive */
-    if (Allocate) return STATUS_SUCCESS;
-
     /* Setup the object attributes */
     InitializeObjectAttributes(&ObjectAttributes,
                                LinkName,
@@ -130,8 +127,17 @@
     ParseContext.CreateOperation = TRUE;
     ParseContext.ChildHive.KeyHive = &RegistryHive->Hive;
     
-    /* Because of CmCreateRootNode, ReactOS Hack */
-    ParseContext.ChildHive.KeyCell = RegistryHive->Hive.BaseBlock->RootCell;
+    /* Check if we have a root keycell or if we need to create it */
+    if (Allocate)
+    {
+        /* Create it */
+        ParseContext.ChildHive.KeyCell = HCELL_NIL;
+    }
+    else
+    {
+        /* We have one */
+        ParseContext.ChildHive.KeyCell = RegistryHive->Hive.BaseBlock->RootCell;   
+    }
     
     /* Capture all the info */
     Status = ObpCaptureObjectAttributes(&ObjectAttributes,
@@ -181,7 +187,7 @@
                                NULL,
                                RemainingPath,
                                KernelMode,
-                               REG_OPTION_VOLATILE,
+                               0,
                                &ParseContext,
                                ParentKey->KeyControlBlock,
                                (PVOID*)&NewKey);
@@ -217,142 +223,23 @@
     return STATUS_SUCCESS;    
 }
 
-static NTSTATUS
-CmiInitControlSetLink (VOID)
-{
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    UNICODE_STRING ControlSetKeyName = RTL_CONSTANT_STRING(
-        L"\\Registry\\Machine\\SYSTEM\\ControlSet001");
-    UNICODE_STRING ControlSetLinkName =  RTL_CONSTANT_STRING(
-        L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet");
-    UNICODE_STRING ControlSetValueName = RTL_CONSTANT_STRING(L"SymbolicLinkValue");
-    HANDLE KeyHandle;
-    NTSTATUS Status;
-
-    /* Create 'ControlSet001' key */
-    InitializeObjectAttributes (&ObjectAttributes,
-                                &ControlSetKeyName,
-                                OBJ_CASE_INSENSITIVE,
-                                NULL,
-                                NULL);
-    Status = ZwCreateKey (&KeyHandle,
-                          KEY_ALL_ACCESS,
-                          &ObjectAttributes,
-                          0,
-                          NULL,
-                          REG_OPTION_NON_VOLATILE,
-                          NULL);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1 ("ZwCreateKey() failed (Status %lx)\n", Status);
-        return Status;
-    }
-    ZwClose (KeyHandle);
-
-    /* Link 'CurrentControlSet' to 'ControlSet001' key */
-    InitializeObjectAttributes (&ObjectAttributes,
-                                &ControlSetLinkName,
-                                OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_OPENLINK,
-                                NULL,
-                                NULL);
-    Status = ZwCreateKey (&KeyHandle,
-                          KEY_ALL_ACCESS | KEY_CREATE_LINK,
-                          &ObjectAttributes,
-                          0,
-                          NULL,
-                          REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK,
-                          NULL);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1 ("ZwCreateKey() failed (Status %lx)\n", Status);
-        return Status;
-    }
-
-    Status = ZwSetValueKey (KeyHandle,
-                            &ControlSetValueName,
-                            0,
-                            REG_LINK,
-                            (PVOID)ControlSetKeyName.Buffer,
-                            ControlSetKeyName.Length);
-    if (!NT_SUCCESS(Status))
-    {
-        DPRINT1 ("ZwSetValueKey() failed (Status %lx)\n", Status);
-    }
-    ZwClose (KeyHandle);
-
-    return STATUS_SUCCESS;
-}
+NTSTATUS
+NTAPI
+CmpGetRegistryPath(IN PWCHAR ConfigPath);
 
 NTSTATUS
 CmiInitHives(BOOLEAN SetupBoot)
 {
-    PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    UNICODE_STRING FileName;
-    UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE");
-    UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath");
-    HANDLE KeyHandle;
-
     NTSTATUS Status;
-
     WCHAR ConfigPath[MAX_PATH];
-
-    ULONG BufferSize;
-    ULONG ResultSize;
     PWSTR EndPtr;
     PCMHIVE CmHive;
     BOOLEAN Allocate = TRUE;
+    UNICODE_STRING FileName, KeyName;
 
     DPRINT("CmiInitHives() called\n");
 
-    if (SetupBoot == TRUE)
-    {
-        InitializeObjectAttributes(&ObjectAttributes,
-                                   &KeyName,
-                                   OBJ_CASE_INSENSITIVE,
-                                   NULL,
-                                   NULL);
-        Status =  ZwOpenKey(&KeyHandle,
-                            KEY_ALL_ACCESS,
-                            &ObjectAttributes);
-        if (!NT_SUCCESS(Status))
-        {
-            DPRINT1("ZwOpenKey() failed (Status %lx)\n", Status);
-            return(Status);
-        }
-
-        BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 4096;
-        ValueInfo = ExAllocatePool(PagedPool, BufferSize);
-        if (ValueInfo == NULL)
-        {
-            ZwClose(KeyHandle);
-            return(STATUS_INSUFFICIENT_RESOURCES);
-        }
-
-        Status = ZwQueryValueKey(KeyHandle,
-                                 &ValueName,
-                                 KeyValuePartialInformation,
-                                 ValueInfo,
-                                 BufferSize,
-                                 &ResultSize);
-        ZwClose(KeyHandle);
-        if (!NT_SUCCESS(Status))
-        {
-            ExFreePool(ValueInfo);
-            return(Status);
-        }
-
-        RtlCopyMemory(ConfigPath,
-                      ValueInfo->Data,
-                      ValueInfo->DataLength);
-        ConfigPath[ValueInfo->DataLength / sizeof(WCHAR)] = (WCHAR)0;
-        ExFreePool(ValueInfo);
-    }
-    else
-    {
-        wcscpy(ConfigPath, L"\\SystemRoot");
-    }
-    wcscat(ConfigPath, L"\\system32\\config");
+    CmpGetRegistryPath(ConfigPath);
     DPRINT("ConfigPath: %S\n", ConfigPath);
     EndPtr = ConfigPath + wcslen(ConfigPath);
 
@@ -401,10 +288,6 @@
     /* Connect the SYSTEM hive only if it has been created */
     if (SetupBoot == TRUE)
     {
-        wcscpy(EndPtr, REG_SYSTEM_FILE_NAME);
-        RtlInitUnicodeString(&FileName, ConfigPath);
-        DPRINT ("ConfigPath: %S\n", ConfigPath);
-#if 0
         HANDLE PrimaryHandle, LogHandle;
         ULONG PrimaryDisposition, SecondaryDisposition;
         ULONG ClusterSize, Length;
@@ -439,7 +322,7 @@
         CmHive->FileHandles[HFILE_TYPE_PRIMARY] = PrimaryHandle;
         
         /* Allow lazy flushing since the handles are there */
-        ASSERT(CmHive->Hive.HiveFlags & HIVE_NOLAZYFLUSH);
+        //ASSERT(CmHive->Hive.HiveFlags & HIVE_NOLAZYFLUSH);
         CmHive->Hive.HiveFlags &= ~HIVE_NOLAZYFLUSH;
         
         /* Get the real size of the hive */
@@ -454,28 +337,6 @@
             /* This shouldn't fail */
             ASSERT(FALSE);
         }
-        
-        /* Setup the key name for the SECURITY hive */
-        RtlInitUnicodeString (&KeyName, REG_SYSTEM_KEY_NAME);
-#else
-        /* Load the hive */
-        Status = CmpInitHiveFromFile(&FileName,
-                                     0,
-                                     &CmHive,
-                                     &Allocate,
-                                     0);
-        
-        /* Setup the key name for the SECURITY hive */
-        RtlInitUnicodeString (&KeyName, REG_SYSTEM_KEY_NAME);
-        
-        Status = CmpLinkHiveToMaster(&KeyName,
-                                     NULL,
-                                     CmHive,
-                                     FALSE,
-                                     NULL);
-
-        Status = CmiInitControlSetLink ();
-#endif
     }
 
     /* Connect the DEFAULT hive */

Modified: trunk/reactos/ntoskrnl/config/cmsysini.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmsysini.c?rev=30695&r1=30694&r2=30695&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/config/cmsysini.c (original)
+++ trunk/reactos/ntoskrnl/config/cmsysini.c Fri Nov 23 18:26:27 2007
@@ -152,11 +152,10 @@
 CmpSetSystemValues(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 {
     OBJECT_ATTRIBUTES ObjectAttributes;
-    UNICODE_STRING KeyName, ValueName;
+    UNICODE_STRING KeyName, ValueName = {0};
     HANDLE KeyHandle;
     NTSTATUS Status;
     ASSERT(LoaderBlock != NULL);
-    if (ExpInTextModeSetup) return STATUS_SUCCESS;
 
     /* Setup attributes for loader options */
     RtlInitUnicodeString(&KeyName,
@@ -198,7 +197,7 @@
     NtClose(KeyHandle);
 
     /* Return the status */
-    return Status;
+    return (ExpInTextModeSetup ? STATUS_SUCCESS : Status);
 }
 
 NTSTATUS
@@ -222,7 +221,6 @@
     ULONG ResultLength, Disposition;
     PLOADER_PARAMETER_EXTENSION LoaderExtension;
     PAGED_CODE();
-    if (ExpInTextModeSetup) return STATUS_SUCCESS;
 
     /* Open the select key */
     InitializeObjectAttributes(&ObjectAttributes,
@@ -231,7 +229,19 @@
                                NULL,
                                NULL);
     Status = NtOpenKey(&SelectHandle, KEY_READ, &ObjectAttributes);
-    if (!NT_SUCCESS(Status)) return(Status);
+    if (!NT_SUCCESS(Status))
+    {
+        /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
+        if (!LoaderBlock->RegistryBase)
+        {
+            /* Use hard-coded setting */
+            ControlSet = 1;
+            goto UseSet;
+        }
+
+        /* Fail for real boots */
+        return Status;
+    }
 
     /* Open the current value */
     RtlInitUnicodeString(&KeyName, L"Current");
@@ -249,6 +259,7 @@
     ControlSet = *(PULONG)((PUCHAR)ValueInfo + ValueInfo->DataOffset);
 
     /* Create the current control set key */
+UseSet:
     RtlInitUnicodeString(&KeyName,
                          L"\\Registry\\Machine\\System\\CurrentControlSet");
     InitializeObjectAttributes(&ObjectAttributes,
@@ -499,10 +510,9 @@
     else
     {
         /* Create it */
-#if 0
         Status = CmpInitializeHive(&SystemHive,
                                    HINIT_CREATE,
-                                   0, //HIVE_NOLAZYFLUSH,
+                                   HIVE_NOLAZYFLUSH,
                                    HFILE_TYPE_LOG,
                                    NULL,
                                    NULL,
@@ -514,7 +524,7 @@
         
         /* Set the hive filename */
         RtlCreateUnicodeString(&SystemHive->FileFullPath, SYSTEM_REG_FILE);
-#endif
+
         /* Tell CmpLinkHiveToMaster to allocate a hive */
         Allocate = TRUE;
     }
@@ -750,11 +760,83 @@
     return TRUE;
 }
 
+NTSTATUS
+NTAPI
+CmpGetRegistryPath(IN PWCHAR ConfigPath)
+{
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    NTSTATUS Status;
+    HANDLE KeyHandle;
+    PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
+    UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE");
+    UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath");
+    ULONG BufferSize,ResultSize;
+
+    /* Check if we are booted in setup */
+    if (ExpInTextModeSetup)
+    {
+        /* Setup the object attributes */
+        InitializeObjectAttributes(&ObjectAttributes,
+                                   &KeyName,
+                                   OBJ_CASE_INSENSITIVE,
+                                   NULL,
+                                   NULL);
+        /* Open the key */
+        Status =  ZwOpenKey(&KeyHandle,
+                            KEY_ALL_ACCESS,
+                            &ObjectAttributes);
+        if (!NT_SUCCESS(Status)) return Status;
+        
+        /* Allocate the buffer */
+        BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 4096;
+        ValueInfo = ExAllocatePoolWithTag(PagedPool, BufferSize, TAG_CM);
+        if (!ValueInfo)
+        {
+            /* Fail */
+            ZwClose(KeyHandle);
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
+
+        /* Query the value */
+        Status = ZwQueryValueKey(KeyHandle,
+                                 &ValueName,
+                                 KeyValuePartialInformation,
+                                 ValueInfo,
+                                 BufferSize,
+                                 &ResultSize);
+        ZwClose(KeyHandle);
+        if (!NT_SUCCESS(Status))
+        {
+            /* Fail */
+            ExFreePool(ValueInfo);
+            return Status;
+        }
+
+        /* Copy the config path and null-terminate it */
+        RtlCopyMemory(ConfigPath,
+                      ValueInfo->Data,
+                      ValueInfo->DataLength);
+        ConfigPath[ValueInfo->DataLength / sizeof(WCHAR)] = UNICODE_NULL;
+        ExFreePool(ValueInfo);
+    }
+    else
+    {
+        /* Just use default path */
+        wcscpy(ConfigPath, L"\\SystemRoot");
+    }
+
+    /* Add registry path */
+    wcscat(ConfigPath, L"\\System32\\Config");
+
+    /* Done */
+    return STATUS_SUCCESS;
+}
+
 VOID
 NTAPI
 CmpLoadHiveThread(IN PVOID StartContext)
 {
-    WCHAR FileBuffer[MAX_PATH], RegBuffer[MAX_PATH];
+    WCHAR FileBuffer[MAX_PATH], RegBuffer[MAX_PATH], ConfigPath[MAX_PATH];
     UNICODE_STRING TempName, FileName, RegName;
     ULONG FileStart, RegStart, i, ErrorResponse, ClusterSize, WorkerCount;
     ULONG PrimaryDisposition, SecondaryDisposition, Length;
@@ -777,7 +859,8 @@
     RtlInitEmptyUnicodeString(&RegName, RegBuffer, MAX_PATH);
     
     /* Now build the system root path */
-    RtlInitUnicodeString(&TempName, L"\\SystemRoot\\System32\\Config\\");
+    CmpGetRegistryPath(ConfigPath);
+    RtlInitUnicodeString(&TempName, ConfigPath);
     RtlAppendStringToString((PSTRING)&FileName, (PSTRING)&TempName);
     FileStart = FileName.Length;
     




More information about the Ros-diffs mailing list