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