VirtualBox

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

最後變更 在這個檔案從11076是 11076,由 vboxsync 提交於 17 年 前

Main: Set SharedMacOnWire when detecing wireless trunk (mac).

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

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