Merge from branch ReactX to Trunk,
[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 BOOLEAN CMAPI
11 CmCreateRootNode(
12 PHHIVE Hive,
13 PCWSTR Name)
14 {
15 PCM_KEY_NODE KeyCell;
16 HCELL_INDEX RootCellIndex;
17 SIZE_T NameSize;
18
19 /* Allocate the cell */
20 NameSize = wcslen(Name) * sizeof(WCHAR);
21 RootCellIndex = HvAllocateCell(Hive,
22 FIELD_OFFSET(CM_KEY_NODE, Name) + NameSize,
23 Stable,
24 HCELL_NIL);
25 if (RootCellIndex == HCELL_NIL) return FALSE;
26
27 /* Seutp the base block */
28 Hive->BaseBlock->RootCell = RootCellIndex;
29 Hive->BaseBlock->CheckSum = HvpHiveHeaderChecksum(Hive->BaseBlock);
30
31 /* Get the key cell */
32 KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, RootCellIndex);
33 if (!KeyCell) return FALSE;
34
35 /* Setup the cell */
36 KeyCell->Signature = (USHORT)CM_KEY_NODE_SIGNATURE;
37 KeyCell->Flags = KEY_HIVE_ENTRY | KEY_NO_DELETE;
38 KeyCell->LastWriteTime.QuadPart = 0;
39 KeyCell->Parent = HCELL_NIL;
40 KeyCell->SubKeyCounts[Stable] = 0;
41 KeyCell->SubKeyCounts[Volatile] = 0;
42 KeyCell->SubKeyLists[Stable] = HCELL_NIL;
43 KeyCell->SubKeyLists[Volatile] = HCELL_NIL;
44 KeyCell->ValueList.Count = 0;
45 KeyCell->ValueList.List = HCELL_NIL;
46 KeyCell->Security = HCELL_NIL;
47 KeyCell->Class = HCELL_NIL;
48 KeyCell->ClassLength = 0;
49 KeyCell->MaxNameLen = 0;
50 KeyCell->MaxClassLen = 0;
51 KeyCell->MaxValueNameLen = 0;
52 KeyCell->MaxValueDataLen = 0;
53
54 /* Write the name */
55 KeyCell->NameLength = (USHORT)NameSize;
56 memcpy(KeyCell->Name, Name, NameSize);
57
58 /* Return success */
59 HvReleaseCell(Hive, RootCellIndex);
60 return TRUE;
61 }
62
63 static VOID CMAPI
64 CmpPrepareKey(
65 PHHIVE RegistryHive,
66 PCM_KEY_NODE KeyCell)
67 {
68 PCM_KEY_NODE SubKeyCell;
69 PCM_KEY_FAST_INDEX HashCell;
70 ULONG i;
71
72 ASSERT(KeyCell->Signature == CM_KEY_NODE_SIGNATURE);
73
74 KeyCell->SubKeyLists[Volatile] = HCELL_NIL;
75 KeyCell->SubKeyCounts[Volatile] = 0;
76
77 /* Enumerate and add subkeys */
78 if (KeyCell->SubKeyCounts[Stable] > 0)
79 {
80 HashCell = HvGetCell(RegistryHive, KeyCell->SubKeyLists[Stable]);
81
82 for (i = 0; i < KeyCell->SubKeyCounts[Stable]; i++)
83 {
84 SubKeyCell = HvGetCell(RegistryHive, HashCell->List[i].Cell);
85 CmpPrepareKey(RegistryHive, SubKeyCell);
86 }
87 }
88 }
89
90 VOID CMAPI
91 CmPrepareHive(
92 PHHIVE RegistryHive)
93 {
94 PCM_KEY_NODE RootCell;
95
96 RootCell = HvGetCell(RegistryHive, RegistryHive->BaseBlock->RootCell);
97 CmpPrepareKey(RegistryHive, RootCell);
98 }