f973ef114ccba4f1843779064e81bca4edc24113
2 * PROJECT: registry manipulation library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
5 * Copyright 2005 Hartmut Birr
6 * Copyright 2001 - 2005 Eric Kohl
15 HV_STORAGE_TYPE Storage
)
17 PHMAP_ENTRY BlockList
;
23 ULONG OldBlockListSize
;
26 BinSize
= ROUND_UP(Size
+ sizeof(HBIN
), HV_BLOCK_SIZE
);
27 BlockCount
= (ULONG
)(BinSize
/ HV_BLOCK_SIZE
);
29 Bin
= RegistryHive
->Allocate(BinSize
, TRUE
);
32 RtlZeroMemory(Bin
, BinSize
);
34 Bin
->Signature
= HV_BIN_SIGNATURE
;
35 Bin
->FileOffset
= RegistryHive
->Storage
[Storage
].Length
*
37 Bin
->Size
= (ULONG
)BinSize
;
39 /* Allocate new block list */
40 OldBlockListSize
= RegistryHive
->Storage
[Storage
].Length
;
41 BlockList
= RegistryHive
->Allocate(sizeof(HMAP_ENTRY
) *
42 (OldBlockListSize
+ BlockCount
), TRUE
);
43 if (BlockList
== NULL
)
45 RegistryHive
->Free(Bin
);
49 if (OldBlockListSize
> 0)
51 RtlCopyMemory(BlockList
, RegistryHive
->Storage
[Storage
].BlockList
,
52 OldBlockListSize
* sizeof(HMAP_ENTRY
));
53 RegistryHive
->Free(RegistryHive
->Storage
[Storage
].BlockList
);
56 RegistryHive
->Storage
[Storage
].BlockList
= BlockList
;
57 RegistryHive
->Storage
[Storage
].Length
+= BlockCount
;
59 for (i
= 0; i
< BlockCount
; i
++)
61 RegistryHive
->Storage
[Storage
].BlockList
[OldBlockListSize
+ i
].Block
=
62 ((ULONG_PTR
)Bin
+ (i
* HV_BLOCK_SIZE
));
63 RegistryHive
->Storage
[Storage
].BlockList
[OldBlockListSize
+ i
].Bin
= (ULONG_PTR
)Bin
;
66 /* Initialize a free block in this heap. */
67 Block
= (PHCELL
)(Bin
+ 1);
68 Block
->Size
= (LONG
)(BinSize
- sizeof(HBIN
));
70 if (Storage
== HvStable
)
72 /* Calculate bitmap size in bytes (always a multiple of 32 bits). */
73 BitmapSize
= ROUND_UP(RegistryHive
->Storage
[HvStable
].Length
,
74 sizeof(ULONG
) * 8) / 8;
76 /* Grow bitmap if necessary. */
77 if (BitmapSize
> RegistryHive
->DirtyVector
.SizeOfBitMap
/ 8)
81 BitmapBuffer
= RegistryHive
->Allocate(BitmapSize
, TRUE
);
82 RtlZeroMemory(BitmapBuffer
, BitmapSize
);
83 RtlCopyMemory(BitmapBuffer
,
84 RegistryHive
->DirtyVector
.Buffer
,
85 RegistryHive
->DirtyVector
.SizeOfBitMap
/ 8);
86 RegistryHive
->Free(RegistryHive
->DirtyVector
.Buffer
);
87 RtlInitializeBitMap(&RegistryHive
->DirtyVector
, BitmapBuffer
,
91 /* Mark new bin dirty. */
92 RtlSetBits(&RegistryHive
->DirtyVector
,
93 Bin
->FileOffset
/ HV_BLOCK_SIZE
,