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