[CMLIB]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 13 Jan 2014 21:18:03 +0000 (21:18 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 13 Jan 2014 21:18:03 +0000 (21:18 +0000)
Pay back the US National Debt.
... well not entirely, but at least remove the "hack similar in magnitude to the US's National Debt"! As a nice side effect we can now load Windows 2003 hive files.

svn path=/trunk/; revision=61621

reactos/lib/cmlib/hivebin.c
reactos/lib/cmlib/hivecell.c
reactos/lib/cmlib/hiveinit.c
reactos/lib/cmlib/hivewrt.c

index 844e2f7..03cdf0b 100644 (file)
@@ -98,6 +98,9 @@ HvpAddBin(
       RtlSetBits(&RegistryHive->DirtyVector,
                  Bin->FileOffset / HV_BLOCK_SIZE,
                  BlockCount);
       RtlSetBits(&RegistryHive->DirtyVector,
                  Bin->FileOffset / HV_BLOCK_SIZE,
                  BlockCount);
+
+      /* Update size in the base block */
+      RegistryHive->BaseBlock->Length += BinSize;
    }
 
    return Bin;
    }
 
    return Bin;
index c82e22b..0c70907 100644 (file)
@@ -149,7 +149,7 @@ HvpComputeFreeListIndex(
    ULONG Size)
 {
    ULONG Index;
    ULONG Size)
 {
    ULONG Index;
-   static CCHAR FindFirstSet[256] = {
+   static CCHAR FindFirstSet[128] = {
       0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
       4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
       5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
       0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
       4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
       5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
@@ -157,23 +157,16 @@ HvpComputeFreeListIndex(
       6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
       6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
       6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
       6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
       6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
       6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
+      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
 
 
+   ASSERT(Size >= (1 << 3));
    Index = (Size >> 3) - 1;
    if (Index >= 16)
    {
    Index = (Size >> 3) - 1;
    if (Index >= 16)
    {
-      if (Index > 255)
+      if (Index > 127)
          Index = 23;
       else
          Index = 23;
       else
-         Index = FindFirstSet[Index] + 7;
+         Index = FindFirstSet[Index] + 16;
    }
 
    return Index;
    }
 
    return Index;
@@ -301,7 +294,7 @@ HvpCreateHiveFreeCellList(
       Hive->Storage[Stable].FreeDisplay[Index] = HCELL_NIL;
       Hive->Storage[Volatile].FreeDisplay[Index] = HCELL_NIL;
    }
       Hive->Storage[Stable].FreeDisplay[Index] = HCELL_NIL;
       Hive->Storage[Volatile].FreeDisplay[Index] = HCELL_NIL;
    }
-
+//__debugbreak();
    BlockOffset = 0;
    BlockIndex = 0;
    while (BlockIndex < Hive->Storage[Stable].Length)
    BlockOffset = 0;
    BlockIndex = 0;
    while (BlockIndex < Hive->Storage[Stable].Length)
index c864f94..7051498 100644 (file)
@@ -107,7 +107,7 @@ HvpCreateHive(
    BaseBlock->Format = HBASE_FORMAT_MEMORY;
    BaseBlock->Cluster = 1;
    BaseBlock->RootCell = HCELL_NIL;
    BaseBlock->Format = HBASE_FORMAT_MEMORY;
    BaseBlock->Cluster = 1;
    BaseBlock->RootCell = HCELL_NIL;
-   BaseBlock->Length = HV_BLOCK_SIZE;
+   BaseBlock->Length = 0;
    BaseBlock->Sequence1 = 1;
    BaseBlock->Sequence2 = 1;
    /* FIXME: Fill in the file name */
    BaseBlock->Sequence1 = 1;
    BaseBlock->Sequence2 = 1;
    /* FIXME: Fill in the file name */
@@ -145,11 +145,7 @@ HvpInitializeMemoryHive(
    PULONG BitmapBuffer;
    SIZE_T ChunkSize;
 
    PULONG BitmapBuffer;
    SIZE_T ChunkSize;
 
-   //
-   // This hack is similar in magnitude to the US's National Debt
-   //
    ChunkSize = ((PHBASE_BLOCK)ChunkBase)->Length;
    ChunkSize = ((PHBASE_BLOCK)ChunkBase)->Length;
-   ((PHBASE_BLOCK)ChunkBase)->Length = HV_BLOCK_SIZE;
    DPRINT("ChunkSize: %lx\n", ChunkSize);
 
    if (ChunkSize < sizeof(HBASE_BLOCK) ||
    DPRINT("ChunkSize: %lx\n", ChunkSize);
 
    if (ChunkSize < sizeof(HBASE_BLOCK) ||
@@ -172,7 +168,7 @@ HvpInitializeMemoryHive(
     * we go.
     */
 
     * we go.
     */
 
-   Hive->Storage[Stable].Length = (ULONG)(ChunkSize / HV_BLOCK_SIZE) - 1;
+   Hive->Storage[Stable].Length = (ULONG)(ChunkSize / HV_BLOCK_SIZE);
    Hive->Storage[Stable].BlockList =
       Hive->Allocate(Hive->Storage[Stable].Length *
                      sizeof(HMAP_ENTRY), FALSE, TAG_CM);
    Hive->Storage[Stable].BlockList =
       Hive->Allocate(Hive->Storage[Stable].Length *
                      sizeof(HMAP_ENTRY), FALSE, TAG_CM);
@@ -305,8 +301,6 @@ HvpGetHiveHeader(IN PHHIVE Hive,
         Hive->Free(BaseBlock, 0);
         BaseBlock = Hive->Allocate(PAGE_SIZE, TRUE, TAG_CM);
         if (!BaseBlock) return NoMemory;
         Hive->Free(BaseBlock, 0);
         BaseBlock = Hive->Allocate(PAGE_SIZE, TRUE, TAG_CM);
         if (!BaseBlock) return NoMemory;
-
-        //BaseBlock->Length = PAGE_SIZE; ??
     }
 
     /* Clear it */
     }
 
     /* Clear it */
@@ -384,8 +378,6 @@ HvLoadHive(IN PHHIVE Hive,
                             FileSize);
     if (!Result) return STATUS_NOT_REGISTRY_FILE;
 
                             FileSize);
     if (!Result) return STATUS_NOT_REGISTRY_FILE;
 
-    /* Apply "US National Debt" hack */
-    ((PHBASE_BLOCK)HiveData)->Length = FileSize;
 
     /* Free our base block... it's usless in this implementation */
     Hive->Free(BaseBlock, 0);
 
     /* Free our base block... it's usless in this implementation */
     Hive->Free(BaseBlock, 0);
index fb046fd..bdbce20 100644 (file)
@@ -27,6 +27,8 @@ HvpWriteLog(
    return TRUE;
 
    ASSERT(RegistryHive->ReadOnly == FALSE);
    return TRUE;
 
    ASSERT(RegistryHive->ReadOnly == FALSE);
+   ASSERT(RegistryHive->BaseBlock->Length ==
+          RegistryHive->Storage[Stable].Length * HV_BLOCK_SIZE);
 
    DPRINT("HvpWriteLog called\n");
 
 
    DPRINT("HvpWriteLog called\n");
 
@@ -150,6 +152,8 @@ HvpWriteHive(
    BOOLEAN Success;
 
    ASSERT(RegistryHive->ReadOnly == FALSE);
    BOOLEAN Success;
 
    ASSERT(RegistryHive->ReadOnly == FALSE);
+   ASSERT(RegistryHive->BaseBlock->Length ==
+          RegistryHive->Storage[Stable].Length * HV_BLOCK_SIZE);
 
    DPRINT("HvpWriteHive called\n");
 
 
    DPRINT("HvpWriteHive called\n");