- Update cmlib interface to NT 5.2.
[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
28 //
29 // Hive types
30 //
31 #define HFILE_TYPE_PRIMARY 0
32 #define HFILE_TYPE_ALTERNATE 1
33 #define HFILE_TYPE_LOG 2
34 #define HFILE_TYPE_EXTERNAL 3
35 #define HFILE_TYPE_MAX 4
36
37 //
38 // Hive sizes
39 //
40 #define HBLOCK_SIZE 0x1000
41 #define HSECTOR_SIZE 0x200
42 #define HSECTOR_COUNT 8
43
44 #define HV_BLOCK_SIZE 4096
45 #define HV_LOG_HEADER_SIZE FIELD_OFFSET(HBASE_BLOCK, Reserved2)
46 #define HV_SIGNATURE 0x66676572
47 #define HV_BIN_SIGNATURE 0x6e696268
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 -1
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
93 typedef enum
94 {
95 Stable = 0,
96 Volatile = 1
97 } HSTORAGE_TYPE;
98
99 #ifdef CMLIB_HOST
100 #include <host/pshpack1.h>
101 #else
102 #include <pshpack1.h>
103 #endif
104
105 /**
106 * @name HBASE_BLOCK
107 *
108 * On-disk header for registry hive file.
109 */
110
111 typedef struct _HBASE_BLOCK
112 {
113 /* Hive identifier "regf" (0x66676572) */
114 ULONG Signature;
115
116 /* Update counter */
117 ULONG Sequence1;
118
119 /* Update counter */
120 ULONG Sequence2;
121
122 /* When this hive file was last modified */
123 LARGE_INTEGER TimeStamp;
124
125 /* Registry format major version (1) */
126 ULONG Major;
127
128 /* Registry format minor version (3)
129 Version 3 added fast indexes, version 5 has large value optimizations */
130 ULONG Minor;
131
132 /* Registry file type (0 - Primary, 1 - Log) */
133 ULONG Type;
134
135 /* Registry format (1 is the only defined value so far) */
136 ULONG Format;
137
138 /* Offset into file from the byte after the end of the base block.
139 If the hive is volatile, this is the actual pointer to the CM_KEY_NODE */
140 HCELL_INDEX RootCell;
141
142 /* Size of each hive block ? */
143 ULONG Length;
144
145 /* (1?) */
146 ULONG Cluster;
147
148 /* Name of hive file */
149 CHAR FileName[64];
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 #ifdef CMLIB_HOST
188 #include <host/poppack.h>
189 #else
190 #include <poppack.h>
191 #endif
192
193 #define IsFreeCell(Cell)(Cell->Size >= 0)
194 #define IsUsedCell(Cell)(Cell->Size < 0)
195
196 #endif /* CMLIB_HIVEDATA_H */