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