diff --git a/reactos/tools/mkhive/CMakeLists.txt b/reactos/tools/mkhive/CMakeLists.txt index aaaae18e09b..04bd7472e5e 100644 --- a/reactos/tools/mkhive/CMakeLists.txt +++ b/reactos/tools/mkhive/CMakeLists.txt @@ -9,6 +9,8 @@ include_directories( list(APPEND SOURCE binhive.c cmi.c + cmindex.c + cmname.c mkhive.c reginf.c registry.c diff --git a/reactos/tools/mkhive/cmi.c b/reactos/tools/mkhive/cmi.c index df8b89475b2..9803e94236f 100644 --- a/reactos/tools/mkhive/cmi.c +++ b/reactos/tools/mkhive/cmi.c @@ -26,7 +26,7 @@ #define NDEBUG #include "mkhive.h" -static PVOID +PVOID NTAPI CmpAllocate( IN SIZE_T Size, @@ -36,7 +36,7 @@ CmpAllocate( return (PVOID) malloc((size_t)Size); } -static VOID +VOID NTAPI CmpFree( IN PVOID Ptr, @@ -221,16 +221,13 @@ CmiAllocateHashTableCell ( } NTSTATUS -CmiAddSubKey( +CmiCreateSubKey( 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) + OUT HCELL_INDEX* pNKBOffset) { - PCM_KEY_FAST_INDEX HashBlock; HCELL_INDEX NKBOffset; PCM_KEY_NODE NewKeyCell; ULONG NewBlockSize; @@ -241,8 +238,6 @@ CmiAddSubKey( HSTORAGE_TYPE Storage; ULONG i; - VERIFY_KEY_CELL(ParentKeyCell); - /* Skip leading backslash */ if (SubKeyName->Buffer[0] == L'\\') { @@ -325,90 +320,46 @@ CmiAddSubKey( 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)) { return Status; } - if (ParentKeyCell->SubKeyLists[Storage] == HCELL_NIL) + if (!CmpAddSubKey(&RegistryHive->Hive, ParentKeyCellOffset, NKBOffset)) { - Status = CmiAllocateHashTableCell ( - RegistryHive, - &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; + /* FIXME: delete newly created cell */ + return STATUS_UNSUCCESSFUL; } KeQuerySystemTime(&ParentKeyCell->LastWriteTime); HvMarkCellDirty(&RegistryHive->Hive, ParentKeyCellOffset, FALSE); - return Status; + *pBlockOffset = NKBOffset; + return STATUS_SUCCESS; } static BOOLEAN diff --git a/reactos/tools/mkhive/mkhive.h b/reactos/tools/mkhive/mkhive.h index 7ce3bb53fd9..5208a62878d 100644 --- a/reactos/tools/mkhive/mkhive.h +++ b/reactos/tools/mkhive/mkhive.h @@ -117,9 +117,12 @@ RegOpenKeyW( #include "registry.h" #include "binhive.h" +#define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\') + #define HIVE_NO_FILE 2 #define VERIFY_REGISTRY_HIVE(hive) extern LIST_ENTRY CmiHiveListHead; #define ABS_VALUE(V) (((V) < 0) ? -(V) : (V)) +#define PAGED_CODE() /* EOF */ diff --git a/reactos/tools/mkhive/rtl.c b/reactos/tools/mkhive/rtl.c index 4a186e253f6..5c89336ca38 100644 --- a/reactos/tools/mkhive/rtl.c +++ b/reactos/tools/mkhive/rtl.c @@ -107,6 +107,37 @@ RtlAnsiStringToUnicodeString( 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 RtlUpcaseUnicodeChar( IN WCHAR Source)