Add a library "host_wcsfuncs" with implementations for UTF-16 string functions needed...
[reactos.git] / reactos / lib / cmlib / cminit.c
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 #include "cmlib.h"
9
10 ULONG CmlibTraceLevel = 0;
11
12 BOOLEAN CMAPI
13 CmCreateRootNode(
14 PHHIVE Hive,
15 PCWSTR Name)
16 {
17 PCM_KEY_NODE KeyCell;
18 HCELL_INDEX RootCellIndex;
19 SIZE_T NameSize;
20
21 /* Allocate the cell */
22 NameSize = utf16_wcslen(Name) * sizeof(WCHAR);
23 RootCellIndex = HvAllocateCell(Hive,
24 FIELD_OFFSET(CM_KEY_NODE, Name) + NameSize,
25 Stable,
26 HCELL_NIL);
27 if (RootCellIndex == HCELL_NIL) return FALSE;
28
29 /* Seutp the base block */
30 Hive->BaseBlock->RootCell = RootCellIndex;
31 Hive->BaseBlock->CheckSum = HvpHiveHeaderChecksum(Hive->BaseBlock);
32
33 /* Get the key cell */
34 KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, RootCellIndex);
35 if (!KeyCell) return FALSE;
36
37 /* Setup the cell */
38 KeyCell->Signature = (USHORT)CM_KEY_NODE_SIGNATURE;
39 KeyCell->Flags = KEY_HIVE_ENTRY | KEY_NO_DELETE;
40 KeyCell->LastWriteTime.QuadPart = 0;
41 KeyCell->Parent = HCELL_NIL;
42 KeyCell->SubKeyCounts[Stable] = 0;
43 KeyCell->SubKeyCounts[Volatile] = 0;
44 KeyCell->SubKeyLists[Stable] = HCELL_NIL;
45 KeyCell->SubKeyLists[Volatile] = HCELL_NIL;
46 KeyCell->ValueList.Count = 0;
47 KeyCell->ValueList.List = HCELL_NIL;
48 KeyCell->Security = HCELL_NIL;
49 KeyCell->Class = HCELL_NIL;
50 KeyCell->ClassLength = 0;
51 KeyCell->MaxNameLen = 0;
52 KeyCell->MaxClassLen = 0;
53 KeyCell->MaxValueNameLen = 0;
54 KeyCell->MaxValueDataLen = 0;
55
56 /* Write the name */
57 KeyCell->NameLength = (USHORT)NameSize;
58 memcpy(KeyCell->Name, Name, NameSize);
59
60 /* Return success */
61 HvReleaseCell(Hive, RootCellIndex);
62 return TRUE;
63 }
64
65 static VOID CMAPI
66 CmpPrepareKey(
67 PHHIVE RegistryHive,
68 PCM_KEY_NODE KeyCell);
69
70 static VOID CMAPI
71 CmpPrepareIndexOfKeys(
72 PHHIVE RegistryHive,
73 PCM_KEY_INDEX IndexCell)
74 {
75 ULONG i;
76
77 if (IndexCell->Signature == CM_KEY_INDEX_ROOT ||
78 IndexCell->Signature == CM_KEY_INDEX_LEAF)
79 {
80 for (i = 0; i < IndexCell->Count; i++)
81 {
82 PCM_KEY_INDEX SubIndexCell = HvGetCell(RegistryHive, IndexCell->List[i]);
83 CmpPrepareIndexOfKeys(RegistryHive, SubIndexCell);
84 }
85 }
86 else if (IndexCell->Signature == CM_KEY_FAST_LEAF ||
87 IndexCell->Signature == CM_KEY_HASH_LEAF)
88 {
89 PCM_KEY_FAST_INDEX HashCell = (PCM_KEY_FAST_INDEX)IndexCell;
90 for (i = 0; i < HashCell->Count; i++)
91 {
92 PCM_KEY_NODE SubKeyCell = HvGetCell(RegistryHive, HashCell->List[i].Cell);
93 CmpPrepareKey(RegistryHive, SubKeyCell);
94 }
95 }
96 else
97 {
98 DbgPrint("IndexCell->Signature %x\n", IndexCell->Signature);
99 ASSERT(FALSE);
100 }
101 }
102
103 static VOID CMAPI
104 CmpPrepareKey(
105 PHHIVE RegistryHive,
106 PCM_KEY_NODE KeyCell)
107 {
108 PCM_KEY_INDEX IndexCell;
109
110 ASSERT(KeyCell->Signature == CM_KEY_NODE_SIGNATURE);
111
112 KeyCell->SubKeyLists[Volatile] = HCELL_NIL;
113 KeyCell->SubKeyCounts[Volatile] = 0;
114
115 /* Enumerate and add subkeys */
116 if (KeyCell->SubKeyCounts[Stable] > 0)
117 {
118 IndexCell = HvGetCell(RegistryHive, KeyCell->SubKeyLists[Stable]);
119 CmpPrepareIndexOfKeys(RegistryHive, IndexCell);
120 }
121 }
122
123 VOID CMAPI
124 CmPrepareHive(
125 PHHIVE RegistryHive)
126 {
127 PCM_KEY_NODE RootCell;
128
129 RootCell = HvGetCell(RegistryHive, RegistryHive->BaseBlock->RootCell);
130 CmpPrepareKey(RegistryHive, RootCell);
131 }