Author: hpoussin
Date: Fri Oct  3 13:15:10 2014
New Revision: 64497

URL: http://svn.reactos.org/svn/reactos?rev=64497&view=rev
Log:
[MKHIVE] Use same code as ntoskrnl to create registry keys
CORE-8584


Modified:
    trunk/reactos/tools/mkhive/CMakeLists.txt
    trunk/reactos/tools/mkhive/cmi.c
    trunk/reactos/tools/mkhive/mkhive.h
    trunk/reactos/tools/mkhive/rtl.c

Modified: trunk/reactos/tools/mkhive/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/CMakeLists.txt?rev=64497&r1=64496&r2=64497&view=diff
==============================================================================
--- trunk/reactos/tools/mkhive/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/CMakeLists.txt   [iso-8859-1] Fri Oct  3 
13:15:10 2014
@@ -9,6 +9,8 @@
 list(APPEND SOURCE
     binhive.c
     cmi.c
+    cmindex.c
+    cmname.c
     mkhive.c
     reginf.c
     registry.c

Modified: trunk/reactos/tools/mkhive/cmi.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/cmi.c?rev=64497&r1=64496&r2=64497&view=diff
==============================================================================
--- trunk/reactos/tools/mkhive/cmi.c    [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/cmi.c    [iso-8859-1] Fri Oct  3 13:15:10 2014
@@ -26,7 +26,7 @@
 #define NDEBUG
 #include "mkhive.h"
 
-static PVOID
+PVOID
 NTAPI
 CmpAllocate(
        IN SIZE_T Size,
@@ -36,7 +36,7 @@
        return (PVOID) malloc((size_t)Size);
 }
 
-static VOID
+VOID
 NTAPI
 CmpFree(
        IN PVOID Ptr,
@@ -221,16 +221,13 @@
 }
 
 NTSTATUS
-CmiAddSubKey(
-       IN PCMHIVE RegistryHive,
-       IN PCM_KEY_NODE ParentKeyCell,
+CmiCreateSubKey(
+       IN PCMHIVE RegistryHive,
        IN HCELL_INDEX ParentKeyCellOffset,
        IN PCUNICODE_STRING SubKeyName,
        IN ULONG CreateOptions,
-       OUT PCM_KEY_NODE *pSubKeyCell,
-       OUT HCELL_INDEX *pBlockOffset)
-{
-       PCM_KEY_FAST_INDEX HashBlock;
+       OUT HCELL_INDEX* pNKBOffset)
+{
        HCELL_INDEX NKBOffset;
        PCM_KEY_NODE NewKeyCell;
        ULONG NewBlockSize;
@@ -240,8 +237,6 @@
        BOOLEAN Packable;
        HSTORAGE_TYPE Storage;
        ULONG i;
-
-       VERIFY_KEY_CELL(ParentKeyCell);
 
        /* Skip leading backslash */
        if (SubKeyName->Buffer[0] == L'\\')
@@ -325,90 +320,46 @@
                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)
-       {
-               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;
+       if (!CmpAddSubKey(&RegistryHive->Hive, ParentKeyCellOffset, 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

Modified: trunk/reactos/tools/mkhive/mkhive.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/mkhive.h?rev=64497&r1=64496&r2=64497&view=diff
==============================================================================
--- trunk/reactos/tools/mkhive/mkhive.h [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/mkhive.h [iso-8859-1] Fri Oct  3 13:15:10 2014
@@ -117,9 +117,12 @@
 #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 */

Modified: trunk/reactos/tools/mkhive/rtl.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/rtl.c?rev=64497&r1=64496&r2=64497&view=diff
==============================================================================
--- trunk/reactos/tools/mkhive/rtl.c    [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/rtl.c    [iso-8859-1] Fri Oct  3 13:15:10 2014
@@ -105,6 +105,37 @@
                WideString[2 * i + 1] = 0;
        }
        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


Reply via email to