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