VirtualBox

source: vbox/trunk/src/VBox/Main/ConsoleImpl2.cpp@ 12432

Last change on this file since 12432 was 12432, checked in by vboxsync, 16 years ago

grr

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 91.1 KB
Line 
1/** $Id: ConsoleImpl2.cpp 12432 2008-09-12 15:32:54Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation
4 *
5 * @remark We've split out the code that the 64-bit VC++ v8 compiler
6 * finds problematic to optimize so we can disable optimizations
7 * and later, perhaps, find a real solution for it.
8 */
9
10/*
11 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.virtualbox.org. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License (GPL) as published by the Free Software
17 * Foundation, in version 2 as it comes in the "COPYING" file of the
18 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
22 * Clara, CA 95054 USA or visit http://www.sun.com if you need
23 * additional information or have any questions.
24 */
25
26/*******************************************************************************
27* Header Files *
28*******************************************************************************/
29#include "ConsoleImpl.h"
30#include "DisplayImpl.h"
31#include "VMMDev.h"
32
33// generated header
34#include "SchemaDefs.h"
35
36#include "Logging.h"
37
38#include <iprt/string.h>
39#include <iprt/path.h>
40#include <iprt/dir.h>
41#include <iprt/param.h>
42
43#include <VBox/vmapi.h>
44#include <VBox/err.h>
45#include <VBox/version.h>
46#include <VBox/HostServices/VBoxClipboardSvc.h>
47#ifdef VBOX_WITH_GUEST_PROPS
48# include <VBox/HostServices/GuestPropertySvc.h>
49# include <VBox/com/defs.h>
50# include <VBox/com/array.h>
51#endif /* VBOX_WITH_GUEST_PROPS */
52#include <VBox/intnet.h>
53
54
55/*
56 * VC++ 8 / amd64 has some serious trouble with this function.
57 * As a temporary measure, we'll drop global optimizations.
58 */
59#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
60# pragma optimize("g", off)
61#endif
62
63/**
64 * Construct the VM configuration tree (CFGM).
65 *
66 * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
67 * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
68 * is done here.
69 *
70 * @param pVM VM handle.
71 * @param pvConsole Pointer to the VMPowerUpTask object.
72 * @return VBox status code.
73 *
74 * @note Locks the Console object for writing.
75 */
76DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
77{
78 LogFlowFuncEnter();
79 /* Note: hardcoded assumption about number of slots; see rom bios */
80 bool afPciDeviceNo[15] = {false};
81
82#if !defined (VBOX_WITH_XPCOM)
83 {
84 /* initialize COM */
85 HRESULT hrc = CoInitializeEx(NULL,
86 COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
87 COINIT_SPEED_OVER_MEMORY);
88 LogFlow (("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
89 AssertComRCReturn (hrc, VERR_GENERAL_FAILURE);
90 }
91#endif
92
93 AssertReturn (pvConsole, VERR_GENERAL_FAILURE);
94 ComObjPtr <Console> pConsole = static_cast <Console *> (pvConsole);
95
96 AutoCaller autoCaller (pConsole);
97 AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
98
99 /* lock the console because we widely use internal fields and methods */
100 AutoWriteLock alock (pConsole);
101
102 ComPtr <IMachine> pMachine = pConsole->machine();
103
104 int rc;
105 HRESULT hrc;
106 char *psz = NULL;
107 BSTR str = NULL;
108
109#define STR_CONV() do { rc = RTUtf16ToUtf8(str, &psz); RC_CHECK(); } while (0)
110#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
111#define RC_CHECK() do { if (VBOX_FAILURE(rc)) { AssertMsgFailed(("rc=%Vrc\n", rc)); STR_FREE(); return rc; } } while (0)
112#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
113
114 /*
115 * Get necessary objects and frequently used parameters.
116 */
117 ComPtr<IVirtualBox> virtualBox;
118 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
119
120 ComPtr<IHost> host;
121 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
122
123 ComPtr <ISystemProperties> systemProperties;
124 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
125
126 ComPtr<IBIOSSettings> biosSettings;
127 hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
128
129 Guid uuid;
130 hrc = pMachine->COMGETTER(Id)(uuid.asOutParam()); H();
131 PCRTUUID pUuid = uuid.raw();
132
133 ULONG cRamMBs;
134 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
135
136#ifdef VBOX_WITH_SMP_GUESTS
137 /* @todo nike: Testing code, should use actual getter when ready */
138 uint16_t cCpus = 2;
139#else
140 uint16_t cCpus = 1;
141#endif
142
143 /*
144 * Get root node first.
145 * This is the only node in the tree.
146 */
147 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
148 Assert(pRoot);
149
150 /*
151 * Set the root level values.
152 */
153 hrc = pMachine->COMGETTER(Name)(&str); H();
154 STR_CONV();
155 rc = CFGMR3InsertString(pRoot, "Name", psz); RC_CHECK();
156 STR_FREE();
157 rc = CFGMR3InsertBytes(pRoot, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
158 rc = CFGMR3InsertInteger(pRoot, "RamSize", cRamMBs * _1M); RC_CHECK();
159 rc = CFGMR3InsertInteger(pRoot, "NumCPUs", cCpus); RC_CHECK();
160 rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
161 rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
162 rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
163 /** @todo Config: RawR0, PATMEnabled and CASMEnabled needs attention later. */
164 rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
165 rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
166
167 /* hardware virtualization extensions */
168 TSBool_T hwVirtExEnabled;
169 BOOL fHWVirtExEnabled;
170 hrc = pMachine->COMGETTER(HWVirtExEnabled)(&hwVirtExEnabled); H();
171 if (hwVirtExEnabled == TSBool_Default)
172 {
173 /* check the default value */
174 hrc = systemProperties->COMGETTER(HWVirtExEnabled)(&fHWVirtExEnabled); H();
175 }
176 else
177 fHWVirtExEnabled = (hwVirtExEnabled == TSBool_True);
178#ifndef RT_OS_DARWIN /** @todo Implement HWVirtExt on darwin. See #1865. */
179 if (fHWVirtExEnabled)
180 {
181 PCFGMNODE pHWVirtExt;
182 rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHWVirtExt); RC_CHECK();
183 rc = CFGMR3InsertInteger(pHWVirtExt, "Enabled", 1); RC_CHECK();
184 }
185#endif
186
187 /* Nested paging (VT-x/AMD-V) */
188 BOOL fEnableNestedPaging = false;
189 hrc = pMachine->COMGETTER(HWVirtExNestedPagingEnabled)(&fEnableNestedPaging); H();
190 rc = CFGMR3InsertInteger(pRoot, "EnableNestedPaging", fEnableNestedPaging); RC_CHECK();
191
192 /* Physical Address Extension (PAE) */
193 BOOL fEnablePAE = false;
194 hrc = pMachine->COMGETTER(PAEEnabled)(&fEnablePAE); H();
195 rc = CFGMR3InsertInteger(pRoot, "EnablePAE", fEnablePAE); RC_CHECK();
196
197 BOOL fIOAPIC;
198 hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
199
200 BOOL fPXEDebug;
201 hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
202
203 /*
204 * Virtual IDE controller type.
205 */
206 IDEControllerType_T controllerType;
207 BOOL fPIIX4;
208 hrc = biosSettings->COMGETTER(IDEControllerType)(&controllerType); H();
209 switch (controllerType)
210 {
211 case IDEControllerType_PIIX3:
212 fPIIX4 = FALSE;
213 break;
214 case IDEControllerType_PIIX4:
215 fPIIX4 = TRUE;
216 break;
217 default:
218 AssertMsgFailed(("Invalid IDE controller type '%d'", controllerType));
219 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
220 N_("Invalid IDE controller type '%d'"), controllerType);
221 }
222
223 /*
224 * PDM config.
225 * Load drivers in VBoxC.[so|dll]
226 */
227 PCFGMNODE pPDM;
228 PCFGMNODE pDrivers;
229 PCFGMNODE pMod;
230 rc = CFGMR3InsertNode(pRoot, "PDM", &pPDM); RC_CHECK();
231 rc = CFGMR3InsertNode(pPDM, "Drivers", &pDrivers); RC_CHECK();
232 rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod); RC_CHECK();
233#ifdef VBOX_WITH_XPCOM
234 // VBoxC is located in the components subdirectory
235 char szPathVBoxC[RTPATH_MAX];
236 rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
237 strcat(szPathVBoxC, "/components/VBoxC");
238 rc = CFGMR3InsertString(pMod, "Path", szPathVBoxC); RC_CHECK();
239#else
240 rc = CFGMR3InsertString(pMod, "Path", "VBoxC"); RC_CHECK();
241#endif
242
243 /*
244 * Devices
245 */
246 PCFGMNODE pDevices = NULL; /* /Devices */
247 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
248 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
249 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
250 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
251 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
252 PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
253 PCFGMNODE pIdeInst = NULL; /* /Devices/piix3ide/0/ */
254 PCFGMNODE pSataInst = NULL; /* /Devices/ahci/0/ */
255 PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
256#ifdef VBOX_WITH_GUEST_PROPS
257 PCFGMNODE pGuestProps = NULL; /* /GuestProps */
258 PCFGMNODE pValues = NULL; /* /GuestProps/Values */
259 PCFGMNODE pTimestamps = NULL; /* /GuestProps/Timestamps */
260 PCFGMNODE pFlags = NULL; /* /GuestProps/Flags */
261#endif /* VBOX_WITH_GUEST_PROPS defined */
262
263 rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); RC_CHECK();
264
265 /*
266 * PC Arch.
267 */
268 rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); RC_CHECK();
269 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
270 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
271 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
272
273 /*
274 * PC Bios.
275 */
276 rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); RC_CHECK();
277 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
278 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
279 rc = CFGMR3InsertNode(pInst, "Config", &pBiosCfg); RC_CHECK();
280 rc = CFGMR3InsertInteger(pBiosCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
281 rc = CFGMR3InsertInteger(pBiosCfg, "NumCPUs", cCpus); RC_CHECK();
282 rc = CFGMR3InsertString(pBiosCfg, "HardDiskDevice", "piix3ide"); RC_CHECK();
283 rc = CFGMR3InsertString(pBiosCfg, "FloppyDevice", "i82078"); RC_CHECK();
284 rc = CFGMR3InsertInteger(pBiosCfg, "IOAPIC", fIOAPIC); RC_CHECK();
285 rc = CFGMR3InsertInteger(pBiosCfg, "PXEDebug", fPXEDebug); RC_CHECK();
286 rc = CFGMR3InsertBytes(pBiosCfg, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
287
288 DeviceType_T bootDevice;
289 if (SchemaDefs::MaxBootPosition > 9)
290 {
291 AssertMsgFailed (("Too many boot devices %d\n",
292 SchemaDefs::MaxBootPosition));
293 return VERR_INVALID_PARAMETER;
294 }
295
296 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; pos ++)
297 {
298 hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
299
300 char szParamName[] = "BootDeviceX";
301 szParamName[sizeof (szParamName) - 2] = ((char (pos - 1)) + '0');
302
303 const char *pszBootDevice;
304 switch (bootDevice)
305 {
306 case DeviceType_Null:
307 pszBootDevice = "NONE";
308 break;
309 case DeviceType_HardDisk:
310 pszBootDevice = "IDE";
311 break;
312 case DeviceType_DVD:
313 pszBootDevice = "DVD";
314 break;
315 case DeviceType_Floppy:
316 pszBootDevice = "FLOPPY";
317 break;
318 case DeviceType_Network:
319 pszBootDevice = "LAN";
320 break;
321 default:
322 AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
323 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
324 N_("Invalid boot device '%d'"), bootDevice);
325 }
326 rc = CFGMR3InsertString(pBiosCfg, szParamName, pszBootDevice); RC_CHECK();
327 }
328
329 /*
330 * The time offset
331 */
332 LONG64 timeOffset;
333 hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
334 PCFGMNODE pTMNode;
335 rc = CFGMR3InsertNode(pRoot, "TM", &pTMNode); RC_CHECK();
336 rc = CFGMR3InsertInteger(pTMNode, "UTCOffset", timeOffset * 1000000); RC_CHECK();
337
338 /*
339 * DMA
340 */
341 rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); RC_CHECK();
342 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
343 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
344
345 /*
346 * PCI bus.
347 */
348 rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ RC_CHECK();
349 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
350 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
351 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
352 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
353
354 /*
355 * PS/2 keyboard & mouse.
356 */
357 rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); RC_CHECK();
358 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
359 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
360 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
361
362 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
363 rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
364 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
365 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
366
367 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
368 rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
369 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
370 Keyboard *pKeyboard = pConsole->mKeyboard;
371 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
372
373 rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); RC_CHECK();
374 rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
375 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
376 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
377
378 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
379 rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
380 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
381 Mouse *pMouse = pConsole->mMouse;
382 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
383
384 /*
385 * i82078 Floppy drive controller
386 */
387 ComPtr<IFloppyDrive> floppyDrive;
388 hrc = pMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam()); H();
389 BOOL fFdcEnabled;
390 hrc = floppyDrive->COMGETTER(Enabled)(&fFdcEnabled); H();
391 if (fFdcEnabled)
392 {
393 rc = CFGMR3InsertNode(pDevices, "i82078", &pDev); RC_CHECK();
394 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
395 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); RC_CHECK();
396 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
397 rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); RC_CHECK();
398 rc = CFGMR3InsertInteger(pCfg, "DMA", 2); RC_CHECK();
399 rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); RC_CHECK();
400 rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); RC_CHECK();
401
402 /* Attach the status driver */
403 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
404 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
405 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
406 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapFDLeds[0]); RC_CHECK();
407 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
408 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
409
410 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
411
412 ComPtr<IFloppyImage> floppyImage;
413 hrc = floppyDrive->GetImage(floppyImage.asOutParam()); H();
414 if (floppyImage)
415 {
416 pConsole->meFloppyState = DriveState_ImageMounted;
417 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
418 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
419 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
420 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
421
422 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
423 rc = CFGMR3InsertString(pLunL1, "Driver", "RawImage"); RC_CHECK();
424 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
425 hrc = floppyImage->COMGETTER(FilePath)(&str); H();
426 STR_CONV();
427 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
428 STR_FREE();
429 }
430 else
431 {
432 ComPtr<IHostFloppyDrive> hostFloppyDrive;
433 hrc = floppyDrive->GetHostDrive(hostFloppyDrive.asOutParam()); H();
434 if (hostFloppyDrive)
435 {
436 pConsole->meFloppyState = DriveState_HostDriveCaptured;
437 rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy"); RC_CHECK();
438 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
439 hrc = hostFloppyDrive->COMGETTER(Name)(&str); H();
440 STR_CONV();
441 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
442 STR_FREE();
443 }
444 else
445 {
446 pConsole->meFloppyState = DriveState_NotMounted;
447 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
448 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
449 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
450 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
451 }
452 }
453 }
454
455 /*
456 * ACPI
457 */
458 BOOL fACPI;
459 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
460 if (fACPI)
461 {
462 rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
463 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
464 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
465 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
466 rc = CFGMR3InsertInteger(pCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
467 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
468
469 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
470 rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
471 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
472 Assert(!afPciDeviceNo[7]);
473 afPciDeviceNo[7] = true;
474 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
475
476 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
477 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
478 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
479 }
480
481 /*
482 * i8254 Programmable Interval Timer And Dummy Speaker
483 */
484 rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
485 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
486 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
487#ifdef DEBUG
488 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
489#endif
490
491 /*
492 * i8259 Programmable Interrupt Controller.
493 */
494 rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
495 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
496 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
497 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
498
499 /*
500 * Advanced Programmable Interrupt Controller.
501 */
502 rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
503 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
504 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
505 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
506 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
507
508 if (fIOAPIC)
509 {
510 /*
511 * I/O Advanced Programmable Interrupt Controller.
512 */
513 rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
514 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
515 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
516 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
517 }
518
519 /*
520 * RTC MC146818.
521 */
522 rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
523 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
524 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
525
526 /*
527 * VGA.
528 */
529 rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
530 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
531 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
532 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
533 Assert(!afPciDeviceNo[2]);
534 afPciDeviceNo[2] = true;
535 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
536 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
537 hrc = pMachine->COMGETTER(VRAMSize)(&cRamMBs); H();
538 rc = CFGMR3InsertInteger(pCfg, "VRamSize", cRamMBs * _1M); RC_CHECK();
539
540 /*
541 * BIOS logo
542 */
543 BOOL fFadeIn;
544 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
545 rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
546 BOOL fFadeOut;
547 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
548 rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
549 ULONG logoDisplayTime;
550 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
551 rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
552 Bstr logoImagePath;
553 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
554 rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath) : ""); RC_CHECK();
555
556 /*
557 * Boot menu
558 */
559 BIOSBootMenuMode_T bootMenuMode;
560 int value;
561 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
562 switch (bootMenuMode)
563 {
564 case BIOSBootMenuMode_Disabled:
565 value = 0;
566 break;
567 case BIOSBootMenuMode_MenuOnly:
568 value = 1;
569 break;
570 default:
571 value = 2;
572 }
573 rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", value); RC_CHECK();
574
575 /* Custom VESA mode list */
576 unsigned cModes = 0;
577 for (unsigned iMode = 1; iMode <= 16; iMode++)
578 {
579 char szExtraDataKey[sizeof("CustomVideoModeXX")];
580 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%d", iMode);
581 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), &str); H();
582 if (!str || !*str)
583 break;
584 STR_CONV();
585 rc = CFGMR3InsertString(pCfg, szExtraDataKey, psz);
586 STR_FREE();
587 cModes++;
588 }
589 rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes);
590
591 /* VESA height reduction */
592 ULONG ulHeightReduction;
593 IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
594 if (pFramebuffer)
595 {
596 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
597 }
598 else
599 {
600 /* If framebuffer is not available, there is no height reduction. */
601 ulHeightReduction = 0;
602 }
603 rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
604
605 /* Attach the display. */
606 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
607 rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
608 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
609 Display *pDisplay = pConsole->mDisplay;
610 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
611
612 /*
613 * IDE (update this when the main interface changes)
614 */
615 rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */ RC_CHECK();
616 rc = CFGMR3InsertNode(pDev, "0", &pIdeInst); RC_CHECK();
617 rc = CFGMR3InsertInteger(pIdeInst, "Trusted", 1); /* boolean */ RC_CHECK();
618 rc = CFGMR3InsertInteger(pIdeInst, "PCIDeviceNo", 1); RC_CHECK();
619 Assert(!afPciDeviceNo[1]);
620 afPciDeviceNo[1] = true;
621 rc = CFGMR3InsertInteger(pIdeInst, "PCIFunctionNo", 1); RC_CHECK();
622 rc = CFGMR3InsertNode(pIdeInst, "Config", &pCfg); RC_CHECK();
623 rc = CFGMR3InsertInteger(pCfg, "PIIX4", fPIIX4); /* boolean */ RC_CHECK();
624
625 /* Attach the status driver */
626 rc = CFGMR3InsertNode(pIdeInst, "LUN#999", &pLunL0); RC_CHECK();
627 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
628 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
629 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapIDELeds[0]);RC_CHECK();
630 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
631 rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
632
633 /*
634 * SATA controller
635 */
636 ComPtr<ISATAController> sataController;
637 hrc = pMachine->COMGETTER(SATAController)(sataController.asOutParam());
638 BOOL enabled = FALSE;
639
640 if (sataController)
641 {
642 hrc = sataController->COMGETTER(Enabled)(&enabled); H();
643
644 if (enabled)
645 {
646 rc = CFGMR3InsertNode(pDevices, "ahci", &pDev); RC_CHECK();
647 rc = CFGMR3InsertNode(pDev, "0", &pSataInst); RC_CHECK();
648 rc = CFGMR3InsertInteger(pSataInst, "Trusted", 1); RC_CHECK();
649 rc = CFGMR3InsertInteger(pSataInst, "PCIDeviceNo", 13); RC_CHECK();
650 Assert(!afPciDeviceNo[13]);
651 afPciDeviceNo[13] = true;
652 rc = CFGMR3InsertInteger(pSataInst, "PCIFunctionNo", 0); RC_CHECK();
653 rc = CFGMR3InsertNode(pSataInst, "Config", &pCfg); RC_CHECK();
654
655 ULONG cPorts = 0;
656 hrc = sataController->COMGETTER(PortCount)(&cPorts); H();
657 rc = CFGMR3InsertInteger(pCfg, "PortCount", cPorts); RC_CHECK();
658
659 /* Needed configuration values for the bios. */
660 rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
661
662 for (uint32_t i = 0; i < 4; i++)
663 {
664 static const char *s_apszConfig[4] =
665 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
666 static const char *s_apszBiosConfig[4] =
667 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
668
669 LONG lPortNumber = -1;
670 hrc = sataController->GetIDEEmulationPort(i, &lPortNumber); H();
671 rc = CFGMR3InsertInteger(pCfg, s_apszConfig[i], lPortNumber); RC_CHECK();
672 rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[i], lPortNumber); RC_CHECK();
673 }
674
675 /* Attach the status driver */
676 rc = CFGMR3InsertNode(pSataInst,"LUN#999", &pLunL0); RC_CHECK();
677 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
678 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
679 AssertRelease(cPorts <= RT_ELEMENTS(pConsole->mapSATALeds));
680 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSATALeds[0]); RC_CHECK();
681 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
682 rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
683 }
684 }
685
686 /* Attach the harddisks */
687 ComPtr<IHardDiskAttachmentCollection> hdaColl;
688 hrc = pMachine->COMGETTER(HardDiskAttachments)(hdaColl.asOutParam()); H();
689 ComPtr<IHardDiskAttachmentEnumerator> hdaEnum;
690 hrc = hdaColl->Enumerate(hdaEnum.asOutParam()); H();
691
692 BOOL fMore = FALSE;
693 while ( SUCCEEDED(hrc = hdaEnum->HasMore(&fMore))
694 && fMore)
695 {
696 PCFGMNODE pHardDiskCtl;
697 ComPtr<IHardDiskAttachment> hda;
698 hrc = hdaEnum->GetNext(hda.asOutParam()); H();
699 ComPtr<IHardDisk> hardDisk;
700 hrc = hda->COMGETTER(HardDisk)(hardDisk.asOutParam()); H();
701 StorageBus_T enmBus;
702 hrc = hda->COMGETTER(Bus)(&enmBus); H();
703 LONG lDev;
704 hrc = hda->COMGETTER(Device)(&lDev); H();
705 LONG lChannel;
706 hrc = hda->COMGETTER(Channel)(&lChannel); H();
707
708 int iLUN;
709 switch (enmBus)
710 {
711 case StorageBus_IDE:
712 {
713 if (lChannel >= 2 || lChannel < 0)
714 {
715 AssertMsgFailed(("invalid controller channel number: %d\n", lChannel));
716 return VERR_GENERAL_FAILURE;
717 }
718
719 if (lDev >= 2 || lDev < 0)
720 {
721 AssertMsgFailed(("invalid controller device number: %d\n", lDev));
722 return VERR_GENERAL_FAILURE;
723 }
724 iLUN = 2*lChannel + lDev;
725 pHardDiskCtl = pIdeInst;
726 }
727 break;
728 case StorageBus_SATA:
729 iLUN = lChannel;
730 pHardDiskCtl = enabled ? pSataInst : NULL;
731 break;
732 default:
733 AssertMsgFailed(("invalid disk controller type: %d\n", enmBus));
734 return VERR_GENERAL_FAILURE;
735 }
736
737 /* Can be NULL if SATA controller is not enabled and current hard disk is attached to SATA controller. */
738 if (pHardDiskCtl)
739 {
740 char szLUN[16];
741 RTStrPrintf(szLUN, sizeof(szLUN), "LUN#%d", iLUN);
742 rc = CFGMR3InsertNode(pHardDiskCtl, szLUN, &pLunL0); RC_CHECK();
743 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
744 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
745 rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); RC_CHECK();
746 rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); RC_CHECK();
747
748 HardDiskStorageType_T hddType;
749 hardDisk->COMGETTER(StorageType)(&hddType);
750 if (hddType == HardDiskStorageType_VirtualDiskImage)
751 {
752 ComPtr<IVirtualDiskImage> vdiDisk = hardDisk;
753 AssertBreakStmt (!vdiDisk.isNull(), hrc = E_FAIL);
754
755 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
756 rc = CFGMR3InsertString(pLunL1, "Driver", "VBoxHDD"); RC_CHECK();
757 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
758 hrc = vdiDisk->COMGETTER(FilePath)(&str); H();
759 STR_CONV();
760 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
761 STR_FREE();
762
763 /* Create an inversed tree of parents. */
764 ComPtr<IHardDisk> parentHardDisk = hardDisk;
765 for (PCFGMNODE pParent = pCfg;;)
766 {
767 ComPtr<IHardDisk> curHardDisk;
768 hrc = parentHardDisk->COMGETTER(Parent)(curHardDisk.asOutParam()); H();
769 if (!curHardDisk)
770 break;
771
772 vdiDisk = curHardDisk;
773 AssertBreakStmt (!vdiDisk.isNull(), hrc = E_FAIL);
774
775 PCFGMNODE pCur;
776 rc = CFGMR3InsertNode(pParent, "Parent", &pCur); RC_CHECK();
777 hrc = vdiDisk->COMGETTER(FilePath)(&str); H();
778 STR_CONV();
779 rc = CFGMR3InsertString(pCur, "Path", psz); RC_CHECK();
780 STR_FREE();
781 rc = CFGMR3InsertInteger(pCur, "ReadOnly", 1); RC_CHECK();
782
783 /* next */
784 pParent = pCur;
785 parentHardDisk = curHardDisk;
786 }
787 }
788 else if (hddType == HardDiskStorageType_ISCSIHardDisk)
789 {
790 ComPtr<IISCSIHardDisk> iSCSIDisk = hardDisk;
791 AssertBreakStmt (!iSCSIDisk.isNull(), hrc = E_FAIL);
792
793 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
794 rc = CFGMR3InsertString(pLunL1, "Driver", "iSCSI"); RC_CHECK();
795 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
796
797 /* Set up the iSCSI initiator driver configuration. */
798 hrc = iSCSIDisk->COMGETTER(Target)(&str); H();
799 STR_CONV();
800 rc = CFGMR3InsertString(pCfg, "TargetName", psz); RC_CHECK();
801 STR_FREE();
802
803 ULONG64 lun;
804 hrc = iSCSIDisk->COMGETTER(Lun)(&lun); H();
805 rc = CFGMR3InsertInteger(pCfg, "LUN", lun); RC_CHECK();
806
807 hrc = iSCSIDisk->COMGETTER(Server)(&str); H();
808 STR_CONV();
809 USHORT port;
810 hrc = iSCSIDisk->COMGETTER(Port)(&port); H();
811 if (port != 0)
812 {
813 char *pszTN;
814 RTStrAPrintf(&pszTN, "%s:%u", psz, port);
815 rc = CFGMR3InsertString(pCfg, "TargetAddress", pszTN); RC_CHECK();
816 RTStrFree(pszTN);
817 }
818 else
819 {
820 rc = CFGMR3InsertString(pCfg, "TargetAddress", psz); RC_CHECK();
821 }
822 STR_FREE();
823
824 hrc = iSCSIDisk->COMGETTER(UserName)(&str); H();
825 if (str)
826 {
827 STR_CONV();
828 rc = CFGMR3InsertString(pCfg, "InitiatorUsername", psz); RC_CHECK();
829 STR_FREE();
830 }
831
832 hrc = iSCSIDisk->COMGETTER(Password)(&str); H();
833 if (str)
834 {
835 STR_CONV();
836 rc = CFGMR3InsertString(pCfg, "InitiatorSecret", psz); RC_CHECK();
837 STR_FREE();
838 }
839
840 // @todo currently there is no target username config.
841 //rc = CFGMR3InsertString(pCfg, "TargetUsername", ""); RC_CHECK();
842
843 // @todo currently there is no target password config.
844 //rc = CFGMR3InsertString(pCfg, "TargetSecret", ""); RC_CHECK();
845
846 /* The iSCSI initiator needs an attached iSCSI transport driver. */
847 rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
848 rc = CFGMR3InsertString(pLunL2, "Driver", "iSCSITCP"); RC_CHECK();
849 /* Currently the transport driver has no config options. */
850 }
851 else if (hddType == HardDiskStorageType_VMDKImage)
852 {
853 ComPtr<IVMDKImage> vmdkDisk = hardDisk;
854 AssertBreakStmt (!vmdkDisk.isNull(), hrc = E_FAIL);
855
856 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
857#if 1 /* Enable new VD container code (and new VMDK), as the bugs are fixed. */
858 rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
859#else
860 rc = CFGMR3InsertString(pLunL1, "Driver", "VmdkHDD"); RC_CHECK();
861#endif
862 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
863 hrc = vmdkDisk->COMGETTER(FilePath)(&str); H();
864 STR_CONV();
865 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
866 STR_FREE();
867 rc = CFGMR3InsertString(pCfg, "Format", "VMDK"); RC_CHECK();
868
869#if defined(VBOX_WITH_PDM_ASYNC_COMPLETION)
870 /*
871 * Create cfgm nodes for async transport driver because VMDK is currently the only
872 * one which may support async I/O. This has to be made generic based on the capabiliy flags
873 * when the new HardDisk interface is merged.
874 */
875 rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
876 rc = CFGMR3InsertString(pLunL2, "Driver", "TransportAsync"); RC_CHECK();
877 /* The async transport driver has no config options yet. */
878#endif
879 }
880 else if (hddType == HardDiskStorageType_CustomHardDisk)
881 {
882 ComPtr<ICustomHardDisk> customHardDisk = hardDisk;
883 AssertBreakStmt (!customHardDisk.isNull(), hrc = E_FAIL);
884
885 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
886 rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
887 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
888 hrc = customHardDisk->COMGETTER(Location)(&str); H();
889 STR_CONV();
890 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
891 STR_FREE();
892 hrc = customHardDisk->COMGETTER(Format)(&str); H();
893 STR_CONV();
894 rc = CFGMR3InsertString(pCfg, "Format", psz); RC_CHECK();
895 STR_FREE();
896 }
897 else if (hddType == HardDiskStorageType_VHDImage)
898 {
899 ComPtr<IVHDImage> vhdDisk = hardDisk;
900 AssertBreakStmt (!vhdDisk.isNull(), hrc = E_FAIL);
901
902 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
903 rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
904 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
905 hrc = vhdDisk->COMGETTER(FilePath)(&str); H();
906 STR_CONV();
907 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
908 rc = CFGMR3InsertString(pCfg, "Format", "VHD"); RC_CHECK();
909 STR_FREE();
910 }
911 else
912 AssertFailed();
913 }
914 }
915 H();
916
917 ComPtr<IDVDDrive> dvdDrive;
918 hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
919 if (dvdDrive)
920 {
921 // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
922 rc = CFGMR3InsertNode(pIdeInst, "LUN#2", &pLunL0); RC_CHECK();
923 ComPtr<IHostDVDDrive> hostDvdDrive;
924 hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
925 if (hostDvdDrive)
926 {
927 pConsole->meDVDState = DriveState_HostDriveCaptured;
928 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
929 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
930 hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
931 STR_CONV();
932 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
933 STR_FREE();
934 BOOL fPassthrough;
935 hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
936 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
937 }
938 else
939 {
940 pConsole->meDVDState = DriveState_NotMounted;
941 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
942 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
943 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
944 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
945
946 ComPtr<IDVDImage> dvdImage;
947 hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
948 if (dvdImage)
949 {
950 pConsole->meDVDState = DriveState_ImageMounted;
951 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
952 rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
953 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
954 hrc = dvdImage->COMGETTER(FilePath)(&str); H();
955 STR_CONV();
956 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
957 STR_FREE();
958 }
959 }
960 }
961
962 /*
963 * Network adapters
964 */
965 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
966 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
967#ifdef VBOX_WITH_E1000
968 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
969 rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
970#endif
971 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
972 {
973 ComPtr<INetworkAdapter> networkAdapter;
974 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
975 BOOL fEnabled = FALSE;
976 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
977 if (!fEnabled)
978 continue;
979
980 /*
981 * The virtual hardware type. Create appropriate device first.
982 */
983 NetworkAdapterType_T adapterType;
984 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
985 switch (adapterType)
986 {
987 case NetworkAdapterType_Am79C970A:
988 case NetworkAdapterType_Am79C973:
989 pDev = pDevPCNet;
990 break;
991#ifdef VBOX_WITH_E1000
992 case NetworkAdapterType_I82540EM:
993 case NetworkAdapterType_I82543GC:
994 pDev = pDevE1000;
995 break;
996#endif
997 default:
998 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
999 adapterType, ulInstance));
1000 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1001 N_("Invalid network adapter type '%d' for slot '%d'"),
1002 adapterType, ulInstance);
1003 }
1004
1005 char szInstance[4]; Assert(ulInstance <= 999);
1006 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1007 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1008 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1009 /* the first network card gets the PCI ID 3, the next 3 gets 8..10. */
1010 const unsigned iPciDeviceNo = !ulInstance ? 3 : ulInstance - 1 + 8;
1011 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
1012 Assert(!afPciDeviceNo[iPciDeviceNo]);
1013 afPciDeviceNo[iPciDeviceNo] = true;
1014 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1015 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1016
1017 /*
1018 * The virtual hardware type. PCNet supports two types.
1019 */
1020 switch (adapterType)
1021 {
1022 case NetworkAdapterType_Am79C970A:
1023 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1024 break;
1025 case NetworkAdapterType_Am79C973:
1026 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1027 break;
1028 case NetworkAdapterType_I82540EM:
1029 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1030 break;
1031 case NetworkAdapterType_I82543GC:
1032 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1033 break;
1034 }
1035
1036 /*
1037 * Get the MAC address and convert it to binary representation
1038 */
1039 Bstr macAddr;
1040 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1041 Assert(macAddr);
1042 Utf8Str macAddrUtf8 = macAddr;
1043 char *macStr = (char*)macAddrUtf8.raw();
1044 Assert(strlen(macStr) == 12);
1045 RTMAC Mac;
1046 memset(&Mac, 0, sizeof(Mac));
1047 char *pMac = (char*)&Mac;
1048 for (uint32_t i = 0; i < 6; i++)
1049 {
1050 char c1 = *macStr++ - '0';
1051 if (c1 > 9)
1052 c1 -= 7;
1053 char c2 = *macStr++ - '0';
1054 if (c2 > 9)
1055 c2 -= 7;
1056 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1057 }
1058 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1059
1060 /*
1061 * Check if the cable is supposed to be unplugged
1062 */
1063 BOOL fCableConnected;
1064 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1065 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1066
1067 /*
1068 * Line speed to report from custom drivers
1069 */
1070 ULONG ulLineSpeed;
1071 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1072 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1073
1074 /*
1075 * Attach the status driver.
1076 */
1077 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1078 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1079 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1080 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1081
1082 /*
1083 * Enable the packet sniffer if requested.
1084 */
1085 BOOL fSniffer;
1086 hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
1087 if (fSniffer)
1088 {
1089 /* insert the sniffer filter driver. */
1090 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1091 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
1092 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1093 hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
1094 if (str) /* check convention for indicating default file. */
1095 {
1096 STR_CONV();
1097 rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
1098 STR_FREE();
1099 }
1100 }
1101
1102 NetworkAttachmentType_T networkAttachment;
1103 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
1104 switch (networkAttachment)
1105 {
1106 case NetworkAttachmentType_Null:
1107 break;
1108
1109 case NetworkAttachmentType_NAT:
1110 {
1111 if (fSniffer)
1112 {
1113 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1114 }
1115 else
1116 {
1117 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1118 }
1119 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
1120 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1121 /* (Port forwarding goes here.) */
1122
1123 /* Configure TFTP prefix and boot filename. */
1124 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
1125 STR_CONV();
1126 if (psz && *psz)
1127 {
1128 char *pszTFTPPrefix = NULL;
1129 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
1130 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
1131 RTStrFree(pszTFTPPrefix);
1132 }
1133 STR_FREE();
1134 hrc = pMachine->COMGETTER(Name)(&str); H();
1135 STR_CONV();
1136 char *pszBootFile = NULL;
1137 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
1138 STR_FREE();
1139 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
1140 RTStrFree(pszBootFile);
1141
1142 hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
1143 if (str)
1144 {
1145 STR_CONV();
1146 if (psz && *psz)
1147 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1148 STR_FREE();
1149 }
1150 break;
1151 }
1152
1153 case NetworkAttachmentType_HostInterface:
1154 {
1155 /*
1156 * Perform the attachment if required (don't return on error!)
1157 */
1158 hrc = pConsole->attachToHostInterface(networkAdapter);
1159 if (SUCCEEDED(hrc))
1160 {
1161#ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
1162 Assert (pConsole->maTapFD[ulInstance] >= 0);
1163 if (pConsole->maTapFD[ulInstance] >= 0)
1164 {
1165 if (fSniffer)
1166 {
1167 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1168 }
1169 else
1170 {
1171 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1172 }
1173 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1174 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1175# if defined(RT_OS_SOLARIS)
1176 /* Device name/number is required for Solaris as we need it for TAP PPA. */
1177 Bstr tapDeviceName;
1178 networkAdapter->COMGETTER(HostInterface)(tapDeviceName.asOutParam());
1179 if (!tapDeviceName.isEmpty())
1180 rc = CFGMR3InsertString(pCfg, "Device", Utf8Str(tapDeviceName)); RC_CHECK();
1181
1182 /* TAP setup application/script */
1183 Bstr tapSetupApp;
1184 networkAdapter->COMGETTER(TAPSetupApplication)(tapSetupApp.asOutParam());
1185 if (!tapSetupApp.isEmpty())
1186 rc = CFGMR3InsertString(pCfg, "TAPSetupApplication", Utf8Str(tapSetupApp)); RC_CHECK();
1187
1188 /* TAP terminate application/script */
1189 Bstr tapTerminateApp;
1190 networkAdapter->COMGETTER(TAPTerminateApplication)(tapTerminateApp.asOutParam());
1191 if (!tapTerminateApp.isEmpty())
1192 rc = CFGMR3InsertString(pCfg, "TAPTerminateApplication", Utf8Str(tapTerminateApp)); RC_CHECK();
1193
1194 /* "FileHandle" must NOT be inserted here, it is done in DrvTAP.cpp */
1195
1196# ifdef VBOX_WITH_CROSSBOW
1197 /* Crossbow: needs the MAC address for setting up TAP. */
1198 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1199# endif
1200# else
1201 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
1202# endif
1203 }
1204
1205#elif defined(VBOX_WITH_NETFLT) && !defined(RT_OS_WINDOWS) /** @todo merge in the windows stuff too */
1206 /*
1207 * This is the new VBoxNetFlt+IntNet stuff.
1208 */
1209 if (fSniffer)
1210 {
1211 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1212 }
1213 else
1214 {
1215 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1216 }
1217
1218 Bstr HifName;
1219 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam()); H();
1220 Utf8Str HifNameUtf8(HifName);
1221 const char *pszHifName = HifNameUtf8.raw();
1222
1223# if defined(RT_OS_DARWIN)
1224 /* The name is on the form 'ifX: long name', chop it off at the colon. */
1225 char szTrunk[8];
1226 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
1227 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1228 if (!pszColon)
1229 {
1230 hrc = networkAdapter->Detach(); H();
1231 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1232 N_("Malformed host interface networking name '%ls'"),
1233 HifName.raw());
1234 }
1235 *pszColon = '\0';
1236 const char *pszTrunk = szTrunk;
1237
1238# elif defined(RT_OS_SOLARIS)
1239 /* The name is on the form format 'ifX - long name, chop it off at space. */
1240 char szTrunk[8];
1241 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
1242 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
1243
1244 /*
1245 * Currently don't bother about malformed names here for the sake of people using
1246 * VBoxManage and setting only the NIC name from there. If there is a space we
1247 * chop it off and proceed, otherwise just use whatever we've got.
1248 */
1249 if (pszSpace)
1250 *pszSpace = '\0';
1251 const char *pszTrunk = szTrunk;
1252# else
1253# error "PORTME (VBOX_WITH_NETFLT)"
1254# endif
1255
1256 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1257 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1258 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1259 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1260 char szNetwork[80];
1261 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s\n", pszHifName);
1262 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1263
1264# if defined(RT_OS_DARWIN)
1265 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
1266 if ( strstr(pszHifName, "Wireless")
1267 || strstr(pszHifName, "AirPort" ))
1268 {
1269 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1270 }
1271# else
1272 /** @todo PORTME: wireless detection */
1273# endif
1274
1275#elif defined(RT_OS_WINDOWS)
1276 if (fSniffer)
1277 {
1278 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1279 }
1280 else
1281 {
1282 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1283 }
1284 Bstr hostInterfaceName;
1285 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1286 ComPtr<IHostNetworkInterfaceCollection> coll;
1287 hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam()); H();
1288 ComPtr<IHostNetworkInterface> hostInterface;
1289 rc = coll->FindByName(hostInterfaceName, hostInterface.asOutParam());
1290 if (!SUCCEEDED(rc))
1291 {
1292 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1293 hrc = networkAdapter->Detach(); H();
1294 }
1295 else
1296 {
1297# ifndef VBOX_WITH_NETFLT
1298 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1299 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1300 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1301# else
1302 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1303 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1304 rc = CFGMR3InsertString(pCfg, "Trunk", Utf8Str(hostInterfaceName)); RC_CHECK();
1305 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1306# endif
1307 Guid hostIFGuid;
1308 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1309 char szDriverGUID[256] = {0};
1310 /* add curly brackets */
1311 szDriverGUID[0] = '{';
1312 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1313 strcat(szDriverGUID, "}");
1314 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1315 }
1316#else
1317# error "Port me"
1318#endif
1319 }
1320 else
1321 {
1322 switch (hrc)
1323 {
1324#ifdef RT_OS_LINUX
1325 case VERR_ACCESS_DENIED:
1326 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1327 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1328 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1329 "change the group of that node and make yourself a member of that group. Make "
1330 "sure that these changes are permanent, especially if you are "
1331 "using udev"));
1332#endif /* RT_OS_LINUX */
1333 default:
1334 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1335 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1336 "Failed to initialize Host Interface Networking"));
1337 }
1338 }
1339 break;
1340 }
1341
1342 case NetworkAttachmentType_Internal:
1343 {
1344 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1345 if (str)
1346 {
1347 STR_CONV();
1348 if (psz && *psz)
1349 {
1350 if (fSniffer)
1351 {
1352 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1353 }
1354 else
1355 {
1356 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1357 }
1358 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1359 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1360 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1361 }
1362 STR_FREE();
1363 }
1364 break;
1365 }
1366
1367 default:
1368 AssertMsgFailed(("should not get here!\n"));
1369 break;
1370 }
1371 }
1372
1373 /*
1374 * Serial (UART) Ports
1375 */
1376 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1377 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1378 {
1379 ComPtr<ISerialPort> serialPort;
1380 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1381 BOOL fEnabled = FALSE;
1382 if (serialPort)
1383 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1384 if (!fEnabled)
1385 continue;
1386
1387 char szInstance[4]; Assert(ulInstance <= 999);
1388 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1389
1390 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1391 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1392
1393 ULONG ulIRQ, ulIOBase;
1394 PortMode_T HostMode;
1395 Bstr path;
1396 BOOL fServer;
1397 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1398 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1399 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1400 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1401 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1402 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1403 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1404 if (HostMode != PortMode_Disconnected)
1405 {
1406 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1407 if (HostMode == PortMode_HostPipe)
1408 {
1409 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1410 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1411 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1412 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1413 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1414 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1415 }
1416 else if (HostMode == PortMode_HostDevice)
1417 {
1418 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1419 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1420 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1421 }
1422 }
1423 }
1424
1425 /*
1426 * Parallel (LPT) Ports
1427 */
1428 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1429 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1430 {
1431 ComPtr<IParallelPort> parallelPort;
1432 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1433 BOOL fEnabled = FALSE;
1434 if (parallelPort)
1435 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1436 if (!fEnabled)
1437 continue;
1438
1439 char szInstance[4]; Assert(ulInstance <= 999);
1440 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1441
1442 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1443 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1444
1445 ULONG ulIRQ, ulIOBase;
1446 Bstr DevicePath;
1447 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1448 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1449 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1450 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1451 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1452 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1453 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1454 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1455 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1456 }
1457
1458 /*
1459 * VMM Device
1460 */
1461 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1462 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1463 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1464 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1465 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1466 Assert(!afPciDeviceNo[4]);
1467 afPciDeviceNo[4] = true;
1468 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1469
1470 /* the VMM device's Main driver */
1471 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1472 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1473 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1474 VMMDev *pVMMDev = pConsole->mVMMDev;
1475 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1476
1477 /*
1478 * Attach the status driver.
1479 */
1480 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1481 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1482 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1483 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1484 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1485 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1486
1487 /*
1488 * Audio Sniffer Device
1489 */
1490 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1491 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1492 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1493
1494 /* the Audio Sniffer device's Main driver */
1495 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1496 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1497 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1498 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1499 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1500
1501 /*
1502 * AC'97 ICH / SoundBlaster16 audio
1503 */
1504 ComPtr<IAudioAdapter> audioAdapter;
1505 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1506 if (audioAdapter)
1507 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1508
1509 if (enabled)
1510 {
1511 AudioControllerType_T audioController;
1512 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1513 switch (audioController)
1514 {
1515 case AudioControllerType_AC97:
1516 {
1517 /* default: ICH AC97 */
1518 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1519 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1520 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1521 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1522 Assert(!afPciDeviceNo[5]);
1523 afPciDeviceNo[5] = true;
1524 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1525 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1526 break;
1527 }
1528 case AudioControllerType_SB16:
1529 {
1530 /* legacy SoundBlaster16 */
1531 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1532 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1533 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1534 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1535 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1536 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1537 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1538 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1539 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1540 break;
1541 }
1542 }
1543
1544 /* the Audio driver */
1545 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1546 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1547 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1548
1549 AudioDriverType_T audioDriver;
1550 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1551 switch (audioDriver)
1552 {
1553 case AudioDriverType_Null:
1554 {
1555 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1556 break;
1557 }
1558#ifdef RT_OS_WINDOWS
1559#ifdef VBOX_WITH_WINMM
1560 case AudioDriverType_WinMM:
1561 {
1562 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1563 break;
1564 }
1565#endif
1566 case AudioDriverType_DirectSound:
1567 {
1568 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1569 break;
1570 }
1571#endif /* RT_OS_WINDOWS */
1572#ifdef RT_OS_SOLARIS
1573 case AudioDriverType_SolAudio:
1574 {
1575 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
1576 break;
1577 }
1578#endif
1579#ifdef RT_OS_LINUX
1580 case AudioDriverType_OSS:
1581 {
1582 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1583 break;
1584 }
1585# ifdef VBOX_WITH_ALSA
1586 case AudioDriverType_ALSA:
1587 {
1588 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1589 break;
1590 }
1591# endif
1592# ifdef VBOX_WITH_PULSE
1593 case AudioDriverType_Pulse:
1594 {
1595 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1596 break;
1597 }
1598# endif
1599#endif /* RT_OS_LINUX */
1600#ifdef RT_OS_DARWIN
1601 case AudioDriverType_CoreAudio:
1602 {
1603 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1604 break;
1605 }
1606#endif
1607 }
1608 hrc = pMachine->COMGETTER(Name)(&str); H();
1609 STR_CONV();
1610 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
1611 STR_FREE();
1612 }
1613
1614 /*
1615 * The USB Controller.
1616 */
1617 ComPtr<IUSBController> USBCtlPtr;
1618 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1619 if (USBCtlPtr)
1620 {
1621 BOOL fEnabled;
1622 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1623 if (fEnabled)
1624 {
1625 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1626 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1627 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1628 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1629 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1630 Assert(!afPciDeviceNo[6]);
1631 afPciDeviceNo[6] = true;
1632 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1633
1634 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1635 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1636 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1637
1638 /*
1639 * Attach the status driver.
1640 */
1641 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1642 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1643 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1644 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
1645 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1646 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1647
1648#ifdef VBOX_WITH_EHCI
1649 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
1650 if (fEnabled)
1651 {
1652 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
1653 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1654 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1655 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1656 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
1657 Assert(!afPciDeviceNo[11]);
1658 afPciDeviceNo[11] = true;
1659 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1660
1661 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1662 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1663 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1664
1665 /*
1666 * Attach the status driver.
1667 */
1668 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1669 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1670 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1671 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
1672 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1673 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1674 }
1675 else
1676#endif
1677 {
1678 /*
1679 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
1680 * on a per device level now.
1681 */
1682 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
1683 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
1684 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
1685 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
1686 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
1687 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
1688 // that it's documented somewhere.) Users needing it can use:
1689 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
1690 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
1691 }
1692 }
1693 }
1694
1695 /*
1696 * Clipboard
1697 */
1698 {
1699 ClipboardMode_T mode = ClipboardMode_Disabled;
1700 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
1701
1702 if (mode != ClipboardMode_Disabled)
1703 {
1704 /* Load the service */
1705 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1706
1707 if (VBOX_FAILURE (rc))
1708 {
1709 LogRel(("VBoxSharedClipboard is not available. rc = %Vrc\n", rc));
1710 /* That is not a fatal failure. */
1711 rc = VINF_SUCCESS;
1712 }
1713 else
1714 {
1715 /* Setup the service. */
1716 VBOXHGCMSVCPARM parm;
1717
1718 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
1719
1720 switch (mode)
1721 {
1722 default:
1723 case ClipboardMode_Disabled:
1724 {
1725 LogRel(("VBoxSharedClipboard mode: Off\n"));
1726 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
1727 break;
1728 }
1729 case ClipboardMode_GuestToHost:
1730 {
1731 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
1732 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
1733 break;
1734 }
1735 case ClipboardMode_HostToGuest:
1736 {
1737 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
1738 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
1739 break;
1740 }
1741 case ClipboardMode_Bidirectional:
1742 {
1743 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
1744 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
1745 break;
1746 }
1747 }
1748
1749 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
1750
1751 Log(("Set VBoxSharedClipboard mode\n"));
1752 }
1753 }
1754 }
1755#ifdef VBOX_WITH_GUEST_PROPS
1756 /*
1757 * Shared information services
1758 */
1759 {
1760 /* Load the service */
1761 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
1762
1763 if (VBOX_FAILURE (rc))
1764 {
1765 LogRel(("VBoxGuestPropSvc is not available. rc = %Vrc\n", rc));
1766 /* That is not a fatal failure. */
1767 rc = VINF_SUCCESS;
1768 }
1769 else
1770 {
1771 rc = CFGMR3InsertNode(pRoot, "GuestProps", &pGuestProps); RC_CHECK();
1772 rc = CFGMR3InsertNode(pGuestProps, "Values", &pValues); RC_CHECK();
1773 rc = CFGMR3InsertNode(pGuestProps, "Timestamps", &pTimestamps); RC_CHECK();
1774 rc = CFGMR3InsertNode(pGuestProps, "Flags", &pFlags); RC_CHECK();
1775
1776 /* Pull over the properties from the server. */
1777 SafeArray <BSTR> names;
1778 SafeArray <BSTR> values;
1779 SafeArray <ULONG64> timestamps;
1780 SafeArray <BSTR> flags;
1781 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(names),
1782 ComSafeArrayAsOutParam(values),
1783 ComSafeArrayAsOutParam(timestamps),
1784 ComSafeArrayAsOutParam(flags)); H();
1785 size_t cProps = names.size();
1786 for (size_t i = 0; i < cProps; ++i)
1787 {
1788 rc = CFGMR3InsertString(pValues, Utf8Str(names[i]).raw(), Utf8Str(values[i]).raw()); RC_CHECK();
1789 rc = CFGMR3InsertInteger(pTimestamps, Utf8Str(names[i]).raw(), timestamps[i]); RC_CHECK();
1790 rc = CFGMR3InsertString(pFlags, Utf8Str(names[i]).raw(), Utf8Str(flags[i]).raw()); RC_CHECK();
1791 }
1792
1793 /* Setup the service. */
1794 VBOXHGCMSVCPARM parms[3];
1795
1796 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
1797 parms[0].u.pointer.addr = pValues;
1798 parms[0].u.pointer.size = sizeof(pValues); /* We don't actually care. */
1799 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
1800 parms[1].u.pointer.addr = pTimestamps;
1801 parms[1].u.pointer.size = sizeof(pTimestamps);
1802 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
1803 parms[2].u.pointer.addr = pFlags;
1804 parms[2].u.pointer.size = sizeof(pFlags);
1805
1806 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_CFGM_NODE, 3, &parms[0]);
1807
1808 Log(("Set VBoxGuestPropSvc property store\n"));
1809 }
1810 }
1811#endif /* VBOX_WITH_GUEST_PROPS defined */
1812
1813 /*
1814 * CFGM overlay handling.
1815 *
1816 * Here we check the extra data entries for CFGM values
1817 * and create the nodes and insert the values on the fly. Existing
1818 * values will be removed and reinserted. If a value is a valid number,
1819 * it will be inserted as a number, otherwise as a string.
1820 *
1821 * We first perform a run on global extra data, then on the machine
1822 * extra data to support global settings with local overrides.
1823 *
1824 */
1825 Bstr strExtraDataKey;
1826 bool fGlobalExtraData = true;
1827 for (;;)
1828 {
1829 Bstr strNextExtraDataKey;
1830 Bstr strExtraDataValue;
1831
1832 /* get the next key */
1833 if (fGlobalExtraData)
1834 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1835 strExtraDataValue.asOutParam());
1836 else
1837 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1838 strExtraDataValue.asOutParam());
1839
1840 /* stop if for some reason there's nothing more to request */
1841 if (FAILED(hrc) || !strNextExtraDataKey)
1842 {
1843 /* if we're out of global keys, continue with machine, otherwise we're done */
1844 if (fGlobalExtraData)
1845 {
1846 fGlobalExtraData = false;
1847 strExtraDataKey.setNull();
1848 continue;
1849 }
1850 break;
1851 }
1852
1853 strExtraDataKey = strNextExtraDataKey;
1854 Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey);
1855
1856 /* we only care about keys starting with "VBoxInternal/" */
1857 if (strncmp(strExtraDataKeyUtf8.raw(), "VBoxInternal/", 13) != 0)
1858 continue;
1859 char *pszExtraDataKey = (char*)strExtraDataKeyUtf8.raw() + 13;
1860
1861 /* the key will be in the format "Node1/Node2/Value" or simply "Value". */
1862 PCFGMNODE pNode;
1863 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
1864 if (pszCFGMValueName)
1865 {
1866 /* terminate the node and advance to the value */
1867 *pszCFGMValueName = '\0';
1868 pszCFGMValueName++;
1869
1870 /* does the node already exist? */
1871 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
1872 if (pNode)
1873 {
1874 /* the value might already exist, remove it to be safe */
1875 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1876 }
1877 else
1878 {
1879 /* create the node */
1880 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
1881 AssertMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
1882 if (VBOX_FAILURE(rc) || !pNode)
1883 continue;
1884 }
1885 }
1886 else
1887 {
1888 pNode = pRoot;
1889 pszCFGMValueName = pszExtraDataKey;
1890 pszExtraDataKey--;
1891
1892 /* the value might already exist, remove it to be safe */
1893 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1894 }
1895
1896 /* now let's have a look at the value */
1897 Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue);
1898 const char *pszCFGMValue = strCFGMValueUtf8.raw();
1899 /* empty value means remove value which we've already done */
1900 if (pszCFGMValue && *pszCFGMValue)
1901 {
1902 /* if it's a valid number, we'll insert it as such, otherwise string */
1903 uint64_t u64Value;
1904 char *pszNext = NULL;
1905 if ( RTStrToUInt64Ex(pszCFGMValue, &pszNext, 0, &u64Value) == VINF_SUCCESS
1906 && (!pszNext || *pszNext == '\0') /* check if the _whole_ string is a valid number */
1907 )
1908 {
1909 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
1910 }
1911 else
1912 {
1913 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
1914 }
1915 AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
1916 }
1917 }
1918
1919#undef H
1920#undef RC_CHECK
1921#undef STR_FREE
1922#undef STR_CONV
1923
1924 /* Register VM state change handler */
1925 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
1926 AssertRC (rc2);
1927 if (VBOX_SUCCESS (rc))
1928 rc = rc2;
1929
1930 /* Register VM runtime error handler */
1931 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
1932 AssertRC (rc2);
1933 if (VBOX_SUCCESS (rc))
1934 rc = rc2;
1935
1936 /* Save the VM pointer in the machine object */
1937 pConsole->mpVM = pVM;
1938
1939 LogFlowFunc (("vrc = %Vrc\n", rc));
1940 LogFlowFuncLeave();
1941
1942 return rc;
1943}
1944
1945
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette