[CMLIB]
[reactos.git] / reactos / lib / cmlib / hivecell.c
index 8151651..3d253a5 100644 (file)
@@ -109,7 +109,7 @@ HvMarkCellDirty(
 
    ASSERT(RegistryHive->ReadOnly == FALSE);
 
-   CMLTRACE(CMLIB_HCELL_DEBUG, "%s - Hive %p, CellIndex %08lx, HoldingLock %b\n",
+   CMLTRACE(CMLIB_HCELL_DEBUG, "%s - Hive %p, CellIndex %08lx, HoldingLock %u\n",
        __FUNCTION__, RegistryHive, CellIndex, HoldingLock);
 
    if ((CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT != Stable)
@@ -120,6 +120,7 @@ HvMarkCellDirty(
 
    RtlSetBits(&RegistryHive->DirtyVector,
               CellBlock, CellLastBlock - CellBlock);
+   RegistryHive->DirtyCount++;
    return TRUE;
 }
 
@@ -149,7 +150,7 @@ HvpComputeFreeListIndex(
    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,
@@ -157,23 +158,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,
-      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)
    {
-      if (Index > 255)
+      if (Index > 127)
          Index = 23;
       else
-         Index = FindFirstSet[Index] + 7;
+         Index = FindFirstSet[Index] + 16;
    }
 
    return Index;
@@ -235,10 +229,10 @@ HvpRemoveFree(
    /* Something bad happened, print a useful trace info and bugcheck */
    CMLTRACE(CMLIB_HCELL_DEBUG, "-- beginning of HvpRemoveFree trace --\n");
    CMLTRACE(CMLIB_HCELL_DEBUG, "block we are about to free: %08x\n", CellIndex);
-   CMLTRACE(CMLIB_HCELL_DEBUG, "chosen free list index: %d\n", Index);
+   CMLTRACE(CMLIB_HCELL_DEBUG, "chosen free list index: %u\n", Index);
    for (FreeListIndex = 0; FreeListIndex < 24; FreeListIndex++)
    {
-      CMLTRACE(CMLIB_HCELL_DEBUG, "free list [%d]: ", FreeListIndex);
+      CMLTRACE(CMLIB_HCELL_DEBUG, "free list [%u]: ", FreeListIndex);
       pFreeCellOffset = &RegistryHive->Storage[Storage].FreeDisplay[FreeListIndex];
       while (*pFreeCellOffset != HCELL_NIL)
       {
@@ -301,7 +295,7 @@ HvpCreateHiveFreeCellList(
       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)
@@ -337,7 +331,7 @@ HvpCreateHiveFreeCellList(
 HCELL_INDEX CMAPI
 HvAllocateCell(
    PHHIVE RegistryHive,
-   SIZE_T Size,
+   ULONG Size,
    HSTORAGE_TYPE Storage,
    HCELL_INDEX Vicinity)
 {
@@ -546,10 +540,9 @@ HvTrackCellRef(PHV_TRACK_CELL_REF CellRef,
         CellRef->StaticCount++;
         return TRUE;
     }
-    
+
     /* FIXME: TODO */
-    DPRINT1("ERROR: Too many references\n");
-    while (TRUE);
+    ASSERTMSG("ERROR: Too many references\n", FALSE);
     return FALSE;
 }
 
@@ -562,10 +555,10 @@ HvReleaseFreeCellRefArray(PHV_TRACK_CELL_REF CellRef)
 
     /* Any references? */
     if (CellRef->StaticCount > 0)
-    { 
+    {
         /* Sanity check */
         ASSERT(CellRef->StaticCount <= STATIC_CELL_PAIR_COUNT);
-        
+
         /* Loop them */
         for (i = 0; i < CellRef->StaticCount;i++)
         {
@@ -577,4 +570,4 @@ HvReleaseFreeCellRefArray(PHV_TRACK_CELL_REF CellRef)
         /* Free again */
         CellRef->StaticCount = 0;
     }
-}
\ No newline at end of file
+}