- Move registry shareable types (not internal to ntoskrnl's configuration manager...
[reactos.git] / reactos / lib / cmlib / cmlib.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_H
9 #define CMLIB_H
10
11 #ifdef CMLIB_HOST
12 #include <host/typedefs.h>
13 #include <stdio.h>
14 #include <string.h>
15
16 // Definitions copied from <ntstatus.h>
17 // We only want to include host headers, so we define them manually
18 #define STATUS_SUCCESS ((NTSTATUS)0x00000000)
19 #define STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002)
20 #define STATUS_NO_MEMORY ((NTSTATUS)0xC0000017)
21 #define STATUS_INSUFFICIENT_RESOURCES ((NTSTATUS)0xC000009A)
22 #define STATUS_REGISTRY_CORRUPT ((NTSTATUS)0xC000014C)
23 #define STATUS_NOT_REGISTRY_FILE ((NTSTATUS)0xC000015C)
24 #define STATUS_REGISTRY_RECOVERED ((NTSTATUS)0x40000009)
25
26 #endif
27
28 #ifndef _TYPEDEFS_HOST_H
29 #include <ntddk.h>
30 #else
31 #define REG_OPTION_VOLATILE 1
32 #define OBJ_CASE_INSENSITIVE 0x00000040L
33 #define USHORT_MAX USHRT_MAX
34
35 VOID NTAPI
36 KeQuerySystemTime(
37 OUT PLARGE_INTEGER CurrentTime);
38
39 VOID NTAPI
40 RtlInitializeBitMap(
41 IN PRTL_BITMAP BitMapHeader,
42 IN PULONG BitMapBuffer,
43 IN ULONG SizeOfBitMap);
44
45 ULONG NTAPI
46 RtlFindSetBits(
47 IN PRTL_BITMAP BitMapHeader,
48 IN ULONG NumberToFind,
49 IN ULONG HintIndex);
50
51 VOID NTAPI
52 RtlSetBits(
53 IN PRTL_BITMAP BitMapHeader,
54 IN ULONG StartingIndex,
55 IN ULONG NumberToSet);
56
57 VOID NTAPI
58 RtlClearAllBits(
59 IN PRTL_BITMAP BitMapHeader);
60
61 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP) / 32]) >> ((BP) % 32)) & 0x1)
62
63 #endif
64
65 #ifndef ROUND_UP
66 #define ROUND_UP(a,b) ((((a)+(b)-1)/(b))*(b))
67 #define ROUND_DOWN(a,b) (((a)/(b))*(b))
68 #endif
69
70 #define TAG_CM 0x68742020
71
72 #define CMAPI NTAPI
73
74 #include <wchar.h>
75 #include "hivedata.h"
76 #include "cmdata.h"
77
78 #ifndef _CM_
79 typedef struct _EREGISTRY_HIVE
80 {
81 HHIVE Hive;
82 LIST_ENTRY HiveList;
83 UNICODE_STRING HiveFileName;
84 UNICODE_STRING LogFileName;
85 PCM_KEY_SECURITY RootSecurityCell;
86 ULONG Flags;
87 HANDLE HiveHandle;
88 HANDLE LogHandle;
89 } EREGISTRY_HIVE, *PEREGISTRY_HIVE;
90 #endif
91
92 /*
93 * Public functions.
94 */
95 NTSTATUS CMAPI
96 HvInitialize(
97 PHHIVE RegistryHive,
98 ULONG Operation,
99 ULONG HiveType,
100 ULONG HiveFlags,
101 PVOID HiveData OPTIONAL,
102 PALLOCATE_ROUTINE Allocate,
103 PFREE_ROUTINE Free,
104 PFILE_SET_SIZE_ROUTINE FileSetSize,
105 PFILE_WRITE_ROUTINE FileWrite,
106 PFILE_READ_ROUTINE FileRead,
107 PFILE_FLUSH_ROUTINE FileFlush,
108 ULONG Cluster OPTIONAL,
109 PUNICODE_STRING FileName);
110
111 VOID CMAPI
112 HvFree(
113 PHHIVE RegistryHive);
114
115 PVOID CMAPI
116 HvGetCell(
117 PHHIVE RegistryHive,
118 HCELL_INDEX CellOffset);
119
120 #define HvReleaseCell(h, c) \
121 if (h->ReleaseCellRoutine) h->ReleaseCellRoutine(h, c)
122
123 LONG CMAPI
124 HvGetCellSize(
125 PHHIVE RegistryHive,
126 PVOID Cell);
127
128 HCELL_INDEX CMAPI
129 HvAllocateCell(
130 PHHIVE RegistryHive,
131 SIZE_T Size,
132 HSTORAGE_TYPE Storage,
133 IN HCELL_INDEX Vicinity);
134
135 BOOLEAN CMAPI
136 HvIsCellAllocated(
137 IN PHHIVE RegistryHive,
138 IN HCELL_INDEX CellIndex
139 );
140
141 HCELL_INDEX CMAPI
142 HvReallocateCell(
143 PHHIVE RegistryHive,
144 HCELL_INDEX CellOffset,
145 ULONG Size);
146
147 VOID CMAPI
148 HvFreeCell(
149 PHHIVE RegistryHive,
150 HCELL_INDEX CellOffset);
151
152 BOOLEAN CMAPI
153 HvMarkCellDirty(
154 PHHIVE RegistryHive,
155 HCELL_INDEX CellOffset,
156 BOOLEAN HoldingLock);
157
158 BOOLEAN CMAPI
159 HvIsCellDirty(
160 IN PHHIVE Hive,
161 IN HCELL_INDEX Cell
162 );
163
164 BOOLEAN CMAPI
165 HvSyncHive(
166 PHHIVE RegistryHive);
167
168 BOOLEAN CMAPI
169 HvWriteHive(
170 PHHIVE RegistryHive);
171
172 BOOLEAN CMAPI
173 CmCreateRootNode(
174 PHHIVE Hive,
175 PCWSTR Name);
176
177 VOID CMAPI
178 CmPrepareHive(
179 PHHIVE RegistryHive);
180
181 /*
182 * Private functions.
183 */
184
185 PHBIN CMAPI
186 HvpAddBin(
187 PHHIVE RegistryHive,
188 ULONG Size,
189 HSTORAGE_TYPE Storage);
190
191 NTSTATUS CMAPI
192 HvpCreateHiveFreeCellList(
193 PHHIVE Hive);
194
195 ULONG CMAPI
196 HvpHiveHeaderChecksum(
197 PHBASE_BLOCK HiveHeader);
198
199 #endif /* CMLIB_H */