VirtualBox

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

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

HostServices/GuestProperties and Main: support property flags - the values are not yet checked

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 93.2 KB
Line 
1/* $Id: ConsoleImpl2.cpp 13293 2008-10-15 16:19:36Z 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 AssertBreakpoint();
1269 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1270 N_("Inexistent host networking interface, name '%ls'"),
1271 HifName.raw());
1272 }
1273
1274 Guid hostIFGuid;
1275 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1276 char szDriverGUID[RTUUID_STR_LENGTH];
1277 strcpy(szDriverGUID , hostIFGuid.toString().raw());
1278 const char *pszTrunk = szDriverGUID;
1279# else
1280# error "PORTME (VBOX_WITH_NETFLT)"
1281# endif
1282
1283 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1284 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1285 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1286 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1287 char szNetwork[80];
1288 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s\n", pszHifName);
1289 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1290
1291# if defined(RT_OS_DARWIN)
1292 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
1293 if ( strstr(pszHifName, "Wireless")
1294 || strstr(pszHifName, "AirPort" ))
1295 {
1296 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1297 }
1298# else
1299 /** @todo PORTME: wireless detection */
1300# endif
1301
1302#elif defined(RT_OS_WINDOWS)
1303 if (fSniffer)
1304 {
1305 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1306 }
1307 else
1308 {
1309 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1310 }
1311 Bstr hostInterfaceName;
1312 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1313 ComPtr<IHostNetworkInterfaceCollection> coll;
1314 hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam()); H();
1315 ComPtr<IHostNetworkInterface> hostInterface;
1316 rc = coll->FindByName(hostInterfaceName, hostInterface.asOutParam());
1317 if (!SUCCEEDED(rc))
1318 {
1319 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1320 hrc = networkAdapter->Detach(); H();
1321 }
1322 else
1323 {
1324# ifndef VBOX_WITH_NETFLT
1325 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1326 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1327 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1328# else
1329 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1330 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1331 rc = CFGMR3InsertString(pCfg, "Trunk", Utf8Str(hostInterfaceName)); RC_CHECK();
1332 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1333# endif
1334 Guid hostIFGuid;
1335 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1336 char szDriverGUID[256] = {0};
1337 /* add curly brackets */
1338 szDriverGUID[0] = '{';
1339 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1340 strcat(szDriverGUID, "}");
1341 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1342 }
1343#else
1344# error "Port me"
1345#endif
1346 }
1347 else
1348 {
1349 switch (hrc)
1350 {
1351#ifdef RT_OS_LINUX
1352 case VERR_ACCESS_DENIED:
1353 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1354 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1355 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1356 "change the group of that node and make yourself a member of that group. Make "
1357 "sure that these changes are permanent, especially if you are "
1358 "using udev"));
1359#endif /* RT_OS_LINUX */
1360 default:
1361 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1362 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1363 "Failed to initialize Host Interface Networking"));
1364 }
1365 }
1366 break;
1367 }
1368
1369 case NetworkAttachmentType_Internal:
1370 {
1371 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1372 if (str)
1373 {
1374 STR_CONV();
1375 if (psz && *psz)
1376 {
1377 if (fSniffer)
1378 {
1379 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1380 }
1381 else
1382 {
1383 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1384 }
1385 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1386 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1387 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1388 }
1389 STR_FREE();
1390 }
1391 break;
1392 }
1393
1394 default:
1395 AssertMsgFailed(("should not get here!\n"));
1396 break;
1397 }
1398 }
1399
1400 /*
1401 * Serial (UART) Ports
1402 */
1403 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1404 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1405 {
1406 ComPtr<ISerialPort> serialPort;
1407 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1408 BOOL fEnabled = FALSE;
1409 if (serialPort)
1410 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1411 if (!fEnabled)
1412 continue;
1413
1414 char szInstance[4]; Assert(ulInstance <= 999);
1415 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1416
1417 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1418 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1419
1420 ULONG ulIRQ, ulIOBase;
1421 PortMode_T HostMode;
1422 Bstr path;
1423 BOOL fServer;
1424 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1425 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1426 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1427 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1428 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1429 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1430 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1431 if (HostMode != PortMode_Disconnected)
1432 {
1433 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1434 if (HostMode == PortMode_HostPipe)
1435 {
1436 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1437 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1438 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1439 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1440 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1441 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1442 }
1443 else if (HostMode == PortMode_HostDevice)
1444 {
1445 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1446 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1447 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1448 }
1449 }
1450 }
1451
1452 /*
1453 * Parallel (LPT) Ports
1454 */
1455 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1456 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1457 {
1458 ComPtr<IParallelPort> parallelPort;
1459 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1460 BOOL fEnabled = FALSE;
1461 if (parallelPort)
1462 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1463 if (!fEnabled)
1464 continue;
1465
1466 char szInstance[4]; Assert(ulInstance <= 999);
1467 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1468
1469 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1470 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1471
1472 ULONG ulIRQ, ulIOBase;
1473 Bstr DevicePath;
1474 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1475 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1476 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1477 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1478 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1479 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1480 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1481 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1482 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1483 }
1484
1485 /*
1486 * VMM Device
1487 */
1488 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1489 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1490 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1491 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1492 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1493 Assert(!afPciDeviceNo[4]);
1494 afPciDeviceNo[4] = true;
1495 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1496
1497 /* the VMM device's Main driver */
1498 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1499 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1500 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1501 VMMDev *pVMMDev = pConsole->mVMMDev;
1502 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1503
1504 /*
1505 * Attach the status driver.
1506 */
1507 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1508 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1509 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1510 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1511 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1512 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1513
1514 /*
1515 * Audio Sniffer Device
1516 */
1517 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1518 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1519 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1520
1521 /* the Audio Sniffer device's Main driver */
1522 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1523 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1524 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1525 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1526 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1527
1528 /*
1529 * AC'97 ICH / SoundBlaster16 audio
1530 */
1531 ComPtr<IAudioAdapter> audioAdapter;
1532 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1533 if (audioAdapter)
1534 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1535
1536 if (enabled)
1537 {
1538 AudioControllerType_T audioController;
1539 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1540 switch (audioController)
1541 {
1542 case AudioControllerType_AC97:
1543 {
1544 /* default: ICH AC97 */
1545 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1546 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1547 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1548 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1549 Assert(!afPciDeviceNo[5]);
1550 afPciDeviceNo[5] = true;
1551 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1552 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1553 break;
1554 }
1555 case AudioControllerType_SB16:
1556 {
1557 /* legacy SoundBlaster16 */
1558 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1559 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1560 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1561 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1562 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1563 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1564 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1565 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1566 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1567 break;
1568 }
1569 }
1570
1571 /* the Audio driver */
1572 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1573 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1574 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1575
1576 AudioDriverType_T audioDriver;
1577 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1578 switch (audioDriver)
1579 {
1580 case AudioDriverType_Null:
1581 {
1582 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1583 break;
1584 }
1585#ifdef RT_OS_WINDOWS
1586#ifdef VBOX_WITH_WINMM
1587 case AudioDriverType_WinMM:
1588 {
1589 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1590 break;
1591 }
1592#endif
1593 case AudioDriverType_DirectSound:
1594 {
1595 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1596 break;
1597 }
1598#endif /* RT_OS_WINDOWS */
1599#ifdef RT_OS_SOLARIS
1600 case AudioDriverType_SolAudio:
1601 {
1602 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
1603 break;
1604 }
1605#endif
1606#ifdef RT_OS_LINUX
1607 case AudioDriverType_OSS:
1608 {
1609 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1610 break;
1611 }
1612# ifdef VBOX_WITH_ALSA
1613 case AudioDriverType_ALSA:
1614 {
1615 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1616 break;
1617 }
1618# endif
1619# ifdef VBOX_WITH_PULSE
1620 case AudioDriverType_Pulse:
1621 {
1622 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1623 break;
1624 }
1625# endif
1626#endif /* RT_OS_LINUX */
1627#ifdef RT_OS_DARWIN
1628 case AudioDriverType_CoreAudio:
1629 {
1630 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1631 break;
1632 }
1633#endif
1634 }
1635 hrc = pMachine->COMGETTER(Name)(&str); H();
1636 STR_CONV();
1637 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
1638 STR_FREE();
1639 }
1640
1641 /*
1642 * The USB Controller.
1643 */
1644 ComPtr<IUSBController> USBCtlPtr;
1645 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1646 if (USBCtlPtr)
1647 {
1648 BOOL fEnabled;
1649 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1650 if (fEnabled)
1651 {
1652 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1653 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1654 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1655 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1656 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1657 Assert(!afPciDeviceNo[6]);
1658 afPciDeviceNo[6] = true;
1659 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1660
1661 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1662 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1663 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1664
1665 /*
1666 * Attach the status driver.
1667 */
1668 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1669 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1670 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1671 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
1672 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1673 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1674
1675#ifdef VBOX_WITH_EHCI
1676 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
1677 if (fEnabled)
1678 {
1679 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
1680 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1681 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1682 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1683 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
1684 Assert(!afPciDeviceNo[11]);
1685 afPciDeviceNo[11] = true;
1686 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1687
1688 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1689 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1690 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1691
1692 /*
1693 * Attach the status driver.
1694 */
1695 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1696 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1697 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1698 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
1699 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1700 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1701 }
1702 else
1703#endif
1704 {
1705 /*
1706 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
1707 * on a per device level now.
1708 */
1709 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
1710 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
1711 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
1712 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
1713 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
1714 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
1715 // that it's documented somewhere.) Users needing it can use:
1716 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
1717 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
1718 }
1719 }
1720 }
1721
1722 /*
1723 * Clipboard
1724 */
1725 {
1726 ClipboardMode_T mode = ClipboardMode_Disabled;
1727 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
1728
1729 if (mode != ClipboardMode_Disabled)
1730 {
1731 /* Load the service */
1732 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1733
1734 if (VBOX_FAILURE (rc))
1735 {
1736 LogRel(("VBoxSharedClipboard is not available. rc = %Vrc\n", rc));
1737 /* That is not a fatal failure. */
1738 rc = VINF_SUCCESS;
1739 }
1740 else
1741 {
1742 /* Setup the service. */
1743 VBOXHGCMSVCPARM parm;
1744
1745 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
1746
1747 switch (mode)
1748 {
1749 default:
1750 case ClipboardMode_Disabled:
1751 {
1752 LogRel(("VBoxSharedClipboard mode: Off\n"));
1753 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
1754 break;
1755 }
1756 case ClipboardMode_GuestToHost:
1757 {
1758 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
1759 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
1760 break;
1761 }
1762 case ClipboardMode_HostToGuest:
1763 {
1764 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
1765 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
1766 break;
1767 }
1768 case ClipboardMode_Bidirectional:
1769 {
1770 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
1771 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
1772 break;
1773 }
1774 }
1775
1776 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
1777
1778 Log(("Set VBoxSharedClipboard mode\n"));
1779 }
1780 }
1781 }
1782#ifdef VBOX_WITH_GUEST_PROPS
1783 /*
1784 * Shared information services
1785 */
1786 {
1787 /* Load the service */
1788 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
1789
1790 if (VBOX_FAILURE (rc))
1791 {
1792 LogRel(("VBoxGuestPropSvc is not available. rc = %Vrc\n", rc));
1793 /* That is not a fatal failure. */
1794 rc = VINF_SUCCESS;
1795 }
1796 else
1797 {
1798 rc = CFGMR3InsertNode(pRoot, "GuestProps", &pGuestProps); RC_CHECK();
1799 rc = CFGMR3InsertNode(pGuestProps, "Values", &pValues); RC_CHECK();
1800 rc = CFGMR3InsertNode(pGuestProps, "Timestamps", &pTimestamps); RC_CHECK();
1801 rc = CFGMR3InsertNode(pGuestProps, "Flags", &pFlags); RC_CHECK();
1802
1803 /* Pull over the properties from the server. */
1804 SafeArray <BSTR> names;
1805 SafeArray <BSTR> values;
1806 SafeArray <ULONG64> timestamps;
1807 SafeArray <BSTR> flags;
1808 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(names),
1809 ComSafeArrayAsOutParam(values),
1810 ComSafeArrayAsOutParam(timestamps),
1811 ComSafeArrayAsOutParam(flags)); H();
1812 size_t cProps = names.size();
1813 for (size_t i = 0; i < cProps; ++i)
1814 {
1815 rc = CFGMR3InsertString(pValues, Utf8Str(names[i]).raw(), Utf8Str(values[i]).raw()); RC_CHECK();
1816 rc = CFGMR3InsertInteger(pTimestamps, Utf8Str(names[i]).raw(), timestamps[i]); RC_CHECK();
1817 uint32_t fFlags;
1818 rc = guestProp::validateFlags(Utf8Str(flags[i]).raw(), &fFlags);
1819 AssertLogRelRCReturn(rc, VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1820 N_("Guest property '%lS' has invalid flags '%lS' in machine definition file"),
1821 names[i], flags[i]));
1822 rc = CFGMR3InsertInteger(pFlags, Utf8Str(names[i]).raw(), fFlags); RC_CHECK();
1823 }
1824
1825 /* Setup the service. */
1826 VBOXHGCMSVCPARM parms[3];
1827
1828 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
1829 parms[0].u.pointer.addr = pValues;
1830 parms[0].u.pointer.size = sizeof(pValues); /* We don't actually care. */
1831 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
1832 parms[1].u.pointer.addr = pTimestamps;
1833 parms[1].u.pointer.size = sizeof(pTimestamps);
1834 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
1835 parms[2].u.pointer.addr = pFlags;
1836 parms[2].u.pointer.size = sizeof(pFlags);
1837
1838 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_CFGM_NODE, 3, &parms[0]);
1839
1840 /* Register the host notification callback */
1841 parms[0].type = VBOX_HGCM_SVC_PARM_CALLBACK;
1842 parms[0].u.callback.pFunction = Console::doGuestPropNotification;
1843 parms[0].u.callback.pvData = pvConsole;
1844
1845 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::REGISTER_CALLBACK, 1, &parms[0]);
1846
1847 Log(("Set VBoxGuestPropSvc property store\n"));
1848 }
1849 }
1850#endif /* VBOX_WITH_GUEST_PROPS defined */
1851
1852 /*
1853 * CFGM overlay handling.
1854 *
1855 * Here we check the extra data entries for CFGM values
1856 * and create the nodes and insert the values on the fly. Existing
1857 * values will be removed and reinserted. If a value is a valid number,
1858 * it will be inserted as a number, otherwise as a string.
1859 *
1860 * We first perform a run on global extra data, then on the machine
1861 * extra data to support global settings with local overrides.
1862 *
1863 */
1864 Bstr strExtraDataKey;
1865 bool fGlobalExtraData = true;
1866 for (;;)
1867 {
1868 Bstr strNextExtraDataKey;
1869 Bstr strExtraDataValue;
1870
1871 /* get the next key */
1872 if (fGlobalExtraData)
1873 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1874 strExtraDataValue.asOutParam());
1875 else
1876 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1877 strExtraDataValue.asOutParam());
1878
1879 /* stop if for some reason there's nothing more to request */
1880 if (FAILED(hrc) || !strNextExtraDataKey)
1881 {
1882 /* if we're out of global keys, continue with machine, otherwise we're done */
1883 if (fGlobalExtraData)
1884 {
1885 fGlobalExtraData = false;
1886 strExtraDataKey.setNull();
1887 continue;
1888 }
1889 break;
1890 }
1891
1892 strExtraDataKey = strNextExtraDataKey;
1893 Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey);
1894
1895 /* we only care about keys starting with "VBoxInternal/" */
1896 if (strncmp(strExtraDataKeyUtf8.raw(), "VBoxInternal/", 13) != 0)
1897 continue;
1898 char *pszExtraDataKey = (char*)strExtraDataKeyUtf8.raw() + 13;
1899
1900 /* the key will be in the format "Node1/Node2/Value" or simply "Value". */
1901 PCFGMNODE pNode;
1902 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
1903 if (pszCFGMValueName)
1904 {
1905 /* terminate the node and advance to the value */
1906 *pszCFGMValueName = '\0';
1907 pszCFGMValueName++;
1908
1909 /* does the node already exist? */
1910 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
1911 if (pNode)
1912 {
1913 /* the value might already exist, remove it to be safe */
1914 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1915 }
1916 else
1917 {
1918 /* create the node */
1919 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
1920 AssertMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
1921 if (VBOX_FAILURE(rc) || !pNode)
1922 continue;
1923 }
1924 }
1925 else
1926 {
1927 pNode = pRoot;
1928 pszCFGMValueName = pszExtraDataKey;
1929 pszExtraDataKey--;
1930
1931 /* the value might already exist, remove it to be safe */
1932 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1933 }
1934
1935 /* now let's have a look at the value */
1936 Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue);
1937 const char *pszCFGMValue = strCFGMValueUtf8.raw();
1938 /* empty value means remove value which we've already done */
1939 if (pszCFGMValue && *pszCFGMValue)
1940 {
1941 /* if it's a valid number, we'll insert it as such, otherwise string */
1942 uint64_t u64Value;
1943 char *pszNext = NULL;
1944 if ( RTStrToUInt64Ex(pszCFGMValue, &pszNext, 0, &u64Value) == VINF_SUCCESS
1945 && (!pszNext || *pszNext == '\0') /* check if the _whole_ string is a valid number */
1946 )
1947 {
1948 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
1949 }
1950 else
1951 {
1952 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
1953 }
1954 AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
1955 }
1956 }
1957
1958#undef H
1959#undef RC_CHECK
1960#undef STR_FREE
1961#undef STR_CONV
1962
1963 /* Register VM state change handler */
1964 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
1965 AssertRC (rc2);
1966 if (VBOX_SUCCESS (rc))
1967 rc = rc2;
1968
1969 /* Register VM runtime error handler */
1970 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
1971 AssertRC (rc2);
1972 if (VBOX_SUCCESS (rc))
1973 rc = rc2;
1974
1975 /* Save the VM pointer in the machine object */
1976 pConsole->mpVM = pVM;
1977
1978 LogFlowFunc (("vrc = %Vrc\n", rc));
1979 LogFlowFuncLeave();
1980
1981 return rc;
1982}
1983
1984
Note: See TracBrowser for help on using the repository browser.

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