https://git.reactos.org/?p=reactos.git;a=commitdiff;h=736331973ecf4f82e0da1…
commit 736331973ecf4f82e0da1c5e9037d536b347057d
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat Apr 2 03:26:46 2022 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Apr 17 04:57:43 2022 +0200
[FREELDR:NTLDR] Rewrite RegInitCurrentControlSet() using CmpFindControlSet().
Also remove useless "success" traces at the end of some registry functions.
(Only show when they enter and when they fail.)
---
boot/freeldr/freeldr/ntldr/registry.c | 111 +++++++-------------------------
boot/freeldr/freeldr/ntldr/registry.h | 2 +-
boot/freeldr/freeldr/ntldr/wlregistry.c | 2 +-
3 files changed, 26 insertions(+), 89 deletions(-)
diff --git a/boot/freeldr/freeldr/ntldr/registry.c
b/boot/freeldr/freeldr/ntldr/registry.c
index 88046036e53..566f1bfa189 100644
--- a/boot/freeldr/freeldr/ntldr/registry.c
+++ b/boot/freeldr/freeldr/ntldr/registry.c
@@ -21,6 +21,7 @@
#include <freeldr.h>
#include <cmlib.h>
#include "registry.h"
+#include <internal/cmboot.h>
#include <debug.h>
DBG_DEFAULT_CHANNEL(REGISTRY);
@@ -99,106 +100,44 @@ RegImportBinaryHive(
ASSERT(KeyNode->Signature == CM_KEY_NODE_SIGNATURE);
HvReleaseCell(SystemHive, SystemRootCell);
- TRACE("RegImportBinaryHive done\n");
return TRUE;
}
-LONG
+BOOLEAN
RegInitCurrentControlSet(
_In_ BOOLEAN LastKnownGood)
{
- WCHAR ControlSetKeyName[80];
- HKEY SelectKey;
- HKEY SystemKey;
- ULONG CurrentSet = 0;
- ULONG DefaultSet = 0;
- ULONG LastKnownGoodSet = 0;
- ULONG DataSize;
- LONG Error;
+ UNICODE_STRING ControlSetName;
+ HCELL_INDEX ControlCell;
+ PCM_KEY_NODE KeyNode;
+ BOOLEAN AutoSelect;
TRACE("RegInitCurrentControlSet\n");
- Error = RegOpenKey(NULL,
- L"\\Registry\\Machine\\SYSTEM\\Select",
- &SelectKey);
- if (Error != ERROR_SUCCESS)
- {
- ERR("RegOpenKey('SYSTEM\\Select') failed (Error %lu)\n",
Error);
- return Error;
- }
-
- DataSize = sizeof(ULONG);
- Error = RegQueryValue(SelectKey,
- L"Default",
- NULL,
- (PUCHAR)&DefaultSet,
- &DataSize);
- if (Error != ERROR_SUCCESS)
- {
- ERR("RegQueryValue('Default') failed (Error %lu)\n", Error);
- RegCloseKey(SelectKey);
- return Error;
- }
-
- DataSize = sizeof(ULONG);
- Error = RegQueryValue(SelectKey,
- L"LastKnownGood",
- NULL,
- (PUCHAR)&LastKnownGoodSet,
- &DataSize);
- if (Error != ERROR_SUCCESS)
- {
- ERR("RegQueryValue('LastKnownGood') failed (Error %lu)\n",
Error);
- RegCloseKey(SelectKey);
- return Error;
- }
-
- RegCloseKey(SelectKey);
-
- CurrentSet = (LastKnownGood) ? LastKnownGoodSet : DefaultSet;
- wcscpy(ControlSetKeyName, L"ControlSet");
- switch(CurrentSet)
- {
- case 1:
- wcscat(ControlSetKeyName, L"001");
- break;
- case 2:
- wcscat(ControlSetKeyName, L"002");
- break;
- case 3:
- wcscat(ControlSetKeyName, L"003");
- break;
- case 4:
- wcscat(ControlSetKeyName, L"004");
- break;
- case 5:
- wcscat(ControlSetKeyName, L"005");
- break;
- }
+ /* Choose which control set to open and set it as the new "Current" */
+ RtlInitUnicodeString(&ControlSetName,
+ LastKnownGood ? L"LastKnownGood"
+ : L"Default");
- Error = RegOpenKey(NULL,
- L"\\Registry\\Machine\\SYSTEM",
- &SystemKey);
- if (Error != ERROR_SUCCESS)
+ ControlCell = CmpFindControlSet(SystemHive,
+ SystemRootCell,
+ &ControlSetName,
+ &AutoSelect);
+ if (ControlCell == HCELL_NIL)
{
- ERR("RegOpenKey('SYSTEM') failed (Error %lu)\n", Error);
- return Error;
+ ERR("CmpFindControlSet('%wZ') failed\n", &ControlSetName);
+ return FALSE;
}
- Error = RegOpenKey(SystemKey,
- ControlSetKeyName,
- &CurrentControlSetKey);
-
- RegCloseKey(SystemKey);
+ CurrentControlSetKey = (HKEY)ControlCell;
- if (Error != ERROR_SUCCESS)
- {
- ERR("RegOpenKey('%S') failed (Error %lu)\n", ControlSetKeyName,
Error);
- return Error;
- }
+ /* Verify it is accessible */
+ KeyNode = (PCM_KEY_NODE)HvGetCell(SystemHive, ControlCell);
+ ASSERT(KeyNode);
+ ASSERT(KeyNode->Signature == CM_KEY_NODE_SIGNATURE);
+ HvReleaseCell(SystemHive, ControlCell);
- TRACE("RegInitCurrentControlSet done\n");
- return ERROR_SUCCESS;
+ return TRUE;
}
static
@@ -429,7 +368,6 @@ RegOpenKey(
HvReleaseCell(Hive, CellIndex);
*Key = (HKEY)CellIndex;
- TRACE("RegOpenKey done\n");
return ERROR_SUCCESS;
}
@@ -513,7 +451,6 @@ RegQueryValue(
HvReleaseCell(Hive, CellIndex);
- TRACE("RegQueryValue success\n");
return ERROR_SUCCESS;
}
diff --git a/boot/freeldr/freeldr/ntldr/registry.h
b/boot/freeldr/freeldr/ntldr/registry.h
index 23626756986..96ed98d7e52 100644
--- a/boot/freeldr/freeldr/ntldr/registry.h
+++ b/boot/freeldr/freeldr/ntldr/registry.h
@@ -30,7 +30,7 @@ RegImportBinaryHive(
_In_ PVOID ChunkBase,
_In_ ULONG ChunkSize);
-LONG
+BOOLEAN
RegInitCurrentControlSet(
_In_ BOOLEAN LastKnownGood);
diff --git a/boot/freeldr/freeldr/ntldr/wlregistry.c
b/boot/freeldr/freeldr/ntldr/wlregistry.c
index e36aae18f2a..88f8c1731ae 100644
--- a/boot/freeldr/freeldr/ntldr/wlregistry.c
+++ b/boot/freeldr/freeldr/ntldr/wlregistry.c
@@ -149,7 +149,7 @@ WinLdrInitSystemHive(
}
/* Initialize the 'CurrentControlSet' link */
- if (RegInitCurrentControlSet(FALSE) != ERROR_SUCCESS)
+ if (!RegInitCurrentControlSet(FALSE))
{
UiMessageBox("Initializing CurrentControlSet link failed!");
return FALSE;