ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

hivebin.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:   registry manipulation library
00003  * LICENSE:   GPL - See COPYING in the top level directory
00004  * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
00005  *            Copyright 2005 Hartmut Birr
00006  *            Copyright 2001 - 2005 Eric Kohl
00007  */
00008 
00009 #include "cmlib.h"
00010 
00011 PHBIN CMAPI
00012 HvpAddBin(
00013    PHHIVE RegistryHive,
00014    ULONG Size,
00015    HSTORAGE_TYPE Storage)
00016 {
00017    PHMAP_ENTRY BlockList;
00018    PHBIN Bin;
00019    SIZE_T BinSize;
00020    ULONG i;
00021    ULONG BitmapSize;
00022    ULONG BlockCount;
00023    ULONG OldBlockListSize;
00024    PHCELL Block;
00025 
00026    BinSize = ROUND_UP(Size + sizeof(HBIN), HV_BLOCK_SIZE);
00027    BlockCount = (ULONG)(BinSize / HV_BLOCK_SIZE);
00028 
00029    Bin = RegistryHive->Allocate(BinSize, TRUE, TAG_CM);
00030    if (Bin == NULL)
00031       return NULL;
00032    RtlZeroMemory(Bin, BinSize);
00033 
00034    Bin->Signature = HV_BIN_SIGNATURE;
00035    Bin->FileOffset = RegistryHive->Storage[Storage].Length *
00036                     HV_BLOCK_SIZE;
00037    Bin->Size = (ULONG)BinSize;
00038 
00039    /* Allocate new block list */
00040    OldBlockListSize = RegistryHive->Storage[Storage].Length;
00041    BlockList = RegistryHive->Allocate(sizeof(HMAP_ENTRY) *
00042                                       (OldBlockListSize + BlockCount),
00043                                       TRUE,
00044                                       TAG_CM);
00045    if (BlockList == NULL)
00046    {
00047       RegistryHive->Free(Bin, 0);
00048       return NULL;
00049    }
00050 
00051    if (OldBlockListSize > 0)
00052    {
00053       RtlCopyMemory(BlockList, RegistryHive->Storage[Storage].BlockList,
00054                     OldBlockListSize * sizeof(HMAP_ENTRY));
00055       RegistryHive->Free(RegistryHive->Storage[Storage].BlockList, 0);
00056    }
00057 
00058    RegistryHive->Storage[Storage].BlockList = BlockList;
00059    RegistryHive->Storage[Storage].Length += BlockCount;
00060 
00061    for (i = 0; i < BlockCount; i++)
00062    {
00063       RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].BlockAddress =
00064          ((ULONG_PTR)Bin + (i * HV_BLOCK_SIZE));
00065       RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].BinAddress = (ULONG_PTR)Bin;
00066    }
00067 
00068    /* Initialize a free block in this heap. */
00069    Block = (PHCELL)(Bin + 1);
00070    Block->Size = (LONG)(BinSize - sizeof(HBIN));
00071 
00072    if (Storage == Stable)
00073    {
00074       /* Calculate bitmap size in bytes (always a multiple of 32 bits). */
00075       BitmapSize = ROUND_UP(RegistryHive->Storage[Stable].Length,
00076                             sizeof(ULONG) * 8) / 8;
00077 
00078       /* Grow bitmap if necessary. */
00079       if (BitmapSize > RegistryHive->DirtyVector.SizeOfBitMap / 8)
00080       {
00081          PULONG BitmapBuffer;
00082 
00083          BitmapBuffer = RegistryHive->Allocate(BitmapSize, TRUE, TAG_CM);
00084          RtlZeroMemory(BitmapBuffer, BitmapSize);
00085          if (RegistryHive->DirtyVector.SizeOfBitMap > 0)
00086          {
00087             ASSERT(RegistryHive->DirtyVector.Buffer);
00088             RtlCopyMemory(BitmapBuffer,
00089                RegistryHive->DirtyVector.Buffer,
00090                RegistryHive->DirtyVector.SizeOfBitMap / 8);
00091             RegistryHive->Free(RegistryHive->DirtyVector.Buffer, 0);
00092          }
00093          RtlInitializeBitMap(&RegistryHive->DirtyVector, BitmapBuffer,
00094                              BitmapSize * 8);
00095       }
00096 
00097       /* Mark new bin dirty. */
00098       RtlSetBits(&RegistryHive->DirtyVector,
00099                  Bin->FileOffset / HV_BLOCK_SIZE,
00100                  BlockCount);
00101    }
00102 
00103    return Bin;
00104 }

Generated on Sat May 26 2012 04:34:52 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.