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