1c180a6da43f31e5f9fcd595da93ea13cc86cbbc
[reactos.git] / sdk / lib / cmlib / hivedata.h
1 /*
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
6 */
7
8 #pragma once
9
10 //
11 // Hive operations
12 //
13 #define HINIT_CREATE 0
14 #define HINIT_MEMORY 1
15 #define HINIT_FILE 2
16 #define HINIT_MEMORY_INPLACE 3
17 #define HINIT_FLAT 4
18 #define HINIT_MAPFILE 5
19
20 //
21 // Hive flags
22 //
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
29
30 //
31 // Hive types
32 //
33 #define HFILE_TYPE_PRIMARY 0
34 #define HFILE_TYPE_LOG 1
35 #define HFILE_TYPE_EXTERNAL 2
36 #define HFILE_TYPE_MAX 3
37
38 //
39 // Hive sizes
40 //
41 #define HBLOCK_SIZE 0x1000
42 #define HSECTOR_SIZE 0x200
43 #define HSECTOR_COUNT 8
44
45 #define HV_LOG_HEADER_SIZE FIELD_OFFSET(HBASE_BLOCK, Reserved2)
46
47 //
48 // Hive structure identifiers
49 //
50 #define HV_HBLOCK_SIGNATURE 0x66676572 // "regf"
51 #define HV_HBIN_SIGNATURE 0x6e696268 // "hbin"
52
53 //
54 // Hive versions
55 //
56 #define HSYS_MAJOR 1
57 #define HSYS_MINOR 3
58 #define HSYS_WHISTLER_BETA1 4
59 #define HSYS_WHISTLER 5
60 #define HSYS_MINOR_SUPPORTED HSYS_WHISTLER
61
62 //
63 // Hive formats
64 //
65 #define HBASE_FORMAT_MEMORY 1
66
67 //
68 // Hive storage
69 //
70 #define HTYPE_COUNT 2
71
72 /**
73 * @name HCELL_INDEX
74 *
75 * A handle to cell index. The highest bit specifies the cell storage and
76 * the other bits specify index into the hive file. The value HCELL_NULL
77 * (-1) is reserved for marking invalid cells.
78 */
79 typedef ULONG HCELL_INDEX, *PHCELL_INDEX;
80
81 //
82 // Cell Magic Values
83 //
84 #define HCELL_NIL MAXULONG
85 #define HCELL_CACHED 1
86
87 #define HCELL_TYPE_MASK 0x80000000
88 #define HCELL_BLOCK_MASK 0x7ffff000
89 #define HCELL_OFFSET_MASK 0x00000fff
90 #define HCELL_TYPE_SHIFT 31
91 #define HCELL_BLOCK_SHIFT 12
92 #define HCELL_OFFSET_SHIFT 0
93
94 #define HvGetCellType(Cell) \
95 ((ULONG)(((Cell) & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT))
96 #define HvGetCellBlock(Cell) \
97 ((ULONG)(((Cell) & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT))
98
99 typedef enum
100 {
101 Stable = 0,
102 Volatile = 1
103 } HSTORAGE_TYPE;
104
105 #include <pshpack1.h>
106
107 /**
108 * @name HBASE_BLOCK
109 *
110 * On-disk header for registry hive file.
111 */
112
113 #define HIVE_FILENAME_MAXLEN 31
114
115 typedef struct _HBASE_BLOCK
116 {
117 /* Hive base block identifier "regf" (0x66676572) */
118 ULONG Signature;
119
120 /* Update counters */
121 ULONG Sequence1;
122 ULONG Sequence2;
123
124 /* When this hive file was last modified */
125 LARGE_INTEGER TimeStamp;
126
127 /* Registry format major version (1) */
128 ULONG Major;
129
130 /* Registry format minor version (3)
131 Version 3 added fast indexes, version 5 has large value optimizations */
132 ULONG Minor;
133
134 /* Registry file type (0 - Primary, 1 - Log) */
135 ULONG Type;
136
137 /* Registry format (1 is the only defined value so far) */
138 ULONG Format;
139
140 /* Offset into file from the byte after the end of the base block.
141 If the hive is volatile, this is the actual pointer to the CM_KEY_NODE */
142 HCELL_INDEX RootCell;
143
144 /* Size in bytes of the full hive, minus the header, multiple of the block size (4KB) */
145 ULONG Length;
146
147 /* (1?) */
148 ULONG Cluster;
149
150 /* Last 31 UNICODE characters, plus terminating NULL character,
151 of the full name of the hive file */
152 WCHAR FileName[HIVE_FILENAME_MAXLEN + 1];
153
154 ULONG Reserved1[99];
155
156 /* Checksum of first 0x200 bytes */
157 ULONG CheckSum;
158
159 ULONG Reserved2[0x37E];
160 ULONG BootType;
161 ULONG BootRecover;
162 } HBASE_BLOCK, *PHBASE_BLOCK;
163
164 C_ASSERT(sizeof(HBASE_BLOCK) == HBLOCK_SIZE);
165
166 typedef struct _HBIN
167 {
168 /* Hive bin identifier "hbin" (0x6E696268) */
169 ULONG Signature;
170
171 /* Block offset of this bin */
172 HCELL_INDEX FileOffset;
173
174 /* Size in bytes of this bin, multiple of the block size (4KB) */
175 ULONG Size;
176
177 ULONG Reserved1[2];
178
179 /* When this bin was last modified */
180 LARGE_INTEGER TimeStamp;
181
182 /* Unused (In-memory only) */
183 ULONG Spare;
184 } HBIN, *PHBIN;
185
186 typedef struct _HCELL
187 {
188 /* <0 if used, >0 if free */
189 LONG Size;
190 } HCELL, *PHCELL;
191
192 #include <poppack.h>
193
194 struct _HHIVE;
195
196 typedef struct _CELL_DATA*
197 (CMAPI *PGET_CELL_ROUTINE)(
198 struct _HHIVE *Hive,
199 HCELL_INDEX Cell
200 );
201
202 typedef VOID
203 (CMAPI *PRELEASE_CELL_ROUTINE)(
204 struct _HHIVE *Hive,
205 HCELL_INDEX Cell
206 );
207
208 typedef PVOID
209 (CMAPI *PALLOCATE_ROUTINE)(
210 SIZE_T Size,
211 BOOLEAN Paged,
212 ULONG Tag
213 );
214
215 typedef VOID
216 (CMAPI *PFREE_ROUTINE)(
217 PVOID Ptr,
218 ULONG Quota
219 );
220
221 typedef BOOLEAN
222 (CMAPI *PFILE_READ_ROUTINE)(
223 struct _HHIVE *RegistryHive,
224 ULONG FileType,
225 PULONG FileOffset,
226 PVOID Buffer,
227 SIZE_T BufferLength
228 );
229
230 typedef BOOLEAN
231 (CMAPI *PFILE_WRITE_ROUTINE)(
232 struct _HHIVE *RegistryHive,
233 ULONG FileType,
234 PULONG FileOffset,
235 PVOID Buffer,
236 SIZE_T BufferLength
237 );
238
239 typedef BOOLEAN
240 (CMAPI *PFILE_SET_SIZE_ROUTINE)(
241 struct _HHIVE *RegistryHive,
242 ULONG FileType,
243 ULONG FileSize,
244 ULONG OldfileSize
245 );
246
247 typedef BOOLEAN
248 (CMAPI *PFILE_FLUSH_ROUTINE)(
249 struct _HHIVE *RegistryHive,
250 ULONG FileType,
251 PLARGE_INTEGER FileOffset,
252 ULONG Length
253 );
254
255 typedef struct _HMAP_ENTRY
256 {
257 ULONG_PTR BlockAddress;
258 ULONG_PTR BinAddress;
259 struct _CM_VIEW_OF_FILE *CmView;
260 ULONG MemAlloc;
261 } HMAP_ENTRY, *PHMAP_ENTRY;
262
263 typedef struct _HMAP_TABLE
264 {
265 HMAP_ENTRY Table[512];
266 } HMAP_TABLE, *PHMAP_TABLE;
267
268 typedef struct _HMAP_DIRECTORY
269 {
270 PHMAP_TABLE Directory[2048];
271 } HMAP_DIRECTORY, *PHMAP_DIRECTORY;
272
273 typedef struct _DUAL
274 {
275 ULONG Length;
276 PHMAP_DIRECTORY Map;
277 PHMAP_ENTRY BlockList; // PHMAP_TABLE SmallDir;
278 ULONG Guard;
279 HCELL_INDEX FreeDisplay[24]; // FREE_DISPLAY FreeDisplay[24];
280 ULONG FreeSummary;
281 LIST_ENTRY FreeBins;
282 } DUAL, *PDUAL;
283
284 typedef struct _HHIVE
285 {
286 /* Hive identifier (0xBEE0BEE0) */
287 ULONG Signature;
288
289 /* Callbacks */
290 PGET_CELL_ROUTINE GetCellRoutine;
291 PRELEASE_CELL_ROUTINE ReleaseCellRoutine;
292 PALLOCATE_ROUTINE Allocate;
293 PFREE_ROUTINE Free;
294 PFILE_SET_SIZE_ROUTINE FileSetSize;
295 PFILE_WRITE_ROUTINE FileWrite;
296 PFILE_READ_ROUTINE FileRead;
297 PFILE_FLUSH_ROUTINE FileFlush;
298
299 #if (NTDDI_VERSION >= NTDDI_WIN7)
300 PVOID HiveLoadFailure; // PHIVE_LOAD_FAILURE
301 #endif
302 PHBASE_BLOCK BaseBlock;
303 RTL_BITMAP DirtyVector;
304 ULONG DirtyCount;
305 ULONG DirtyAlloc;
306 ULONG BaseBlockAlloc;
307 ULONG Cluster;
308 BOOLEAN Flat;
309 BOOLEAN ReadOnly;
310 #if (NTDDI_VERSION < NTDDI_VISTA) // NTDDI_LONGHORN
311 BOOLEAN Log;
312 #endif
313 BOOLEAN DirtyFlag;
314 #if (NTDDI_VERSION >= NTDDI_VISTA) // NTDDI_LONGHORN
315 ULONG HvBinHeadersUse;
316 ULONG HvFreeCellsUse;
317 ULONG HvUsedCellsUse;
318 ULONG CmUsedCellsUse;
319 #endif
320 ULONG HiveFlags;
321 #if (NTDDI_VERSION < NTDDI_VISTA) // NTDDI_LONGHORN
322 ULONG LogSize;
323 #else
324 ULONG CurrentLog;
325 ULONG LogSize[2];
326 #endif
327 ULONG RefreshCount;
328 ULONG StorageTypeCount;
329 ULONG Version;
330 DUAL Storage[HTYPE_COUNT];
331 } HHIVE, *PHHIVE;
332
333 #define IsFreeCell(Cell) ((Cell)->Size >= 0)
334 #define IsUsedCell(Cell) ((Cell)->Size < 0)