VirtualBox

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

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

UI/config part of win NetFlt

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

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