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