1 | /* $Id: CFGM.cpp 36819 2011-04-22 19:40:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * CFGM - Configuration Manager.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2008 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /** @page pg_cfgm CFGM - The Configuration Manager
|
---|
19 | *
|
---|
20 | * The configuration manager is a directory containing the VM configuration at
|
---|
21 | * run time. It works in a manner similar to the windows registry - it's like a
|
---|
22 | * file system hierarchy, but the files (values) live in a separate name space
|
---|
23 | * and can include the path separators.
|
---|
24 | *
|
---|
25 | * The configuration is normally created via a callback passed to VMR3Create()
|
---|
26 | * via the pfnCFGMConstructor parameter. To make testcase writing a bit simpler,
|
---|
27 | * we allow the callback to be NULL, in which case a simple default
|
---|
28 | * configuration will be created by CFGMR3ConstructDefaultTree(). The
|
---|
29 | * Console::configConstructor() method in Main/ConsoleImpl2.cpp creates the
|
---|
30 | * configuration from the XML.
|
---|
31 | *
|
---|
32 | * Devices, drivers, services and other PDM stuff are given their own subtree
|
---|
33 | * where they are protected from accessing information of any parents. This is
|
---|
34 | * is implemented via the CFGMR3SetRestrictedRoot() API.
|
---|
35 | *
|
---|
36 | * Data validation out over the basic primitives is left to the caller. The
|
---|
37 | * caller is in a better position to know the proper validation rules of the
|
---|
38 | * individual properties.
|
---|
39 | *
|
---|
40 | * @see grp_cfgm
|
---|
41 | *
|
---|
42 | *
|
---|
43 | * @section sec_cfgm_primitives Data Primitives
|
---|
44 | *
|
---|
45 | * CFGM supports the following data primitives:
|
---|
46 | * - Integers. Representation is unsigned 64-bit. Boolean, unsigned and
|
---|
47 | * small integers, and pointers are all represented using this primitive.
|
---|
48 | * - Zero terminated character strings. These are of course UTF-8.
|
---|
49 | * - Variable length byte strings. This can be used to get/put binary
|
---|
50 | * objects like for instance RTMAC.
|
---|
51 | *
|
---|
52 | */
|
---|
53 |
|
---|
54 | /*******************************************************************************
|
---|
55 | * Header Files *
|
---|
56 | *******************************************************************************/
|
---|
57 | #define LOG_GROUP LOG_GROUP_CFGM
|
---|
58 | #include <VBox/vmm/cfgm.h>
|
---|
59 | #include <VBox/vmm/dbgf.h>
|
---|
60 | #include <VBox/vmm/mm.h>
|
---|
61 | #include "CFGMInternal.h"
|
---|
62 | #include <VBox/vmm/vm.h>
|
---|
63 | #include <VBox/err.h>
|
---|
64 |
|
---|
65 | #include <VBox/log.h>
|
---|
66 | #include <iprt/assert.h>
|
---|
67 | #include <iprt/string.h>
|
---|
68 | #include <iprt/uuid.h>
|
---|
69 |
|
---|
70 |
|
---|
71 | /*******************************************************************************
|
---|
72 | * Internal Functions *
|
---|
73 | *******************************************************************************/
|
---|
74 | static void cfgmR3DumpPath(PCFGMNODE pNode, PCDBGFINFOHLP pHlp);
|
---|
75 | static void cfgmR3Dump(PCFGMNODE pRoot, unsigned iLevel, PCDBGFINFOHLP pHlp);
|
---|
76 | static DECLCALLBACK(void) cfgmR3Info(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
|
---|
77 | static int cfgmR3ResolveNode(PCFGMNODE pNode, const char *pszPath, PCFGMNODE *ppChild);
|
---|
78 | static int cfgmR3ResolveLeaf(PCFGMNODE pNode, const char *pszName, PCFGMLEAF *ppLeaf);
|
---|
79 | static int cfgmR3InsertLeaf(PCFGMNODE pNode, const char *pszName, PCFGMLEAF *ppLeaf);
|
---|
80 | static void cfgmR3RemoveLeaf(PCFGMNODE pNode, PCFGMLEAF pLeaf);
|
---|
81 | static void cfgmR3FreeValue(PCFGMLEAF pLeaf);
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Constructs the configuration for the VM.
|
---|
87 | *
|
---|
88 | * @returns VBox status code.
|
---|
89 | * @param pVM Pointer to VM which configuration has not yet been loaded.
|
---|
90 | * @param pfnCFGMConstructor Pointer to callback function for constructing the VM configuration tree.
|
---|
91 | * This is called in the EM.
|
---|
92 | * @param pvUser The user argument passed to pfnCFGMConstructor.
|
---|
93 | * @thread EMT.
|
---|
94 | */
|
---|
95 | VMMR3DECL(int) CFGMR3Init(PVM pVM, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUser)
|
---|
96 | {
|
---|
97 | LogFlow(("CFGMR3Init: pfnCFGMConstructor=%p pvUser=%p\n", pfnCFGMConstructor, pvUser));
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * Init data members.
|
---|
101 | */
|
---|
102 | pVM->cfgm.s.pRoot = NULL;
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * Register DBGF into item.
|
---|
106 | */
|
---|
107 | int rc = DBGFR3InfoRegisterInternal(pVM, "cfgm", "Dumps a part of the CFGM tree. The argument indicates where to start.", cfgmR3Info);
|
---|
108 | AssertRCReturn(rc,rc);
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * Root Node.
|
---|
112 | */
|
---|
113 | PCFGMNODE pRoot = (PCFGMNODE)MMR3HeapAllocZ(pVM, MM_TAG_CFGM, sizeof(*pRoot));
|
---|
114 | if (!pRoot)
|
---|
115 | return VERR_NO_MEMORY;
|
---|
116 | pRoot->pVM = pVM;
|
---|
117 | pRoot->cchName = 0;
|
---|
118 | pVM->cfgm.s.pRoot = pRoot;
|
---|
119 |
|
---|
120 | /*
|
---|
121 | * Call the constructor if specified, if not use the default one.
|
---|
122 | */
|
---|
123 | if (pfnCFGMConstructor)
|
---|
124 | rc = pfnCFGMConstructor(pVM, pvUser);
|
---|
125 | else
|
---|
126 | rc = CFGMR3ConstructDefaultTree(pVM);
|
---|
127 | if (RT_SUCCESS(rc))
|
---|
128 | {
|
---|
129 | Log(("CFGMR3Init: Successfully constructed the configuration\n"));
|
---|
130 | CFGMR3Dump(CFGMR3GetRoot(pVM));
|
---|
131 | }
|
---|
132 | else
|
---|
133 | AssertMsgFailed(("Constructor failed with rc=%Rrc pfnCFGMConstructor=%p\n", rc, pfnCFGMConstructor));
|
---|
134 |
|
---|
135 | return rc;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Terminates the configuration manager.
|
---|
141 | *
|
---|
142 | * @returns VBox status code.
|
---|
143 | * @param pVM VM handle.
|
---|
144 | */
|
---|
145 | VMMR3DECL(int) CFGMR3Term(PVM pVM)
|
---|
146 | {
|
---|
147 | CFGMR3RemoveNode(pVM->cfgm.s.pRoot);
|
---|
148 | pVM->cfgm.s.pRoot = NULL;
|
---|
149 | return 0;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Gets the root node for the VM.
|
---|
155 | *
|
---|
156 | * @returns Pointer to root node.
|
---|
157 | * @param pVM VM handle.
|
---|
158 | */
|
---|
159 | VMMR3DECL(PCFGMNODE) CFGMR3GetRoot(PVM pVM)
|
---|
160 | {
|
---|
161 | return pVM->cfgm.s.pRoot;
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Gets the parent of a CFGM node.
|
---|
167 | *
|
---|
168 | * @returns Pointer to the parent node.
|
---|
169 | * @returns NULL if pNode is Root or pNode is the start of a
|
---|
170 | * restricted subtree (use CFGMr3GetParentEx() for that).
|
---|
171 | *
|
---|
172 | * @param pNode The node which parent we query.
|
---|
173 | */
|
---|
174 | VMMR3DECL(PCFGMNODE) CFGMR3GetParent(PCFGMNODE pNode)
|
---|
175 | {
|
---|
176 | if (pNode && !pNode->fRestrictedRoot)
|
---|
177 | return pNode->pParent;
|
---|
178 | return NULL;
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Gets the parent of a CFGM node.
|
---|
184 | *
|
---|
185 | * @returns Pointer to the parent node.
|
---|
186 | * @returns NULL if pNode is Root or pVM is not correct.
|
---|
187 | *
|
---|
188 | * @param pVM The VM handle, used as token that the caller is trusted.
|
---|
189 | * @param pNode The node which parent we query.
|
---|
190 | */
|
---|
191 | VMMR3DECL(PCFGMNODE) CFGMR3GetParentEx(PVM pVM, PCFGMNODE pNode)
|
---|
192 | {
|
---|
193 | if (pNode && pNode->pVM == pVM)
|
---|
194 | return pNode->pParent;
|
---|
195 | return NULL;
|
---|
196 | }
|
---|
197 |
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Query a child node.
|
---|
201 | *
|
---|
202 | * @returns Pointer to the specified node.
|
---|
203 | * @returns NULL if node was not found or pNode is NULL.
|
---|
204 | * @param pNode Node pszPath is relative to.
|
---|
205 | * @param pszPath Path to the child node or pNode.
|
---|
206 | * It's good style to end this with '/'.
|
---|
207 | */
|
---|
208 | VMMR3DECL(PCFGMNODE) CFGMR3GetChild(PCFGMNODE pNode, const char *pszPath)
|
---|
209 | {
|
---|
210 | PCFGMNODE pChild;
|
---|
211 | int rc = cfgmR3ResolveNode(pNode, pszPath, &pChild);
|
---|
212 | if (RT_SUCCESS(rc))
|
---|
213 | return pChild;
|
---|
214 | return NULL;
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * Query a child node by a format string.
|
---|
220 | *
|
---|
221 | * @returns Pointer to the specified node.
|
---|
222 | * @returns NULL if node was not found or pNode is NULL.
|
---|
223 | * @param pNode Node pszPath is relative to.
|
---|
224 | * @param pszPathFormat Path to the child node or pNode.
|
---|
225 | * It's good style to end this with '/'.
|
---|
226 | * @param ... Arguments to pszPathFormat.
|
---|
227 | */
|
---|
228 | VMMR3DECL(PCFGMNODE) CFGMR3GetChildF(PCFGMNODE pNode, const char *pszPathFormat, ...)
|
---|
229 | {
|
---|
230 | va_list Args;
|
---|
231 | va_start(Args, pszPathFormat);
|
---|
232 | PCFGMNODE pRet = CFGMR3GetChildFV(pNode, pszPathFormat, Args);
|
---|
233 | va_end(Args);
|
---|
234 | return pRet;
|
---|
235 | }
|
---|
236 |
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Query a child node by a format string.
|
---|
240 | *
|
---|
241 | * @returns Pointer to the specified node.
|
---|
242 | * @returns NULL if node was not found or pNode is NULL.
|
---|
243 | * @param pNode Node pszPath is relative to.
|
---|
244 | * @param pszPathFormat Path to the child node or pNode.
|
---|
245 | * It's good style to end this with '/'.
|
---|
246 | * @param Args Arguments to pszPathFormat.
|
---|
247 | */
|
---|
248 | VMMR3DECL(PCFGMNODE) CFGMR3GetChildFV(PCFGMNODE pNode, const char *pszPathFormat, va_list Args)
|
---|
249 | {
|
---|
250 | char *pszPath;
|
---|
251 | RTStrAPrintfV(&pszPath, pszPathFormat, Args);
|
---|
252 | if (pszPath)
|
---|
253 | {
|
---|
254 | PCFGMNODE pChild;
|
---|
255 | int rc = cfgmR3ResolveNode(pNode, pszPath, &pChild);
|
---|
256 | RTStrFree(pszPath);
|
---|
257 | if (RT_SUCCESS(rc))
|
---|
258 | return pChild;
|
---|
259 | }
|
---|
260 | return NULL;
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Gets the first child node.
|
---|
266 | * Use this to start an enumeration of child nodes.
|
---|
267 | *
|
---|
268 | * @returns Pointer to the first child.
|
---|
269 | * @returns NULL if no children.
|
---|
270 | * @param pNode Node to enumerate children for.
|
---|
271 | */
|
---|
272 | VMMR3DECL(PCFGMNODE) CFGMR3GetFirstChild(PCFGMNODE pNode)
|
---|
273 | {
|
---|
274 | return pNode ? pNode->pFirstChild : NULL;
|
---|
275 | }
|
---|
276 |
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * Gets the next sibling node.
|
---|
280 | * Use this to continue an enumeration.
|
---|
281 | *
|
---|
282 | * @returns Pointer to the first child.
|
---|
283 | * @returns NULL if no children.
|
---|
284 | * @param pCur Node to returned by a call to CFGMR3GetFirstChild()
|
---|
285 | * or successive calls to this function.
|
---|
286 | */
|
---|
287 | VMMR3DECL(PCFGMNODE) CFGMR3GetNextChild(PCFGMNODE pCur)
|
---|
288 | {
|
---|
289 | return pCur ? pCur->pNext : NULL;
|
---|
290 | }
|
---|
291 |
|
---|
292 |
|
---|
293 | /**
|
---|
294 | * Gets the name of the current node.
|
---|
295 | * (Needed for enumeration.)
|
---|
296 | *
|
---|
297 | * @returns VBox status code.
|
---|
298 | * @param pCur Node to returned by a call to CFGMR3GetFirstChild()
|
---|
299 | * or successive calls to CFGMR3GetNextChild().
|
---|
300 | * @param pszName Where to store the node name.
|
---|
301 | * @param cchName Size of the buffer pointed to by pszName (with terminator).
|
---|
302 | */
|
---|
303 | VMMR3DECL(int) CFGMR3GetName(PCFGMNODE pCur, char *pszName, size_t cchName)
|
---|
304 | {
|
---|
305 | int rc;
|
---|
306 | if (pCur)
|
---|
307 | {
|
---|
308 | if (cchName > pCur->cchName)
|
---|
309 | {
|
---|
310 | rc = VINF_SUCCESS;
|
---|
311 | memcpy(pszName, pCur->szName, pCur->cchName + 1);
|
---|
312 | }
|
---|
313 | else
|
---|
314 | rc = VERR_CFGM_NOT_ENOUGH_SPACE;
|
---|
315 | }
|
---|
316 | else
|
---|
317 | rc = VERR_CFGM_NO_NODE;
|
---|
318 | return rc;
|
---|
319 | }
|
---|
320 |
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * Gets the length of the current node's name.
|
---|
324 | * (Needed for enumeration.)
|
---|
325 | *
|
---|
326 | * @returns Node name length in bytes including the terminating null char.
|
---|
327 | * @returns 0 if pCur is NULL.
|
---|
328 | * @param pCur Node to returned by a call to CFGMR3GetFirstChild()
|
---|
329 | * or successive calls to CFGMR3GetNextChild().
|
---|
330 | */
|
---|
331 | VMMR3DECL(size_t) CFGMR3GetNameLen(PCFGMNODE pCur)
|
---|
332 | {
|
---|
333 | return pCur ? pCur->cchName + 1 : 0;
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Validates that the child nodes are within a set of valid names.
|
---|
339 | *
|
---|
340 | * @returns true if all names are found in pszzAllowed.
|
---|
341 | * @returns false if not.
|
---|
342 | * @param pNode The node which children should be examined.
|
---|
343 | * @param pszzValid List of valid names separated by '\\0' and ending with
|
---|
344 | * a double '\\0'.
|
---|
345 | *
|
---|
346 | * @deprecated Use CFGMR3ValidateConfig.
|
---|
347 | */
|
---|
348 | VMMR3DECL(bool) CFGMR3AreChildrenValid(PCFGMNODE pNode, const char *pszzValid)
|
---|
349 | {
|
---|
350 | if (pNode)
|
---|
351 | {
|
---|
352 | for (PCFGMNODE pChild = pNode->pFirstChild; pChild; pChild = pChild->pNext)
|
---|
353 | {
|
---|
354 | /* search pszzValid for the name */
|
---|
355 | const char *psz = pszzValid;
|
---|
356 | while (*psz)
|
---|
357 | {
|
---|
358 | size_t cch = strlen(psz);
|
---|
359 | if ( cch == pChild->cchName
|
---|
360 | && !memcmp(psz, pChild->szName, cch))
|
---|
361 | break;
|
---|
362 |
|
---|
363 | /* next */
|
---|
364 | psz += cch + 1;
|
---|
365 | }
|
---|
366 |
|
---|
367 | /* if at end of pszzValid we didn't find it => failure */
|
---|
368 | if (!*psz)
|
---|
369 | {
|
---|
370 | AssertMsgFailed(("Couldn't find '%s' in the valid values\n", pChild->szName));
|
---|
371 | return false;
|
---|
372 | }
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | /* all ok. */
|
---|
377 | return true;
|
---|
378 | }
|
---|
379 |
|
---|
380 |
|
---|
381 | /**
|
---|
382 | * Gets the first value of a node.
|
---|
383 | * Use this to start an enumeration of values.
|
---|
384 | *
|
---|
385 | * @returns Pointer to the first value.
|
---|
386 | * @param pCur The node (Key) which values to enumerate.
|
---|
387 | */
|
---|
388 | VMMR3DECL(PCFGMLEAF) CFGMR3GetFirstValue(PCFGMNODE pCur)
|
---|
389 | {
|
---|
390 | return pCur ? pCur->pFirstLeaf : NULL;
|
---|
391 | }
|
---|
392 |
|
---|
393 | /**
|
---|
394 | * Gets the next value in enumeration.
|
---|
395 | *
|
---|
396 | * @returns Pointer to the next value.
|
---|
397 | * @param pCur The current value as returned by this function or CFGMR3GetFirstValue().
|
---|
398 | */
|
---|
399 | VMMR3DECL(PCFGMLEAF) CFGMR3GetNextValue(PCFGMLEAF pCur)
|
---|
400 | {
|
---|
401 | return pCur ? pCur->pNext : NULL;
|
---|
402 | }
|
---|
403 |
|
---|
404 | /**
|
---|
405 | * Get the value name.
|
---|
406 | * (Needed for enumeration.)
|
---|
407 | *
|
---|
408 | * @returns VBox status code.
|
---|
409 | * @param pCur Value returned by a call to CFGMR3GetFirstValue()
|
---|
410 | * or successive calls to CFGMR3GetNextValue().
|
---|
411 | * @param pszName Where to store the value name.
|
---|
412 | * @param cchName Size of the buffer pointed to by pszName (with terminator).
|
---|
413 | */
|
---|
414 | VMMR3DECL(int) CFGMR3GetValueName(PCFGMLEAF pCur, char *pszName, size_t cchName)
|
---|
415 | {
|
---|
416 | int rc;
|
---|
417 | if (pCur)
|
---|
418 | {
|
---|
419 | if (cchName > pCur->cchName)
|
---|
420 | {
|
---|
421 | rc = VINF_SUCCESS;
|
---|
422 | memcpy(pszName, pCur->szName, pCur->cchName + 1);
|
---|
423 | }
|
---|
424 | else
|
---|
425 | rc = VERR_CFGM_NOT_ENOUGH_SPACE;
|
---|
426 | }
|
---|
427 | else
|
---|
428 | rc = VERR_CFGM_NO_NODE;
|
---|
429 | return rc;
|
---|
430 | }
|
---|
431 |
|
---|
432 |
|
---|
433 | /**
|
---|
434 | * Gets the length of the current node's name.
|
---|
435 | * (Needed for enumeration.)
|
---|
436 | *
|
---|
437 | * @returns Value name length in bytes including the terminating null char.
|
---|
438 | * @returns 0 if pCur is NULL.
|
---|
439 | * @param pCur Value returned by a call to CFGMR3GetFirstValue()
|
---|
440 | * or successive calls to CFGMR3GetNextValue().
|
---|
441 | */
|
---|
442 | VMMR3DECL(size_t) CFGMR3GetValueNameLen(PCFGMLEAF pCur)
|
---|
443 | {
|
---|
444 | return pCur ? pCur->cchName + 1 : 0;
|
---|
445 | }
|
---|
446 |
|
---|
447 |
|
---|
448 | /**
|
---|
449 | * Gets the value type.
|
---|
450 | * (For enumeration.)
|
---|
451 | *
|
---|
452 | * @returns VBox status code.
|
---|
453 | * @param pCur Value returned by a call to CFGMR3GetFirstValue()
|
---|
454 | * or successive calls to CFGMR3GetNextValue().
|
---|
455 | */
|
---|
456 | VMMR3DECL(CFGMVALUETYPE) CFGMR3GetValueType(PCFGMLEAF pCur)
|
---|
457 | {
|
---|
458 | Assert(pCur);
|
---|
459 | return pCur->enmType;
|
---|
460 | }
|
---|
461 |
|
---|
462 |
|
---|
463 | /**
|
---|
464 | * Validates that the values are within a set of valid names.
|
---|
465 | *
|
---|
466 | * @returns true if all names are found in pszzAllowed.
|
---|
467 | * @returns false if not.
|
---|
468 | * @param pNode The node which values should be examined.
|
---|
469 | * @param pszzValid List of valid names separated by '\\0' and ending with
|
---|
470 | * a double '\\0'.
|
---|
471 | * @deprecated Use CFGMR3ValidateConfig.
|
---|
472 | */
|
---|
473 | VMMR3DECL(bool) CFGMR3AreValuesValid(PCFGMNODE pNode, const char *pszzValid)
|
---|
474 | {
|
---|
475 | if (pNode)
|
---|
476 | {
|
---|
477 | for (PCFGMLEAF pLeaf = pNode->pFirstLeaf; pLeaf; pLeaf = pLeaf->pNext)
|
---|
478 | {
|
---|
479 | /* search pszzValid for the name */
|
---|
480 | const char *psz = pszzValid;
|
---|
481 | while (*psz)
|
---|
482 | {
|
---|
483 | size_t cch = strlen(psz);
|
---|
484 | if ( cch == pLeaf->cchName
|
---|
485 | && !memcmp(psz, pLeaf->szName, cch))
|
---|
486 | break;
|
---|
487 |
|
---|
488 | /* next */
|
---|
489 | psz += cch + 1;
|
---|
490 | }
|
---|
491 |
|
---|
492 | /* if at end of pszzValid we didn't find it => failure */
|
---|
493 | if (!*psz)
|
---|
494 | {
|
---|
495 | AssertMsgFailed(("Couldn't find '%s' in the valid values\n", pLeaf->szName));
|
---|
496 | return false;
|
---|
497 | }
|
---|
498 | }
|
---|
499 | }
|
---|
500 |
|
---|
501 | /* all ok. */
|
---|
502 | return true;
|
---|
503 | }
|
---|
504 |
|
---|
505 |
|
---|
506 |
|
---|
507 | /**
|
---|
508 | * Query value type.
|
---|
509 | *
|
---|
510 | * @returns VBox status code.
|
---|
511 | * @param pNode Which node to search for pszName in.
|
---|
512 | * @param pszName Name of an integer value.
|
---|
513 | * @param penmType Where to store the type.
|
---|
514 | */
|
---|
515 | VMMR3DECL(int) CFGMR3QueryType(PCFGMNODE pNode, const char *pszName, PCFGMVALUETYPE penmType)
|
---|
516 | {
|
---|
517 | PCFGMLEAF pLeaf;
|
---|
518 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
519 | if (RT_SUCCESS(rc))
|
---|
520 | {
|
---|
521 | if (penmType)
|
---|
522 | *penmType = pLeaf->enmType;
|
---|
523 | }
|
---|
524 | return rc;
|
---|
525 | }
|
---|
526 |
|
---|
527 |
|
---|
528 | /**
|
---|
529 | * Query value size.
|
---|
530 | * This works on all types of values.
|
---|
531 | *
|
---|
532 | * @returns VBox status code.
|
---|
533 | * @param pNode Which node to search for pszName in.
|
---|
534 | * @param pszName Name of an integer value.
|
---|
535 | * @param pcb Where to store the value size.
|
---|
536 | */
|
---|
537 | VMMR3DECL(int) CFGMR3QuerySize(PCFGMNODE pNode, const char *pszName, size_t *pcb)
|
---|
538 | {
|
---|
539 | PCFGMLEAF pLeaf;
|
---|
540 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
541 | if (RT_SUCCESS(rc))
|
---|
542 | {
|
---|
543 | switch (pLeaf->enmType)
|
---|
544 | {
|
---|
545 | case CFGMVALUETYPE_INTEGER:
|
---|
546 | *pcb = sizeof(pLeaf->Value.Integer.u64);
|
---|
547 | break;
|
---|
548 |
|
---|
549 | case CFGMVALUETYPE_STRING:
|
---|
550 | *pcb = pLeaf->Value.String.cb;
|
---|
551 | break;
|
---|
552 |
|
---|
553 | case CFGMVALUETYPE_BYTES:
|
---|
554 | *pcb = pLeaf->Value.Bytes.cb;
|
---|
555 | break;
|
---|
556 |
|
---|
557 | default:
|
---|
558 | rc = VERR_INTERNAL_ERROR;
|
---|
559 | AssertMsgFailed(("Invalid value type %d\n", pLeaf->enmType));
|
---|
560 | break;
|
---|
561 | }
|
---|
562 | }
|
---|
563 | return rc;
|
---|
564 | }
|
---|
565 |
|
---|
566 |
|
---|
567 | /**
|
---|
568 | * Query integer value.
|
---|
569 | *
|
---|
570 | * @returns VBox status code.
|
---|
571 | * @param pNode Which node to search for pszName in.
|
---|
572 | * @param pszName Name of an integer value.
|
---|
573 | * @param pu64 Where to store the integer value.
|
---|
574 | */
|
---|
575 | VMMR3DECL(int) CFGMR3QueryInteger(PCFGMNODE pNode, const char *pszName, uint64_t *pu64)
|
---|
576 | {
|
---|
577 | PCFGMLEAF pLeaf;
|
---|
578 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
579 | if (RT_SUCCESS(rc))
|
---|
580 | {
|
---|
581 | if (pLeaf->enmType == CFGMVALUETYPE_INTEGER)
|
---|
582 | *pu64 = pLeaf->Value.Integer.u64;
|
---|
583 | else
|
---|
584 | rc = VERR_CFGM_NOT_INTEGER;
|
---|
585 | }
|
---|
586 | return rc;
|
---|
587 | }
|
---|
588 |
|
---|
589 |
|
---|
590 | /**
|
---|
591 | * Query integer value with default.
|
---|
592 | *
|
---|
593 | * @returns VBox status code.
|
---|
594 | * @param pNode Which node to search for pszName in.
|
---|
595 | * @param pszName Name of an integer value.
|
---|
596 | * @param pu64 Where to store the integer value. This is set to the default on failure.
|
---|
597 | * @param u64Def The default value. This is always set.
|
---|
598 | */
|
---|
599 | VMMR3DECL(int) CFGMR3QueryIntegerDef(PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def)
|
---|
600 | {
|
---|
601 | PCFGMLEAF pLeaf;
|
---|
602 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
603 | if (RT_SUCCESS(rc))
|
---|
604 | {
|
---|
605 | if (pLeaf->enmType == CFGMVALUETYPE_INTEGER)
|
---|
606 | *pu64 = pLeaf->Value.Integer.u64;
|
---|
607 | else
|
---|
608 | rc = VERR_CFGM_NOT_INTEGER;
|
---|
609 | }
|
---|
610 |
|
---|
611 | if (RT_FAILURE(rc))
|
---|
612 | {
|
---|
613 | *pu64 = u64Def;
|
---|
614 | if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
|
---|
615 | rc = VINF_SUCCESS;
|
---|
616 | }
|
---|
617 |
|
---|
618 | return rc;
|
---|
619 | }
|
---|
620 |
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * Query zero terminated character value.
|
---|
624 | *
|
---|
625 | * @returns VBox status code.
|
---|
626 | * @param pNode Which node to search for pszName in.
|
---|
627 | * @param pszName Name of a zero terminate character value.
|
---|
628 | * @param pszString Where to store the string.
|
---|
629 | * @param cchString Size of the string buffer. (Includes terminator.)
|
---|
630 | */
|
---|
631 | VMMR3DECL(int) CFGMR3QueryString(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString)
|
---|
632 | {
|
---|
633 | PCFGMLEAF pLeaf;
|
---|
634 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
635 | if (RT_SUCCESS(rc))
|
---|
636 | {
|
---|
637 | if (pLeaf->enmType == CFGMVALUETYPE_STRING)
|
---|
638 | {
|
---|
639 | size_t cbSrc = pLeaf->Value.String.cb;
|
---|
640 | if (cchString >= cbSrc)
|
---|
641 | {
|
---|
642 | memcpy(pszString, pLeaf->Value.String.psz, cbSrc);
|
---|
643 | memset(pszString + cbSrc, 0, cchString - cbSrc);
|
---|
644 | }
|
---|
645 | else
|
---|
646 | rc = VERR_CFGM_NOT_ENOUGH_SPACE;
|
---|
647 | }
|
---|
648 | else
|
---|
649 | rc = VERR_CFGM_NOT_STRING;
|
---|
650 | }
|
---|
651 | return rc;
|
---|
652 | }
|
---|
653 |
|
---|
654 |
|
---|
655 | /**
|
---|
656 | * Query zero terminated character value with default.
|
---|
657 | *
|
---|
658 | * @returns VBox status code.
|
---|
659 | * @param pNode Which node to search for pszName in.
|
---|
660 | * @param pszName Name of a zero terminate character value.
|
---|
661 | * @param pszString Where to store the string. This will not be set on overflow error.
|
---|
662 | * @param cchString Size of the string buffer. (Includes terminator.)
|
---|
663 | * @param pszDef The default value.
|
---|
664 | */
|
---|
665 | VMMR3DECL(int) CFGMR3QueryStringDef(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef)
|
---|
666 | {
|
---|
667 | PCFGMLEAF pLeaf;
|
---|
668 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
669 | if (RT_SUCCESS(rc))
|
---|
670 | {
|
---|
671 | if (pLeaf->enmType == CFGMVALUETYPE_STRING)
|
---|
672 | {
|
---|
673 | size_t cbSrc = pLeaf->Value.String.cb;
|
---|
674 | if (cchString >= cbSrc)
|
---|
675 | {
|
---|
676 | memcpy(pszString, pLeaf->Value.String.psz, cbSrc);
|
---|
677 | memset(pszString + cbSrc, 0, cchString - cbSrc);
|
---|
678 | }
|
---|
679 | else
|
---|
680 | rc = VERR_CFGM_NOT_ENOUGH_SPACE;
|
---|
681 | }
|
---|
682 | else
|
---|
683 | rc = VERR_CFGM_NOT_STRING;
|
---|
684 | }
|
---|
685 |
|
---|
686 | if (RT_FAILURE(rc) && rc != VERR_CFGM_NOT_ENOUGH_SPACE)
|
---|
687 | {
|
---|
688 | size_t cchDef = strlen(pszDef);
|
---|
689 | if (cchString > cchDef)
|
---|
690 | {
|
---|
691 | memcpy(pszString, pszDef, cchDef);
|
---|
692 | memset(pszString + cchDef, 0, cchString - cchDef);
|
---|
693 | if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
|
---|
694 | rc = VINF_SUCCESS;
|
---|
695 | }
|
---|
696 | else if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
|
---|
697 | rc = VERR_CFGM_NOT_ENOUGH_SPACE;
|
---|
698 | }
|
---|
699 |
|
---|
700 | return rc;
|
---|
701 | }
|
---|
702 |
|
---|
703 |
|
---|
704 | /**
|
---|
705 | * Query byte string value.
|
---|
706 | *
|
---|
707 | * @returns VBox status code.
|
---|
708 | * @param pNode Which node to search for pszName in.
|
---|
709 | * @param pszName Name of a byte string value.
|
---|
710 | * @param pvData Where to store the binary data.
|
---|
711 | * @param cbData Size of buffer pvData points too.
|
---|
712 | */
|
---|
713 | VMMR3DECL(int) CFGMR3QueryBytes(PCFGMNODE pNode, const char *pszName, void *pvData, size_t cbData)
|
---|
714 | {
|
---|
715 | PCFGMLEAF pLeaf;
|
---|
716 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
717 | if (RT_SUCCESS(rc))
|
---|
718 | {
|
---|
719 | if (pLeaf->enmType == CFGMVALUETYPE_BYTES)
|
---|
720 | {
|
---|
721 | if (cbData >= pLeaf->Value.Bytes.cb)
|
---|
722 | {
|
---|
723 | memcpy(pvData, pLeaf->Value.Bytes.pau8, pLeaf->Value.Bytes.cb);
|
---|
724 | memset((char *)pvData + pLeaf->Value.Bytes.cb, 0, cbData - pLeaf->Value.Bytes.cb);
|
---|
725 | }
|
---|
726 | else
|
---|
727 | rc = VERR_CFGM_NOT_ENOUGH_SPACE;
|
---|
728 | }
|
---|
729 | else
|
---|
730 | rc = VERR_CFGM_NOT_BYTES;
|
---|
731 | }
|
---|
732 | return rc;
|
---|
733 | }
|
---|
734 |
|
---|
735 |
|
---|
736 | /**
|
---|
737 | * Validate one level of a configuration node.
|
---|
738 | *
|
---|
739 | * This replaces the CFGMR3AreChildrenValid and CFGMR3AreValuesValid APIs.
|
---|
740 | *
|
---|
741 | * @returns VBox status code.
|
---|
742 | *
|
---|
743 | * When an error is returned, both VMSetError and AssertLogRelMsgFailed
|
---|
744 | * have been called. So, all the caller needs to do is to propagate
|
---|
745 | * the error status up to PDM.
|
---|
746 | *
|
---|
747 | * @param pNode The node to validate.
|
---|
748 | * @param pszNode The node path, always ends with a slash. Use
|
---|
749 | * "/" for the root config node.
|
---|
750 | * @param pszValidValues Patterns describing the valid value names. See
|
---|
751 | * RTStrSimplePatternMultiMatch for details on the
|
---|
752 | * pattern syntax.
|
---|
753 | * @param pszValidNodes Patterns describing the valid node (key) names.
|
---|
754 | * See RTStrSimplePatternMultiMatch for details on
|
---|
755 | * the pattern syntax.
|
---|
756 | * @param pszWho Who is calling.
|
---|
757 | * @param uInstance The instance number of the caller.
|
---|
758 | */
|
---|
759 | VMMR3DECL(int) CFGMR3ValidateConfig(PCFGMNODE pNode, const char *pszNode,
|
---|
760 | const char *pszValidValues, const char *pszValidNodes,
|
---|
761 | const char *pszWho, uint32_t uInstance)
|
---|
762 | {
|
---|
763 | /* Input validation. */
|
---|
764 | AssertPtrNullReturn(pNode, VERR_INVALID_POINTER);
|
---|
765 | AssertPtrReturn(pszNode, VERR_INVALID_POINTER);
|
---|
766 | Assert(*pszNode && pszNode[strlen(pszNode) - 1] == '/');
|
---|
767 | AssertPtrReturn(pszValidValues, VERR_INVALID_POINTER);
|
---|
768 | AssertPtrReturn(pszValidNodes, VERR_INVALID_POINTER);
|
---|
769 | AssertPtrReturn(pszWho, VERR_INVALID_POINTER);
|
---|
770 |
|
---|
771 | if (pNode)
|
---|
772 | {
|
---|
773 | /*
|
---|
774 | * Enumerate the leafs and check them against pszValidValues.
|
---|
775 | */
|
---|
776 | for (PCFGMLEAF pLeaf = pNode->pFirstLeaf; pLeaf; pLeaf = pLeaf->pNext)
|
---|
777 | {
|
---|
778 | if (!RTStrSimplePatternMultiMatch(pszValidValues, RTSTR_MAX,
|
---|
779 | pLeaf->szName, pLeaf->cchName,
|
---|
780 | NULL))
|
---|
781 | {
|
---|
782 | AssertLogRelMsgFailed(("%s/%u: Value '%s/%s' didn't match '%s'\n",
|
---|
783 | pszWho, uInstance, pszNode, pLeaf->szName, pszValidValues));
|
---|
784 | return VMSetError(pNode->pVM, VERR_CFGM_CONFIG_UNKNOWN_VALUE, RT_SRC_POS,
|
---|
785 | N_("Unknown configuration value '%s/%s' found in the configuration of %s instance #%u"),
|
---|
786 | pszNode, pLeaf->szName, pszWho, uInstance);
|
---|
787 | }
|
---|
788 |
|
---|
789 | }
|
---|
790 |
|
---|
791 | /*
|
---|
792 | * Enumerate the child nodes and check them against pszValidNodes.
|
---|
793 | */
|
---|
794 | for (PCFGMNODE pChild = pNode->pFirstChild; pChild; pChild = pChild->pNext)
|
---|
795 | {
|
---|
796 | if (!RTStrSimplePatternMultiMatch(pszValidNodes, RTSTR_MAX,
|
---|
797 | pChild->szName, pChild->cchName,
|
---|
798 | NULL))
|
---|
799 | {
|
---|
800 | AssertLogRelMsgFailed(("%s/%u: Node '%s/%s' didn't match '%s'\n",
|
---|
801 | pszWho, uInstance, pszNode, pChild->szName, pszValidNodes));
|
---|
802 | return VMSetError(pNode->pVM, VERR_CFGM_CONFIG_UNKNOWN_NODE, RT_SRC_POS,
|
---|
803 | N_("Unknown configuration node '%s/%s' found in the configuration of %s instance #%u"),
|
---|
804 | pszNode, pChild->szName, pszWho, uInstance);
|
---|
805 | }
|
---|
806 | }
|
---|
807 | }
|
---|
808 |
|
---|
809 | /* All is well. */
|
---|
810 | return VINF_SUCCESS;
|
---|
811 | }
|
---|
812 |
|
---|
813 |
|
---|
814 |
|
---|
815 | /**
|
---|
816 | * Populates the CFGM tree with the default configuration.
|
---|
817 | *
|
---|
818 | * This assumes an empty tree and is intended for testcases and such that only
|
---|
819 | * need to do very small adjustments to the config.
|
---|
820 | *
|
---|
821 | * @returns VBox status code.
|
---|
822 | * @param pVM VM handle.
|
---|
823 | */
|
---|
824 | VMMR3DECL(int) CFGMR3ConstructDefaultTree(PVM pVM)
|
---|
825 | {
|
---|
826 | int rc;
|
---|
827 | int rcAll = VINF_SUCCESS;
|
---|
828 | #define UPDATERC() do { if (RT_FAILURE(rc) && RT_SUCCESS(rcAll)) rcAll = rc; } while (0)
|
---|
829 |
|
---|
830 | PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
|
---|
831 | AssertReturn(pRoot, VERR_WRONG_ORDER);
|
---|
832 |
|
---|
833 | /*
|
---|
834 | * Create VM default values.
|
---|
835 | */
|
---|
836 | rc = CFGMR3InsertString(pRoot, "Name", "Default VM");
|
---|
837 | UPDATERC();
|
---|
838 | rc = CFGMR3InsertInteger(pRoot, "RamSize", 128U * _1M);
|
---|
839 | UPDATERC();
|
---|
840 | rc = CFGMR3InsertInteger(pRoot, "RamHoleSize", 512U * _1M);
|
---|
841 | UPDATERC();
|
---|
842 | rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10);
|
---|
843 | UPDATERC();
|
---|
844 | rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1);
|
---|
845 | UPDATERC();
|
---|
846 | /** @todo CFGM Defaults: RawR0, PATMEnabled and CASMEnabled needs attention later. */
|
---|
847 | rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1);
|
---|
848 | UPDATERC();
|
---|
849 | rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1);
|
---|
850 | UPDATERC();
|
---|
851 | rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1);
|
---|
852 | UPDATERC();
|
---|
853 |
|
---|
854 | /*
|
---|
855 | * PDM.
|
---|
856 | */
|
---|
857 | PCFGMNODE pPdm;
|
---|
858 | rc = CFGMR3InsertNode(pRoot, "PDM", &pPdm);
|
---|
859 | UPDATERC();
|
---|
860 | PCFGMNODE pDevices = NULL;
|
---|
861 | rc = CFGMR3InsertNode(pPdm, "Devices", &pDevices);
|
---|
862 | UPDATERC();
|
---|
863 | rc = CFGMR3InsertInteger(pDevices, "LoadBuiltin", 1); /* boolean */
|
---|
864 | UPDATERC();
|
---|
865 | PCFGMNODE pDrivers = NULL;
|
---|
866 | rc = CFGMR3InsertNode(pPdm, "Drivers", &pDrivers);
|
---|
867 | UPDATERC();
|
---|
868 | rc = CFGMR3InsertInteger(pDrivers, "LoadBuiltin", 1); /* boolean */
|
---|
869 | UPDATERC();
|
---|
870 |
|
---|
871 |
|
---|
872 | /*
|
---|
873 | * Devices
|
---|
874 | */
|
---|
875 | pDevices = NULL;
|
---|
876 | rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices);
|
---|
877 | UPDATERC();
|
---|
878 | /* device */
|
---|
879 | PCFGMNODE pDev = NULL;
|
---|
880 | PCFGMNODE pInst = NULL;
|
---|
881 | PCFGMNODE pCfg = NULL;
|
---|
882 | #if 0
|
---|
883 | PCFGMNODE pLunL0 = NULL;
|
---|
884 | PCFGMNODE pLunL1 = NULL;
|
---|
885 | #endif
|
---|
886 |
|
---|
887 | /*
|
---|
888 | * PC Arch.
|
---|
889 | */
|
---|
890 | rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev);
|
---|
891 | UPDATERC();
|
---|
892 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
893 | UPDATERC();
|
---|
894 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */
|
---|
895 | UPDATERC();
|
---|
896 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
897 | UPDATERC();
|
---|
898 |
|
---|
899 | /*
|
---|
900 | * PC Bios.
|
---|
901 | */
|
---|
902 | rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev);
|
---|
903 | UPDATERC();
|
---|
904 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
905 | UPDATERC();
|
---|
906 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */
|
---|
907 | UPDATERC();
|
---|
908 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
909 | UPDATERC();
|
---|
910 | rc = CFGMR3InsertInteger(pCfg, "RamSize", 128U * _1M);
|
---|
911 | UPDATERC();
|
---|
912 | rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", 512U * _1M);
|
---|
913 | UPDATERC();
|
---|
914 | rc = CFGMR3InsertString(pCfg, "BootDevice0", "IDE");
|
---|
915 | UPDATERC();
|
---|
916 | rc = CFGMR3InsertString(pCfg, "BootDevice1", "NONE");
|
---|
917 | UPDATERC();
|
---|
918 | rc = CFGMR3InsertString(pCfg, "BootDevice2", "NONE");
|
---|
919 | UPDATERC();
|
---|
920 | rc = CFGMR3InsertString(pCfg, "BootDevice3", "NONE");
|
---|
921 | UPDATERC();
|
---|
922 | rc = CFGMR3InsertString(pCfg, "HardDiskDevice", "piix3ide");
|
---|
923 | UPDATERC();
|
---|
924 | rc = CFGMR3InsertString(pCfg, "FloppyDevice", "");
|
---|
925 | UPDATERC();
|
---|
926 | RTUUID Uuid;
|
---|
927 | RTUuidClear(&Uuid);
|
---|
928 | rc = CFGMR3InsertBytes(pCfg, "UUID", &Uuid, sizeof(Uuid));
|
---|
929 | UPDATERC();
|
---|
930 |
|
---|
931 | /*
|
---|
932 | * PCI bus.
|
---|
933 | */
|
---|
934 | rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */
|
---|
935 | UPDATERC();
|
---|
936 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
937 | UPDATERC();
|
---|
938 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */
|
---|
939 | UPDATERC();
|
---|
940 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
941 | UPDATERC();
|
---|
942 |
|
---|
943 | /*
|
---|
944 | * PS/2 keyboard & mouse
|
---|
945 | */
|
---|
946 | rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev);
|
---|
947 | UPDATERC();
|
---|
948 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
949 | UPDATERC();
|
---|
950 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
951 | UPDATERC();
|
---|
952 | #if 0
|
---|
953 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
|
---|
954 | UPDATERC();
|
---|
955 | rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue");
|
---|
956 | UPDATERC();
|
---|
957 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
|
---|
958 | UPDATERC();
|
---|
959 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64);
|
---|
960 | UPDATERC();
|
---|
961 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
962 | UPDATERC();
|
---|
963 | rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard");
|
---|
964 | UPDATERC();
|
---|
965 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg);
|
---|
966 | UPDATERC();
|
---|
967 | #endif
|
---|
968 | #if 0
|
---|
969 | rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0);
|
---|
970 | UPDATERC();
|
---|
971 | rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue");
|
---|
972 | UPDATERC();
|
---|
973 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
|
---|
974 | UPDATERC();
|
---|
975 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128);
|
---|
976 | UPDATERC();
|
---|
977 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
978 | UPDATERC();
|
---|
979 | rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse");
|
---|
980 | UPDATERC();
|
---|
981 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg);
|
---|
982 | UPDATERC();
|
---|
983 | #endif
|
---|
984 |
|
---|
985 | /*
|
---|
986 | * i8254 Programmable Interval Timer And Dummy Speaker
|
---|
987 | */
|
---|
988 | rc = CFGMR3InsertNode(pDevices, "i8254", &pDev);
|
---|
989 | UPDATERC();
|
---|
990 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
991 | UPDATERC();
|
---|
992 | #ifdef DEBUG
|
---|
993 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */
|
---|
994 | UPDATERC();
|
---|
995 | #endif
|
---|
996 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
997 | UPDATERC();
|
---|
998 |
|
---|
999 | /*
|
---|
1000 | * i8259 Programmable Interrupt Controller.
|
---|
1001 | */
|
---|
1002 | rc = CFGMR3InsertNode(pDevices, "i8259", &pDev);
|
---|
1003 | UPDATERC();
|
---|
1004 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
1005 | UPDATERC();
|
---|
1006 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1007 | UPDATERC();
|
---|
1008 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
1009 | UPDATERC();
|
---|
1010 |
|
---|
1011 | /*
|
---|
1012 | * RTC MC146818.
|
---|
1013 | */
|
---|
1014 | rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev);
|
---|
1015 | UPDATERC();
|
---|
1016 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
1017 | UPDATERC();
|
---|
1018 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
1019 | UPDATERC();
|
---|
1020 |
|
---|
1021 | /*
|
---|
1022 | * VGA.
|
---|
1023 | */
|
---|
1024 | rc = CFGMR3InsertNode(pDevices, "vga", &pDev);
|
---|
1025 | UPDATERC();
|
---|
1026 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
1027 | UPDATERC();
|
---|
1028 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1029 | UPDATERC();
|
---|
1030 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
1031 | UPDATERC();
|
---|
1032 | rc = CFGMR3InsertInteger(pCfg, "VRamSize", 4 * _1M);
|
---|
1033 | UPDATERC();
|
---|
1034 |
|
---|
1035 | /* Bios logo. */
|
---|
1036 | rc = CFGMR3InsertInteger(pCfg, "FadeIn", 1);
|
---|
1037 | UPDATERC();
|
---|
1038 | rc = CFGMR3InsertInteger(pCfg, "FadeOut", 1);
|
---|
1039 | UPDATERC();
|
---|
1040 | rc = CFGMR3InsertInteger(pCfg, "LogoTime", 0);
|
---|
1041 | UPDATERC();
|
---|
1042 | rc = CFGMR3InsertString(pCfg, "LogoFile", "");
|
---|
1043 | UPDATERC();
|
---|
1044 |
|
---|
1045 | #if 0
|
---|
1046 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
|
---|
1047 | UPDATERC();
|
---|
1048 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay");
|
---|
1049 | UPDATERC();
|
---|
1050 | #endif
|
---|
1051 |
|
---|
1052 | /*
|
---|
1053 | * IDE controller.
|
---|
1054 | */
|
---|
1055 | rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */
|
---|
1056 | UPDATERC();
|
---|
1057 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
1058 | UPDATERC();
|
---|
1059 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1060 | UPDATERC();
|
---|
1061 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
1062 | UPDATERC();
|
---|
1063 |
|
---|
1064 |
|
---|
1065 |
|
---|
1066 | /*
|
---|
1067 | * ...
|
---|
1068 | */
|
---|
1069 |
|
---|
1070 | #undef UPDATERC
|
---|
1071 | return rcAll;
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 |
|
---|
1075 |
|
---|
1076 |
|
---|
1077 | /**
|
---|
1078 | * Resolves a path reference to a child node.
|
---|
1079 | *
|
---|
1080 | * @returns VBox status code.
|
---|
1081 | * @param pNode Which node to search for pszName in.
|
---|
1082 | * @param pszPath Path to the child node.
|
---|
1083 | * @param ppChild Where to store the pointer to the child node.
|
---|
1084 | */
|
---|
1085 | static int cfgmR3ResolveNode(PCFGMNODE pNode, const char *pszPath, PCFGMNODE *ppChild)
|
---|
1086 | {
|
---|
1087 | *ppChild = NULL;
|
---|
1088 | if (!pNode)
|
---|
1089 | return VERR_CFGM_NO_PARENT;
|
---|
1090 | PCFGMNODE pChild = NULL;
|
---|
1091 | for (;;)
|
---|
1092 | {
|
---|
1093 | /* skip leading slashes. */
|
---|
1094 | while (*pszPath == '/')
|
---|
1095 | pszPath++;
|
---|
1096 |
|
---|
1097 | /* End of path? */
|
---|
1098 | if (!*pszPath)
|
---|
1099 | {
|
---|
1100 | if (!pChild)
|
---|
1101 | return VERR_CFGM_INVALID_CHILD_PATH;
|
---|
1102 | *ppChild = pChild;
|
---|
1103 | return VINF_SUCCESS;
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | /* find end of component. */
|
---|
1107 | const char *pszNext = strchr(pszPath, '/');
|
---|
1108 | if (!pszNext)
|
---|
1109 | pszNext = strchr(pszPath, '\0');
|
---|
1110 | RTUINT cchName = pszNext - pszPath;
|
---|
1111 |
|
---|
1112 | /* search child list. */
|
---|
1113 | pChild = pNode->pFirstChild;
|
---|
1114 | for ( ; pChild; pChild = pChild->pNext)
|
---|
1115 | if (pChild->cchName == cchName)
|
---|
1116 | {
|
---|
1117 | int iDiff = memcmp(pszPath, pChild->szName, cchName);
|
---|
1118 | if (iDiff <= 0)
|
---|
1119 | {
|
---|
1120 | if (iDiff != 0)
|
---|
1121 | pChild = NULL;
|
---|
1122 | break;
|
---|
1123 | }
|
---|
1124 | }
|
---|
1125 | if (!pChild)
|
---|
1126 | return VERR_CFGM_CHILD_NOT_FOUND;
|
---|
1127 |
|
---|
1128 | /* next iteration */
|
---|
1129 | pNode = pChild;
|
---|
1130 | pszPath = pszNext;
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | /* won't get here */
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 |
|
---|
1137 | /**
|
---|
1138 | * Resolves a path reference to a child node.
|
---|
1139 | *
|
---|
1140 | * @returns VBox status code.
|
---|
1141 | * @param pNode Which node to search for pszName in.
|
---|
1142 | * @param pszName Name of a byte string value.
|
---|
1143 | * @param ppLeaf Where to store the pointer to the leaf node.
|
---|
1144 | */
|
---|
1145 | static int cfgmR3ResolveLeaf(PCFGMNODE pNode, const char *pszName, PCFGMLEAF *ppLeaf)
|
---|
1146 | {
|
---|
1147 | *ppLeaf = NULL;
|
---|
1148 | if (!pNode)
|
---|
1149 | return VERR_CFGM_NO_PARENT;
|
---|
1150 |
|
---|
1151 | size_t cchName = strlen(pszName);
|
---|
1152 | PCFGMLEAF pLeaf = pNode->pFirstLeaf;
|
---|
1153 | while (pLeaf)
|
---|
1154 | {
|
---|
1155 | if (cchName == pLeaf->cchName)
|
---|
1156 | {
|
---|
1157 | int iDiff = memcmp(pszName, pLeaf->szName, cchName);
|
---|
1158 | if (iDiff <= 0)
|
---|
1159 | {
|
---|
1160 | if (iDiff != 0)
|
---|
1161 | break;
|
---|
1162 | *ppLeaf = pLeaf;
|
---|
1163 | return VINF_SUCCESS;
|
---|
1164 | }
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | /* next */
|
---|
1168 | pLeaf = pLeaf->pNext;
|
---|
1169 | }
|
---|
1170 | return VERR_CFGM_VALUE_NOT_FOUND;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 |
|
---|
1174 |
|
---|
1175 | /**
|
---|
1176 | * Creates a CFGM tree.
|
---|
1177 | *
|
---|
1178 | * This is intended for creating device/driver configs can be
|
---|
1179 | * passed around and later attached to the main tree in the
|
---|
1180 | * correct location.
|
---|
1181 | *
|
---|
1182 | * @returns Pointer to the root node.
|
---|
1183 | * @param pVM The VM handle.
|
---|
1184 | */
|
---|
1185 | VMMR3DECL(PCFGMNODE) CFGMR3CreateTree(PVM pVM)
|
---|
1186 | {
|
---|
1187 | PCFGMNODE pNew = (PCFGMNODE)MMR3HeapAlloc(pVM, MM_TAG_CFGM, sizeof(*pNew));
|
---|
1188 | if (pNew)
|
---|
1189 | {
|
---|
1190 | pNew->pPrev = NULL;
|
---|
1191 | pNew->pNext = NULL;
|
---|
1192 | pNew->pParent = NULL;
|
---|
1193 | pNew->pFirstChild = NULL;
|
---|
1194 | pNew->pFirstLeaf = NULL;
|
---|
1195 | pNew->pVM = pVM;
|
---|
1196 | pNew->fRestrictedRoot = false;
|
---|
1197 | pNew->cchName = 0;
|
---|
1198 | pNew->szName[0] = 0;
|
---|
1199 | }
|
---|
1200 | return pNew;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 |
|
---|
1204 | /**
|
---|
1205 | * Insert subtree.
|
---|
1206 | *
|
---|
1207 | * This function inserts (no duplication) a tree created by CFGMR3CreateTree()
|
---|
1208 | * into the main tree.
|
---|
1209 | *
|
---|
1210 | * The root node of the inserted subtree will need to be reallocated, which
|
---|
1211 | * effectually means that the passed in pSubTree handle becomes invalid
|
---|
1212 | * upon successful return. Use the value returned in ppChild instead
|
---|
1213 | * of pSubTree.
|
---|
1214 | *
|
---|
1215 | * @returns VBox status code.
|
---|
1216 | * @returns VERR_CFGM_NODE_EXISTS if the final child node name component exists.
|
---|
1217 | * @param pNode Parent node.
|
---|
1218 | * @param pszName Name or path of the new child node.
|
---|
1219 | * @param pSubTree The subtree to insert. Must be returned by CFGMR3CreateTree().
|
---|
1220 | * @param ppChild Where to store the address of the new child node. (optional)
|
---|
1221 | */
|
---|
1222 | VMMR3DECL(int) CFGMR3InsertSubTree(PCFGMNODE pNode, const char *pszName, PCFGMNODE pSubTree, PCFGMNODE *ppChild)
|
---|
1223 | {
|
---|
1224 | /*
|
---|
1225 | * Validate input.
|
---|
1226 | */
|
---|
1227 | AssertPtrReturn(pSubTree, VERR_INVALID_POINTER);
|
---|
1228 | AssertReturn(!pSubTree->pParent, VERR_INVALID_PARAMETER);
|
---|
1229 | AssertReturn(pSubTree->pVM, VERR_INVALID_PARAMETER);
|
---|
1230 | AssertReturn(pSubTree->pParent != pSubTree->pVM->cfgm.s.pRoot, VERR_INVALID_PARAMETER);
|
---|
1231 | Assert(!pSubTree->pNext);
|
---|
1232 | Assert(!pSubTree->pPrev);
|
---|
1233 |
|
---|
1234 | /*
|
---|
1235 | * Use CFGMR3InsertNode to create a new node and then
|
---|
1236 | * re-attach the children and leafs of the subtree to it.
|
---|
1237 | */
|
---|
1238 | PCFGMNODE pNewChild;
|
---|
1239 | int rc = CFGMR3InsertNode(pNode, pszName, &pNewChild);
|
---|
1240 | if (RT_SUCCESS(rc))
|
---|
1241 | {
|
---|
1242 | Assert(!pNewChild->pFirstChild);
|
---|
1243 | pNewChild->pFirstChild = pSubTree->pFirstChild;
|
---|
1244 | Assert(!pNewChild->pFirstLeaf);
|
---|
1245 | pNewChild->pFirstLeaf = pSubTree->pFirstLeaf;
|
---|
1246 | if (ppChild)
|
---|
1247 | *ppChild = pNewChild;
|
---|
1248 |
|
---|
1249 | /* free the old subtree root */
|
---|
1250 | pSubTree->pVM = NULL;
|
---|
1251 | pSubTree->pFirstLeaf = NULL;
|
---|
1252 | pSubTree->pFirstChild = NULL;
|
---|
1253 | MMR3HeapFree(pSubTree);
|
---|
1254 | }
|
---|
1255 | return rc;
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 |
|
---|
1259 | /**
|
---|
1260 | * Compares two names.
|
---|
1261 | *
|
---|
1262 | * @returns Similar to memcpy.
|
---|
1263 | * @param pszName1 The first name.
|
---|
1264 | * @param cchName1 The length of the first name.
|
---|
1265 | * @param pszName2 The second name.
|
---|
1266 | * @param cchName2 The length of the second name.
|
---|
1267 | */
|
---|
1268 | DECLINLINE(int) cfgmR3CompareNames(const char *pszName1, size_t cchName1, const char *pszName2, size_t cchName2)
|
---|
1269 | {
|
---|
1270 | int iDiff;
|
---|
1271 | if (cchName1 <= cchName2)
|
---|
1272 | {
|
---|
1273 | iDiff = memcmp(pszName1, pszName2, cchName1);
|
---|
1274 | if (!iDiff && cchName1 < cchName2)
|
---|
1275 | iDiff = -1;
|
---|
1276 | }
|
---|
1277 | else
|
---|
1278 | {
|
---|
1279 | iDiff = memcmp(pszName1, pszName2, cchName2);
|
---|
1280 | if (!iDiff)
|
---|
1281 | iDiff = 1;
|
---|
1282 | }
|
---|
1283 | return iDiff;
|
---|
1284 | }
|
---|
1285 |
|
---|
1286 |
|
---|
1287 | /**
|
---|
1288 | * Insert a node.
|
---|
1289 | *
|
---|
1290 | * @returns VBox status code.
|
---|
1291 | * @returns VERR_CFGM_NODE_EXISTS if the final child node name component exists.
|
---|
1292 | * @param pNode Parent node.
|
---|
1293 | * @param pszName Name or path of the new child node.
|
---|
1294 | * @param ppChild Where to store the address of the new child node. (optional)
|
---|
1295 | */
|
---|
1296 | VMMR3DECL(int) CFGMR3InsertNode(PCFGMNODE pNode, const char *pszName, PCFGMNODE *ppChild)
|
---|
1297 | {
|
---|
1298 | int rc;
|
---|
1299 | if (pNode)
|
---|
1300 | {
|
---|
1301 | /*
|
---|
1302 | * If given a path we have to deal with it component by component.
|
---|
1303 | */
|
---|
1304 | while (*pszName == '/')
|
---|
1305 | pszName++;
|
---|
1306 | if (strchr(pszName, '/'))
|
---|
1307 | {
|
---|
1308 | char *pszDup = RTStrDup(pszName);
|
---|
1309 | if (pszDup)
|
---|
1310 | {
|
---|
1311 | char *psz = pszDup;
|
---|
1312 | for (;;)
|
---|
1313 | {
|
---|
1314 | /* Terminate at '/' and find the next component. */
|
---|
1315 | char *pszNext = strchr(psz, '/');
|
---|
1316 | if (pszNext)
|
---|
1317 | {
|
---|
1318 | *pszNext++ = '\0';
|
---|
1319 | while (*pszNext == '/')
|
---|
1320 | pszNext++;
|
---|
1321 | if (*pszNext == '\0')
|
---|
1322 | pszNext = NULL;
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | /* does it exist? */
|
---|
1326 | PCFGMNODE pChild = CFGMR3GetChild(pNode, psz);
|
---|
1327 | if (!pChild)
|
---|
1328 | {
|
---|
1329 | /* no, insert it */
|
---|
1330 | rc = CFGMR3InsertNode(pNode, psz, &pChild);
|
---|
1331 | if (RT_FAILURE(rc))
|
---|
1332 | break;
|
---|
1333 | if (!pszNext)
|
---|
1334 | {
|
---|
1335 | if (ppChild)
|
---|
1336 | *ppChild = pChild;
|
---|
1337 | break;
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | }
|
---|
1341 | /* if last component fail */
|
---|
1342 | else if (!pszNext)
|
---|
1343 | {
|
---|
1344 | rc = VERR_CFGM_NODE_EXISTS;
|
---|
1345 | break;
|
---|
1346 | }
|
---|
1347 |
|
---|
1348 | /* next */
|
---|
1349 | pNode = pChild;
|
---|
1350 | psz = pszNext;
|
---|
1351 | }
|
---|
1352 | RTStrFree(pszDup);
|
---|
1353 | }
|
---|
1354 | else
|
---|
1355 | rc = VERR_NO_TMP_MEMORY;
|
---|
1356 | }
|
---|
1357 | /*
|
---|
1358 | * Not multicomponent, just make sure it's a non-zero name.
|
---|
1359 | */
|
---|
1360 | else if (*pszName)
|
---|
1361 | {
|
---|
1362 | /*
|
---|
1363 | * Check if already exists and find last node in chain.
|
---|
1364 | */
|
---|
1365 | size_t cchName = strlen(pszName);
|
---|
1366 | PCFGMNODE pPrev = NULL;
|
---|
1367 | PCFGMNODE pNext = pNode->pFirstChild;
|
---|
1368 | if (pNext)
|
---|
1369 | {
|
---|
1370 | for ( ; pNext; pPrev = pNext, pNext = pNext->pNext)
|
---|
1371 | {
|
---|
1372 | int iDiff = cfgmR3CompareNames(pszName, cchName, pNext->szName, pNext->cchName);
|
---|
1373 | if (iDiff <= 0)
|
---|
1374 | {
|
---|
1375 | if (!iDiff)
|
---|
1376 | return VERR_CFGM_NODE_EXISTS;
|
---|
1377 | break;
|
---|
1378 | }
|
---|
1379 | }
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | /*
|
---|
1383 | * Allocate and init node.
|
---|
1384 | */
|
---|
1385 | PCFGMNODE pNew = (PCFGMNODE)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM, sizeof(*pNew) + cchName);
|
---|
1386 | if (pNew)
|
---|
1387 | {
|
---|
1388 | pNew->pParent = pNode;
|
---|
1389 | pNew->pFirstChild = NULL;
|
---|
1390 | pNew->pFirstLeaf = NULL;
|
---|
1391 | pNew->pVM = pNode->pVM;
|
---|
1392 | pNew->fRestrictedRoot = false;
|
---|
1393 | pNew->cchName = cchName;
|
---|
1394 | memcpy(pNew->szName, pszName, cchName + 1);
|
---|
1395 |
|
---|
1396 | /*
|
---|
1397 | * Insert into child list.
|
---|
1398 | */
|
---|
1399 | pNew->pPrev = pPrev;
|
---|
1400 | if (pPrev)
|
---|
1401 | pPrev->pNext = pNew;
|
---|
1402 | else
|
---|
1403 | pNode->pFirstChild = pNew;
|
---|
1404 | pNew->pNext = pNext;
|
---|
1405 | if (pNext)
|
---|
1406 | pNext->pPrev = pNew;
|
---|
1407 |
|
---|
1408 | if (ppChild)
|
---|
1409 | *ppChild = pNew;
|
---|
1410 | rc = VINF_SUCCESS;
|
---|
1411 | }
|
---|
1412 | else
|
---|
1413 | rc = VERR_NO_MEMORY;
|
---|
1414 | }
|
---|
1415 | else
|
---|
1416 | {
|
---|
1417 | rc = VERR_CFGM_INVALID_NODE_PATH;
|
---|
1418 | AssertMsgFailed(("Invalid path %s\n", pszName));
|
---|
1419 | }
|
---|
1420 | }
|
---|
1421 | else
|
---|
1422 | {
|
---|
1423 | rc = VERR_CFGM_NO_PARENT;
|
---|
1424 | AssertMsgFailed(("No parent! path %s\n", pszName));
|
---|
1425 | }
|
---|
1426 |
|
---|
1427 | return rc;
|
---|
1428 | }
|
---|
1429 |
|
---|
1430 |
|
---|
1431 | /**
|
---|
1432 | * Insert a node, format string name.
|
---|
1433 | *
|
---|
1434 | * @returns VBox status code.
|
---|
1435 | * @param pNode Parent node.
|
---|
1436 | * @param ppChild Where to store the address of the new child node. (optional)
|
---|
1437 | * @param pszNameFormat Name of or path the new child node.
|
---|
1438 | * @param ... Name format arguments.
|
---|
1439 | */
|
---|
1440 | VMMR3DECL(int) CFGMR3InsertNodeF(PCFGMNODE pNode, PCFGMNODE *ppChild, const char *pszNameFormat, ...)
|
---|
1441 | {
|
---|
1442 | va_list Args;
|
---|
1443 | va_start(Args, pszNameFormat);
|
---|
1444 | int rc = CFGMR3InsertNodeFV(pNode, ppChild, pszNameFormat, Args);
|
---|
1445 | va_end(Args);
|
---|
1446 | return rc;
|
---|
1447 | }
|
---|
1448 |
|
---|
1449 |
|
---|
1450 | /**
|
---|
1451 | * Insert a node, format string name.
|
---|
1452 | *
|
---|
1453 | * @returns VBox status code.
|
---|
1454 | * @param pNode Parent node.
|
---|
1455 | * @param ppChild Where to store the address of the new child node. (optional)
|
---|
1456 | * @param pszNameFormat Name or path of the new child node.
|
---|
1457 | * @param Args Name format arguments.
|
---|
1458 | */
|
---|
1459 | VMMR3DECL(int) CFGMR3InsertNodeFV(PCFGMNODE pNode, PCFGMNODE *ppChild, const char *pszNameFormat, va_list Args)
|
---|
1460 | {
|
---|
1461 | int rc;
|
---|
1462 | char *pszName;
|
---|
1463 | RTStrAPrintfV(&pszName, pszNameFormat, Args);
|
---|
1464 | if (pszName)
|
---|
1465 | {
|
---|
1466 | rc = CFGMR3InsertNode(pNode, pszName, ppChild);
|
---|
1467 | RTStrFree(pszName);
|
---|
1468 | }
|
---|
1469 | else
|
---|
1470 | rc = VERR_NO_MEMORY;
|
---|
1471 | return rc;
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 |
|
---|
1475 | /**
|
---|
1476 | * Marks the node as the root of a restricted subtree, i.e. the end of
|
---|
1477 | * a CFGMR3GetParent() journey.
|
---|
1478 | *
|
---|
1479 | * @param pNode The node to mark.
|
---|
1480 | */
|
---|
1481 | VMMR3DECL(void) CFGMR3SetRestrictedRoot(PCFGMNODE pNode)
|
---|
1482 | {
|
---|
1483 | if (pNode)
|
---|
1484 | pNode->fRestrictedRoot = true;
|
---|
1485 | }
|
---|
1486 |
|
---|
1487 |
|
---|
1488 | /**
|
---|
1489 | * Insert a node.
|
---|
1490 | *
|
---|
1491 | * @returns VBox status code.
|
---|
1492 | * @param pNode Parent node.
|
---|
1493 | * @param pszName Name of the new child node.
|
---|
1494 | * @param ppLeaf Where to store the new leaf.
|
---|
1495 | * The caller must fill in the enmType and Value fields!
|
---|
1496 | */
|
---|
1497 | static int cfgmR3InsertLeaf(PCFGMNODE pNode, const char *pszName, PCFGMLEAF *ppLeaf)
|
---|
1498 | {
|
---|
1499 | int rc;
|
---|
1500 | if (*pszName)
|
---|
1501 | {
|
---|
1502 | if (pNode)
|
---|
1503 | {
|
---|
1504 | /*
|
---|
1505 | * Check if already exists and find last node in chain.
|
---|
1506 | */
|
---|
1507 | size_t cchName = strlen(pszName);
|
---|
1508 | PCFGMLEAF pPrev = NULL;
|
---|
1509 | PCFGMLEAF pNext = pNode->pFirstLeaf;
|
---|
1510 | if (pNext)
|
---|
1511 | {
|
---|
1512 | for ( ; pNext; pPrev = pNext, pNext = pNext->pNext)
|
---|
1513 | {
|
---|
1514 | int iDiff = cfgmR3CompareNames(pszName, cchName, pNext->szName, pNext->cchName);
|
---|
1515 | if (iDiff <= 0)
|
---|
1516 | {
|
---|
1517 | if (!iDiff)
|
---|
1518 | return VERR_CFGM_LEAF_EXISTS;
|
---|
1519 | break;
|
---|
1520 | }
|
---|
1521 | }
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | /*
|
---|
1525 | * Allocate and init node.
|
---|
1526 | */
|
---|
1527 | PCFGMLEAF pNew = (PCFGMLEAF)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM, sizeof(*pNew) + cchName);
|
---|
1528 | if (pNew)
|
---|
1529 | {
|
---|
1530 | pNew->cchName = cchName;
|
---|
1531 | memcpy(pNew->szName, pszName, cchName + 1);
|
---|
1532 |
|
---|
1533 | /*
|
---|
1534 | * Insert into child list.
|
---|
1535 | */
|
---|
1536 | pNew->pPrev = pPrev;
|
---|
1537 | if (pPrev)
|
---|
1538 | pPrev->pNext = pNew;
|
---|
1539 | else
|
---|
1540 | pNode->pFirstLeaf = pNew;
|
---|
1541 | pNew->pNext = pNext;
|
---|
1542 | if (pNext)
|
---|
1543 | pNext->pPrev = pNew;
|
---|
1544 |
|
---|
1545 | *ppLeaf = pNew;
|
---|
1546 | rc = VINF_SUCCESS;
|
---|
1547 | }
|
---|
1548 | else
|
---|
1549 | rc = VERR_NO_MEMORY;
|
---|
1550 | }
|
---|
1551 | else
|
---|
1552 | rc = VERR_CFGM_NO_PARENT;
|
---|
1553 | }
|
---|
1554 | else
|
---|
1555 | rc = VERR_CFGM_INVALID_CHILD_PATH;
|
---|
1556 | return rc;
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 |
|
---|
1560 | /**
|
---|
1561 | * Remove a node.
|
---|
1562 | *
|
---|
1563 | * @param pNode Parent node.
|
---|
1564 | */
|
---|
1565 | VMMR3DECL(void) CFGMR3RemoveNode(PCFGMNODE pNode)
|
---|
1566 | {
|
---|
1567 | if (pNode)
|
---|
1568 | {
|
---|
1569 | /*
|
---|
1570 | * Free children.
|
---|
1571 | */
|
---|
1572 | while (pNode->pFirstChild)
|
---|
1573 | CFGMR3RemoveNode(pNode->pFirstChild);
|
---|
1574 |
|
---|
1575 | /*
|
---|
1576 | * Free leafs.
|
---|
1577 | */
|
---|
1578 | while (pNode->pFirstLeaf)
|
---|
1579 | cfgmR3RemoveLeaf(pNode, pNode->pFirstLeaf);
|
---|
1580 |
|
---|
1581 | /*
|
---|
1582 | * Unlink ourselves.
|
---|
1583 | */
|
---|
1584 | if (pNode->pPrev)
|
---|
1585 | pNode->pPrev->pNext = pNode->pNext;
|
---|
1586 | else
|
---|
1587 | {
|
---|
1588 | if (pNode->pParent)
|
---|
1589 | pNode->pParent->pFirstChild = pNode->pNext;
|
---|
1590 | else if (pNode == pNode->pVM->cfgm.s.pRoot) /* might be a different tree */
|
---|
1591 | pNode->pVM->cfgm.s.pRoot = NULL;
|
---|
1592 | }
|
---|
1593 | if (pNode->pNext)
|
---|
1594 | pNode->pNext->pPrev = pNode->pPrev;
|
---|
1595 |
|
---|
1596 | /*
|
---|
1597 | * Free ourselves. (bit of paranoia first)
|
---|
1598 | */
|
---|
1599 | pNode->pVM = NULL;
|
---|
1600 | pNode->pNext = NULL;
|
---|
1601 | pNode->pPrev = NULL;
|
---|
1602 | pNode->pParent = NULL;
|
---|
1603 | MMR3HeapFree(pNode);
|
---|
1604 | }
|
---|
1605 | }
|
---|
1606 |
|
---|
1607 |
|
---|
1608 | /**
|
---|
1609 | * Removes a leaf.
|
---|
1610 | *
|
---|
1611 | * @param pNode Parent node.
|
---|
1612 | * @param pLeaf Leaf to remove.
|
---|
1613 | */
|
---|
1614 | static void cfgmR3RemoveLeaf(PCFGMNODE pNode, PCFGMLEAF pLeaf)
|
---|
1615 | {
|
---|
1616 | if (pNode && pLeaf)
|
---|
1617 | {
|
---|
1618 | /*
|
---|
1619 | * Unlink.
|
---|
1620 | */
|
---|
1621 | if (pLeaf->pPrev)
|
---|
1622 | pLeaf->pPrev->pNext = pLeaf->pNext;
|
---|
1623 | else
|
---|
1624 | pNode->pFirstLeaf = pLeaf->pNext;
|
---|
1625 | if (pLeaf->pNext)
|
---|
1626 | pLeaf->pNext->pPrev = pLeaf->pPrev;
|
---|
1627 |
|
---|
1628 | /*
|
---|
1629 | * Free value and node.
|
---|
1630 | */
|
---|
1631 | cfgmR3FreeValue(pLeaf);
|
---|
1632 | pLeaf->pNext = NULL;
|
---|
1633 | pLeaf->pPrev = NULL;
|
---|
1634 | MMR3HeapFree(pLeaf);
|
---|
1635 | }
|
---|
1636 | }
|
---|
1637 |
|
---|
1638 |
|
---|
1639 | /**
|
---|
1640 | * Frees whatever resources the leaf value is owning.
|
---|
1641 | *
|
---|
1642 | * Use this before assigning a new value to a leaf.
|
---|
1643 | * The caller must either free the leaf or assign a new value to it.
|
---|
1644 | *
|
---|
1645 | * @param pLeaf Pointer to the leaf which value should be free.
|
---|
1646 | */
|
---|
1647 | static void cfgmR3FreeValue(PCFGMLEAF pLeaf)
|
---|
1648 | {
|
---|
1649 | if (pLeaf)
|
---|
1650 | {
|
---|
1651 | switch (pLeaf->enmType)
|
---|
1652 | {
|
---|
1653 | case CFGMVALUETYPE_BYTES:
|
---|
1654 | MMR3HeapFree(pLeaf->Value.Bytes.pau8);
|
---|
1655 | pLeaf->Value.Bytes.pau8 = NULL;
|
---|
1656 | pLeaf->Value.Bytes.cb = 0;
|
---|
1657 | break;
|
---|
1658 |
|
---|
1659 | case CFGMVALUETYPE_STRING:
|
---|
1660 | MMR3HeapFree(pLeaf->Value.String.psz);
|
---|
1661 | pLeaf->Value.String.psz = NULL;
|
---|
1662 | pLeaf->Value.String.cb = 0;
|
---|
1663 | break;
|
---|
1664 |
|
---|
1665 | case CFGMVALUETYPE_INTEGER:
|
---|
1666 | break;
|
---|
1667 | }
|
---|
1668 | pLeaf->enmType = (CFGMVALUETYPE)0;
|
---|
1669 | }
|
---|
1670 | }
|
---|
1671 |
|
---|
1672 |
|
---|
1673 | /**
|
---|
1674 | * Inserts a new integer value.
|
---|
1675 | *
|
---|
1676 | * @returns VBox status code.
|
---|
1677 | * @param pNode Parent node.
|
---|
1678 | * @param pszName Value name.
|
---|
1679 | * @param u64Integer The value.
|
---|
1680 | */
|
---|
1681 | VMMR3DECL(int) CFGMR3InsertInteger(PCFGMNODE pNode, const char *pszName, uint64_t u64Integer)
|
---|
1682 | {
|
---|
1683 | PCFGMLEAF pLeaf;
|
---|
1684 | int rc = cfgmR3InsertLeaf(pNode, pszName, &pLeaf);
|
---|
1685 | if (RT_SUCCESS(rc))
|
---|
1686 | {
|
---|
1687 | pLeaf->enmType = CFGMVALUETYPE_INTEGER;
|
---|
1688 | pLeaf->Value.Integer.u64 = u64Integer;
|
---|
1689 | }
|
---|
1690 | return rc;
|
---|
1691 | }
|
---|
1692 |
|
---|
1693 |
|
---|
1694 | /**
|
---|
1695 | * Inserts a new string value. This variant expects that the caller know the length
|
---|
1696 | * of the string already so we can avoid calling strlen() here.
|
---|
1697 | *
|
---|
1698 | * @returns VBox status code.
|
---|
1699 | * @param pNode Parent node.
|
---|
1700 | * @param pszName Value name.
|
---|
1701 | * @param pszString The value. Must not be NULL.
|
---|
1702 | * @param cchString The length of the string excluding the
|
---|
1703 | * terminator.
|
---|
1704 | */
|
---|
1705 | VMMR3DECL(int) CFGMR3InsertStringN(PCFGMNODE pNode, const char *pszName, const char *pszString, size_t cchString)
|
---|
1706 | {
|
---|
1707 | Assert(RTStrNLen(pszString, cchString) == cchString);
|
---|
1708 |
|
---|
1709 | int rc;
|
---|
1710 | if (pNode)
|
---|
1711 | {
|
---|
1712 | /*
|
---|
1713 | * Allocate string object first.
|
---|
1714 | */
|
---|
1715 | char *pszStringCopy = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cchString + 1);
|
---|
1716 | if (pszStringCopy)
|
---|
1717 | {
|
---|
1718 | memcpy(pszStringCopy, pszString, cchString);
|
---|
1719 | pszStringCopy[cchString] = '\0';
|
---|
1720 |
|
---|
1721 | /*
|
---|
1722 | * Create value leaf and set it to string type.
|
---|
1723 | */
|
---|
1724 | PCFGMLEAF pLeaf;
|
---|
1725 | rc = cfgmR3InsertLeaf(pNode, pszName, &pLeaf);
|
---|
1726 | if (RT_SUCCESS(rc))
|
---|
1727 | {
|
---|
1728 | pLeaf->enmType = CFGMVALUETYPE_STRING;
|
---|
1729 | pLeaf->Value.String.psz = pszStringCopy;
|
---|
1730 | pLeaf->Value.String.cb = cchString + 1;
|
---|
1731 | }
|
---|
1732 | else
|
---|
1733 | MMR3HeapFree(pszStringCopy);
|
---|
1734 | }
|
---|
1735 | else
|
---|
1736 | rc = VERR_NO_MEMORY;
|
---|
1737 | }
|
---|
1738 | else
|
---|
1739 | rc = VERR_CFGM_NO_PARENT;
|
---|
1740 |
|
---|
1741 | return rc;
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 |
|
---|
1745 | /**
|
---|
1746 | * Inserts a new string value. Calls strlen(pszString) internally; if you know the
|
---|
1747 | * length of the string, CFGMR3InsertStringLengthKnown() is faster.
|
---|
1748 | *
|
---|
1749 | * @returns VBox status code.
|
---|
1750 | * @param pNode Parent node.
|
---|
1751 | * @param pszName Value name.
|
---|
1752 | * @param pszString The value.
|
---|
1753 | */
|
---|
1754 | VMMR3DECL(int) CFGMR3InsertString(PCFGMNODE pNode, const char *pszName, const char *pszString)
|
---|
1755 | {
|
---|
1756 | return CFGMR3InsertStringN(pNode, pszName, pszString, strlen(pszString));
|
---|
1757 | }
|
---|
1758 |
|
---|
1759 |
|
---|
1760 | /**
|
---|
1761 | * Same as CFGMR3InsertString except the string value given in RTStrPrintfV
|
---|
1762 | * fashion.
|
---|
1763 | *
|
---|
1764 | * @returns VBox status code.
|
---|
1765 | * @param pNode Parent node.
|
---|
1766 | * @param pszName Value name.
|
---|
1767 | * @param pszFormat The value given as a format string.
|
---|
1768 | * @param va Argument to pszFormat.
|
---|
1769 | */
|
---|
1770 | VMMR3DECL(int) CFGMR3InsertStringFV(PCFGMNODE pNode, const char *pszName, const char *pszFormat, va_list va)
|
---|
1771 | {
|
---|
1772 | int rc;
|
---|
1773 | if (pNode)
|
---|
1774 | {
|
---|
1775 | /*
|
---|
1776 | * Allocate string object first.
|
---|
1777 | */
|
---|
1778 | char *pszString = MMR3HeapAPrintfVU(pNode->pVM->pUVM, MM_TAG_CFGM_STRING, pszFormat, va);
|
---|
1779 | if (pszString)
|
---|
1780 | {
|
---|
1781 | /*
|
---|
1782 | * Create value leaf and set it to string type.
|
---|
1783 | */
|
---|
1784 | PCFGMLEAF pLeaf;
|
---|
1785 | rc = cfgmR3InsertLeaf(pNode, pszName, &pLeaf);
|
---|
1786 | if (RT_SUCCESS(rc))
|
---|
1787 | {
|
---|
1788 | pLeaf->enmType = CFGMVALUETYPE_STRING;
|
---|
1789 | pLeaf->Value.String.psz = pszString;
|
---|
1790 | pLeaf->Value.String.cb = strlen(pszString) + 1;
|
---|
1791 | }
|
---|
1792 | else
|
---|
1793 | MMR3HeapFree(pszString);
|
---|
1794 | }
|
---|
1795 | else
|
---|
1796 | rc = VERR_NO_MEMORY;
|
---|
1797 | }
|
---|
1798 | else
|
---|
1799 | rc = VERR_CFGM_NO_PARENT;
|
---|
1800 |
|
---|
1801 | return rc;
|
---|
1802 | }
|
---|
1803 |
|
---|
1804 |
|
---|
1805 | /**
|
---|
1806 | * Same as CFGMR3InsertString except the string value given in RTStrPrintf
|
---|
1807 | * fashion.
|
---|
1808 | *
|
---|
1809 | * @returns VBox status code.
|
---|
1810 | * @param pNode Parent node.
|
---|
1811 | * @param pszName Value name.
|
---|
1812 | * @param pszFormat The value given as a format string.
|
---|
1813 | * @param ... Argument to pszFormat.
|
---|
1814 | */
|
---|
1815 | VMMR3DECL(int) CFGMR3InsertStringF(PCFGMNODE pNode, const char *pszName, const char *pszFormat, ...)
|
---|
1816 | {
|
---|
1817 | va_list va;
|
---|
1818 | va_start(va, pszFormat);
|
---|
1819 | int rc = CFGMR3InsertStringFV(pNode, pszName, pszFormat, va);
|
---|
1820 | va_end(va);
|
---|
1821 | return rc;
|
---|
1822 | }
|
---|
1823 |
|
---|
1824 |
|
---|
1825 | /**
|
---|
1826 | * Same as CFGMR3InsertString except the string value given as a UTF-16 string.
|
---|
1827 | *
|
---|
1828 | * @returns VBox status code.
|
---|
1829 | * @param pNode Parent node.
|
---|
1830 | * @param pszName Value name.
|
---|
1831 | * @param pwszValue The string value (UTF-16).
|
---|
1832 | */
|
---|
1833 | VMMR3DECL(int) CFGMR3InsertStringW(PCFGMNODE pNode, const char *pszName, PCRTUTF16 pwszValue)
|
---|
1834 | {
|
---|
1835 | char *pszValue;
|
---|
1836 | int rc = RTUtf16ToUtf8(pwszValue, &pszValue);
|
---|
1837 | if (RT_SUCCESS(rc))
|
---|
1838 | {
|
---|
1839 | rc = CFGMR3InsertString(pNode, pszName, pszValue);
|
---|
1840 | RTStrFree(pszValue);
|
---|
1841 | }
|
---|
1842 | return rc;
|
---|
1843 | }
|
---|
1844 |
|
---|
1845 |
|
---|
1846 | /**
|
---|
1847 | * Inserts a new integer value.
|
---|
1848 | *
|
---|
1849 | * @returns VBox status code.
|
---|
1850 | * @param pNode Parent node.
|
---|
1851 | * @param pszName Value name.
|
---|
1852 | * @param pvBytes The value.
|
---|
1853 | * @param cbBytes The value size.
|
---|
1854 | */
|
---|
1855 | VMMR3DECL(int) CFGMR3InsertBytes(PCFGMNODE pNode, const char *pszName, const void *pvBytes, size_t cbBytes)
|
---|
1856 | {
|
---|
1857 | int rc;
|
---|
1858 | if (pNode)
|
---|
1859 | {
|
---|
1860 | if (cbBytes == (RTUINT)cbBytes)
|
---|
1861 | {
|
---|
1862 | /*
|
---|
1863 | * Allocate string object first.
|
---|
1864 | */
|
---|
1865 | void *pvCopy = MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cbBytes);
|
---|
1866 | if (pvCopy || !cbBytes)
|
---|
1867 | {
|
---|
1868 | memcpy(pvCopy, pvBytes, cbBytes);
|
---|
1869 |
|
---|
1870 | /*
|
---|
1871 | * Create value leaf and set it to string type.
|
---|
1872 | */
|
---|
1873 | PCFGMLEAF pLeaf;
|
---|
1874 | rc = cfgmR3InsertLeaf(pNode, pszName, &pLeaf);
|
---|
1875 | if (RT_SUCCESS(rc))
|
---|
1876 | {
|
---|
1877 | pLeaf->enmType = CFGMVALUETYPE_BYTES;
|
---|
1878 | pLeaf->Value.Bytes.cb = cbBytes;
|
---|
1879 | pLeaf->Value.Bytes.pau8 = (uint8_t *)pvCopy;
|
---|
1880 | }
|
---|
1881 | }
|
---|
1882 | else
|
---|
1883 | rc = VERR_NO_MEMORY;
|
---|
1884 | }
|
---|
1885 | else
|
---|
1886 | rc = VERR_OUT_OF_RANGE;
|
---|
1887 | }
|
---|
1888 | else
|
---|
1889 | rc = VERR_CFGM_NO_PARENT;
|
---|
1890 |
|
---|
1891 | return rc;
|
---|
1892 | }
|
---|
1893 |
|
---|
1894 |
|
---|
1895 | /**
|
---|
1896 | * Remove a value.
|
---|
1897 | *
|
---|
1898 | * @returns VBox status code.
|
---|
1899 | * @param pNode Parent node.
|
---|
1900 | * @param pszName Name of the new child node.
|
---|
1901 | */
|
---|
1902 | VMMR3DECL(int) CFGMR3RemoveValue(PCFGMNODE pNode, const char *pszName)
|
---|
1903 | {
|
---|
1904 | PCFGMLEAF pLeaf;
|
---|
1905 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
1906 | if (RT_SUCCESS(rc))
|
---|
1907 | cfgmR3RemoveLeaf(pNode, pLeaf);
|
---|
1908 | return rc;
|
---|
1909 | }
|
---|
1910 |
|
---|
1911 |
|
---|
1912 |
|
---|
1913 | /*
|
---|
1914 | * -+- helper apis -+-
|
---|
1915 | */
|
---|
1916 |
|
---|
1917 |
|
---|
1918 | /**
|
---|
1919 | * Query unsigned 64-bit integer value.
|
---|
1920 | *
|
---|
1921 | * @returns VBox status code.
|
---|
1922 | * @param pNode Which node to search for pszName in.
|
---|
1923 | * @param pszName Name of an integer value.
|
---|
1924 | * @param pu64 Where to store the integer value.
|
---|
1925 | */
|
---|
1926 | VMMR3DECL(int) CFGMR3QueryU64(PCFGMNODE pNode, const char *pszName, uint64_t *pu64)
|
---|
1927 | {
|
---|
1928 | return CFGMR3QueryInteger(pNode, pszName, pu64);
|
---|
1929 | }
|
---|
1930 |
|
---|
1931 |
|
---|
1932 | /**
|
---|
1933 | * Query unsigned 64-bit integer value with default.
|
---|
1934 | *
|
---|
1935 | * @returns VBox status code.
|
---|
1936 | * @param pNode Which node to search for pszName in.
|
---|
1937 | * @param pszName Name of an integer value.
|
---|
1938 | * @param pu64 Where to store the integer value. Set to default on failure.
|
---|
1939 | * @param u64Def The default value.
|
---|
1940 | */
|
---|
1941 | VMMR3DECL(int) CFGMR3QueryU64Def(PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def)
|
---|
1942 | {
|
---|
1943 | return CFGMR3QueryIntegerDef(pNode, pszName, pu64, u64Def);
|
---|
1944 | }
|
---|
1945 |
|
---|
1946 |
|
---|
1947 | /**
|
---|
1948 | * Query signed 64-bit integer value.
|
---|
1949 | *
|
---|
1950 | * @returns VBox status code.
|
---|
1951 | * @param pNode Which node to search for pszName in.
|
---|
1952 | * @param pszName Name of an integer value.
|
---|
1953 | * @param pi64 Where to store the value.
|
---|
1954 | */
|
---|
1955 | VMMR3DECL(int) CFGMR3QueryS64(PCFGMNODE pNode, const char *pszName, int64_t *pi64)
|
---|
1956 | {
|
---|
1957 | uint64_t u64;
|
---|
1958 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
1959 | if (RT_SUCCESS(rc))
|
---|
1960 | *pi64 = (int64_t)u64;
|
---|
1961 | return rc;
|
---|
1962 | }
|
---|
1963 |
|
---|
1964 |
|
---|
1965 | /**
|
---|
1966 | * Query signed 64-bit integer value with default.
|
---|
1967 | *
|
---|
1968 | * @returns VBox status code.
|
---|
1969 | * @param pNode Which node to search for pszName in.
|
---|
1970 | * @param pszName Name of an integer value.
|
---|
1971 | * @param pi64 Where to store the value. Set to default on failure.
|
---|
1972 | * @param i64Def The default value.
|
---|
1973 | */
|
---|
1974 | VMMR3DECL(int) CFGMR3QueryS64Def(PCFGMNODE pNode, const char *pszName, int64_t *pi64, int64_t i64Def)
|
---|
1975 | {
|
---|
1976 | uint64_t u64;
|
---|
1977 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, i64Def);
|
---|
1978 | *pi64 = (int64_t)u64;
|
---|
1979 | return rc;
|
---|
1980 | }
|
---|
1981 |
|
---|
1982 |
|
---|
1983 | /**
|
---|
1984 | * Query unsigned 32-bit integer value.
|
---|
1985 | *
|
---|
1986 | * @returns VBox status code.
|
---|
1987 | * @param pNode Which node to search for pszName in.
|
---|
1988 | * @param pszName Name of an integer value.
|
---|
1989 | * @param pu32 Where to store the value.
|
---|
1990 | */
|
---|
1991 | VMMR3DECL(int) CFGMR3QueryU32(PCFGMNODE pNode, const char *pszName, uint32_t *pu32)
|
---|
1992 | {
|
---|
1993 | uint64_t u64;
|
---|
1994 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
1995 | if (RT_SUCCESS(rc))
|
---|
1996 | {
|
---|
1997 | if (!(u64 & UINT64_C(0xffffffff00000000)))
|
---|
1998 | *pu32 = (uint32_t)u64;
|
---|
1999 | else
|
---|
2000 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2001 | }
|
---|
2002 | return rc;
|
---|
2003 | }
|
---|
2004 |
|
---|
2005 |
|
---|
2006 | /**
|
---|
2007 | * Query unsigned 32-bit integer value with default.
|
---|
2008 | *
|
---|
2009 | * @returns VBox status code.
|
---|
2010 | * @param pNode Which node to search for pszName in.
|
---|
2011 | * @param pszName Name of an integer value.
|
---|
2012 | * @param pu32 Where to store the value. Set to default on failure.
|
---|
2013 | * @param u32Def The default value.
|
---|
2014 | */
|
---|
2015 | VMMR3DECL(int) CFGMR3QueryU32Def(PCFGMNODE pNode, const char *pszName, uint32_t *pu32, uint32_t u32Def)
|
---|
2016 | {
|
---|
2017 | uint64_t u64;
|
---|
2018 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, u32Def);
|
---|
2019 | if (RT_SUCCESS(rc))
|
---|
2020 | {
|
---|
2021 | if (!(u64 & UINT64_C(0xffffffff00000000)))
|
---|
2022 | *pu32 = (uint32_t)u64;
|
---|
2023 | else
|
---|
2024 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2025 | }
|
---|
2026 | if (RT_FAILURE(rc))
|
---|
2027 | *pu32 = u32Def;
|
---|
2028 | return rc;
|
---|
2029 | }
|
---|
2030 |
|
---|
2031 |
|
---|
2032 | /**
|
---|
2033 | * Query signed 32-bit integer value.
|
---|
2034 | *
|
---|
2035 | * @returns VBox status code.
|
---|
2036 | * @param pNode Which node to search for pszName in.
|
---|
2037 | * @param pszName Name of an integer value.
|
---|
2038 | * @param pi32 Where to store the value.
|
---|
2039 | */
|
---|
2040 | VMMR3DECL(int) CFGMR3QueryS32(PCFGMNODE pNode, const char *pszName, int32_t *pi32)
|
---|
2041 | {
|
---|
2042 | uint64_t u64;
|
---|
2043 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2044 | if (RT_SUCCESS(rc))
|
---|
2045 | {
|
---|
2046 | if ( !(u64 & UINT64_C(0xffffffff80000000))
|
---|
2047 | || (u64 & UINT64_C(0xffffffff80000000)) == UINT64_C(0xffffffff80000000))
|
---|
2048 | *pi32 = (int32_t)u64;
|
---|
2049 | else
|
---|
2050 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2051 | }
|
---|
2052 | return rc;
|
---|
2053 | }
|
---|
2054 |
|
---|
2055 |
|
---|
2056 | /**
|
---|
2057 | * Query signed 32-bit integer value with default.
|
---|
2058 | *
|
---|
2059 | * @returns VBox status code.
|
---|
2060 | * @param pNode Which node to search for pszName in.
|
---|
2061 | * @param pszName Name of an integer value.
|
---|
2062 | * @param pi32 Where to store the value. Set to default on failure.
|
---|
2063 | * @param i32Def The default value.
|
---|
2064 | */
|
---|
2065 | VMMR3DECL(int) CFGMR3QueryS32Def(PCFGMNODE pNode, const char *pszName, int32_t *pi32, int32_t i32Def)
|
---|
2066 | {
|
---|
2067 | uint64_t u64;
|
---|
2068 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, i32Def);
|
---|
2069 | if (RT_SUCCESS(rc))
|
---|
2070 | {
|
---|
2071 | if ( !(u64 & UINT64_C(0xffffffff80000000))
|
---|
2072 | || (u64 & UINT64_C(0xffffffff80000000)) == UINT64_C(0xffffffff80000000))
|
---|
2073 | *pi32 = (int32_t)u64;
|
---|
2074 | else
|
---|
2075 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2076 | }
|
---|
2077 | if (RT_FAILURE(rc))
|
---|
2078 | *pi32 = i32Def;
|
---|
2079 | return rc;
|
---|
2080 | }
|
---|
2081 |
|
---|
2082 |
|
---|
2083 | /**
|
---|
2084 | * Query unsigned 16-bit integer value.
|
---|
2085 | *
|
---|
2086 | * @returns VBox status code.
|
---|
2087 | * @param pNode Which node to search for pszName in.
|
---|
2088 | * @param pszName Name of an integer value.
|
---|
2089 | * @param pu16 Where to store the value.
|
---|
2090 | */
|
---|
2091 | VMMR3DECL(int) CFGMR3QueryU16(PCFGMNODE pNode, const char *pszName, uint16_t *pu16)
|
---|
2092 | {
|
---|
2093 | uint64_t u64;
|
---|
2094 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2095 | if (RT_SUCCESS(rc))
|
---|
2096 | {
|
---|
2097 | if (!(u64 & UINT64_C(0xffffffffffff0000)))
|
---|
2098 | *pu16 = (int16_t)u64;
|
---|
2099 | else
|
---|
2100 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2101 | }
|
---|
2102 | return rc;
|
---|
2103 | }
|
---|
2104 |
|
---|
2105 |
|
---|
2106 | /**
|
---|
2107 | * Query unsigned 16-bit integer value with default.
|
---|
2108 | *
|
---|
2109 | * @returns VBox status code.
|
---|
2110 | * @param pNode Which node to search for pszName in.
|
---|
2111 | * @param pszName Name of an integer value.
|
---|
2112 | * @param pu16 Where to store the value. Set to default on failure.
|
---|
2113 | * @param i16Def The default value.
|
---|
2114 | */
|
---|
2115 | VMMR3DECL(int) CFGMR3QueryU16Def(PCFGMNODE pNode, const char *pszName, uint16_t *pu16, uint16_t u16Def)
|
---|
2116 | {
|
---|
2117 | uint64_t u64;
|
---|
2118 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, u16Def);
|
---|
2119 | if (RT_SUCCESS(rc))
|
---|
2120 | {
|
---|
2121 | if (!(u64 & UINT64_C(0xffffffffffff0000)))
|
---|
2122 | *pu16 = (int16_t)u64;
|
---|
2123 | else
|
---|
2124 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2125 | }
|
---|
2126 | if (RT_FAILURE(rc))
|
---|
2127 | *pu16 = u16Def;
|
---|
2128 | return rc;
|
---|
2129 | }
|
---|
2130 |
|
---|
2131 |
|
---|
2132 | /**
|
---|
2133 | * Query signed 16-bit integer value.
|
---|
2134 | *
|
---|
2135 | * @returns VBox status code.
|
---|
2136 | * @param pNode Which node to search for pszName in.
|
---|
2137 | * @param pszName Name of an integer value.
|
---|
2138 | * @param pi16 Where to store the value.
|
---|
2139 | */
|
---|
2140 | VMMR3DECL(int) CFGMR3QueryS16(PCFGMNODE pNode, const char *pszName, int16_t *pi16)
|
---|
2141 | {
|
---|
2142 | uint64_t u64;
|
---|
2143 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2144 | if (RT_SUCCESS(rc))
|
---|
2145 | {
|
---|
2146 | if ( !(u64 & UINT64_C(0xffffffffffff8000))
|
---|
2147 | || (u64 & UINT64_C(0xffffffffffff8000)) == UINT64_C(0xffffffffffff8000))
|
---|
2148 | *pi16 = (int16_t)u64;
|
---|
2149 | else
|
---|
2150 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2151 | }
|
---|
2152 | return rc;
|
---|
2153 | }
|
---|
2154 |
|
---|
2155 |
|
---|
2156 | /**
|
---|
2157 | * Query signed 16-bit integer value with default.
|
---|
2158 | *
|
---|
2159 | * @returns VBox status code.
|
---|
2160 | * @param pNode Which node to search for pszName in.
|
---|
2161 | * @param pszName Name of an integer value.
|
---|
2162 | * @param pi16 Where to store the value. Set to default on failure.
|
---|
2163 | * @param i16Def The default value.
|
---|
2164 | */
|
---|
2165 | VMMR3DECL(int) CFGMR3QueryS16Def(PCFGMNODE pNode, const char *pszName, int16_t *pi16, int16_t i16Def)
|
---|
2166 | {
|
---|
2167 | uint64_t u64;
|
---|
2168 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, i16Def);
|
---|
2169 | if (RT_SUCCESS(rc))
|
---|
2170 | {
|
---|
2171 | if ( !(u64 & UINT64_C(0xffffffffffff8000))
|
---|
2172 | || (u64 & UINT64_C(0xffffffffffff8000)) == UINT64_C(0xffffffffffff8000))
|
---|
2173 | *pi16 = (int16_t)u64;
|
---|
2174 | else
|
---|
2175 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2176 | }
|
---|
2177 | if (RT_FAILURE(rc))
|
---|
2178 | *pi16 = i16Def;
|
---|
2179 | return rc;
|
---|
2180 | }
|
---|
2181 |
|
---|
2182 |
|
---|
2183 | /**
|
---|
2184 | * Query unsigned 8-bit integer value.
|
---|
2185 | *
|
---|
2186 | * @returns VBox status code.
|
---|
2187 | * @param pNode Which node to search for pszName in.
|
---|
2188 | * @param pszName Name of an integer value.
|
---|
2189 | * @param pu8 Where to store the value.
|
---|
2190 | */
|
---|
2191 | VMMR3DECL(int) CFGMR3QueryU8(PCFGMNODE pNode, const char *pszName, uint8_t *pu8)
|
---|
2192 | {
|
---|
2193 | uint64_t u64;
|
---|
2194 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2195 | if (RT_SUCCESS(rc))
|
---|
2196 | {
|
---|
2197 | if (!(u64 & UINT64_C(0xffffffffffffff00)))
|
---|
2198 | *pu8 = (uint8_t)u64;
|
---|
2199 | else
|
---|
2200 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2201 | }
|
---|
2202 | return rc;
|
---|
2203 | }
|
---|
2204 |
|
---|
2205 |
|
---|
2206 | /**
|
---|
2207 | * Query unsigned 8-bit integer value with default.
|
---|
2208 | *
|
---|
2209 | * @returns VBox status code.
|
---|
2210 | * @param pNode Which node to search for pszName in.
|
---|
2211 | * @param pszName Name of an integer value.
|
---|
2212 | * @param pu8 Where to store the value. Set to default on failure.
|
---|
2213 | * @param u8Def The default value.
|
---|
2214 | */
|
---|
2215 | VMMR3DECL(int) CFGMR3QueryU8Def(PCFGMNODE pNode, const char *pszName, uint8_t *pu8, uint8_t u8Def)
|
---|
2216 | {
|
---|
2217 | uint64_t u64;
|
---|
2218 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, u8Def);
|
---|
2219 | if (RT_SUCCESS(rc))
|
---|
2220 | {
|
---|
2221 | if (!(u64 & UINT64_C(0xffffffffffffff00)))
|
---|
2222 | *pu8 = (uint8_t)u64;
|
---|
2223 | else
|
---|
2224 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2225 | }
|
---|
2226 | if (RT_FAILURE(rc))
|
---|
2227 | *pu8 = u8Def;
|
---|
2228 | return rc;
|
---|
2229 | }
|
---|
2230 |
|
---|
2231 |
|
---|
2232 | /**
|
---|
2233 | * Query signed 8-bit integer value.
|
---|
2234 | *
|
---|
2235 | * @returns VBox status code.
|
---|
2236 | * @param pNode Which node to search for pszName in.
|
---|
2237 | * @param pszName Name of an integer value.
|
---|
2238 | * @param pi8 Where to store the value.
|
---|
2239 | */
|
---|
2240 | VMMR3DECL(int) CFGMR3QueryS8(PCFGMNODE pNode, const char *pszName, int8_t *pi8)
|
---|
2241 | {
|
---|
2242 | uint64_t u64;
|
---|
2243 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2244 | if (RT_SUCCESS(rc))
|
---|
2245 | {
|
---|
2246 | if ( !(u64 & UINT64_C(0xffffffffffffff80))
|
---|
2247 | || (u64 & UINT64_C(0xffffffffffffff80)) == UINT64_C(0xffffffffffffff80))
|
---|
2248 | *pi8 = (int8_t)u64;
|
---|
2249 | else
|
---|
2250 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2251 | }
|
---|
2252 | return rc;
|
---|
2253 | }
|
---|
2254 |
|
---|
2255 |
|
---|
2256 | /**
|
---|
2257 | * Query signed 8-bit integer value with default.
|
---|
2258 | *
|
---|
2259 | * @returns VBox status code.
|
---|
2260 | * @param pNode Which node to search for pszName in.
|
---|
2261 | * @param pszName Name of an integer value.
|
---|
2262 | * @param pi8 Where to store the value. Set to default on failure.
|
---|
2263 | * @param i8Def The default value.
|
---|
2264 | */
|
---|
2265 | VMMR3DECL(int) CFGMR3QueryS8Def(PCFGMNODE pNode, const char *pszName, int8_t *pi8, int8_t i8Def)
|
---|
2266 | {
|
---|
2267 | uint64_t u64;
|
---|
2268 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, i8Def);
|
---|
2269 | if (RT_SUCCESS(rc))
|
---|
2270 | {
|
---|
2271 | if ( !(u64 & UINT64_C(0xffffffffffffff80))
|
---|
2272 | || (u64 & UINT64_C(0xffffffffffffff80)) == UINT64_C(0xffffffffffffff80))
|
---|
2273 | *pi8 = (int8_t)u64;
|
---|
2274 | else
|
---|
2275 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2276 | }
|
---|
2277 | if (RT_FAILURE(rc))
|
---|
2278 | *pi8 = i8Def;
|
---|
2279 | return rc;
|
---|
2280 | }
|
---|
2281 |
|
---|
2282 |
|
---|
2283 | /**
|
---|
2284 | * Query boolean integer value.
|
---|
2285 | *
|
---|
2286 | * @returns VBox status code.
|
---|
2287 | * @param pNode Which node to search for pszName in.
|
---|
2288 | * @param pszName Name of an integer value.
|
---|
2289 | * @param pf Where to store the value.
|
---|
2290 | * @remark This function will interpret any non-zero value as true.
|
---|
2291 | */
|
---|
2292 | VMMR3DECL(int) CFGMR3QueryBool(PCFGMNODE pNode, const char *pszName, bool *pf)
|
---|
2293 | {
|
---|
2294 | uint64_t u64;
|
---|
2295 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2296 | if (RT_SUCCESS(rc))
|
---|
2297 | *pf = u64 ? true : false;
|
---|
2298 | return rc;
|
---|
2299 | }
|
---|
2300 |
|
---|
2301 |
|
---|
2302 | /**
|
---|
2303 | * Query boolean integer value with default.
|
---|
2304 | *
|
---|
2305 | * @returns VBox status code.
|
---|
2306 | * @param pNode Which node to search for pszName in.
|
---|
2307 | * @param pszName Name of an integer value.
|
---|
2308 | * @param pf Where to store the value. Set to default on failure.
|
---|
2309 | * @param fDef The default value.
|
---|
2310 | * @remark This function will interpret any non-zero value as true.
|
---|
2311 | */
|
---|
2312 | VMMR3DECL(int) CFGMR3QueryBoolDef(PCFGMNODE pNode, const char *pszName, bool *pf, bool fDef)
|
---|
2313 | {
|
---|
2314 | uint64_t u64;
|
---|
2315 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, fDef);
|
---|
2316 | *pf = u64 ? true : false;
|
---|
2317 | return rc;
|
---|
2318 | }
|
---|
2319 |
|
---|
2320 |
|
---|
2321 | /**
|
---|
2322 | * Query I/O port address value.
|
---|
2323 | *
|
---|
2324 | * @returns VBox status code.
|
---|
2325 | * @param pNode Which node to search for pszName in.
|
---|
2326 | * @param pszName Name of an integer value.
|
---|
2327 | * @param pPort Where to store the value.
|
---|
2328 | */
|
---|
2329 | VMMR3DECL(int) CFGMR3QueryPort(PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort)
|
---|
2330 | {
|
---|
2331 | AssertCompileSize(RTIOPORT, 2);
|
---|
2332 | return CFGMR3QueryU16(pNode, pszName, pPort);
|
---|
2333 | }
|
---|
2334 |
|
---|
2335 |
|
---|
2336 | /**
|
---|
2337 | * Query I/O port address value with default.
|
---|
2338 | *
|
---|
2339 | * @returns VBox status code.
|
---|
2340 | * @param pNode Which node to search for pszName in.
|
---|
2341 | * @param pszName Name of an integer value.
|
---|
2342 | * @param pPort Where to store the value. Set to default on failure.
|
---|
2343 | * @param PortDef The default value.
|
---|
2344 | */
|
---|
2345 | VMMR3DECL(int) CFGMR3QueryPortDef(PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort, RTIOPORT PortDef)
|
---|
2346 | {
|
---|
2347 | AssertCompileSize(RTIOPORT, 2);
|
---|
2348 | return CFGMR3QueryU16Def(pNode, pszName, pPort, PortDef);
|
---|
2349 | }
|
---|
2350 |
|
---|
2351 |
|
---|
2352 | /**
|
---|
2353 | * Query unsigned int address value.
|
---|
2354 | *
|
---|
2355 | * @returns VBox status code.
|
---|
2356 | * @param pNode Which node to search for pszName in.
|
---|
2357 | * @param pszName Name of an integer value.
|
---|
2358 | * @param pu Where to store the value.
|
---|
2359 | */
|
---|
2360 | VMMR3DECL(int) CFGMR3QueryUInt(PCFGMNODE pNode, const char *pszName, unsigned int *pu)
|
---|
2361 | {
|
---|
2362 | AssertCompileSize(unsigned int, 4);
|
---|
2363 | return CFGMR3QueryU32(pNode, pszName, (uint32_t *)pu);
|
---|
2364 | }
|
---|
2365 |
|
---|
2366 |
|
---|
2367 | /**
|
---|
2368 | * Query unsigned int address value with default.
|
---|
2369 | *
|
---|
2370 | * @returns VBox status code.
|
---|
2371 | * @param pNode Which node to search for pszName in.
|
---|
2372 | * @param pszName Name of an integer value.
|
---|
2373 | * @param pu Where to store the value. Set to default on failure.
|
---|
2374 | * @param uDef The default value.
|
---|
2375 | */
|
---|
2376 | VMMR3DECL(int) CFGMR3QueryUIntDef(PCFGMNODE pNode, const char *pszName, unsigned int *pu, unsigned int uDef)
|
---|
2377 | {
|
---|
2378 | AssertCompileSize(unsigned int, 4);
|
---|
2379 | return CFGMR3QueryU32Def(pNode, pszName, (uint32_t *)pu, uDef);
|
---|
2380 | }
|
---|
2381 |
|
---|
2382 |
|
---|
2383 | /**
|
---|
2384 | * Query signed int address value.
|
---|
2385 | *
|
---|
2386 | * @returns VBox status code.
|
---|
2387 | * @param pNode Which node to search for pszName in.
|
---|
2388 | * @param pszName Name of an integer value.
|
---|
2389 | * @param pi Where to store the value.
|
---|
2390 | */
|
---|
2391 | VMMR3DECL(int) CFGMR3QuerySInt(PCFGMNODE pNode, const char *pszName, signed int *pi)
|
---|
2392 | {
|
---|
2393 | AssertCompileSize(signed int, 4);
|
---|
2394 | return CFGMR3QueryS32(pNode, pszName, (int32_t *)pi);
|
---|
2395 | }
|
---|
2396 |
|
---|
2397 |
|
---|
2398 | /**
|
---|
2399 | * Query unsigned int address value with default.
|
---|
2400 | *
|
---|
2401 | * @returns VBox status code.
|
---|
2402 | * @param pNode Which node to search for pszName in.
|
---|
2403 | * @param pszName Name of an integer value.
|
---|
2404 | * @param pi Where to store the value. Set to default on failure.
|
---|
2405 | * @param iDef The default value.
|
---|
2406 | */
|
---|
2407 | VMMR3DECL(int) CFGMR3QuerySIntDef(PCFGMNODE pNode, const char *pszName, signed int *pi, signed int iDef)
|
---|
2408 | {
|
---|
2409 | AssertCompileSize(signed int, 4);
|
---|
2410 | return CFGMR3QueryS32Def(pNode, pszName, (int32_t *)pi, iDef);
|
---|
2411 | }
|
---|
2412 |
|
---|
2413 |
|
---|
2414 | /**
|
---|
2415 | * Query pointer integer value.
|
---|
2416 | *
|
---|
2417 | * @returns VBox status code.
|
---|
2418 | * @param pNode Which node to search for pszName in.
|
---|
2419 | * @param pszName Name of an integer value.
|
---|
2420 | * @param ppv Where to store the value.
|
---|
2421 | */
|
---|
2422 | VMMR3DECL(int) CFGMR3QueryPtr(PCFGMNODE pNode, const char *pszName, void **ppv)
|
---|
2423 | {
|
---|
2424 | uint64_t u64;
|
---|
2425 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2426 | if (RT_SUCCESS(rc))
|
---|
2427 | {
|
---|
2428 | uintptr_t u = (uintptr_t)u64;
|
---|
2429 | if (u64 == u)
|
---|
2430 | *ppv = (void *)u;
|
---|
2431 | else
|
---|
2432 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2433 | }
|
---|
2434 | return rc;
|
---|
2435 | }
|
---|
2436 |
|
---|
2437 |
|
---|
2438 | /**
|
---|
2439 | * Query pointer integer value with default.
|
---|
2440 | *
|
---|
2441 | * @returns VBox status code.
|
---|
2442 | * @param pNode Which node to search for pszName in.
|
---|
2443 | * @param pszName Name of an integer value.
|
---|
2444 | * @param ppv Where to store the value. Set to default on failure.
|
---|
2445 | * @param pvDef The default value.
|
---|
2446 | */
|
---|
2447 | VMMR3DECL(int) CFGMR3QueryPtrDef(PCFGMNODE pNode, const char *pszName, void **ppv, void *pvDef)
|
---|
2448 | {
|
---|
2449 | uint64_t u64;
|
---|
2450 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, (uintptr_t)pvDef);
|
---|
2451 | if (RT_SUCCESS(rc))
|
---|
2452 | {
|
---|
2453 | uintptr_t u = (uintptr_t)u64;
|
---|
2454 | if (u64 == u)
|
---|
2455 | *ppv = (void *)u;
|
---|
2456 | else
|
---|
2457 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2458 | }
|
---|
2459 | if (RT_FAILURE(rc))
|
---|
2460 | *ppv = pvDef;
|
---|
2461 | return rc;
|
---|
2462 | }
|
---|
2463 |
|
---|
2464 |
|
---|
2465 | /**
|
---|
2466 | * Query Guest Context pointer integer value.
|
---|
2467 | *
|
---|
2468 | * @returns VBox status code.
|
---|
2469 | * @param pNode Which node to search for pszName in.
|
---|
2470 | * @param pszName Name of an integer value.
|
---|
2471 | * @param pGCPtr Where to store the value.
|
---|
2472 | */
|
---|
2473 | VMMR3DECL(int) CFGMR3QueryGCPtr(PCFGMNODE pNode, const char *pszName, PRTGCPTR pGCPtr)
|
---|
2474 | {
|
---|
2475 | uint64_t u64;
|
---|
2476 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2477 | if (RT_SUCCESS(rc))
|
---|
2478 | {
|
---|
2479 | RTGCPTR u = (RTGCPTR)u64;
|
---|
2480 | if (u64 == u)
|
---|
2481 | *pGCPtr = u;
|
---|
2482 | else
|
---|
2483 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2484 | }
|
---|
2485 | return rc;
|
---|
2486 | }
|
---|
2487 |
|
---|
2488 |
|
---|
2489 | /**
|
---|
2490 | * Query Guest Context pointer integer value with default.
|
---|
2491 | *
|
---|
2492 | * @returns VBox status code.
|
---|
2493 | * @param pNode Which node to search for pszName in.
|
---|
2494 | * @param pszName Name of an integer value.
|
---|
2495 | * @param pGCPtr Where to store the value. Set to default on failure.
|
---|
2496 | * @param GCPtrDef The default value.
|
---|
2497 | */
|
---|
2498 | VMMR3DECL(int) CFGMR3QueryGCPtrDef(PCFGMNODE pNode, const char *pszName, PRTGCPTR pGCPtr, RTGCPTR GCPtrDef)
|
---|
2499 | {
|
---|
2500 | uint64_t u64;
|
---|
2501 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, GCPtrDef);
|
---|
2502 | if (RT_SUCCESS(rc))
|
---|
2503 | {
|
---|
2504 | RTGCPTR u = (RTGCPTR)u64;
|
---|
2505 | if (u64 == u)
|
---|
2506 | *pGCPtr = u;
|
---|
2507 | else
|
---|
2508 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2509 | }
|
---|
2510 | if (RT_FAILURE(rc))
|
---|
2511 | *pGCPtr = GCPtrDef;
|
---|
2512 | return rc;
|
---|
2513 | }
|
---|
2514 |
|
---|
2515 |
|
---|
2516 | /**
|
---|
2517 | * Query Guest Context unsigned pointer value.
|
---|
2518 | *
|
---|
2519 | * @returns VBox status code.
|
---|
2520 | * @param pNode Which node to search for pszName in.
|
---|
2521 | * @param pszName Name of an integer value.
|
---|
2522 | * @param pGCPtr Where to store the value.
|
---|
2523 | */
|
---|
2524 | VMMR3DECL(int) CFGMR3QueryGCPtrU(PCFGMNODE pNode, const char *pszName, PRTGCUINTPTR pGCPtr)
|
---|
2525 | {
|
---|
2526 | uint64_t u64;
|
---|
2527 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2528 | if (RT_SUCCESS(rc))
|
---|
2529 | {
|
---|
2530 | RTGCUINTPTR u = (RTGCUINTPTR)u64;
|
---|
2531 | if (u64 == u)
|
---|
2532 | *pGCPtr = u;
|
---|
2533 | else
|
---|
2534 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2535 | }
|
---|
2536 | return rc;
|
---|
2537 | }
|
---|
2538 |
|
---|
2539 |
|
---|
2540 | /**
|
---|
2541 | * Query Guest Context unsigned pointer value with default.
|
---|
2542 | *
|
---|
2543 | * @returns VBox status code.
|
---|
2544 | * @param pNode Which node to search for pszName in.
|
---|
2545 | * @param pszName Name of an integer value.
|
---|
2546 | * @param pGCPtr Where to store the value. Set to default on failure.
|
---|
2547 | * @param GCPtrDef The default value.
|
---|
2548 | */
|
---|
2549 | VMMR3DECL(int) CFGMR3QueryGCPtrUDef(PCFGMNODE pNode, const char *pszName, PRTGCUINTPTR pGCPtr, RTGCUINTPTR GCPtrDef)
|
---|
2550 | {
|
---|
2551 | uint64_t u64;
|
---|
2552 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, GCPtrDef);
|
---|
2553 | if (RT_SUCCESS(rc))
|
---|
2554 | {
|
---|
2555 | RTGCUINTPTR u = (RTGCUINTPTR)u64;
|
---|
2556 | if (u64 == u)
|
---|
2557 | *pGCPtr = u;
|
---|
2558 | else
|
---|
2559 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2560 | }
|
---|
2561 | if (RT_FAILURE(rc))
|
---|
2562 | *pGCPtr = GCPtrDef;
|
---|
2563 | return rc;
|
---|
2564 | }
|
---|
2565 |
|
---|
2566 |
|
---|
2567 | /**
|
---|
2568 | * Query Guest Context signed pointer value.
|
---|
2569 | *
|
---|
2570 | * @returns VBox status code.
|
---|
2571 | * @param pNode Which node to search for pszName in.
|
---|
2572 | * @param pszName Name of an integer value.
|
---|
2573 | * @param pGCPtr Where to store the value.
|
---|
2574 | */
|
---|
2575 | VMMR3DECL(int) CFGMR3QueryGCPtrS(PCFGMNODE pNode, const char *pszName, PRTGCINTPTR pGCPtr)
|
---|
2576 | {
|
---|
2577 | uint64_t u64;
|
---|
2578 | int rc = CFGMR3QueryInteger(pNode, pszName, &u64);
|
---|
2579 | if (RT_SUCCESS(rc))
|
---|
2580 | {
|
---|
2581 | RTGCINTPTR u = (RTGCINTPTR)u64;
|
---|
2582 | if (u64 == (uint64_t)u)
|
---|
2583 | *pGCPtr = u;
|
---|
2584 | else
|
---|
2585 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2586 | }
|
---|
2587 | return rc;
|
---|
2588 | }
|
---|
2589 |
|
---|
2590 |
|
---|
2591 | /**
|
---|
2592 | * Query Guest Context signed pointer value with default.
|
---|
2593 | *
|
---|
2594 | * @returns VBox status code.
|
---|
2595 | * @param pNode Which node to search for pszName in.
|
---|
2596 | * @param pszName Name of an integer value.
|
---|
2597 | * @param pGCPtr Where to store the value. Set to default on failure.
|
---|
2598 | * @param GCPtrDef The default value.
|
---|
2599 | */
|
---|
2600 | VMMR3DECL(int) CFGMR3QueryGCPtrSDef(PCFGMNODE pNode, const char *pszName, PRTGCINTPTR pGCPtr, RTGCINTPTR GCPtrDef)
|
---|
2601 | {
|
---|
2602 | uint64_t u64;
|
---|
2603 | int rc = CFGMR3QueryIntegerDef(pNode, pszName, &u64, GCPtrDef);
|
---|
2604 | if (RT_SUCCESS(rc))
|
---|
2605 | {
|
---|
2606 | RTGCINTPTR u = (RTGCINTPTR)u64;
|
---|
2607 | if (u64 == (uint64_t)u)
|
---|
2608 | *pGCPtr = u;
|
---|
2609 | else
|
---|
2610 | rc = VERR_CFGM_INTEGER_TOO_BIG;
|
---|
2611 | }
|
---|
2612 | if (RT_FAILURE(rc))
|
---|
2613 | *pGCPtr = GCPtrDef;
|
---|
2614 | return rc;
|
---|
2615 | }
|
---|
2616 |
|
---|
2617 |
|
---|
2618 | /**
|
---|
2619 | * Query zero terminated character value storing it in a
|
---|
2620 | * buffer allocated from the MM heap.
|
---|
2621 | *
|
---|
2622 | * @returns VBox status code.
|
---|
2623 | * @param pNode Which node to search for pszName in.
|
---|
2624 | * @param pszName Value name. This value must be of zero terminated character string type.
|
---|
2625 | * @param ppszString Where to store the string pointer.
|
---|
2626 | * Free this using MMR3HeapFree().
|
---|
2627 | */
|
---|
2628 | VMMR3DECL(int) CFGMR3QueryStringAlloc(PCFGMNODE pNode, const char *pszName, char **ppszString)
|
---|
2629 | {
|
---|
2630 | size_t cbString;
|
---|
2631 | int rc = CFGMR3QuerySize(pNode, pszName, &cbString);
|
---|
2632 | if (RT_SUCCESS(rc))
|
---|
2633 | {
|
---|
2634 | char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbString);
|
---|
2635 | if (pszString)
|
---|
2636 | {
|
---|
2637 | rc = CFGMR3QueryString(pNode, pszName, pszString, cbString);
|
---|
2638 | if (RT_SUCCESS(rc))
|
---|
2639 | *ppszString = pszString;
|
---|
2640 | else
|
---|
2641 | MMR3HeapFree(pszString);
|
---|
2642 | }
|
---|
2643 | else
|
---|
2644 | rc = VERR_NO_MEMORY;
|
---|
2645 | }
|
---|
2646 | return rc;
|
---|
2647 | }
|
---|
2648 |
|
---|
2649 |
|
---|
2650 | /**
|
---|
2651 | * Query zero terminated character value storing it in a
|
---|
2652 | * buffer allocated from the MM heap.
|
---|
2653 | *
|
---|
2654 | * @returns VBox status code.
|
---|
2655 | * @param pNode Which node to search for pszName in.
|
---|
2656 | * @param pszName Value name. This value must be of zero terminated character string type.
|
---|
2657 | * @param ppszString Where to store the string pointer. Not set on failure.
|
---|
2658 | * Free this using MMR3HeapFree().
|
---|
2659 | * @param pszDef The default return value. This can be NULL.
|
---|
2660 | */
|
---|
2661 | VMMR3DECL(int) CFGMR3QueryStringAllocDef(PCFGMNODE pNode, const char *pszName, char **ppszString, const char *pszDef)
|
---|
2662 | {
|
---|
2663 | /*
|
---|
2664 | * (Don't call CFGMR3QuerySize and CFGMR3QueryStringDef here as the latter
|
---|
2665 | * cannot handle pszDef being NULL.)
|
---|
2666 | */
|
---|
2667 | PCFGMLEAF pLeaf;
|
---|
2668 | int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
|
---|
2669 | if (RT_SUCCESS(rc))
|
---|
2670 | {
|
---|
2671 | if (pLeaf->enmType == CFGMVALUETYPE_STRING)
|
---|
2672 | {
|
---|
2673 | size_t const cbSrc = pLeaf->Value.String.cb;
|
---|
2674 | char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbSrc);
|
---|
2675 | if (pszString)
|
---|
2676 | {
|
---|
2677 | memcpy(pszString, pLeaf->Value.String.psz, cbSrc);
|
---|
2678 | *ppszString = pszString;
|
---|
2679 | }
|
---|
2680 | else
|
---|
2681 | rc = VERR_NO_MEMORY;
|
---|
2682 | }
|
---|
2683 | else
|
---|
2684 | rc = VERR_CFGM_NOT_STRING;
|
---|
2685 | }
|
---|
2686 | if (RT_FAILURE(rc))
|
---|
2687 | {
|
---|
2688 | if (!pszDef)
|
---|
2689 | *ppszString = NULL;
|
---|
2690 | else
|
---|
2691 | *ppszString = MMR3HeapStrDup(pNode->pVM, MM_TAG_CFGM_USER, pszDef);
|
---|
2692 | if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
|
---|
2693 | rc = VINF_SUCCESS;
|
---|
2694 | }
|
---|
2695 |
|
---|
2696 | return rc;
|
---|
2697 | }
|
---|
2698 |
|
---|
2699 |
|
---|
2700 | /**
|
---|
2701 | * Dumps the configuration (sub)tree to the release log.
|
---|
2702 | *
|
---|
2703 | * @param pRoot The root node of the dump.
|
---|
2704 | */
|
---|
2705 | VMMR3DECL(void) CFGMR3Dump(PCFGMNODE pRoot)
|
---|
2706 | {
|
---|
2707 | LogRel(("************************* CFGM dump *************************\n"));
|
---|
2708 | bool fOldBuffered = RTLogRelSetBuffering(true /*fBuffered*/);
|
---|
2709 | cfgmR3Dump(pRoot, 0, DBGFR3InfoLogRelHlp());
|
---|
2710 | RTLogRelSetBuffering(fOldBuffered);
|
---|
2711 | LogRel(("********************* End of CFGM dump **********************\n"));
|
---|
2712 | }
|
---|
2713 |
|
---|
2714 |
|
---|
2715 | /**
|
---|
2716 | * Info handler, internal version.
|
---|
2717 | *
|
---|
2718 | * @param pVM The VM handle.
|
---|
2719 | * @param pHlp Callback functions for doing output.
|
---|
2720 | * @param pszArgs Argument string. Optional and specific to the handler.
|
---|
2721 | */
|
---|
2722 | static DECLCALLBACK(void) cfgmR3Info(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
|
---|
2723 | {
|
---|
2724 | /*
|
---|
2725 | * Figure where to start.
|
---|
2726 | */
|
---|
2727 | PCFGMNODE pRoot = pVM->cfgm.s.pRoot;
|
---|
2728 | if (pszArgs && *pszArgs)
|
---|
2729 | {
|
---|
2730 | int rc = cfgmR3ResolveNode(pRoot, pszArgs, &pRoot);
|
---|
2731 | if (RT_FAILURE(rc))
|
---|
2732 | {
|
---|
2733 | pHlp->pfnPrintf(pHlp, "Failed to resolve CFGM path '%s', %Rrc", pszArgs, rc);
|
---|
2734 | return;
|
---|
2735 | }
|
---|
2736 | }
|
---|
2737 |
|
---|
2738 | /*
|
---|
2739 | * Dump the specified tree.
|
---|
2740 | */
|
---|
2741 | pHlp->pfnPrintf(pHlp, "pRoot=%p:{", pRoot);
|
---|
2742 | cfgmR3DumpPath(pRoot, pHlp);
|
---|
2743 | pHlp->pfnPrintf(pHlp, "}\n");
|
---|
2744 | cfgmR3Dump(pRoot, 0, pHlp);
|
---|
2745 | }
|
---|
2746 |
|
---|
2747 |
|
---|
2748 | /**
|
---|
2749 | * Recursively prints a path name.
|
---|
2750 | */
|
---|
2751 | static void cfgmR3DumpPath(PCFGMNODE pNode, PCDBGFINFOHLP pHlp)
|
---|
2752 | {
|
---|
2753 | if (pNode->pParent)
|
---|
2754 | cfgmR3DumpPath(pNode->pParent, pHlp);
|
---|
2755 | pHlp->pfnPrintf(pHlp, "%s/", pNode->szName);
|
---|
2756 | }
|
---|
2757 |
|
---|
2758 |
|
---|
2759 | /**
|
---|
2760 | * Dumps a branch of a tree.
|
---|
2761 | */
|
---|
2762 | static void cfgmR3Dump(PCFGMNODE pRoot, unsigned iLevel, PCDBGFINFOHLP pHlp)
|
---|
2763 | {
|
---|
2764 | /*
|
---|
2765 | * Path.
|
---|
2766 | */
|
---|
2767 | pHlp->pfnPrintf(pHlp, "[");
|
---|
2768 | cfgmR3DumpPath(pRoot, pHlp);
|
---|
2769 | pHlp->pfnPrintf(pHlp, "] (level %d)%s\n", iLevel, pRoot->fRestrictedRoot ? " (restricted root)" : "");
|
---|
2770 |
|
---|
2771 | /*
|
---|
2772 | * Values.
|
---|
2773 | */
|
---|
2774 | PCFGMLEAF pLeaf;
|
---|
2775 | size_t cchMax = 0;
|
---|
2776 | for (pLeaf = CFGMR3GetFirstValue(pRoot); pLeaf; pLeaf = CFGMR3GetNextValue(pLeaf))
|
---|
2777 | cchMax = RT_MAX(cchMax, pLeaf->cchName);
|
---|
2778 | for (pLeaf = CFGMR3GetFirstValue(pRoot); pLeaf; pLeaf = CFGMR3GetNextValue(pLeaf))
|
---|
2779 | {
|
---|
2780 | switch (CFGMR3GetValueType(pLeaf))
|
---|
2781 | {
|
---|
2782 | case CFGMVALUETYPE_INTEGER:
|
---|
2783 | pHlp->pfnPrintf(pHlp, " %-*s <integer> = %#018llx (%lld)\n", (int)cchMax, pLeaf->szName, pLeaf->Value.Integer.u64, pLeaf->Value.Integer.u64);
|
---|
2784 | break;
|
---|
2785 |
|
---|
2786 | case CFGMVALUETYPE_STRING:
|
---|
2787 | pHlp->pfnPrintf(pHlp, " %-*s <string> = \"%s\" (cb=%zu)\n", (int)cchMax, pLeaf->szName, pLeaf->Value.String.psz, pLeaf->Value.String.cb);
|
---|
2788 | break;
|
---|
2789 |
|
---|
2790 | case CFGMVALUETYPE_BYTES:
|
---|
2791 | pHlp->pfnPrintf(pHlp, " %-*s <bytes> = \"%.*Rhxs\" (cb=%zu)\n", (int)cchMax, pLeaf->szName, pLeaf->Value.Bytes.cb, pLeaf->Value.Bytes.pau8, pLeaf->Value.Bytes.cb);
|
---|
2792 | break;
|
---|
2793 |
|
---|
2794 | default:
|
---|
2795 | AssertMsgFailed(("bad leaf!\n"));
|
---|
2796 | break;
|
---|
2797 | }
|
---|
2798 | }
|
---|
2799 | pHlp->pfnPrintf(pHlp, "\n");
|
---|
2800 |
|
---|
2801 | /*
|
---|
2802 | * Children.
|
---|
2803 | */
|
---|
2804 | for (PCFGMNODE pChild = CFGMR3GetFirstChild(pRoot); pChild; pChild = CFGMR3GetNextChild(pChild))
|
---|
2805 | {
|
---|
2806 | Assert(pChild->pNext != pChild);
|
---|
2807 | Assert(pChild->pPrev != pChild);
|
---|
2808 | Assert(pChild->pPrev != pChild->pNext || !pChild->pPrev);
|
---|
2809 | Assert(pChild->pFirstChild != pChild);
|
---|
2810 | Assert(pChild->pParent != pChild);
|
---|
2811 | cfgmR3Dump(pChild, iLevel + 1, pHlp);
|
---|
2812 | }
|
---|
2813 | }
|
---|
2814 |
|
---|