ReactOS  0.4.15-dev-1184-g23e04ae
hivebin.c File Reference
#include "cmlib.h"
Include dependency graph for hivebin.c:

Go to the source code of this file.

Functions

PHBIN CMAPI HvpAddBin (PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage)
 

Function Documentation

◆ HvpAddBin()

PHBIN CMAPI HvpAddBin ( PHHIVE  RegistryHive,
ULONG  Size,
HSTORAGE_TYPE  Storage 
)

Definition at line 12 of file hivebin.c.

16 {
17  PHMAP_ENTRY BlockList;
18  PHBIN Bin;
19  ULONG BinSize;
20  ULONG i;
21  ULONG BitmapSize;
22  ULONG BlockCount;
23  ULONG OldBlockListSize;
24  PHCELL Block;
25 
26  BinSize = ROUND_UP(Size + sizeof(HBIN), HBLOCK_SIZE);
27  BlockCount = BinSize / HBLOCK_SIZE;
28 
29  Bin = RegistryHive->Allocate(BinSize, TRUE, TAG_CM);
30  if (Bin == NULL)
31  return NULL;
32  RtlZeroMemory(Bin, BinSize);
33 
34  Bin->Signature = HV_HBIN_SIGNATURE;
35  Bin->FileOffset = RegistryHive->Storage[Storage].Length *
37  Bin->Size = BinSize;
38 
39  /* Allocate new block list */
40  OldBlockListSize = RegistryHive->Storage[Storage].Length;
41  BlockList = RegistryHive->Allocate(sizeof(HMAP_ENTRY) *
42  (OldBlockListSize + BlockCount),
43  TRUE,
44  TAG_CM);
45  if (BlockList == NULL)
46  {
47  RegistryHive->Free(Bin, 0);
48  return NULL;
49  }
50 
51  if (OldBlockListSize > 0)
52  {
53  RtlCopyMemory(BlockList, RegistryHive->Storage[Storage].BlockList,
54  OldBlockListSize * sizeof(HMAP_ENTRY));
55  RegistryHive->Free(RegistryHive->Storage[Storage].BlockList, 0);
56  }
57 
58  RegistryHive->Storage[Storage].BlockList = BlockList;
59  RegistryHive->Storage[Storage].Length += BlockCount;
60 
61  for (i = 0; i < BlockCount; i++)
62  {
63  RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].BlockAddress =
64  ((ULONG_PTR)Bin + (i * HBLOCK_SIZE));
65  RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].BinAddress = (ULONG_PTR)Bin;
66  }
67 
68  /* Initialize a free block in this heap. */
69  Block = (PHCELL)(Bin + 1);
70  Block->Size = (LONG)(BinSize - sizeof(HBIN));
71 
72  if (Storage == Stable)
73  {
74  /* Calculate bitmap size in bytes (always a multiple of 32 bits). */
75  BitmapSize = ROUND_UP(RegistryHive->Storage[Stable].Length,
76  sizeof(ULONG) * 8) / 8;
77 
78  /* Grow bitmap if necessary. */
79  if (BitmapSize > RegistryHive->DirtyVector.SizeOfBitMap / 8)
80  {
82 
83  BitmapBuffer = RegistryHive->Allocate(BitmapSize, TRUE, TAG_CM);
84  RtlZeroMemory(BitmapBuffer, BitmapSize);
85  if (RegistryHive->DirtyVector.SizeOfBitMap > 0)
86  {
87  ASSERT(RegistryHive->DirtyVector.Buffer);
89  RegistryHive->DirtyVector.Buffer,
90  RegistryHive->DirtyVector.SizeOfBitMap / 8);
91  RegistryHive->Free(RegistryHive->DirtyVector.Buffer, 0);
92  }
94  BitmapSize * 8);
95  }
96 
97  /* Mark new bin dirty. */
98  RtlSetBits(&RegistryHive->DirtyVector,
99  Bin->FileOffset / HBLOCK_SIZE,
100  BlockCount);
101 
102  /* Update size in the base block */
103  RegistryHive->BaseBlock->Length += BinSize;
104  }
105 
106  return Bin;
107 }
PULONG Buffer
Definition: typedefs.h:91
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define HBLOCK_SIZE
Definition: hivedata.h:41
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
RTL_BITMAP DirtyVector
Definition: hivedata.h:304
#define TRUE
Definition: types.h:120
Definition: hivedata.h:256
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
ULONG_PTR BlockAddress
Definition: hivedata.h:258
PFREE_ROUTINE Free
Definition: hivedata.h:294
PALLOCATE_ROUTINE Allocate
Definition: hivedata.h:293
ULONG Length
Definition: hivedata.h:146
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
Definition: bin.h:43
DUAL Storage[HTYPE_COUNT]
Definition: hivedata.h:331
#define HV_HBIN_SIGNATURE
Definition: hivedata.h:52
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static ULONG BitmapBuffer[(XMS_BLOCKS+31)/32]
Definition: himem.c:86
#define TAG_CM
Definition: cmlib.h:204
ULONG SizeOfBitMap
Definition: typedefs.h:90
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PHMAP_ENTRY BlockList
Definition: hivedata.h:278
LONG Size
Definition: hivedata.h:190
ULONG_PTR BinAddress
Definition: hivedata.h:259
NTSYSAPI void WINAPI RtlSetBits(PRTL_BITMAP, ULONG, ULONG)
unsigned int * PULONG
Definition: retypes.h:1
ULONG Length
Definition: hivedata.h:276
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
struct _HCELL * PHCELL
static IStorage Storage
Definition: ole2.c:3548

Referenced by HvAllocateCell().