- Implement CmGetSystemControlValues and all related low-level Cm functionality requi...
[reactos.git] / reactos / ntoskrnl / config / cmvalue.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/config/cmvalue.c
5 * PURPOSE: Configuration Manager - Cell Values
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "ntoskrnl.h"
12 #include "cm.h"
13 #define NDEBUG
14 #include "debug.h"
15
16 /* GLOBALS *******************************************************************/
17
18 /* FUNCTIONS *****************************************************************/
19
20 HCELL_INDEX
21 NTAPI
22 CmpFindValueByName(IN PHHIVE Hive,
23 IN PCM_KEY_NODE KeyNode,
24 IN PUNICODE_STRING Name)
25 {
26 HCELL_INDEX CellIndex;
27
28 /* Call the main function */
29 if (!CmpFindNameInList(Hive,
30 &KeyNode->ValueList,
31 Name,
32 NULL,
33 &CellIndex))
34 {
35 /* Santy check */
36 ASSERT(CellIndex == HCELL_NIL);
37 }
38
39 /* Return the index */
40 return CellIndex;
41 }
42
43 BOOLEAN
44 NTAPI
45 CmpGetValueData(IN PHHIVE Hive,
46 IN PCM_KEY_VALUE Value,
47 IN PULONG Length,
48 OUT PVOID *Buffer,
49 OUT PBOOLEAN BufferAllocated,
50 OUT PHCELL_INDEX CellToRelease)
51 {
52 PAGED_CODE();
53
54 /* Sanity check */
55 ASSERT(Value->Signature == CM_KEY_VALUE_SIGNATURE);
56
57 /* Set failure defaults */
58 *BufferAllocated = FALSE;
59 *Buffer = NULL;
60 *CellToRelease = HCELL_NIL;
61
62 /* Check if this is a small key */
63 if (CmpIsKeyValueSmall(Length, Value->DataLength))
64 {
65 /* Return the data immediately */
66 *Buffer = &Value->Data;
67 return TRUE;
68 }
69
70 /* Check if this is a big cell */
71 if (CmpIsKeyValueBig(Hive, *Length))
72 {
73 /* FIXME: We don't support big cells */
74 DPRINT1("Unsupported cell type!\n");
75 while (TRUE);
76 }
77
78 /* Get the data from the cell */
79 *Buffer = HvGetCell(Hive, Value->Data);
80 if (!(*Buffer)) return FALSE;
81
82 /* Return success and the cell to be released */
83 *CellToRelease = Value->Data;
84 return TRUE;
85 }
86
87 PCELL_DATA
88 NTAPI
89 CmpValueToData(IN PHHIVE Hive,
90 IN PCM_KEY_VALUE Value,
91 OUT PULONG Length)
92 {
93 PCELL_DATA Buffer;
94 BOOLEAN BufferAllocated;
95 HCELL_INDEX CellToRelease;
96 PAGED_CODE();
97
98 /* Sanity check */
99 ASSERT(Hive->ReleaseCellRoutine == NULL);
100
101 /* Get the actual data */
102 if (!CmpGetValueData(Hive,
103 Value,
104 Length,
105 (PVOID)&Buffer,
106 &BufferAllocated,
107 &CellToRelease))
108 {
109 /* We failed */
110 ASSERT(BufferAllocated == FALSE);
111 ASSERT(Buffer == NULL);
112 return NULL;
113 }
114
115 /* This should never happen!*/
116 if (BufferAllocated)
117 {
118 /* Free the buffer and bugcheck */
119 ExFreePool(Buffer);
120 KEBUGCHECKEX(REGISTRY_ERROR, 8, 0, (ULONG_PTR)Hive, (ULONG_PTR)Value);
121 }
122
123 /* Otherwise, return the cell data */
124 return Buffer;
125 }