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