Remobed duplicate functionality and cleaned-up the registry code.

svn path=/trunk/; revision=4813
This commit is contained in:
Eric Kohl 2003-06-01 17:39:14 +00:00
parent d197898a75
commit 8eb47000b7
3 changed files with 74 additions and 158 deletions

View file

@ -423,9 +423,7 @@ CmiScanKeyList(IN PKEY_OBJECT Parent,
IN ULONG Attributes); IN ULONG Attributes);
NTSTATUS NTSTATUS
CmiCreateRegistryHive(PWSTR Filename, CmiCreateVolatileHive(PREGISTRY_HIVE *RegistryHive);
PREGISTRY_HIVE *RegistryHive,
BOOLEAN CreateNew);
NTSTATUS NTSTATUS
CmiLoadHive(POBJECT_ATTRIBUTES KeyObjectAttributes, CmiLoadHive(POBJECT_ATTRIBUTES KeyObjectAttributes,

View file

@ -848,8 +848,7 @@ CmiCreateHiveBitmap(PREGISTRY_HIVE Hive)
static NTSTATUS static NTSTATUS
CmiInitNonVolatileRegistryHive (PREGISTRY_HIVE RegistryHive, CmiInitNonVolatileRegistryHive (PREGISTRY_HIVE RegistryHive,
PWSTR Filename, PWSTR Filename)
BOOLEAN CreateNew)
{ {
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
ULONG CreateDisposition; ULONG CreateDisposition;
@ -906,21 +905,7 @@ CmiInitNonVolatileRegistryHive(PREGISTRY_HIVE RegistryHive,
NULL, NULL,
NULL); NULL);
/*
* Note:
* This is a workaround to prevent a BSOD because of missing registry hives.
* The workaround is only useful for developers. An implementation for the
* ordinary user must bail out on missing registry hives because they are
* essential to booting and configuring the OS.
*/
#if 0
if (CreateNew == TRUE)
CreateDisposition = FILE_OPEN_IF; CreateDisposition = FILE_OPEN_IF;
else
CreateDisposition = FILE_OPEN;
#endif
CreateDisposition = FILE_OPEN_IF;
Status = NtCreateFile(&FileHandle, Status = NtCreateFile(&FileHandle,
FILE_ALL_ACCESS, FILE_ALL_ACCESS,
&ObjectAttributes, &ObjectAttributes,
@ -940,10 +925,6 @@ CmiInitNonVolatileRegistryHive(PREGISTRY_HIVE RegistryHive,
return(Status); return(Status);
} }
/* Note: Another workaround! See the note above! */
#if 0
if ((CreateNew) && (IoSB.Information == FILE_CREATED))
#endif
if (IoSB.Information != FILE_OPENED) if (IoSB.Information != FILE_OPENED)
{ {
Status = CmiCreateNewRegFile(FileHandle); Status = CmiCreateNewRegFile(FileHandle);
@ -1068,80 +1049,57 @@ CmiInitNonVolatileRegistryHive(PREGISTRY_HIVE RegistryHive,
} }
static NTSTATUS NTSTATUS
CmiInitVolatileRegistryHive(PREGISTRY_HIVE RegistryHive) CmiCreateVolatileHive(PREGISTRY_HIVE *RegistryHive)
{ {
PKEY_CELL RootKeyCell; PKEY_CELL RootKeyCell;
RegistryHive->Flags |= (HIVE_NO_FILE | HIVE_POINTER);
CmiCreateDefaultHiveHeader(RegistryHive->HiveHeader);
RootKeyCell = (PKEY_CELL) ExAllocatePool(NonPagedPool, sizeof(KEY_CELL));
if (RootKeyCell == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
CmiCreateDefaultRootKeyCell(RootKeyCell);
RegistryHive->HiveHeader->RootKeyCell = (BLOCK_OFFSET) RootKeyCell;
return STATUS_SUCCESS;
}
NTSTATUS
CmiCreateRegistryHive(PWSTR Filename,
PREGISTRY_HIVE *RegistryHive,
BOOLEAN CreateNew)
{
PREGISTRY_HIVE Hive; PREGISTRY_HIVE Hive;
NTSTATUS Status;
DPRINT("CmiCreateRegistryHive(Filename %S)\n", Filename);
*RegistryHive = NULL; *RegistryHive = NULL;
Hive = ExAllocatePool(NonPagedPool, sizeof(REGISTRY_HIVE)); Hive = ExAllocatePool (NonPagedPool,
sizeof(REGISTRY_HIVE));
if (Hive == NULL) if (Hive == NULL)
return(STATUS_INSUFFICIENT_RESOURCES); return STATUS_INSUFFICIENT_RESOURCES;
RtlZeroMemory (Hive,
sizeof(REGISTRY_HIVE));
DPRINT("Hive %x\n", Hive); DPRINT("Hive %x\n", Hive);
RtlZeroMemory(Hive, sizeof(REGISTRY_HIVE)); Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool (NonPagedPool,
sizeof(HIVE_HEADER));
Hive->HiveHeader = (PHIVE_HEADER)
ExAllocatePool(NonPagedPool, sizeof(HIVE_HEADER));
if (Hive->HiveHeader == NULL) if (Hive->HiveHeader == NULL)
{ {
ExFreePool (Hive); ExFreePool (Hive);
return(STATUS_INSUFFICIENT_RESOURCES); return STATUS_INSUFFICIENT_RESOURCES;
} }
if (Filename != NULL) Hive->Flags = (HIVE_NO_FILE | HIVE_POINTER);
{
Status = CmiInitNonVolatileRegistryHive(Hive, Filename, CreateNew);
}
else
{
Status = CmiInitVolatileRegistryHive(Hive);
}
if (!NT_SUCCESS(Status)) CmiCreateDefaultHiveHeader (Hive->HiveHeader);
RootKeyCell = (PKEY_CELL)ExAllocatePool (NonPagedPool,
sizeof(KEY_CELL));
if (RootKeyCell == NULL)
{ {
ExFreePool(Hive->HiveHeader); ExFreePool(Hive->HiveHeader);
ExFreePool(Hive); ExFreePool(Hive);
return(Status); return STATUS_INSUFFICIENT_RESOURCES;
} }
CmiCreateDefaultRootKeyCell (RootKeyCell);
Hive->HiveHeader->RootKeyCell = (BLOCK_OFFSET)RootKeyCell;
ExInitializeResourceLite (&Hive->HiveResource); ExInitializeResourceLite (&Hive->HiveResource);
/* Acquire hive list lock exclusively */ /* Acquire hive list lock exclusively */
ExAcquireResourceExclusiveLite(&CmiHiveListLock, TRUE); ExAcquireResourceExclusiveLite (&CmiHiveListLock,
TRUE);
/* Add the new hive to the hive list */ /* Add the new hive to the hive list */
InsertTailList(&CmiHiveListHead, &Hive->HiveList); InsertTailList (&CmiHiveListHead,
&Hive->HiveList);
/* Release hive list lock */ /* Release hive list lock */
ExReleaseResourceLite (&CmiHiveListLock); ExReleaseResourceLite (&CmiHiveListLock);
@ -1150,9 +1108,7 @@ CmiCreateRegistryHive(PWSTR Filename,
*RegistryHive = Hive; *RegistryHive = Hive;
DPRINT("CmiCreateRegistryHive(Filename %S) - Finished.\n", Filename); return STATUS_SUCCESS;
return(STATUS_SUCCESS);
} }
@ -1180,6 +1136,7 @@ CmiLoadHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes,
sizeof(REGISTRY_HIVE)); sizeof(REGISTRY_HIVE));
DPRINT ("Hive %x\n", Hive); DPRINT ("Hive %x\n", Hive);
Hive->Flags = (Flags & REG_NO_LAZY_FLUSH) ? HIVE_NO_SYNCH : 0;
Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool(NonPagedPool, Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool(NonPagedPool,
sizeof(HIVE_HEADER)); sizeof(HIVE_HEADER));
@ -1191,8 +1148,7 @@ CmiLoadHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes,
} }
Status = CmiInitNonVolatileRegistryHive (Hive, Status = CmiInitNonVolatileRegistryHive (Hive,
FileName->Buffer, FileName->Buffer);
TRUE);
if (!NT_SUCCESS (Status)) if (!NT_SUCCESS (Status))
{ {
DPRINT1 ("CmiInitNonVolatileRegistryHive() failed (Status %lx)\n", Status); DPRINT1 ("CmiInitNonVolatileRegistryHive() failed (Status %lx)\n", Status);

View file

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.100 2003/06/01 15:10:52 ekohl Exp $ /* $Id: registry.c,v 1.101 2003/06/01 17:39:14 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -283,7 +283,7 @@ CmInitializeRegistry(VOID)
ExInitializeResourceLite(&CmiHiveListLock); ExInitializeResourceLite(&CmiHiveListLock);
/* Build volatile registry store */ /* Build volatile registry store */
Status = CmiCreateRegistryHive(NULL, &CmiVolatileHive, FALSE); Status = CmiCreateVolatileHive (&CmiVolatileHive);
assert(NT_SUCCESS(Status)); assert(NT_SUCCESS(Status));
/* Create '\Registry' key. */ /* Create '\Registry' key. */
@ -670,8 +670,7 @@ CmiDisconnectHive (IN POBJECT_ATTRIBUTES KeyObjectAttributes,
static NTSTATUS static NTSTATUS
CmiInitializeSystemHive (POBJECT_ATTRIBUTES KeyObjectAttributes, CmiInitControlSetLink (VOID)
PWSTR FileName)
{ {
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING ControlSetKeyName; UNICODE_STRING ControlSetKeyName;
@ -679,25 +678,6 @@ CmiInitializeSystemHive (POBJECT_ATTRIBUTES KeyObjectAttributes,
UNICODE_STRING ControlSetValueName; UNICODE_STRING ControlSetValueName;
HANDLE KeyHandle; HANDLE KeyHandle;
NTSTATUS Status; NTSTATUS Status;
PREGISTRY_HIVE RegistryHive;
Status = CmiCreateRegistryHive (FileName,
&RegistryHive,
TRUE);
if (!NT_SUCCESS(Status))
{
DPRINT1 ("CmiCreateRegistryHive() failed (Status %lx)\n", Status);
return Status;
}
Status = CmiConnectHive (KeyObjectAttributes,
RegistryHive);
if (!NT_SUCCESS(Status))
{
DPRINT1 ("CmiConnectHive() failed (Status %lx)\n", Status);
CmiRemoveRegistryHive (RegistryHive);
return Status;
}
/* Create 'ControlSet001' key */ /* Create 'ControlSet001' key */
RtlInitUnicodeStringFromLiteral (&ControlSetKeyName, RtlInitUnicodeStringFromLiteral (&ControlSetKeyName,
@ -760,50 +740,12 @@ CmiInitializeSystemHive (POBJECT_ATTRIBUTES KeyObjectAttributes,
} }
NTSTATUS
CmiInitializeHive(POBJECT_ATTRIBUTES KeyObjectAttributes,
PWSTR FileName,
BOOLEAN CreateNew)
{
PREGISTRY_HIVE RegistryHive;
NTSTATUS Status;
DPRINT("CmiInitializeHive(%s) called\n", KeyName);
Status = CmiCreateRegistryHive(FileName,
&RegistryHive,
CreateNew);
if (!NT_SUCCESS(Status))
{
DPRINT1("CmiCreateRegistryHive() failed (Status %lx)\n", Status);
/* FIXME: Try to load the backup hive */
KeBugCheck(0);
return(Status);
}
/* Connect the hive */
Status = CmiConnectHive(KeyObjectAttributes, //KeyName,
RegistryHive);
if (!NT_SUCCESS(Status))
{
DPRINT1("CmiConnectHive() failed (Status %lx)\n", Status);
CmiRemoveRegistryHive(RegistryHive);
return(Status);
}
DPRINT("CmiInitializeHive() done\n");
return(STATUS_SUCCESS);
}
NTSTATUS NTSTATUS
CmiInitHives(BOOLEAN SetupBoot) CmiInitHives(BOOLEAN SetupBoot)
{ {
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo; PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING FileName;
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
UNICODE_STRING ValueName; UNICODE_STRING ValueName;
HANDLE KeyHandle; HANDLE KeyHandle;
@ -895,17 +837,30 @@ CmiInitHives(BOOLEAN SetupBoot)
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
Status = CmiInitializeSystemHive (&ObjectAttributes,
RtlInitUnicodeString (&FileName,
ConfigPath); ConfigPath);
Status = CmiLoadHive (&ObjectAttributes,
&FileName,
0);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("CmiInitializeSystemHive() failed (Status %lx)\n", Status); DPRINT1 ("CmiLoadHive() failed (Status %lx)\n", Status);
return Status;
}
Status = CmiInitControlSetLink ();
if (!NT_SUCCESS(Status))
{
DPRINT1("CmiInitControlSetLink() failed (Status %lx)\n", Status);
return(Status); return(Status);
} }
} }
/* Connect the SOFTWARE hive */ /* Connect the SOFTWARE hive */
wcscpy(EndPtr, REG_SOFTWARE_FILE_NAME); wcscpy(EndPtr, REG_SOFTWARE_FILE_NAME);
RtlInitUnicodeString (&FileName,
ConfigPath);
DPRINT ("ConfigPath: %S\n", ConfigPath); DPRINT ("ConfigPath: %S\n", ConfigPath);
RtlInitUnicodeString (&KeyName, RtlInitUnicodeString (&KeyName,
@ -915,9 +870,10 @@ CmiInitHives(BOOLEAN SetupBoot)
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
Status = CmiInitializeHive(&ObjectAttributes,
ConfigPath, Status = CmiLoadHive (&ObjectAttributes,
SetupBoot); &FileName,
0);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status);
@ -926,6 +882,8 @@ CmiInitHives(BOOLEAN SetupBoot)
/* Connect the SAM hive */ /* Connect the SAM hive */
wcscpy(EndPtr, REG_SAM_FILE_NAME); wcscpy(EndPtr, REG_SAM_FILE_NAME);
RtlInitUnicodeString (&FileName,
ConfigPath);
DPRINT ("ConfigPath: %S\n", ConfigPath); DPRINT ("ConfigPath: %S\n", ConfigPath);
RtlInitUnicodeString (&KeyName, RtlInitUnicodeString (&KeyName,
@ -935,9 +893,9 @@ CmiInitHives(BOOLEAN SetupBoot)
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
Status = CmiInitializeHive(&ObjectAttributes, Status = CmiLoadHive (&ObjectAttributes,
ConfigPath, &FileName,
SetupBoot); 0);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status);
@ -946,6 +904,8 @@ CmiInitHives(BOOLEAN SetupBoot)
/* Connect the SECURITY hive */ /* Connect the SECURITY hive */
wcscpy(EndPtr, REG_SEC_FILE_NAME); wcscpy(EndPtr, REG_SEC_FILE_NAME);
RtlInitUnicodeString (&FileName,
ConfigPath);
DPRINT ("ConfigPath: %S\n", ConfigPath); DPRINT ("ConfigPath: %S\n", ConfigPath);
RtlInitUnicodeString (&KeyName, RtlInitUnicodeString (&KeyName,
@ -955,9 +915,9 @@ CmiInitHives(BOOLEAN SetupBoot)
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
Status = CmiInitializeHive(&ObjectAttributes, Status = CmiLoadHive (&ObjectAttributes,
ConfigPath, &FileName,
SetupBoot); 0);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status);
@ -966,6 +926,8 @@ CmiInitHives(BOOLEAN SetupBoot)
/* Connect the DEFAULT hive */ /* Connect the DEFAULT hive */
wcscpy(EndPtr, REG_DEFAULT_USER_FILE_NAME); wcscpy(EndPtr, REG_DEFAULT_USER_FILE_NAME);
RtlInitUnicodeString (&FileName,
ConfigPath);
DPRINT ("ConfigPath: %S\n", ConfigPath); DPRINT ("ConfigPath: %S\n", ConfigPath);
RtlInitUnicodeString (&KeyName, RtlInitUnicodeString (&KeyName,
@ -975,9 +937,9 @@ CmiInitHives(BOOLEAN SetupBoot)
OBJ_CASE_INSENSITIVE, OBJ_CASE_INSENSITIVE,
NULL, NULL,
NULL); NULL);
Status = CmiInitializeHive(&ObjectAttributes, Status = CmiLoadHive (&ObjectAttributes,
ConfigPath, &FileName,
SetupBoot); 0);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status); DPRINT1("CmiInitializeHive() failed (Status %lx)\n", Status);