mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 03:55:41 +00:00
[MKHIVE] Use same code as ntoskrnl to create registry keys
CORE-8584 svn path=/trunk/; revision=64497
This commit is contained in:
parent
cf215482dd
commit
3bbcfb760d
4 changed files with 69 additions and 82 deletions
|
@ -9,6 +9,8 @@ include_directories(
|
||||||
list(APPEND SOURCE
|
list(APPEND SOURCE
|
||||||
binhive.c
|
binhive.c
|
||||||
cmi.c
|
cmi.c
|
||||||
|
cmindex.c
|
||||||
|
cmname.c
|
||||||
mkhive.c
|
mkhive.c
|
||||||
reginf.c
|
reginf.c
|
||||||
registry.c
|
registry.c
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include "mkhive.h"
|
#include "mkhive.h"
|
||||||
|
|
||||||
static PVOID
|
PVOID
|
||||||
NTAPI
|
NTAPI
|
||||||
CmpAllocate(
|
CmpAllocate(
|
||||||
IN SIZE_T Size,
|
IN SIZE_T Size,
|
||||||
|
@ -36,7 +36,7 @@ CmpAllocate(
|
||||||
return (PVOID) malloc((size_t)Size);
|
return (PVOID) malloc((size_t)Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID
|
VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
CmpFree(
|
CmpFree(
|
||||||
IN PVOID Ptr,
|
IN PVOID Ptr,
|
||||||
|
@ -221,16 +221,13 @@ CmiAllocateHashTableCell (
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
CmiAddSubKey(
|
CmiCreateSubKey(
|
||||||
IN PCMHIVE RegistryHive,
|
IN PCMHIVE RegistryHive,
|
||||||
IN PCM_KEY_NODE ParentKeyCell,
|
|
||||||
IN HCELL_INDEX ParentKeyCellOffset,
|
IN HCELL_INDEX ParentKeyCellOffset,
|
||||||
IN PCUNICODE_STRING SubKeyName,
|
IN PCUNICODE_STRING SubKeyName,
|
||||||
IN ULONG CreateOptions,
|
IN ULONG CreateOptions,
|
||||||
OUT PCM_KEY_NODE *pSubKeyCell,
|
OUT HCELL_INDEX* pNKBOffset)
|
||||||
OUT HCELL_INDEX *pBlockOffset)
|
|
||||||
{
|
{
|
||||||
PCM_KEY_FAST_INDEX HashBlock;
|
|
||||||
HCELL_INDEX NKBOffset;
|
HCELL_INDEX NKBOffset;
|
||||||
PCM_KEY_NODE NewKeyCell;
|
PCM_KEY_NODE NewKeyCell;
|
||||||
ULONG NewBlockSize;
|
ULONG NewBlockSize;
|
||||||
|
@ -241,8 +238,6 @@ CmiAddSubKey(
|
||||||
HSTORAGE_TYPE Storage;
|
HSTORAGE_TYPE Storage;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
|
||||||
VERIFY_KEY_CELL(ParentKeyCell);
|
|
||||||
|
|
||||||
/* Skip leading backslash */
|
/* Skip leading backslash */
|
||||||
if (SubKeyName->Buffer[0] == L'\\')
|
if (SubKeyName->Buffer[0] == L'\\')
|
||||||
{
|
{
|
||||||
|
@ -325,90 +320,46 @@ CmiAddSubKey(
|
||||||
VERIFY_KEY_CELL(NewKeyCell);
|
VERIFY_KEY_CELL(NewKeyCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
*pNKBOffset = NKBOffset;
|
||||||
|
}
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
CmiAddSubKey(
|
||||||
|
IN PCMHIVE RegistryHive,
|
||||||
|
IN PCM_KEY_NODE ParentKeyCell,
|
||||||
|
IN HCELL_INDEX ParentKeyCellOffset,
|
||||||
|
IN PCUNICODE_STRING SubKeyName,
|
||||||
|
IN ULONG CreateOptions,
|
||||||
|
OUT PCM_KEY_NODE *pSubKeyCell,
|
||||||
|
OUT HCELL_INDEX *pBlockOffset)
|
||||||
|
{
|
||||||
|
HCELL_INDEX NKBOffset;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
VERIFY_KEY_CELL(ParentKeyCell);
|
||||||
|
|
||||||
|
/* Create the new key */
|
||||||
|
Status = CmiCreateSubKey(RegistryHive, ParentKeyCellOffset, SubKeyName, CreateOptions, &NKBOffset);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ParentKeyCell->SubKeyLists[Storage] == HCELL_NIL)
|
if (!CmpAddSubKey(&RegistryHive->Hive, ParentKeyCellOffset, NKBOffset))
|
||||||
{
|
{
|
||||||
Status = CmiAllocateHashTableCell (
|
/* FIXME: delete newly created cell */
|
||||||
RegistryHive,
|
return STATUS_UNSUCCESSFUL;
|
||||||
&HashBlock,
|
|
||||||
&ParentKeyCell->SubKeyLists[Storage],
|
|
||||||
REG_INIT_HASH_TABLE_SIZE,
|
|
||||||
Storage);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HashBlock = (PCM_KEY_FAST_INDEX)HvGetCell (
|
|
||||||
&RegistryHive->Hive,
|
|
||||||
ParentKeyCell->SubKeyLists[Storage]);
|
|
||||||
ASSERT(HashBlock->Signature == CM_KEY_FAST_LEAF);
|
|
||||||
|
|
||||||
if (HashBlock->Count ==
|
|
||||||
((HvGetCellSize(&RegistryHive->Hive, HashBlock) - FIELD_OFFSET(CM_KEY_FAST_INDEX, List)) / sizeof(CM_INDEX)))
|
|
||||||
{
|
|
||||||
PCM_KEY_FAST_INDEX NewHashBlock;
|
|
||||||
HCELL_INDEX HTOffset;
|
|
||||||
|
|
||||||
/* Reallocate the hash table cell */
|
|
||||||
Status = CmiAllocateHashTableCell (
|
|
||||||
RegistryHive,
|
|
||||||
&NewHashBlock,
|
|
||||||
&HTOffset,
|
|
||||||
HashBlock->Count +
|
|
||||||
REG_EXTEND_HASH_TABLE_SIZE,
|
|
||||||
Storage);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
RtlCopyMemory(
|
|
||||||
&NewHashBlock->List[0],
|
|
||||||
&HashBlock->List[0],
|
|
||||||
sizeof(NewHashBlock->List[0]) * HashBlock->Count);
|
|
||||||
NewHashBlock->Count = HashBlock->Count;
|
|
||||||
HvFreeCell (&RegistryHive->Hive, ParentKeyCell->SubKeyLists[Storage]);
|
|
||||||
ParentKeyCell->SubKeyLists[Storage] = HTOffset;
|
|
||||||
HashBlock = NewHashBlock;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Status = CmiAddKeyToHashTable(
|
|
||||||
RegistryHive,
|
|
||||||
HashBlock,
|
|
||||||
ParentKeyCell->SubKeyLists[Storage],
|
|
||||||
NewKeyCell,
|
|
||||||
NKBOffset);
|
|
||||||
if (NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
ParentKeyCell->SubKeyCounts[Storage]++;
|
|
||||||
if (Packable)
|
|
||||||
{
|
|
||||||
if (NameLength*sizeof(WCHAR) > ParentKeyCell->MaxNameLen)
|
|
||||||
ParentKeyCell->MaxNameLen = NameLength*sizeof(WCHAR);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (NameLength > ParentKeyCell->MaxNameLen)
|
|
||||||
ParentKeyCell->MaxNameLen = NameLength;
|
|
||||||
}
|
|
||||||
if (NewKeyCell->ClassLength > ParentKeyCell->MaxClassLen)
|
|
||||||
ParentKeyCell->MaxClassLen = NewKeyCell->ClassLength;
|
|
||||||
|
|
||||||
*pSubKeyCell = NewKeyCell;
|
|
||||||
*pBlockOffset = NKBOffset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KeQuerySystemTime(&ParentKeyCell->LastWriteTime);
|
KeQuerySystemTime(&ParentKeyCell->LastWriteTime);
|
||||||
HvMarkCellDirty(&RegistryHive->Hive, ParentKeyCellOffset, FALSE);
|
HvMarkCellDirty(&RegistryHive->Hive, ParentKeyCellOffset, FALSE);
|
||||||
|
|
||||||
return Status;
|
*pBlockOffset = NKBOffset;
|
||||||
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOLEAN
|
static BOOLEAN
|
||||||
|
|
|
@ -117,9 +117,12 @@ RegOpenKeyW(
|
||||||
#include "registry.h"
|
#include "registry.h"
|
||||||
#include "binhive.h"
|
#include "binhive.h"
|
||||||
|
|
||||||
|
#define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
|
||||||
|
|
||||||
#define HIVE_NO_FILE 2
|
#define HIVE_NO_FILE 2
|
||||||
#define VERIFY_REGISTRY_HIVE(hive)
|
#define VERIFY_REGISTRY_HIVE(hive)
|
||||||
extern LIST_ENTRY CmiHiveListHead;
|
extern LIST_ENTRY CmiHiveListHead;
|
||||||
#define ABS_VALUE(V) (((V) < 0) ? -(V) : (V))
|
#define ABS_VALUE(V) (((V) < 0) ? -(V) : (V))
|
||||||
|
#define PAGED_CODE()
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -107,6 +107,37 @@ RtlAnsiStringToUnicodeString(
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LONG NTAPI
|
||||||
|
RtlCompareUnicodeString(
|
||||||
|
IN PCUNICODE_STRING String1,
|
||||||
|
IN PCUNICODE_STRING String2,
|
||||||
|
IN BOOLEAN CaseInSensitive)
|
||||||
|
{
|
||||||
|
USHORT i;
|
||||||
|
WCHAR c1, c2;
|
||||||
|
|
||||||
|
for (i = 0; i <= String1->Length / sizeof(WCHAR) && i <= String2->Length / sizeof(WCHAR); i++)
|
||||||
|
{
|
||||||
|
if (CaseInSensitive)
|
||||||
|
{
|
||||||
|
c1 = RtlUpcaseUnicodeChar(String1->Buffer[i]);
|
||||||
|
c2 = RtlUpcaseUnicodeChar(String2->Buffer[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c1 = String1->Buffer[i];
|
||||||
|
c2 = String2->Buffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c1 < c2)
|
||||||
|
return -1;
|
||||||
|
else if (c1 > c2)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
WCHAR NTAPI
|
WCHAR NTAPI
|
||||||
RtlUpcaseUnicodeChar(
|
RtlUpcaseUnicodeChar(
|
||||||
IN WCHAR Source)
|
IN WCHAR Source)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue