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 2001 - 2005 Eric Kohl
13 #define HINIT_CREATE 0
14 #define HINIT_MEMORY 1
16 #define HINIT_MEMORY_INPLACE 3
18 #define HINIT_MAPFILE 5
23 #define HIVE_VOLATILE 1
24 #define HIVE_NOLAZYFLUSH 2
25 #define HIVE_HAS_BEEN_REPLACED 4
26 #define HIVE_HAS_BEEN_FREED 8
27 #define HIVE_UNKNOWN 0x10
28 #define HIVE_IS_UNLOADING 0x20
33 #define HFILE_TYPE_PRIMARY 0
34 #define HFILE_TYPE_LOG 1
35 #define HFILE_TYPE_EXTERNAL 2
36 #define HFILE_TYPE_MAX 3
41 #define HBLOCK_SIZE 0x1000
42 #define HSECTOR_SIZE 0x200
43 #define HSECTOR_COUNT 8
45 #define HV_LOG_HEADER_SIZE FIELD_OFFSET(HBASE_BLOCK, Reserved2)
48 // Hive structure identifiers
50 #define HV_HHIVE_SIGNATURE 0xbee0bee0
51 #define HV_HBLOCK_SIGNATURE 0x66676572 // "regf"
52 #define HV_HBIN_SIGNATURE 0x6e696268 // "hbin"
59 #define HSYS_WHISTLER_BETA1 4
60 #define HSYS_WHISTLER 5
61 #define HSYS_MINOR_SUPPORTED HSYS_WHISTLER
66 #define HBASE_FORMAT_MEMORY 1
76 * A handle to cell index. The highest bit specifies the cell storage and
77 * the other bits specify index into the hive file. The value HCELL_NULL
78 * (-1) is reserved for marking invalid cells.
80 typedef ULONG HCELL_INDEX
, *PHCELL_INDEX
;
85 #define HCELL_NIL MAXULONG
86 #define HCELL_CACHED 1
88 #define HCELL_TYPE_MASK 0x80000000
89 #define HCELL_BLOCK_MASK 0x7ffff000
90 #define HCELL_OFFSET_MASK 0x00000fff
91 #define HCELL_TYPE_SHIFT 31
92 #define HCELL_BLOCK_SHIFT 12
93 #define HCELL_OFFSET_SHIFT 0
95 #define HvGetCellType(Cell) \
96 ((ULONG)(((Cell) & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT))
97 #define HvGetCellBlock(Cell) \
98 ((ULONG)(((Cell) & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT))
106 #include <pshpack1.h>
111 * On-disk header for registry hive file.
114 #define HIVE_FILENAME_MAXLEN 31
116 typedef struct _HBASE_BLOCK
118 /* Hive base block identifier "regf" (0x66676572) */
121 /* Update counters */
125 /* When this hive file was last modified */
126 LARGE_INTEGER TimeStamp
;
128 /* Registry format major version (1) */
131 /* Registry format minor version (3)
132 Version 3 added fast indexes, version 5 has large value optimizations */
135 /* Registry file type (0 - Primary, 1 - Log) */
138 /* Registry format (1 is the only defined value so far) */
141 /* Offset into file from the byte after the end of the base block.
142 If the hive is volatile, this is the actual pointer to the CM_KEY_NODE */
143 HCELL_INDEX RootCell
;
145 /* Size in bytes of the full hive, minus the header, multiple of the block size (4KB) */
151 /* Last 31 UNICODE characters, plus terminating NULL character,
152 of the full name of the hive file */
153 WCHAR FileName
[HIVE_FILENAME_MAXLEN
+ 1];
157 /* Checksum of first 0x200 bytes */
160 ULONG Reserved2
[0x37E];
163 } HBASE_BLOCK
, *PHBASE_BLOCK
;
165 C_ASSERT(sizeof(HBASE_BLOCK
) == HBLOCK_SIZE
);
169 /* Hive bin identifier "hbin" (0x6E696268) */
172 /* Block offset of this bin */
173 HCELL_INDEX FileOffset
;
175 /* Size in bytes of this bin, multiple of the block size (4KB) */
180 /* When this bin was last modified */
181 LARGE_INTEGER TimeStamp
;
183 /* Unused (In-memory only) */
187 typedef struct _HCELL
189 /* <0 if used, >0 if free */
197 typedef struct _CELL_DATA
*
198 (CMAPI
*PGET_CELL_ROUTINE
)(
204 (CMAPI
*PRELEASE_CELL_ROUTINE
)(
210 (CMAPI
*PALLOCATE_ROUTINE
)(
217 (CMAPI
*PFREE_ROUTINE
)(
223 (CMAPI
*PFILE_READ_ROUTINE
)(
224 struct _HHIVE
*RegistryHive
,
232 (CMAPI
*PFILE_WRITE_ROUTINE
)(
233 struct _HHIVE
*RegistryHive
,
241 (CMAPI
*PFILE_SET_SIZE_ROUTINE
)(
242 struct _HHIVE
*RegistryHive
,
249 (CMAPI
*PFILE_FLUSH_ROUTINE
)(
250 struct _HHIVE
*RegistryHive
,
252 PLARGE_INTEGER FileOffset
,
256 typedef struct _HMAP_ENTRY
258 ULONG_PTR BlockAddress
;
259 ULONG_PTR BinAddress
;
260 struct _CM_VIEW_OF_FILE
*CmView
;
262 } HMAP_ENTRY
, *PHMAP_ENTRY
;
264 typedef struct _HMAP_TABLE
266 HMAP_ENTRY Table
[512];
267 } HMAP_TABLE
, *PHMAP_TABLE
;
269 typedef struct _HMAP_DIRECTORY
271 PHMAP_TABLE Directory
[2048];
272 } HMAP_DIRECTORY
, *PHMAP_DIRECTORY
;
278 PHMAP_ENTRY BlockList
; // PHMAP_TABLE SmallDir;
280 HCELL_INDEX FreeDisplay
[24]; // FREE_DISPLAY FreeDisplay[24];
285 typedef struct _HHIVE
287 /* Hive identifier (0xBEE0BEE0) */
291 PGET_CELL_ROUTINE GetCellRoutine
;
292 PRELEASE_CELL_ROUTINE ReleaseCellRoutine
;
293 PALLOCATE_ROUTINE Allocate
;
295 PFILE_SET_SIZE_ROUTINE FileSetSize
;
296 PFILE_WRITE_ROUTINE FileWrite
;
297 PFILE_READ_ROUTINE FileRead
;
298 PFILE_FLUSH_ROUTINE FileFlush
;
300 #if (NTDDI_VERSION >= NTDDI_WIN7)
301 PVOID HiveLoadFailure
; // PHIVE_LOAD_FAILURE
303 PHBASE_BLOCK BaseBlock
;
304 RTL_BITMAP DirtyVector
;
307 ULONG BaseBlockAlloc
;
311 #if (NTDDI_VERSION < NTDDI_VISTA) // NTDDI_LONGHORN
315 #if (NTDDI_VERSION >= NTDDI_VISTA) // NTDDI_LONGHORN
316 ULONG HvBinHeadersUse
;
317 ULONG HvFreeCellsUse
;
318 ULONG HvUsedCellsUse
;
319 ULONG CmUsedCellsUse
;
322 #if (NTDDI_VERSION < NTDDI_VISTA) // NTDDI_LONGHORN
329 ULONG StorageTypeCount
;
331 DUAL Storage
[HTYPE_COUNT
];
334 #define IsFreeCell(Cell) ((Cell)->Size >= 0)
335 #define IsUsedCell(Cell) ((Cell)->Size < 0)