VirtualBox

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

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

Main/ConsoleImpl2.cpp: pcibridge config example (disabled).

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

© 2023 Oracle
ContactPrivacy policyTerms of Use