ReactOS  0.4.14-dev-50-g13bb5e2
cminit.c
Go to the documentation of this file.
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 
13 
14 // FIXME: This function must be replaced by CmpCreateRootNode from ntoskrnl/config/cmsysini.c
15 // (and CmpCreateRootNode be moved there).
18  PHHIVE Hive,
19  PCWSTR Name)
20 {
22  PCM_KEY_NODE KeyCell;
23  HCELL_INDEX RootCellIndex;
24 
25  /* Initialize the node name and allocate it */
27  RootCellIndex = HvAllocateCell(Hive,
29  CmpNameSize(Hive, &KeyName),
30  Stable,
31  HCELL_NIL);
32  if (RootCellIndex == HCELL_NIL) return FALSE;
33 
34  /* Seutp the base block */
35  Hive->BaseBlock->RootCell = RootCellIndex;
37 
38  /* Get the key cell */
39  KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, RootCellIndex);
40  if (!KeyCell)
41  {
42  HvFreeCell(Hive, RootCellIndex);
43  return FALSE;
44  }
45 
46  /* Setup the cell */
48  KeyCell->Flags = KEY_HIVE_ENTRY | KEY_NO_DELETE;
49  // KeQuerySystemTime(&KeyCell->LastWriteTime);
50  KeyCell->LastWriteTime.QuadPart = 0ULL;
51  KeyCell->Parent = HCELL_NIL;
52  KeyCell->SubKeyCounts[Stable] = 0;
53  KeyCell->SubKeyCounts[Volatile] = 0;
54  KeyCell->SubKeyLists[Stable] = HCELL_NIL;
55  KeyCell->SubKeyLists[Volatile] = HCELL_NIL;
56  KeyCell->ValueList.Count = 0;
57  KeyCell->ValueList.List = HCELL_NIL;
58  KeyCell->Security = HCELL_NIL;
59  KeyCell->Class = HCELL_NIL;
60  KeyCell->ClassLength = 0;
61  KeyCell->MaxNameLen = 0;
62  KeyCell->MaxClassLen = 0;
63  KeyCell->MaxValueNameLen = 0;
64  KeyCell->MaxValueDataLen = 0;
65  KeyCell->NameLength = CmpCopyName(Hive, KeyCell->Name, &KeyName);
66  if (KeyCell->NameLength < KeyName.Length) KeyCell->Flags |= KEY_COMP_NAME;
67 
68  /* Return success */
69  HvReleaseCell(Hive, RootCellIndex);
70  return TRUE;
71 }
72 
73 static VOID CMAPI
75  PHHIVE RegistryHive,
76  PCM_KEY_NODE KeyCell);
77 
78 static VOID CMAPI
80  PHHIVE RegistryHive,
81  PCM_KEY_INDEX IndexCell)
82 {
83  ULONG i;
84 
85  if (IndexCell->Signature == CM_KEY_INDEX_ROOT ||
86  IndexCell->Signature == CM_KEY_INDEX_LEAF)
87  {
88  for (i = 0; i < IndexCell->Count; i++)
89  {
90  PCM_KEY_INDEX SubIndexCell = HvGetCell(RegistryHive, IndexCell->List[i]);
91  if (SubIndexCell->Signature == CM_KEY_NODE_SIGNATURE)
92  CmpPrepareKey(RegistryHive, (PCM_KEY_NODE)SubIndexCell);
93  else
94  CmpPrepareIndexOfKeys(RegistryHive, SubIndexCell);
95  }
96  }
97  else if (IndexCell->Signature == CM_KEY_FAST_LEAF ||
98  IndexCell->Signature == CM_KEY_HASH_LEAF)
99  {
100  PCM_KEY_FAST_INDEX HashCell = (PCM_KEY_FAST_INDEX)IndexCell;
101  for (i = 0; i < HashCell->Count; i++)
102  {
103  PCM_KEY_NODE SubKeyCell = HvGetCell(RegistryHive, HashCell->List[i].Cell);
104  CmpPrepareKey(RegistryHive, SubKeyCell);
105  }
106  }
107  else
108  {
109  DPRINT1("IndexCell->Signature %x\n", IndexCell->Signature);
110  ASSERT(FALSE);
111  }
112 }
113 
114 static VOID CMAPI
116  PHHIVE RegistryHive,
117  PCM_KEY_NODE KeyCell)
118 {
119  PCM_KEY_INDEX IndexCell;
120 
122 
123  KeyCell->SubKeyCounts[Volatile] = 0;
124  // KeyCell->SubKeyLists[Volatile] = HCELL_NIL; // FIXME! Done only on Windows < XP.
125 
126  /* Enumerate and add subkeys */
127  if (KeyCell->SubKeyCounts[Stable] > 0)
128  {
129  IndexCell = HvGetCell(RegistryHive, KeyCell->SubKeyLists[Stable]);
130  CmpPrepareIndexOfKeys(RegistryHive, IndexCell);
131  }
132 }
133 
134 VOID CMAPI
136  PHHIVE RegistryHive)
137 {
138  PCM_KEY_NODE RootCell;
139 
140  RootCell = HvGetCell(RegistryHive, RegistryHive->BaseBlock->RootCell);
141  CmpPrepareKey(RegistryHive, RootCell);
142 }
#define KEY_COMP_NAME
Definition: cmdata.h:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
const uint16_t * PCWSTR
Definition: typedefs.h:55
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
#define TRUE
Definition: types.h:120
HCELL_INDEX List
Definition: cmdata.h:75
HCELL_INDEX Cell
Definition: cmdata.h:165
ULONG CMAPI HvpHiveHeaderChecksum(PHBASE_BLOCK HiveHeader)
Definition: hivesum.c:17
ULONG MaxValueNameLen
Definition: cmdata.h:111
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:303
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
USHORT ClassLength
Definition: cmdata.h:115
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
USHORT NameLength
Definition: cmdata.h:114
ULONG MaxNameLen
Definition: cmdata.h:109
HCELL_INDEX Class
Definition: cmdata.h:108
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CMAPI
Definition: cfgmgr32.h:41
USHORT Signature
Definition: cmdata.h:178
ULONG CheckSum
Definition: hivedata.h:158
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
static VOID CMAPI CmpPrepareIndexOfKeys(PHHIVE RegistryHive, PCM_KEY_INDEX IndexCell)
Definition: cminit.c:79
HCELL_INDEX SubKeyLists[HTYPE_COUNT]
Definition: cmdata.h:102
unsigned char BOOLEAN
#define CM_KEY_HASH_LEAF
Definition: cmdata.h:16
struct _CM_KEY_NODE * PCM_KEY_NODE
CM_INDEX List[ANYSIZE_ARRAY]
Definition: cmdata.h:190
BOOLEAN CMAPI CmCreateRootNode(PHHIVE Hive, PCWSTR Name)
Definition: cminit.c:17
#define CM_KEY_INDEX_ROOT
Definition: cmdata.h:13
struct _CM_KEY_FAST_INDEX * PCM_KEY_FAST_INDEX
#define ULL(a, b)
Definition: format_msg.c:27
static VOID CMAPI CmpPrepareKey(PHHIVE RegistryHive, PCM_KEY_NODE KeyCell)
Definition: cminit.c:115
CHILD_LIST ValueList
Definition: cmdata.h:103
USHORT Count
Definition: cmdata.h:179
USHORT NTAPI CmpCopyName(IN PHHIVE Hive, OUT PWCHAR Destination, IN PUNICODE_STRING Source)
Definition: cmname.c:21
HCELL_INDEX Parent
Definition: cmdata.h:96
ULONG HCELL_INDEX
Definition: hivedata.h:80
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
USHORT Signature
Definition: cmdata.h:92
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
USHORT NTAPI CmpNameSize(IN PHHIVE Hive, IN PUNICODE_STRING Name)
Definition: cmname.c:74
VOID CMAPI CmPrepareHive(PHHIVE RegistryHive)
Definition: cminit.c:135
LARGE_INTEGER LastWriteTime
Definition: cmdata.h:94
#define KEY_NO_DELETE
Definition: cmdata.h:33
HCELL_INDEX RootCell
Definition: hivedata.h:143
ULONG Count
Definition: cmdata.h:74
HCELL_INDEX Security
Definition: cmdata.h:107
HCELL_INDEX List[ANYSIZE_ARRAY]
Definition: cmdata.h:180
ULONG MaxClassLen
Definition: cmdata.h:110
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
ULONG MaxValueDataLen
Definition: cmdata.h:112
#define CM_KEY_FAST_LEAF
Definition: cmdata.h:15
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define CM_KEY_INDEX_LEAF
Definition: cmdata.h:14
ULONG CmlibTraceLevel
Definition: cminit.c:12
USHORT Flags
Definition: cmdata.h:93
LONGLONG QuadPart
Definition: typedefs.h:112
#define KEY_HIVE_ENTRY
Definition: cmdata.h:32