1 | /* $Id: ConsoleImpl2.cpp 30976 2010-07-22 10:06:58Z 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 finds
|
---|
6 | * problematic to optimize so we can disable optimizations and later,
|
---|
7 | * perhaps, find a real solution for it (like rewriting the code and
|
---|
8 | * to stop resemble a tonne of spaghetti).
|
---|
9 | */
|
---|
10 |
|
---|
11 | /*
|
---|
12 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
13 | *
|
---|
14 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
15 | * available from http://www.virtualbox.org. This file is free software;
|
---|
16 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
17 | * General Public License (GPL) as published by the Free Software
|
---|
18 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
19 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
20 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | // for some reason Windows burns in sdk\...\winsock.h if this isn't included first
|
---|
27 | #include "VBox/com/ptr.h"
|
---|
28 |
|
---|
29 | #include "ConsoleImpl.h"
|
---|
30 | #include "DisplayImpl.h"
|
---|
31 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
32 | # include "GuestImpl.h"
|
---|
33 | #endif
|
---|
34 | #include "VMMDev.h"
|
---|
35 | #include "Global.h"
|
---|
36 |
|
---|
37 | // generated header
|
---|
38 | #include "SchemaDefs.h"
|
---|
39 |
|
---|
40 | #include "AutoCaller.h"
|
---|
41 | #include "Logging.h"
|
---|
42 |
|
---|
43 | #include <iprt/buildconfig.h>
|
---|
44 | #include <iprt/ctype.h>
|
---|
45 | #include <iprt/dir.h>
|
---|
46 | #include <iprt/file.h>
|
---|
47 | #include <iprt/param.h>
|
---|
48 | #include <iprt/path.h>
|
---|
49 | #include <iprt/string.h>
|
---|
50 | #include <iprt/system.h>
|
---|
51 | #include <iprt/cpp/exception.h>
|
---|
52 | #if 0 /* enable to play with lots of memory. */
|
---|
53 | # include <iprt/env.h>
|
---|
54 | #endif
|
---|
55 | #include <iprt/stream.h>
|
---|
56 |
|
---|
57 | #include <VBox/vmapi.h>
|
---|
58 | #include <VBox/err.h>
|
---|
59 | #include <VBox/param.h>
|
---|
60 | #include <VBox/pdmapi.h> /* For PDMR3DriverAttach/PDMR3DriverDetach */
|
---|
61 | #include <VBox/version.h>
|
---|
62 | #include <VBox/HostServices/VBoxClipboardSvc.h>
|
---|
63 | #ifdef VBOX_WITH_CROGL
|
---|
64 | # include <VBox/HostServices/VBoxCrOpenGLSvc.h>
|
---|
65 | #endif
|
---|
66 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
67 | # include <VBox/HostServices/GuestPropertySvc.h>
|
---|
68 | # include <VBox/com/defs.h>
|
---|
69 | # include <VBox/com/array.h>
|
---|
70 | # include <hgcm/HGCM.h> /** @todo it should be possible to register a service
|
---|
71 | * extension using a VMMDev callback. */
|
---|
72 | # include <vector>
|
---|
73 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
74 | #include <VBox/intnet.h>
|
---|
75 |
|
---|
76 | #include <VBox/com/com.h>
|
---|
77 | #include <VBox/com/string.h>
|
---|
78 | #include <VBox/com/array.h>
|
---|
79 |
|
---|
80 | #ifdef VBOX_WITH_NETFLT
|
---|
81 | # if defined(RT_OS_SOLARIS)
|
---|
82 | # include <zone.h>
|
---|
83 | # elif defined(RT_OS_LINUX)
|
---|
84 | # include <unistd.h>
|
---|
85 | # include <sys/ioctl.h>
|
---|
86 | # include <sys/socket.h>
|
---|
87 | # include <linux/types.h>
|
---|
88 | # include <linux/if.h>
|
---|
89 | # include <linux/wireless.h>
|
---|
90 | # elif defined(RT_OS_FREEBSD)
|
---|
91 | # include <unistd.h>
|
---|
92 | # include <sys/types.h>
|
---|
93 | # include <sys/ioctl.h>
|
---|
94 | # include <sys/socket.h>
|
---|
95 | # include <net/if.h>
|
---|
96 | # include <net80211/ieee80211_ioctl.h>
|
---|
97 | # endif
|
---|
98 | # if defined(RT_OS_WINDOWS)
|
---|
99 | # include <VBox/WinNetConfig.h>
|
---|
100 | # include <Ntddndis.h>
|
---|
101 | # include <devguid.h>
|
---|
102 | # else
|
---|
103 | # include <HostNetworkInterfaceImpl.h>
|
---|
104 | # include <netif.h>
|
---|
105 | # include <stdlib.h>
|
---|
106 | # endif
|
---|
107 | #endif /* VBOX_WITH_NETFLT */
|
---|
108 |
|
---|
109 | #include "DHCPServerRunner.h"
|
---|
110 |
|
---|
111 | #if defined(RT_OS_DARWIN)
|
---|
112 |
|
---|
113 | # include "IOKit/IOKitLib.h"
|
---|
114 |
|
---|
115 | static int DarwinSmcKey(char *pabKey, uint32_t cbKey)
|
---|
116 | {
|
---|
117 | /*
|
---|
118 | * Method as described in Amit Singh's article:
|
---|
119 | * http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
|
---|
120 | */
|
---|
121 | typedef struct
|
---|
122 | {
|
---|
123 | uint32_t key;
|
---|
124 | uint8_t pad0[22];
|
---|
125 | uint32_t datasize;
|
---|
126 | uint8_t pad1[10];
|
---|
127 | uint8_t cmd;
|
---|
128 | uint32_t pad2;
|
---|
129 | uint8_t data[32];
|
---|
130 | } AppleSMCBuffer;
|
---|
131 |
|
---|
132 | AssertReturn(cbKey >= 65, VERR_INTERNAL_ERROR);
|
---|
133 |
|
---|
134 | io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
|
---|
135 | IOServiceMatching("AppleSMC"));
|
---|
136 | if (!service)
|
---|
137 | return VERR_NOT_FOUND;
|
---|
138 |
|
---|
139 | io_connect_t port = (io_connect_t)0;
|
---|
140 | kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
|
---|
141 | IOObjectRelease(service);
|
---|
142 |
|
---|
143 | if (kr != kIOReturnSuccess)
|
---|
144 | return RTErrConvertFromDarwin(kr);
|
---|
145 |
|
---|
146 | AppleSMCBuffer inputStruct = { 0, {0}, 32, {0}, 5, };
|
---|
147 | AppleSMCBuffer outputStruct;
|
---|
148 | size_t cbOutputStruct = sizeof(outputStruct);
|
---|
149 |
|
---|
150 | for (int i = 0; i < 2; i++)
|
---|
151 | {
|
---|
152 | inputStruct.key = (uint32_t)((i == 0) ? 'OSK0' : 'OSK1');
|
---|
153 | kr = IOConnectCallStructMethod((mach_port_t)port,
|
---|
154 | (uint32_t)2,
|
---|
155 | (const void *)&inputStruct,
|
---|
156 | sizeof(inputStruct),
|
---|
157 | (void *)&outputStruct,
|
---|
158 | &cbOutputStruct);
|
---|
159 | if (kr != kIOReturnSuccess)
|
---|
160 | {
|
---|
161 | IOServiceClose(port);
|
---|
162 | return RTErrConvertFromDarwin(kr);
|
---|
163 | }
|
---|
164 |
|
---|
165 | for (int j = 0; j < 32; j++)
|
---|
166 | pabKey[j + i*32] = outputStruct.data[j];
|
---|
167 | }
|
---|
168 |
|
---|
169 | IOServiceClose(port);
|
---|
170 |
|
---|
171 | pabKey[64] = 0;
|
---|
172 |
|
---|
173 | return VINF_SUCCESS;
|
---|
174 | }
|
---|
175 |
|
---|
176 | #endif /* RT_OS_DARWIN */
|
---|
177 |
|
---|
178 | /* Darwin compile cludge */
|
---|
179 | #undef PVM
|
---|
180 |
|
---|
181 | /* Comment out the following line to remove VMWare compatibility hack. */
|
---|
182 | #define VMWARE_NET_IN_SLOT_11
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Translate IDE StorageControllerType_T to string representation.
|
---|
186 | */
|
---|
187 | const char* controllerString(StorageControllerType_T enmType)
|
---|
188 | {
|
---|
189 | switch (enmType)
|
---|
190 | {
|
---|
191 | case StorageControllerType_PIIX3:
|
---|
192 | return "PIIX3";
|
---|
193 | case StorageControllerType_PIIX4:
|
---|
194 | return "PIIX4";
|
---|
195 | case StorageControllerType_ICH6:
|
---|
196 | return "ICH6";
|
---|
197 | default:
|
---|
198 | return "Unknown";
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Simple class for storing network boot information.
|
---|
204 | */
|
---|
205 | struct BootNic
|
---|
206 | {
|
---|
207 | ULONG mInstance;
|
---|
208 | unsigned mPciDev;
|
---|
209 | unsigned mPciFn;
|
---|
210 | ULONG mBootPrio;
|
---|
211 | bool operator < (const BootNic &rhs) const
|
---|
212 | {
|
---|
213 | ULONG lval = mBootPrio - 1; /* 0 will wrap around and get the lowest priority. */
|
---|
214 | ULONG rval = rhs.mBootPrio - 1;
|
---|
215 | return lval < rval; /* Zero compares as highest number (lowest prio). */
|
---|
216 | }
|
---|
217 | };
|
---|
218 |
|
---|
219 | /*
|
---|
220 | * VC++ 8 / amd64 has some serious trouble with this function.
|
---|
221 | * As a temporary measure, we'll drop global optimizations.
|
---|
222 | */
|
---|
223 | #if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
|
---|
224 | # pragma optimize("g", off)
|
---|
225 | #endif
|
---|
226 |
|
---|
227 | static int findEfiRom(IVirtualBox* vbox, FirmwareType_T aFirmwareType, Utf8Str& aEfiRomFile)
|
---|
228 | {
|
---|
229 | int rc;
|
---|
230 | BOOL fPresent = FALSE;
|
---|
231 | Bstr aFilePath, empty;
|
---|
232 |
|
---|
233 | rc = vbox->CheckFirmwarePresent(aFirmwareType, empty,
|
---|
234 | empty.asOutParam(), aFilePath.asOutParam(), &fPresent);
|
---|
235 | if (RT_FAILURE(rc))
|
---|
236 | AssertComRCReturn(rc, VERR_FILE_NOT_FOUND);
|
---|
237 |
|
---|
238 | if (!fPresent)
|
---|
239 | return VERR_FILE_NOT_FOUND;
|
---|
240 |
|
---|
241 | aEfiRomFile = Utf8Str(aFilePath);
|
---|
242 |
|
---|
243 | return S_OK;
|
---|
244 | }
|
---|
245 |
|
---|
246 | static int getSmcDeviceKey(IMachine *pMachine, BSTR *aKey, bool *pfGetKeyFromRealSMC)
|
---|
247 | {
|
---|
248 | *pfGetKeyFromRealSMC = false;
|
---|
249 |
|
---|
250 | /*
|
---|
251 | * The extra data takes precedence (if non-zero).
|
---|
252 | */
|
---|
253 | HRESULT hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/SmcDeviceKey"), aKey);
|
---|
254 | if (FAILED(hrc))
|
---|
255 | return Global::vboxStatusCodeFromCOM(hrc);
|
---|
256 | if ( SUCCEEDED(hrc)
|
---|
257 | && *aKey
|
---|
258 | && **aKey)
|
---|
259 | return VINF_SUCCESS;
|
---|
260 |
|
---|
261 | #ifdef RT_OS_DARWIN
|
---|
262 | /*
|
---|
263 | * Query it here and now.
|
---|
264 | */
|
---|
265 | char abKeyBuf[65];
|
---|
266 | int rc = DarwinSmcKey(abKeyBuf, sizeof(abKeyBuf));
|
---|
267 | if (SUCCEEDED(rc))
|
---|
268 | {
|
---|
269 | Bstr(abKeyBuf).detachTo(aKey);
|
---|
270 | return rc;
|
---|
271 | }
|
---|
272 | LogRel(("Warning: DarwinSmcKey failed with rc=%Rrc!\n", rc));
|
---|
273 |
|
---|
274 | #else
|
---|
275 | /*
|
---|
276 | * Is it apple hardware in bootcamp?
|
---|
277 | */
|
---|
278 | /** @todo implement + test RTSYSDMISTR_MANUFACTURER on all hosts.
|
---|
279 | * Currently falling back on the product name. */
|
---|
280 | char szManufacturer[256];
|
---|
281 | szManufacturer[0] = '\0';
|
---|
282 | RTSystemQueryDmiString(RTSYSDMISTR_MANUFACTURER, szManufacturer, sizeof(szManufacturer));
|
---|
283 | if (szManufacturer[0] != '\0')
|
---|
284 | {
|
---|
285 | if ( !strcmp(szManufacturer, "Apple Computer, Inc.")
|
---|
286 | || !strcmp(szManufacturer, "Apple Inc.")
|
---|
287 | )
|
---|
288 | *pfGetKeyFromRealSMC = true;
|
---|
289 | }
|
---|
290 | else
|
---|
291 | {
|
---|
292 | char szProdName[256];
|
---|
293 | szProdName[0] = '\0';
|
---|
294 | RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szProdName, sizeof(szProdName));
|
---|
295 | if ( ( !strncmp(szProdName, "Mac", 3)
|
---|
296 | || !strncmp(szProdName, "iMac", 4)
|
---|
297 | || !strncmp(szProdName, "iMac", 4)
|
---|
298 | || !strncmp(szProdName, "Xserve", 6)
|
---|
299 | )
|
---|
300 | && !strchr(szProdName, ' ') /* no spaces */
|
---|
301 | && RT_C_IS_DIGIT(szProdName[strlen(szProdName) - 1]) /* version number */
|
---|
302 | )
|
---|
303 | *pfGetKeyFromRealSMC = true;
|
---|
304 | }
|
---|
305 |
|
---|
306 | int rc = VINF_SUCCESS;
|
---|
307 | #endif
|
---|
308 |
|
---|
309 | return rc;
|
---|
310 | }
|
---|
311 |
|
---|
312 | class ConfigError : public iprt::Error
|
---|
313 | {
|
---|
314 | public:
|
---|
315 |
|
---|
316 | ConfigError(const char *pcszFunction,
|
---|
317 | int vrc,
|
---|
318 | const char *pcszName)
|
---|
319 | : iprt::Error(Utf8StrFmt("%s failed: rc=%Rrc, pcszName=%s", pcszFunction, vrc, pcszName)),
|
---|
320 | m_vrc(vrc)
|
---|
321 | {
|
---|
322 | AssertMsgFailed(("%s\n", what())); // in strict mode, hit a breakpoint here
|
---|
323 | }
|
---|
324 |
|
---|
325 | int m_vrc;
|
---|
326 | };
|
---|
327 |
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * Helper that calls CFGMR3InsertString and throws an iprt::Error if that
|
---|
331 | * fails (C-string variant).
|
---|
332 | * @param pParent See CFGMR3InsertStringN.
|
---|
333 | * @param pcszNodeName See CFGMR3InsertStringN.
|
---|
334 | * @param pcszValue The string value.
|
---|
335 | */
|
---|
336 | static void InsertConfigString(PCFGMNODE pNode,
|
---|
337 | const char *pcszName,
|
---|
338 | const char *pcszValue)
|
---|
339 | {
|
---|
340 | int vrc = CFGMR3InsertString(pNode,
|
---|
341 | pcszName,
|
---|
342 | pcszValue);
|
---|
343 | if (RT_FAILURE(vrc))
|
---|
344 | throw ConfigError("CFGMR3InsertString", vrc, pcszName);
|
---|
345 | }
|
---|
346 |
|
---|
347 | /**
|
---|
348 | * Helper that calls CFGMR3InsertString and throws an iprt::Error if that
|
---|
349 | * fails (Utf8Str variant).
|
---|
350 | * @param pParent See CFGMR3InsertStringN.
|
---|
351 | * @param pcszNodeName See CFGMR3InsertStringN.
|
---|
352 | * @param rStrValue The string value.
|
---|
353 | */
|
---|
354 | static void InsertConfigString(PCFGMNODE pNode,
|
---|
355 | const char *pcszName,
|
---|
356 | const Utf8Str &rStrValue)
|
---|
357 | {
|
---|
358 | int vrc = CFGMR3InsertStringN(pNode,
|
---|
359 | pcszName,
|
---|
360 | rStrValue.c_str(),
|
---|
361 | rStrValue.length());
|
---|
362 | if (RT_FAILURE(vrc))
|
---|
363 | throw ConfigError("CFGMR3InsertStringLengthKnown", vrc, pcszName);
|
---|
364 | }
|
---|
365 |
|
---|
366 | /**
|
---|
367 | * Helper that calls CFGMR3InsertString and throws an iprt::Error if that
|
---|
368 | * fails (Bstr variant).
|
---|
369 | *
|
---|
370 | * @param pParent See CFGMR3InsertStringN.
|
---|
371 | * @param pcszNodeName See CFGMR3InsertStringN.
|
---|
372 | * @param rBstrValue The string value.
|
---|
373 | */
|
---|
374 | static void InsertConfigString(PCFGMNODE pNode,
|
---|
375 | const char *pcszName,
|
---|
376 | const Bstr &rBstrValue)
|
---|
377 | {
|
---|
378 | InsertConfigString(pNode, pcszName, Utf8Str(rBstrValue));
|
---|
379 | }
|
---|
380 |
|
---|
381 | /**
|
---|
382 | * Helper that calls CFGMR3InsertBytes and throws an iprt::Error if that fails.
|
---|
383 | *
|
---|
384 | * @param pNode See CFGMR3InsertBytes.
|
---|
385 | * @param pcszName See CFGMR3InsertBytes.
|
---|
386 | * @param pvBytes See CFGMR3InsertBytes.
|
---|
387 | * @param cbBytes See CFGMR3InsertBytes.
|
---|
388 | */
|
---|
389 | static void InsertConfigBytes(PCFGMNODE pNode,
|
---|
390 | const char *pcszName,
|
---|
391 | const void *pvBytes,
|
---|
392 | size_t cbBytes)
|
---|
393 | {
|
---|
394 | int vrc = CFGMR3InsertBytes(pNode,
|
---|
395 | pcszName,
|
---|
396 | pvBytes,
|
---|
397 | cbBytes);
|
---|
398 | if (RT_FAILURE(vrc))
|
---|
399 | throw ConfigError("CFGMR3InsertBytes", vrc, pcszName);
|
---|
400 | }
|
---|
401 |
|
---|
402 | /**
|
---|
403 | * Helper that calls CFGMR3InsertInteger and thows an iprt::Error if that
|
---|
404 | * fails.
|
---|
405 | *
|
---|
406 | * @param pNode See CFGMR3InsertInteger.
|
---|
407 | * @param pcszName See CFGMR3InsertInteger.
|
---|
408 | * @param u64Integer See CFGMR3InsertInteger.
|
---|
409 | */
|
---|
410 | static void InsertConfigInteger(PCFGMNODE pNode,
|
---|
411 | const char *pcszName,
|
---|
412 | uint64_t u64Integer)
|
---|
413 | {
|
---|
414 | int vrc = CFGMR3InsertInteger(pNode,
|
---|
415 | pcszName,
|
---|
416 | u64Integer);
|
---|
417 | if (RT_FAILURE(vrc))
|
---|
418 | throw ConfigError("CFGMR3InsertInteger", vrc, pcszName);
|
---|
419 | }
|
---|
420 |
|
---|
421 | /**
|
---|
422 | * Helper that calls CFGMR3InsertNode and throws an iprt::Error if that fails.
|
---|
423 | *
|
---|
424 | * @param pNode See CFGMR3InsertNode.
|
---|
425 | * @param pcszName See CFGMR3InsertNode.
|
---|
426 | * @param ppChild See CFGMR3InsertNode.
|
---|
427 | */
|
---|
428 | static void InsertConfigNode(PCFGMNODE pNode,
|
---|
429 | const char *pcszName,
|
---|
430 | PCFGMNODE *ppChild)
|
---|
431 | {
|
---|
432 | int vrc = CFGMR3InsertNode(pNode, pcszName, ppChild);
|
---|
433 | if (RT_FAILURE(vrc))
|
---|
434 | throw ConfigError("CFGMR3InsertNode", vrc, pcszName);
|
---|
435 | }
|
---|
436 |
|
---|
437 | /**
|
---|
438 | * Helper that calls CFGMR3RemoveValue and throws an iprt::Error if that fails.
|
---|
439 | *
|
---|
440 | * @param pNode See CFGMR3RemoveValue.
|
---|
441 | * @param pcszName See CFGMR3RemoveValue.
|
---|
442 | */
|
---|
443 | static void RemoveConfigValue(PCFGMNODE pNode,
|
---|
444 | const char *pcszName)
|
---|
445 | {
|
---|
446 | int vrc = CFGMR3RemoveValue(pNode, pcszName);
|
---|
447 | if (RT_FAILURE(vrc))
|
---|
448 | throw ConfigError("CFGMR3RemoveValue", vrc, pcszName);
|
---|
449 | }
|
---|
450 |
|
---|
451 |
|
---|
452 | /**
|
---|
453 | * Construct the VM configuration tree (CFGM).
|
---|
454 | *
|
---|
455 | * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
|
---|
456 | * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
|
---|
457 | * is done here.
|
---|
458 | *
|
---|
459 | * @param pVM VM handle.
|
---|
460 | * @param pvConsole Pointer to the VMPowerUpTask object.
|
---|
461 | * @return VBox status code.
|
---|
462 | *
|
---|
463 | * @note Locks the Console object for writing.
|
---|
464 | */
|
---|
465 | DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
|
---|
466 | {
|
---|
467 | LogFlowFuncEnter();
|
---|
468 | /* Note: hardcoded assumption about number of slots; see rom bios */
|
---|
469 | bool afPciDeviceNo[32] = {false};
|
---|
470 | bool fFdcEnabled = false;
|
---|
471 | BOOL fIs64BitGuest = false;
|
---|
472 |
|
---|
473 | #if !defined(VBOX_WITH_XPCOM)
|
---|
474 | {
|
---|
475 | /* initialize COM */
|
---|
476 | HRESULT hrc = CoInitializeEx(NULL,
|
---|
477 | COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
|
---|
478 | COINIT_SPEED_OVER_MEMORY);
|
---|
479 | LogFlow(("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
|
---|
480 | AssertComRCReturn(hrc, VERR_GENERAL_FAILURE);
|
---|
481 | }
|
---|
482 | #endif
|
---|
483 |
|
---|
484 | AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
|
---|
485 | ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
|
---|
486 |
|
---|
487 | AutoCaller autoCaller(pConsole);
|
---|
488 | AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
|
---|
489 |
|
---|
490 | /* lock the console because we widely use internal fields and methods */
|
---|
491 | AutoWriteLock alock(pConsole COMMA_LOCKVAL_SRC_POS);
|
---|
492 |
|
---|
493 | /* Save the VM pointer in the machine object */
|
---|
494 | pConsole->mpVM = pVM;
|
---|
495 |
|
---|
496 | ComPtr<IMachine> pMachine = pConsole->machine();
|
---|
497 |
|
---|
498 | int rc;
|
---|
499 | HRESULT hrc;
|
---|
500 | Bstr bstr;
|
---|
501 |
|
---|
502 | #define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
|
---|
503 |
|
---|
504 | /*
|
---|
505 | * Get necessary objects and frequently used parameters.
|
---|
506 | */
|
---|
507 | ComPtr<IVirtualBox> virtualBox;
|
---|
508 | hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
|
---|
509 |
|
---|
510 | ComPtr<IHost> host;
|
---|
511 | hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
|
---|
512 |
|
---|
513 | ComPtr<ISystemProperties> systemProperties;
|
---|
514 | hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
|
---|
515 |
|
---|
516 | ComPtr<IBIOSSettings> biosSettings;
|
---|
517 | hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
|
---|
518 |
|
---|
519 | hrc = pMachine->COMGETTER(HardwareUUID)(bstr.asOutParam()); H();
|
---|
520 | RTUUID HardwareUuid;
|
---|
521 | rc = RTUuidFromUtf16(&HardwareUuid, bstr.raw());
|
---|
522 | AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
|
---|
523 |
|
---|
524 | ULONG cRamMBs;
|
---|
525 | hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
|
---|
526 | #if 0 /* enable to play with lots of memory. */
|
---|
527 | if (RTEnvExist("VBOX_RAM_SIZE"))
|
---|
528 | cRamMBs = RTStrToUInt64(RTEnvGet("VBOX_RAM_SIZE"));
|
---|
529 | #endif
|
---|
530 | uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
|
---|
531 | uint32_t const cbRamHole = MM_RAM_HOLE_SIZE_DEFAULT;
|
---|
532 |
|
---|
533 | ULONG cCpus = 1;
|
---|
534 | hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
|
---|
535 |
|
---|
536 | Bstr osTypeId;
|
---|
537 | hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
|
---|
538 |
|
---|
539 | BOOL fIOAPIC;
|
---|
540 | hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
|
---|
541 |
|
---|
542 | ComPtr<IGuestOSType> guestOSType;
|
---|
543 | hrc = virtualBox->GetGuestOSType(osTypeId, guestOSType.asOutParam()); H();
|
---|
544 |
|
---|
545 | Bstr guestTypeFamilyId;
|
---|
546 | hrc = guestOSType->COMGETTER(FamilyId)(guestTypeFamilyId.asOutParam()); H();
|
---|
547 | BOOL fOsXGuest = guestTypeFamilyId == Bstr("MacOS");
|
---|
548 |
|
---|
549 | /*
|
---|
550 | * Get root node first.
|
---|
551 | * This is the only node in the tree.
|
---|
552 | */
|
---|
553 | PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
|
---|
554 | Assert(pRoot);
|
---|
555 |
|
---|
556 | // InsertConfigString throws
|
---|
557 | try
|
---|
558 | {
|
---|
559 |
|
---|
560 | /*
|
---|
561 | * Set the root (and VMM) level values.
|
---|
562 | */
|
---|
563 | hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
|
---|
564 | InsertConfigString(pRoot, "Name", bstr);
|
---|
565 | InsertConfigBytes(pRoot, "UUID", &HardwareUuid, sizeof(HardwareUuid));
|
---|
566 | InsertConfigInteger(pRoot, "RamSize", cbRam);
|
---|
567 | InsertConfigInteger(pRoot, "RamHoleSize", cbRamHole);
|
---|
568 | InsertConfigInteger(pRoot, "NumCPUs", cCpus);
|
---|
569 | InsertConfigInteger(pRoot, "TimerMillies", 10);
|
---|
570 | #ifdef VBOX_WITH_RAW_MODE
|
---|
571 | InsertConfigInteger(pRoot, "RawR3Enabled", 1); /* boolean */
|
---|
572 | InsertConfigInteger(pRoot, "RawR0Enabled", 1); /* boolean */
|
---|
573 | /** @todo Config: RawR0, PATMEnabled and CSAMEnabled needs attention later. */
|
---|
574 | InsertConfigInteger(pRoot, "PATMEnabled", 1); /* boolean */
|
---|
575 | InsertConfigInteger(pRoot, "CSAMEnabled", 1); /* boolean */
|
---|
576 | #endif
|
---|
577 | /* Not necessary, but to make sure these two settings end up in the release log. */
|
---|
578 | BOOL fPageFusion = FALSE;
|
---|
579 | hrc = pMachine->COMGETTER(PageFusionEnabled)(&fPageFusion); H();
|
---|
580 | InsertConfigInteger(pRoot, "PageFusion", fPageFusion); /* boolean */
|
---|
581 | ULONG ulBalloonSize = 0;
|
---|
582 | hrc = pMachine->COMGETTER(MemoryBalloonSize)(&ulBalloonSize); H();
|
---|
583 | InsertConfigInteger(pRoot, "MemBalloonSize", ulBalloonSize);
|
---|
584 |
|
---|
585 | /*
|
---|
586 | * CPUM values.
|
---|
587 | */
|
---|
588 | PCFGMNODE pCPUM;
|
---|
589 | InsertConfigNode(pRoot, "CPUM", &pCPUM);
|
---|
590 |
|
---|
591 | /* cpuid leaf overrides. */
|
---|
592 | static uint32_t const s_auCpuIdRanges[] =
|
---|
593 | {
|
---|
594 | UINT32_C(0x00000000), UINT32_C(0x0000000a),
|
---|
595 | UINT32_C(0x80000000), UINT32_C(0x8000000a)
|
---|
596 | };
|
---|
597 | for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
|
---|
598 | for (uint32_t uLeaf = s_auCpuIdRanges[i]; uLeaf < s_auCpuIdRanges[i + 1]; uLeaf++)
|
---|
599 | {
|
---|
600 | ULONG ulEax, ulEbx, ulEcx, ulEdx;
|
---|
601 | hrc = pMachine->GetCPUIDLeaf(uLeaf, &ulEax, &ulEbx, &ulEcx, &ulEdx);
|
---|
602 | if (SUCCEEDED(hrc))
|
---|
603 | {
|
---|
604 | PCFGMNODE pLeaf;
|
---|
605 | InsertConfigNode(pCPUM, Utf8StrFmt("HostCPUID/%RX32", uLeaf).c_str(), &pLeaf);
|
---|
606 |
|
---|
607 | InsertConfigInteger(pLeaf, "eax", ulEax);
|
---|
608 | InsertConfigInteger(pLeaf, "ebx", ulEbx);
|
---|
609 | InsertConfigInteger(pLeaf, "ecx", ulEcx);
|
---|
610 | InsertConfigInteger(pLeaf, "edx", ulEdx);
|
---|
611 | }
|
---|
612 | else if (hrc != E_INVALIDARG) H();
|
---|
613 | }
|
---|
614 |
|
---|
615 | /* We must limit CPUID count for Windows NT 4, as otherwise it stops
|
---|
616 | with error 0x3e (MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED). */
|
---|
617 | if (osTypeId == "WindowsNT4")
|
---|
618 | {
|
---|
619 | LogRel(("Limiting CPUID leaf count for NT4 guests\n"));
|
---|
620 | InsertConfigInteger(pCPUM, "NT4LeafLimit", true);
|
---|
621 | }
|
---|
622 |
|
---|
623 | /* Expose extended MWAIT features to Mac OS X guests. */
|
---|
624 | if (fOsXGuest)
|
---|
625 | {
|
---|
626 | LogRel(("Using MWAIT extensions\n"));
|
---|
627 | InsertConfigInteger(pCPUM, "MWaitExtensions", true);
|
---|
628 | }
|
---|
629 |
|
---|
630 | /*
|
---|
631 | * Hardware virtualization extensions.
|
---|
632 | */
|
---|
633 | BOOL fHWVirtExEnabled;
|
---|
634 | BOOL fHwVirtExtForced;
|
---|
635 | #ifdef VBOX_WITH_RAW_MODE
|
---|
636 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &fHWVirtExEnabled); H();
|
---|
637 | if (cCpus > 1) /** @todo SMP: This isn't nice, but things won't work on mac otherwise. */
|
---|
638 | fHWVirtExEnabled = TRUE;
|
---|
639 | # ifdef RT_OS_DARWIN
|
---|
640 | fHwVirtExtForced = fHWVirtExEnabled;
|
---|
641 | # else
|
---|
642 | /* - With more than 4GB PGM will use different RAMRANGE sizes for raw
|
---|
643 | mode and hv mode to optimize lookup times.
|
---|
644 | - With more than one virtual CPU, raw-mode isn't a fallback option. */
|
---|
645 | fHwVirtExtForced = fHWVirtExEnabled
|
---|
646 | && ( cbRam > (_4G - cbRamHole)
|
---|
647 | || cCpus > 1);
|
---|
648 | # endif
|
---|
649 | #else /* !VBOX_WITH_RAW_MODE */
|
---|
650 | fHWVirtExEnabled = fHwVirtExtForced = TRUE;
|
---|
651 | #endif /* !VBOX_WITH_RAW_MODE */
|
---|
652 | InsertConfigInteger(pRoot, "HwVirtExtForced", fHwVirtExtForced);
|
---|
653 |
|
---|
654 | PCFGMNODE pHWVirtExt;
|
---|
655 | InsertConfigNode(pRoot, "HWVirtExt", &pHWVirtExt);
|
---|
656 | if (fHWVirtExEnabled)
|
---|
657 | {
|
---|
658 | InsertConfigInteger(pHWVirtExt, "Enabled", 1);
|
---|
659 |
|
---|
660 | /* Indicate whether 64-bit guests are supported or not. */
|
---|
661 | /** @todo This is currently only forced off on 32-bit hosts only because it
|
---|
662 | * makes a lof of difference there (REM and Solaris performance).
|
---|
663 | */
|
---|
664 | BOOL fSupportsLongMode = false;
|
---|
665 | hrc = host->GetProcessorFeature(ProcessorFeature_LongMode,
|
---|
666 | &fSupportsLongMode); H();
|
---|
667 | hrc = guestOSType->COMGETTER(Is64Bit)(&fIs64BitGuest); H();
|
---|
668 |
|
---|
669 | if (fSupportsLongMode && fIs64BitGuest)
|
---|
670 | {
|
---|
671 | InsertConfigInteger(pHWVirtExt, "64bitEnabled", 1);
|
---|
672 | #if ARCH_BITS == 32 /* The recompiler must use VBoxREM64 (32-bit host only). */
|
---|
673 | PCFGMNODE pREM;
|
---|
674 | InsertConfigNode(pRoot, "REM", &pREM);
|
---|
675 | InsertConfigInteger(pREM, "64bitEnabled", 1);
|
---|
676 | #endif
|
---|
677 | }
|
---|
678 | #if ARCH_BITS == 32 /* 32-bit guests only. */
|
---|
679 | else
|
---|
680 | {
|
---|
681 | InsertConfigInteger(pHWVirtExt, "64bitEnabled", 0);
|
---|
682 | }
|
---|
683 | #endif
|
---|
684 |
|
---|
685 | /** @todo Not exactly pretty to check strings; VBOXOSTYPE would be better, but that requires quite a bit of API change in Main. */
|
---|
686 | if ( !fIs64BitGuest
|
---|
687 | && fIOAPIC
|
---|
688 | && ( osTypeId == "WindowsNT4"
|
---|
689 | || osTypeId == "Windows2000"
|
---|
690 | || osTypeId == "WindowsXP"
|
---|
691 | || osTypeId == "Windows2003"))
|
---|
692 | {
|
---|
693 | /* Only allow TPR patching for NT, Win2k, XP and Windows Server 2003. (32 bits mode)
|
---|
694 | * We may want to consider adding more guest OSes (Solaris) later on.
|
---|
695 | */
|
---|
696 | InsertConfigInteger(pHWVirtExt, "TPRPatchingEnabled", 1);
|
---|
697 | }
|
---|
698 | }
|
---|
699 |
|
---|
700 | /* HWVirtEx exclusive mode */
|
---|
701 | BOOL fHWVirtExExclusive = true;
|
---|
702 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &fHWVirtExExclusive); H();
|
---|
703 | InsertConfigInteger(pHWVirtExt, "Exclusive", fHWVirtExExclusive);
|
---|
704 |
|
---|
705 | /* Nested paging (VT-x/AMD-V) */
|
---|
706 | BOOL fEnableNestedPaging = false;
|
---|
707 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &fEnableNestedPaging); H();
|
---|
708 | InsertConfigInteger(pHWVirtExt, "EnableNestedPaging", fEnableNestedPaging);
|
---|
709 |
|
---|
710 | /* Large pages; requires nested paging */
|
---|
711 | BOOL fEnableLargePages = false;
|
---|
712 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &fEnableLargePages); H();
|
---|
713 | InsertConfigInteger(pHWVirtExt, "EnableLargePages", fEnableLargePages);
|
---|
714 |
|
---|
715 | /* VPID (VT-x) */
|
---|
716 | BOOL fEnableVPID = false;
|
---|
717 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &fEnableVPID); H();
|
---|
718 | InsertConfigInteger(pHWVirtExt, "EnableVPID", fEnableVPID);
|
---|
719 |
|
---|
720 | /* Physical Address Extension (PAE) */
|
---|
721 | BOOL fEnablePAE = false;
|
---|
722 | hrc = pMachine->GetCPUProperty(CPUPropertyType_PAE, &fEnablePAE); H();
|
---|
723 | InsertConfigInteger(pRoot, "EnablePAE", fEnablePAE);
|
---|
724 |
|
---|
725 | /* Synthetic CPU */
|
---|
726 | BOOL fSyntheticCpu = false;
|
---|
727 | hrc = pMachine->GetCPUProperty(CPUPropertyType_Synthetic, &fSyntheticCpu); H();
|
---|
728 | InsertConfigInteger(pRoot, "SyntheticCpu", fSyntheticCpu);
|
---|
729 |
|
---|
730 | BOOL fPXEDebug;
|
---|
731 | hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
|
---|
732 |
|
---|
733 | /*
|
---|
734 | * PDM config.
|
---|
735 | * Load drivers in VBoxC.[so|dll]
|
---|
736 | */
|
---|
737 | PCFGMNODE pPDM;
|
---|
738 | PCFGMNODE pDrivers;
|
---|
739 | PCFGMNODE pMod;
|
---|
740 | InsertConfigNode(pRoot, "PDM", &pPDM);
|
---|
741 | InsertConfigNode(pPDM, "Drivers", &pDrivers);
|
---|
742 | InsertConfigNode(pDrivers, "VBoxC", &pMod);
|
---|
743 | #ifdef VBOX_WITH_XPCOM
|
---|
744 | // VBoxC is located in the components subdirectory
|
---|
745 | char szPathVBoxC[RTPATH_MAX];
|
---|
746 | rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
|
---|
747 | strcat(szPathVBoxC, "/components/VBoxC");
|
---|
748 | InsertConfigString(pMod, "Path", szPathVBoxC);
|
---|
749 | #else
|
---|
750 | InsertConfigString(pMod, "Path", "VBoxC");
|
---|
751 | #endif
|
---|
752 |
|
---|
753 | /*
|
---|
754 | * I/O settings (cach, max bandwidth, ...).
|
---|
755 | */
|
---|
756 | PCFGMNODE pPDMAc;
|
---|
757 | PCFGMNODE pPDMAcFile;
|
---|
758 | InsertConfigNode(pPDM, "AsyncCompletion", &pPDMAc);
|
---|
759 | InsertConfigNode(pPDMAc, "File", &pPDMAcFile);
|
---|
760 |
|
---|
761 | /* Builtin I/O cache */
|
---|
762 | BOOL fIoCache = true;
|
---|
763 | hrc = pMachine->COMGETTER(IoCacheEnabled)(&fIoCache); H();
|
---|
764 | InsertConfigInteger(pPDMAcFile, "CacheEnabled", fIoCache);
|
---|
765 |
|
---|
766 | /* I/O cache size */
|
---|
767 | ULONG ioCacheSize = 5;
|
---|
768 | hrc = pMachine->COMGETTER(IoCacheSize)(&ioCacheSize); H();
|
---|
769 | InsertConfigInteger(pPDMAcFile, "CacheSize", ioCacheSize * _1M);
|
---|
770 |
|
---|
771 | /* Maximum I/O bandwidth */
|
---|
772 | ULONG ioBandwidthMax = 0;
|
---|
773 | hrc = pMachine->COMGETTER(IoBandwidthMax)(&ioBandwidthMax); H();
|
---|
774 | if (ioBandwidthMax != 0)
|
---|
775 | {
|
---|
776 | InsertConfigInteger(pPDMAcFile, "VMTransferPerSecMax", ioBandwidthMax * _1M);
|
---|
777 | }
|
---|
778 |
|
---|
779 | /*
|
---|
780 | * Devices
|
---|
781 | */
|
---|
782 | PCFGMNODE pDevices = NULL; /* /Devices */
|
---|
783 | PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
|
---|
784 | PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
|
---|
785 | PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
|
---|
786 | PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
|
---|
787 | PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
|
---|
788 | PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
|
---|
789 | PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
|
---|
790 | PCFGMNODE pNetBootCfg = NULL; /* /Devices/pcbios/0/Config/NetBoot/ */
|
---|
791 |
|
---|
792 | InsertConfigNode(pRoot, "Devices", &pDevices);
|
---|
793 |
|
---|
794 | /*
|
---|
795 | * PC Arch.
|
---|
796 | */
|
---|
797 | InsertConfigNode(pDevices, "pcarch", &pDev);
|
---|
798 | InsertConfigNode(pDev, "0", &pInst);
|
---|
799 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
800 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
801 |
|
---|
802 | /*
|
---|
803 | * The time offset
|
---|
804 | */
|
---|
805 | LONG64 timeOffset;
|
---|
806 | hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
|
---|
807 | PCFGMNODE pTMNode;
|
---|
808 | InsertConfigNode(pRoot, "TM", &pTMNode);
|
---|
809 | InsertConfigInteger(pTMNode, "UTCOffset", timeOffset * 1000000);
|
---|
810 |
|
---|
811 | /*
|
---|
812 | * DMA
|
---|
813 | */
|
---|
814 | InsertConfigNode(pDevices, "8237A", &pDev);
|
---|
815 | InsertConfigNode(pDev, "0", &pInst);
|
---|
816 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
817 |
|
---|
818 | /*
|
---|
819 | * PCI buses.
|
---|
820 | */
|
---|
821 | InsertConfigNode(pDevices, "pci", &pDev); /* piix3 */
|
---|
822 | InsertConfigNode(pDev, "0", &pInst);
|
---|
823 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
824 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
825 | InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
|
---|
826 |
|
---|
827 | #if 0 /* enable this to test PCI bridging */
|
---|
828 | InsertConfigNode(pDevices, "pcibridge", &pDev);
|
---|
829 | InsertConfigNode(pDev, "0", &pInst);
|
---|
830 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
831 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
832 | InsertConfigInteger(pInst, "PCIDeviceNo", 14);
|
---|
833 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
834 | rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 0);/* -> pci[0] */ RC_CHECK();
|
---|
835 |
|
---|
836 | InsertConfigNode(pDev, "1", &pInst);
|
---|
837 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
838 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
839 | InsertConfigInteger(pInst, "PCIDeviceNo", 1);
|
---|
840 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
841 | rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
|
---|
842 |
|
---|
843 | InsertConfigNode(pDev, "2", &pInst);
|
---|
844 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
845 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
846 | InsertConfigInteger(pInst, "PCIDeviceNo", 3);
|
---|
847 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
848 | rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
|
---|
849 | #endif
|
---|
850 |
|
---|
851 | /*
|
---|
852 | * Enable 3 following devices: HPET, SMC, LPC on MacOS X guests
|
---|
853 | */
|
---|
854 | /*
|
---|
855 | * High Precision Event Timer (HPET)
|
---|
856 | */
|
---|
857 | BOOL fHpetEnabled;
|
---|
858 | #ifdef VBOX_WITH_HPET
|
---|
859 | /* Other guests may wish to use HPET too, but MacOS X not functional without it */
|
---|
860 | hrc = pMachine->COMGETTER(HpetEnabled)(&fHpetEnabled); H();
|
---|
861 | /* so always enable HPET in extended profile */
|
---|
862 | fHpetEnabled |= fOsXGuest;
|
---|
863 | #else
|
---|
864 | fHpetEnabled = false;
|
---|
865 | #endif
|
---|
866 | if (fHpetEnabled)
|
---|
867 | {
|
---|
868 | InsertConfigNode(pDevices, "hpet", &pDev);
|
---|
869 | InsertConfigNode(pDev, "0", &pInst);
|
---|
870 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
871 | }
|
---|
872 |
|
---|
873 | /*
|
---|
874 | * System Management Controller (SMC)
|
---|
875 | */
|
---|
876 | BOOL fSmcEnabled;
|
---|
877 | #ifdef VBOX_WITH_SMC
|
---|
878 | fSmcEnabled = fOsXGuest;
|
---|
879 | #else
|
---|
880 | fSmcEnabled = false;
|
---|
881 | #endif
|
---|
882 | if (fSmcEnabled)
|
---|
883 | {
|
---|
884 | InsertConfigNode(pDevices, "smc", &pDev);
|
---|
885 | InsertConfigNode(pDev, "0", &pInst);
|
---|
886 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
887 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
888 |
|
---|
889 | bool fGetKeyFromRealSMC;
|
---|
890 | Bstr bstrKey;
|
---|
891 | rc = getSmcDeviceKey(pMachine, bstrKey.asOutParam(), &fGetKeyFromRealSMC);
|
---|
892 | AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
|
---|
893 |
|
---|
894 | InsertConfigString(pCfg, "DeviceKey", bstrKey);
|
---|
895 | InsertConfigInteger(pCfg, "GetKeyFromRealSMC", fGetKeyFromRealSMC);
|
---|
896 | }
|
---|
897 |
|
---|
898 | /*
|
---|
899 | * Low Pin Count (LPC) bus
|
---|
900 | */
|
---|
901 | BOOL fLpcEnabled;
|
---|
902 | /** @todo: implement appropriate getter */
|
---|
903 | #ifdef VBOX_WITH_LPC
|
---|
904 | fLpcEnabled = fOsXGuest;
|
---|
905 | #else
|
---|
906 | fLpcEnabled = false;
|
---|
907 | #endif
|
---|
908 | if (fLpcEnabled)
|
---|
909 | {
|
---|
910 | InsertConfigNode(pDevices, "lpc", &pDev);
|
---|
911 | InsertConfigNode(pDev, "0", &pInst);
|
---|
912 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
913 | }
|
---|
914 |
|
---|
915 | /*
|
---|
916 | * PS/2 keyboard & mouse.
|
---|
917 | */
|
---|
918 | InsertConfigNode(pDevices, "pckbd", &pDev);
|
---|
919 | InsertConfigNode(pDev, "0", &pInst);
|
---|
920 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
921 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
922 |
|
---|
923 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
924 | InsertConfigString(pLunL0, "Driver", "KeyboardQueue");
|
---|
925 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
926 | InsertConfigInteger(pCfg, "QueueSize", 64);
|
---|
927 |
|
---|
928 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
929 | InsertConfigString(pLunL1, "Driver", "MainKeyboard");
|
---|
930 | InsertConfigNode(pLunL1, "Config", &pCfg);
|
---|
931 | Keyboard *pKeyboard = pConsole->mKeyboard;
|
---|
932 | InsertConfigInteger(pCfg, "Object", (uintptr_t)pKeyboard);
|
---|
933 |
|
---|
934 | InsertConfigNode(pInst, "LUN#1", &pLunL0);
|
---|
935 | InsertConfigString(pLunL0, "Driver", "MouseQueue");
|
---|
936 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
937 | InsertConfigInteger(pCfg, "QueueSize", 128);
|
---|
938 |
|
---|
939 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
940 | InsertConfigString(pLunL1, "Driver", "MainMouse");
|
---|
941 | InsertConfigNode(pLunL1, "Config", &pCfg);
|
---|
942 | Mouse *pMouse = pConsole->mMouse;
|
---|
943 | InsertConfigInteger(pCfg, "Object", (uintptr_t)pMouse);
|
---|
944 |
|
---|
945 | /*
|
---|
946 | * i8254 Programmable Interval Timer And Dummy Speaker
|
---|
947 | */
|
---|
948 | InsertConfigNode(pDevices, "i8254", &pDev);
|
---|
949 | InsertConfigNode(pDev, "0", &pInst);
|
---|
950 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
951 | #ifdef DEBUG
|
---|
952 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
953 | #endif
|
---|
954 |
|
---|
955 | /*
|
---|
956 | * i8259 Programmable Interrupt Controller.
|
---|
957 | */
|
---|
958 | InsertConfigNode(pDevices, "i8259", &pDev);
|
---|
959 | InsertConfigNode(pDev, "0", &pInst);
|
---|
960 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
961 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
962 |
|
---|
963 | /*
|
---|
964 | * Advanced Programmable Interrupt Controller.
|
---|
965 | * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
|
---|
966 | * thus only single insert
|
---|
967 | */
|
---|
968 | InsertConfigNode(pDevices, "apic", &pDev);
|
---|
969 | InsertConfigNode(pDev, "0", &pInst);
|
---|
970 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
971 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
972 | InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
|
---|
973 | InsertConfigInteger(pCfg, "NumCPUs", cCpus);
|
---|
974 |
|
---|
975 | if (fIOAPIC)
|
---|
976 | {
|
---|
977 | /*
|
---|
978 | * I/O Advanced Programmable Interrupt Controller.
|
---|
979 | */
|
---|
980 | InsertConfigNode(pDevices, "ioapic", &pDev);
|
---|
981 | InsertConfigNode(pDev, "0", &pInst);
|
---|
982 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
983 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
984 | }
|
---|
985 |
|
---|
986 | /*
|
---|
987 | * RTC MC146818.
|
---|
988 | */
|
---|
989 | InsertConfigNode(pDevices, "mc146818", &pDev);
|
---|
990 | InsertConfigNode(pDev, "0", &pInst);
|
---|
991 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
992 | BOOL fRTCUseUTC;
|
---|
993 | hrc = pMachine->COMGETTER(RTCUseUTC)(&fRTCUseUTC); H();
|
---|
994 | InsertConfigInteger(pCfg, "UseUTC", fRTCUseUTC ? 1 : 0);
|
---|
995 |
|
---|
996 | /*
|
---|
997 | * VGA.
|
---|
998 | */
|
---|
999 | InsertConfigNode(pDevices, "vga", &pDev);
|
---|
1000 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1001 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1002 | InsertConfigInteger(pInst, "PCIDeviceNo", 2);
|
---|
1003 | Assert(!afPciDeviceNo[2]);
|
---|
1004 | afPciDeviceNo[2] = true;
|
---|
1005 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
1006 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1007 | ULONG cVRamMBs;
|
---|
1008 | hrc = pMachine->COMGETTER(VRAMSize)(&cVRamMBs); H();
|
---|
1009 | InsertConfigInteger(pCfg, "VRamSize", cVRamMBs * _1M);
|
---|
1010 | ULONG cMonitorCount;
|
---|
1011 | hrc = pMachine->COMGETTER(MonitorCount)(&cMonitorCount); H();
|
---|
1012 | InsertConfigInteger(pCfg, "MonitorCount", cMonitorCount);
|
---|
1013 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
1014 | InsertConfigInteger(pCfg, "R0Enabled", fHWVirtExEnabled);
|
---|
1015 | #endif
|
---|
1016 |
|
---|
1017 | /*
|
---|
1018 | * BIOS logo
|
---|
1019 | */
|
---|
1020 | BOOL fFadeIn;
|
---|
1021 | hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
|
---|
1022 | InsertConfigInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0);
|
---|
1023 | BOOL fFadeOut;
|
---|
1024 | hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
|
---|
1025 | InsertConfigInteger(pCfg, "FadeOut", fFadeOut ? 1: 0);
|
---|
1026 | ULONG logoDisplayTime;
|
---|
1027 | hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
|
---|
1028 | InsertConfigInteger(pCfg, "LogoTime", logoDisplayTime);
|
---|
1029 | Bstr logoImagePath;
|
---|
1030 | hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
|
---|
1031 | InsertConfigString(pCfg, "LogoFile", Utf8Str(logoImagePath ? logoImagePath : "") );
|
---|
1032 |
|
---|
1033 | /*
|
---|
1034 | * Boot menu
|
---|
1035 | */
|
---|
1036 | BIOSBootMenuMode_T eBootMenuMode;
|
---|
1037 | int iShowBootMenu;
|
---|
1038 | biosSettings->COMGETTER(BootMenuMode)(&eBootMenuMode);
|
---|
1039 | switch (eBootMenuMode)
|
---|
1040 | {
|
---|
1041 | case BIOSBootMenuMode_Disabled: iShowBootMenu = 0; break;
|
---|
1042 | case BIOSBootMenuMode_MenuOnly: iShowBootMenu = 1; break;
|
---|
1043 | default: iShowBootMenu = 2; break;
|
---|
1044 | }
|
---|
1045 | InsertConfigInteger(pCfg, "ShowBootMenu", iShowBootMenu);
|
---|
1046 |
|
---|
1047 | /* Custom VESA mode list */
|
---|
1048 | unsigned cModes = 0;
|
---|
1049 | for (unsigned iMode = 1; iMode <= 16; ++iMode)
|
---|
1050 | {
|
---|
1051 | char szExtraDataKey[sizeof("CustomVideoModeXX")];
|
---|
1052 | RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%u", iMode);
|
---|
1053 | hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), bstr.asOutParam()); H();
|
---|
1054 | if (bstr.isEmpty())
|
---|
1055 | break;
|
---|
1056 | InsertConfigString(pCfg, szExtraDataKey, bstr);
|
---|
1057 | ++cModes;
|
---|
1058 | }
|
---|
1059 | InsertConfigInteger(pCfg, "CustomVideoModes", cModes);
|
---|
1060 |
|
---|
1061 | /* VESA height reduction */
|
---|
1062 | ULONG ulHeightReduction;
|
---|
1063 | IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
|
---|
1064 | if (pFramebuffer)
|
---|
1065 | {
|
---|
1066 | hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
|
---|
1067 | }
|
---|
1068 | else
|
---|
1069 | {
|
---|
1070 | /* If framebuffer is not available, there is no height reduction. */
|
---|
1071 | ulHeightReduction = 0;
|
---|
1072 | }
|
---|
1073 | InsertConfigInteger(pCfg, "HeightReduction", ulHeightReduction);
|
---|
1074 |
|
---|
1075 | /* Attach the display. */
|
---|
1076 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
1077 | InsertConfigString(pLunL0, "Driver", "MainDisplay");
|
---|
1078 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1079 | Display *pDisplay = pConsole->mDisplay;
|
---|
1080 | InsertConfigInteger(pCfg, "Object", (uintptr_t)pDisplay);
|
---|
1081 |
|
---|
1082 |
|
---|
1083 | /*
|
---|
1084 | * Firmware.
|
---|
1085 | */
|
---|
1086 | FirmwareType_T eFwType = FirmwareType_BIOS;
|
---|
1087 | hrc = pMachine->COMGETTER(FirmwareType)(&eFwType); H();
|
---|
1088 |
|
---|
1089 | #ifdef VBOX_WITH_EFI
|
---|
1090 | BOOL fEfiEnabled = (eFwType >= FirmwareType_EFI) && (eFwType <= FirmwareType_EFIDUAL);
|
---|
1091 | #else
|
---|
1092 | BOOL fEfiEnabled = false;
|
---|
1093 | #endif
|
---|
1094 | if (!fEfiEnabled)
|
---|
1095 | {
|
---|
1096 | /*
|
---|
1097 | * PC Bios.
|
---|
1098 | */
|
---|
1099 | InsertConfigNode(pDevices, "pcbios", &pDev);
|
---|
1100 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1101 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1102 | InsertConfigNode(pInst, "Config", &pBiosCfg);
|
---|
1103 | InsertConfigInteger(pBiosCfg, "RamSize", cbRam);
|
---|
1104 | InsertConfigInteger(pBiosCfg, "RamHoleSize", cbRamHole);
|
---|
1105 | InsertConfigInteger(pBiosCfg, "NumCPUs", cCpus);
|
---|
1106 | InsertConfigString(pBiosCfg, "HardDiskDevice", "piix3ide");
|
---|
1107 | InsertConfigString(pBiosCfg, "FloppyDevice", "i82078");
|
---|
1108 | InsertConfigInteger(pBiosCfg, "IOAPIC", fIOAPIC);
|
---|
1109 | InsertConfigInteger(pBiosCfg, "PXEDebug", fPXEDebug);
|
---|
1110 | InsertConfigBytes(pBiosCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));
|
---|
1111 | InsertConfigNode(pBiosCfg, "NetBoot", &pNetBootCfg);
|
---|
1112 |
|
---|
1113 | DeviceType_T bootDevice;
|
---|
1114 | if (SchemaDefs::MaxBootPosition > 9)
|
---|
1115 | {
|
---|
1116 | AssertMsgFailed(("Too many boot devices %d\n",
|
---|
1117 | SchemaDefs::MaxBootPosition));
|
---|
1118 | return VERR_INVALID_PARAMETER;
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; ++pos)
|
---|
1122 | {
|
---|
1123 | hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
|
---|
1124 |
|
---|
1125 | char szParamName[] = "BootDeviceX";
|
---|
1126 | szParamName[sizeof(szParamName) - 2] = ((char (pos - 1)) + '0');
|
---|
1127 |
|
---|
1128 | const char *pszBootDevice;
|
---|
1129 | switch (bootDevice)
|
---|
1130 | {
|
---|
1131 | case DeviceType_Null:
|
---|
1132 | pszBootDevice = "NONE";
|
---|
1133 | break;
|
---|
1134 | case DeviceType_HardDisk:
|
---|
1135 | pszBootDevice = "IDE";
|
---|
1136 | break;
|
---|
1137 | case DeviceType_DVD:
|
---|
1138 | pszBootDevice = "DVD";
|
---|
1139 | break;
|
---|
1140 | case DeviceType_Floppy:
|
---|
1141 | pszBootDevice = "FLOPPY";
|
---|
1142 | break;
|
---|
1143 | case DeviceType_Network:
|
---|
1144 | pszBootDevice = "LAN";
|
---|
1145 | break;
|
---|
1146 | default:
|
---|
1147 | AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
|
---|
1148 | return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
1149 | N_("Invalid boot device '%d'"), bootDevice);
|
---|
1150 | }
|
---|
1151 | InsertConfigString(pBiosCfg, szParamName, pszBootDevice);
|
---|
1152 | }
|
---|
1153 | }
|
---|
1154 | else
|
---|
1155 | {
|
---|
1156 | Utf8Str efiRomFile;
|
---|
1157 |
|
---|
1158 | /* Autodetect firmware type, basing on guest type */
|
---|
1159 | if (eFwType == FirmwareType_EFI)
|
---|
1160 | {
|
---|
1161 | eFwType =
|
---|
1162 | fIs64BitGuest ?
|
---|
1163 | (FirmwareType_T)FirmwareType_EFI64
|
---|
1164 | :
|
---|
1165 | (FirmwareType_T)FirmwareType_EFI32;
|
---|
1166 | }
|
---|
1167 | bool f64BitEntry = eFwType == FirmwareType_EFI64;
|
---|
1168 |
|
---|
1169 | rc = findEfiRom(virtualBox, eFwType, efiRomFile);
|
---|
1170 | AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
|
---|
1171 |
|
---|
1172 | /* Get boot args */
|
---|
1173 | Bstr bootArgs;
|
---|
1174 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiBootArgs"), bootArgs.asOutParam()); H();
|
---|
1175 |
|
---|
1176 | /* Get device props */
|
---|
1177 | Bstr deviceProps;
|
---|
1178 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiDeviceProps"), deviceProps.asOutParam()); H();
|
---|
1179 | /* Get GOP mode settings */
|
---|
1180 | uint32_t u32GopMode = UINT32_MAX;
|
---|
1181 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiGopMode"), bstr.asOutParam()); H();
|
---|
1182 | if (!bstr.isEmpty())
|
---|
1183 | u32GopMode = Utf8Str(bstr).toUInt32();
|
---|
1184 |
|
---|
1185 | /* UGA mode settings */
|
---|
1186 | uint32_t u32UgaHorisontal = 0;
|
---|
1187 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaHorizontalResolution"), bstr.asOutParam()); H();
|
---|
1188 | if (!bstr.isEmpty())
|
---|
1189 | u32UgaHorisontal = Utf8Str(bstr).toUInt32();
|
---|
1190 |
|
---|
1191 | uint32_t u32UgaVertical = 0;
|
---|
1192 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaVerticalResolution"), bstr.asOutParam()); H();
|
---|
1193 | if (!bstr.isEmpty())
|
---|
1194 | u32UgaVertical = Utf8Str(bstr).toUInt32();
|
---|
1195 |
|
---|
1196 | /*
|
---|
1197 | * EFI subtree.
|
---|
1198 | */
|
---|
1199 | InsertConfigNode(pDevices, "efi", &pDev);
|
---|
1200 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1201 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1202 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1203 | InsertConfigInteger(pCfg, "RamSize", cbRam);
|
---|
1204 | InsertConfigInteger(pCfg, "RamHoleSize", cbRamHole);
|
---|
1205 | InsertConfigInteger(pCfg, "NumCPUs", cCpus);
|
---|
1206 | InsertConfigString(pCfg, "EfiRom", efiRomFile);
|
---|
1207 | InsertConfigString(pCfg, "BootArgs", bootArgs);
|
---|
1208 | InsertConfigString(pCfg, "DeviceProps", deviceProps);
|
---|
1209 | InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
|
---|
1210 | InsertConfigBytes(pCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));
|
---|
1211 | InsertConfigInteger(pCfg, "64BitEntry", f64BitEntry); /* boolean */
|
---|
1212 | InsertConfigInteger(pCfg, "GopMode", u32GopMode);
|
---|
1213 | InsertConfigInteger(pCfg, "UgaHorizontalResolution", u32UgaHorisontal);
|
---|
1214 | InsertConfigInteger(pCfg, "UgaVerticalResolution", u32UgaVertical);
|
---|
1215 |
|
---|
1216 | /* For OS X guests we'll force passing host's DMI info to the guest */
|
---|
1217 | if (fOsXGuest)
|
---|
1218 | {
|
---|
1219 | InsertConfigInteger(pCfg, "DmiUseHostInfo", 1);
|
---|
1220 | InsertConfigInteger(pCfg, "DmiExposeMemoryTable", 1);
|
---|
1221 | }
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | /*
|
---|
1225 | * Storage controllers.
|
---|
1226 | */
|
---|
1227 | com::SafeIfaceArray<IStorageController> ctrls;
|
---|
1228 | PCFGMNODE aCtrlNodes[StorageControllerType_LsiLogicSas + 1] = {};
|
---|
1229 | hrc = pMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(ctrls)); H();
|
---|
1230 |
|
---|
1231 | for (size_t i = 0; i < ctrls.size(); ++i)
|
---|
1232 | {
|
---|
1233 | DeviceType_T *paLedDevType = NULL;
|
---|
1234 |
|
---|
1235 | StorageControllerType_T enmCtrlType;
|
---|
1236 | rc = ctrls[i]->COMGETTER(ControllerType)(&enmCtrlType); H();
|
---|
1237 | AssertRelease((unsigned)enmCtrlType < RT_ELEMENTS(aCtrlNodes));
|
---|
1238 |
|
---|
1239 | StorageBus_T enmBus;
|
---|
1240 | rc = ctrls[i]->COMGETTER(Bus)(&enmBus); H();
|
---|
1241 |
|
---|
1242 | Bstr controllerName;
|
---|
1243 | rc = ctrls[i]->COMGETTER(Name)(controllerName.asOutParam()); H();
|
---|
1244 |
|
---|
1245 | ULONG ulInstance = 999;
|
---|
1246 | rc = ctrls[i]->COMGETTER(Instance)(&ulInstance); H();
|
---|
1247 |
|
---|
1248 | BOOL fUseHostIOCache;
|
---|
1249 | rc = ctrls[i]->COMGETTER(UseHostIOCache)(&fUseHostIOCache); H();
|
---|
1250 |
|
---|
1251 | /* /Devices/<ctrldev>/ */
|
---|
1252 | const char *pszCtrlDev = pConsole->convertControllerTypeToDev(enmCtrlType);
|
---|
1253 | pDev = aCtrlNodes[enmCtrlType];
|
---|
1254 | if (!pDev)
|
---|
1255 | {
|
---|
1256 | InsertConfigNode(pDevices, pszCtrlDev, &pDev);
|
---|
1257 | aCtrlNodes[enmCtrlType] = pDev; /* IDE variants are handled in the switch */
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | /* /Devices/<ctrldev>/<instance>/ */
|
---|
1261 | PCFGMNODE pCtlInst = NULL;
|
---|
1262 | InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pCtlInst);
|
---|
1263 |
|
---|
1264 | /* Device config: /Devices/<ctrldev>/<instance>/<values> & /ditto/Config/<values> */
|
---|
1265 | InsertConfigInteger(pCtlInst, "Trusted", 1);
|
---|
1266 | InsertConfigNode(pCtlInst, "Config", &pCfg);
|
---|
1267 |
|
---|
1268 | switch (enmCtrlType)
|
---|
1269 | {
|
---|
1270 | case StorageControllerType_LsiLogic:
|
---|
1271 | {
|
---|
1272 | InsertConfigInteger(pCtlInst, "PCIDeviceNo", 20);
|
---|
1273 | Assert(!afPciDeviceNo[20]);
|
---|
1274 | afPciDeviceNo[20] = true;
|
---|
1275 | InsertConfigInteger(pCtlInst, "PCIFunctionNo", 0);
|
---|
1276 |
|
---|
1277 | /* Attach the status driver */
|
---|
1278 | InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
|
---|
1279 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1280 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1281 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]);
|
---|
1282 | InsertConfigInteger(pCfg, "First", 0);
|
---|
1283 | Assert(cLedScsi >= 16);
|
---|
1284 | InsertConfigInteger(pCfg, "Last", 15);
|
---|
1285 | paLedDevType = &pConsole->maStorageDevType[iLedScsi];
|
---|
1286 | break;
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | case StorageControllerType_BusLogic:
|
---|
1290 | {
|
---|
1291 | InsertConfigInteger(pCtlInst, "PCIDeviceNo", 21);
|
---|
1292 | Assert(!afPciDeviceNo[21]);
|
---|
1293 | afPciDeviceNo[21] = true;
|
---|
1294 | InsertConfigInteger(pCtlInst, "PCIFunctionNo", 0);
|
---|
1295 |
|
---|
1296 | /* Attach the status driver */
|
---|
1297 | InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
|
---|
1298 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1299 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1300 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]);
|
---|
1301 | InsertConfigInteger(pCfg, "First", 0);
|
---|
1302 | Assert(cLedScsi >= 16);
|
---|
1303 | InsertConfigInteger(pCfg, "Last", 15);
|
---|
1304 | paLedDevType = &pConsole->maStorageDevType[iLedScsi];
|
---|
1305 | break;
|
---|
1306 | }
|
---|
1307 |
|
---|
1308 | case StorageControllerType_IntelAhci:
|
---|
1309 | {
|
---|
1310 | InsertConfigInteger(pCtlInst, "PCIDeviceNo", 13);
|
---|
1311 | Assert(!afPciDeviceNo[13]);
|
---|
1312 | afPciDeviceNo[13] = true;
|
---|
1313 | InsertConfigInteger(pCtlInst, "PCIFunctionNo", 0);
|
---|
1314 |
|
---|
1315 | ULONG cPorts = 0;
|
---|
1316 | hrc = ctrls[i]->COMGETTER(PortCount)(&cPorts); H();
|
---|
1317 | InsertConfigInteger(pCfg, "PortCount", cPorts);
|
---|
1318 |
|
---|
1319 | /* Needed configuration values for the bios. */
|
---|
1320 | if (pBiosCfg)
|
---|
1321 | {
|
---|
1322 | InsertConfigString(pBiosCfg, "SataHardDiskDevice", "ahci");
|
---|
1323 | }
|
---|
1324 |
|
---|
1325 | for (uint32_t j = 0; j < 4; ++j)
|
---|
1326 | {
|
---|
1327 | static const char * const s_apszConfig[4] =
|
---|
1328 | { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
|
---|
1329 | static const char * const s_apszBiosConfig[4] =
|
---|
1330 | { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
|
---|
1331 |
|
---|
1332 | LONG lPortNumber = -1;
|
---|
1333 | hrc = ctrls[i]->GetIDEEmulationPort(j, &lPortNumber); H();
|
---|
1334 | InsertConfigInteger(pCfg, s_apszConfig[j], lPortNumber);
|
---|
1335 | if (pBiosCfg)
|
---|
1336 | InsertConfigInteger(pBiosCfg, s_apszBiosConfig[j], lPortNumber);
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | /* Attach the status driver */
|
---|
1340 | InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
|
---|
1341 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1342 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1343 | AssertRelease(cPorts <= cLedSata);
|
---|
1344 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedSata]);
|
---|
1345 | InsertConfigInteger(pCfg, "First", 0);
|
---|
1346 | InsertConfigInteger(pCfg, "Last", cPorts - 1);
|
---|
1347 | paLedDevType = &pConsole->maStorageDevType[iLedSata];
|
---|
1348 | break;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | case StorageControllerType_PIIX3:
|
---|
1352 | case StorageControllerType_PIIX4:
|
---|
1353 | case StorageControllerType_ICH6:
|
---|
1354 | {
|
---|
1355 | /*
|
---|
1356 | * IDE (update this when the main interface changes)
|
---|
1357 | */
|
---|
1358 | InsertConfigInteger(pCtlInst, "PCIDeviceNo", 1);
|
---|
1359 | Assert(!afPciDeviceNo[1]);
|
---|
1360 | afPciDeviceNo[1] = true;
|
---|
1361 | InsertConfigInteger(pCtlInst, "PCIFunctionNo", 1);
|
---|
1362 | InsertConfigString(pCfg, "Type", controllerString(enmCtrlType));
|
---|
1363 |
|
---|
1364 | /* Attach the status driver */
|
---|
1365 | InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
|
---|
1366 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1367 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1368 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedIde]);
|
---|
1369 | InsertConfigInteger(pCfg, "First", 0);
|
---|
1370 | Assert(cLedIde >= 4);
|
---|
1371 | InsertConfigInteger(pCfg, "Last", 3);
|
---|
1372 | paLedDevType = &pConsole->maStorageDevType[iLedIde];
|
---|
1373 |
|
---|
1374 | /* IDE flavors */
|
---|
1375 | aCtrlNodes[StorageControllerType_PIIX3] = pDev;
|
---|
1376 | aCtrlNodes[StorageControllerType_PIIX4] = pDev;
|
---|
1377 | aCtrlNodes[StorageControllerType_ICH6] = pDev;
|
---|
1378 | break;
|
---|
1379 | }
|
---|
1380 |
|
---|
1381 | case StorageControllerType_I82078:
|
---|
1382 | {
|
---|
1383 | /*
|
---|
1384 | * i82078 Floppy drive controller
|
---|
1385 | */
|
---|
1386 | fFdcEnabled = true;
|
---|
1387 | InsertConfigInteger(pCfg, "IRQ", 6);
|
---|
1388 | InsertConfigInteger(pCfg, "DMA", 2);
|
---|
1389 | InsertConfigInteger(pCfg, "MemMapped", 0 );
|
---|
1390 | InsertConfigInteger(pCfg, "IOBase", 0x3f0);
|
---|
1391 |
|
---|
1392 | /* Attach the status driver */
|
---|
1393 | InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
|
---|
1394 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1395 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1396 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedFloppy]);
|
---|
1397 | InsertConfigInteger(pCfg, "First", 0);
|
---|
1398 | Assert(cLedFloppy >= 1);
|
---|
1399 | InsertConfigInteger(pCfg, "Last", 0);
|
---|
1400 | paLedDevType = &pConsole->maStorageDevType[iLedFloppy];
|
---|
1401 | break;
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 | case StorageControllerType_LsiLogicSas:
|
---|
1405 | {
|
---|
1406 | InsertConfigInteger(pCtlInst, "PCIDeviceNo", 22);
|
---|
1407 | Assert(!afPciDeviceNo[22]);
|
---|
1408 | afPciDeviceNo[22] = true;
|
---|
1409 | InsertConfigInteger(pCtlInst, "PCIFunctionNo", 0);
|
---|
1410 |
|
---|
1411 | InsertConfigString(pCfg, "ControllerType", "SAS1068");
|
---|
1412 |
|
---|
1413 | /* Attach the status driver */
|
---|
1414 | InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
|
---|
1415 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1416 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1417 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedSas]);
|
---|
1418 | InsertConfigInteger(pCfg, "First", 0);
|
---|
1419 | Assert(cLedSas >= 8);
|
---|
1420 | InsertConfigInteger(pCfg, "Last", 7);
|
---|
1421 | paLedDevType = &pConsole->maStorageDevType[iLedSas];
|
---|
1422 | break;
|
---|
1423 | }
|
---|
1424 |
|
---|
1425 | default:
|
---|
1426 | AssertMsgFailedReturn(("invalid storage controller type: %d\n", enmCtrlType), VERR_GENERAL_FAILURE);
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | /* Attach the media to the storage controllers. */
|
---|
1430 | com::SafeIfaceArray<IMediumAttachment> atts;
|
---|
1431 | hrc = pMachine->GetMediumAttachmentsOfController(controllerName,
|
---|
1432 | ComSafeArrayAsOutParam(atts)); H();
|
---|
1433 |
|
---|
1434 | for (size_t j = 0; j < atts.size(); ++j)
|
---|
1435 | {
|
---|
1436 | rc = pConsole->configMediumAttachment(pCtlInst,
|
---|
1437 | pszCtrlDev,
|
---|
1438 | ulInstance,
|
---|
1439 | enmBus,
|
---|
1440 | fUseHostIOCache,
|
---|
1441 | false /* fSetupMerge */,
|
---|
1442 | 0 /* uMergeSource */,
|
---|
1443 | 0 /* uMergeTarget */,
|
---|
1444 | atts[j],
|
---|
1445 | pConsole->mMachineState,
|
---|
1446 | NULL /* phrc */,
|
---|
1447 | false /* fAttachDetach */,
|
---|
1448 | false /* fForceUnmount */,
|
---|
1449 | pVM,
|
---|
1450 | paLedDevType);
|
---|
1451 | if (RT_FAILURE(rc))
|
---|
1452 | return rc;
|
---|
1453 | }
|
---|
1454 | H();
|
---|
1455 | }
|
---|
1456 | H();
|
---|
1457 |
|
---|
1458 | /*
|
---|
1459 | * Network adapters
|
---|
1460 | */
|
---|
1461 | #ifdef VMWARE_NET_IN_SLOT_11
|
---|
1462 | bool fSwapSlots3and11 = false;
|
---|
1463 | #endif
|
---|
1464 | PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
|
---|
1465 | InsertConfigNode(pDevices, "pcnet", &pDevPCNet);
|
---|
1466 | #ifdef VBOX_WITH_E1000
|
---|
1467 | PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
|
---|
1468 | InsertConfigNode(pDevices, "e1000", &pDevE1000);
|
---|
1469 | #endif
|
---|
1470 | #ifdef VBOX_WITH_VIRTIO
|
---|
1471 | PCFGMNODE pDevVirtioNet = NULL; /* Virtio network devices */
|
---|
1472 | InsertConfigNode(pDevices, "virtio-net", &pDevVirtioNet);
|
---|
1473 | #endif /* VBOX_WITH_VIRTIO */
|
---|
1474 | std::list<BootNic> llBootNics;
|
---|
1475 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ++ulInstance)
|
---|
1476 | {
|
---|
1477 | ComPtr<INetworkAdapter> networkAdapter;
|
---|
1478 | hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
|
---|
1479 | BOOL fEnabled = FALSE;
|
---|
1480 | hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1481 | if (!fEnabled)
|
---|
1482 | continue;
|
---|
1483 |
|
---|
1484 | /*
|
---|
1485 | * The virtual hardware type. Create appropriate device first.
|
---|
1486 | */
|
---|
1487 | const char *pszAdapterName = "pcnet";
|
---|
1488 | NetworkAdapterType_T adapterType;
|
---|
1489 | hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
|
---|
1490 | switch (adapterType)
|
---|
1491 | {
|
---|
1492 | case NetworkAdapterType_Am79C970A:
|
---|
1493 | case NetworkAdapterType_Am79C973:
|
---|
1494 | pDev = pDevPCNet;
|
---|
1495 | break;
|
---|
1496 | #ifdef VBOX_WITH_E1000
|
---|
1497 | case NetworkAdapterType_I82540EM:
|
---|
1498 | case NetworkAdapterType_I82543GC:
|
---|
1499 | case NetworkAdapterType_I82545EM:
|
---|
1500 | pDev = pDevE1000;
|
---|
1501 | pszAdapterName = "e1000";
|
---|
1502 | break;
|
---|
1503 | #endif
|
---|
1504 | #ifdef VBOX_WITH_VIRTIO
|
---|
1505 | case NetworkAdapterType_Virtio:
|
---|
1506 | pDev = pDevVirtioNet;
|
---|
1507 | pszAdapterName = "virtio-net";
|
---|
1508 | break;
|
---|
1509 | #endif /* VBOX_WITH_VIRTIO */
|
---|
1510 | default:
|
---|
1511 | AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
|
---|
1512 | adapterType, ulInstance));
|
---|
1513 | return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
1514 | N_("Invalid network adapter type '%d' for slot '%d'"),
|
---|
1515 | adapterType, ulInstance);
|
---|
1516 | }
|
---|
1517 |
|
---|
1518 | InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
|
---|
1519 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1520 | /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
|
---|
1521 | * next 4 get 16..19. */
|
---|
1522 | unsigned iPciDeviceNo = 3;
|
---|
1523 | if (ulInstance)
|
---|
1524 | {
|
---|
1525 | if (ulInstance < 4)
|
---|
1526 | iPciDeviceNo = ulInstance - 1 + 8;
|
---|
1527 | else
|
---|
1528 | iPciDeviceNo = ulInstance - 4 + 16;
|
---|
1529 | }
|
---|
1530 | #ifdef VMWARE_NET_IN_SLOT_11
|
---|
1531 | /*
|
---|
1532 | * Dirty hack for PCI slot compatibility with VMWare,
|
---|
1533 | * it assigns slot 11 to the first network controller.
|
---|
1534 | */
|
---|
1535 | if (iPciDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
|
---|
1536 | {
|
---|
1537 | iPciDeviceNo = 0x11;
|
---|
1538 | fSwapSlots3and11 = true;
|
---|
1539 | }
|
---|
1540 | else if (iPciDeviceNo == 0x11 && fSwapSlots3and11)
|
---|
1541 | iPciDeviceNo = 3;
|
---|
1542 | #endif
|
---|
1543 | InsertConfigInteger(pInst, "PCIDeviceNo", iPciDeviceNo);
|
---|
1544 | Assert(!afPciDeviceNo[iPciDeviceNo]);
|
---|
1545 | afPciDeviceNo[iPciDeviceNo] = true;
|
---|
1546 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
1547 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1548 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
|
---|
1549 | if (pDev == pDevPCNet)
|
---|
1550 | {
|
---|
1551 | InsertConfigInteger(pCfg, "R0Enabled", false);
|
---|
1552 | }
|
---|
1553 | #endif
|
---|
1554 | /*
|
---|
1555 | * Collect information needed for network booting and add it to the list.
|
---|
1556 | */
|
---|
1557 | BootNic nic;
|
---|
1558 |
|
---|
1559 | nic.mInstance = ulInstance;
|
---|
1560 | nic.mPciDev = iPciDeviceNo;
|
---|
1561 | nic.mPciFn = 0;
|
---|
1562 |
|
---|
1563 | hrc = networkAdapter->COMGETTER(BootPriority)(&nic.mBootPrio); H();
|
---|
1564 |
|
---|
1565 | llBootNics.push_back(nic);
|
---|
1566 |
|
---|
1567 | /*
|
---|
1568 | * The virtual hardware type. PCNet supports two types.
|
---|
1569 | */
|
---|
1570 | switch (adapterType)
|
---|
1571 | {
|
---|
1572 | case NetworkAdapterType_Am79C970A:
|
---|
1573 | InsertConfigInteger(pCfg, "Am79C973", 0);
|
---|
1574 | break;
|
---|
1575 | case NetworkAdapterType_Am79C973:
|
---|
1576 | InsertConfigInteger(pCfg, "Am79C973", 1);
|
---|
1577 | break;
|
---|
1578 | case NetworkAdapterType_I82540EM:
|
---|
1579 | InsertConfigInteger(pCfg, "AdapterType", 0);
|
---|
1580 | break;
|
---|
1581 | case NetworkAdapterType_I82543GC:
|
---|
1582 | InsertConfigInteger(pCfg, "AdapterType", 1);
|
---|
1583 | break;
|
---|
1584 | case NetworkAdapterType_I82545EM:
|
---|
1585 | InsertConfigInteger(pCfg, "AdapterType", 2);
|
---|
1586 | break;
|
---|
1587 | }
|
---|
1588 |
|
---|
1589 | /*
|
---|
1590 | * Get the MAC address and convert it to binary representation
|
---|
1591 | */
|
---|
1592 | Bstr macAddr;
|
---|
1593 | hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
|
---|
1594 | Assert(macAddr);
|
---|
1595 | Utf8Str macAddrUtf8 = macAddr;
|
---|
1596 | char *macStr = (char*)macAddrUtf8.raw();
|
---|
1597 | Assert(strlen(macStr) == 12);
|
---|
1598 | RTMAC Mac;
|
---|
1599 | memset(&Mac, 0, sizeof(Mac));
|
---|
1600 | char *pMac = (char*)&Mac;
|
---|
1601 | for (uint32_t i = 0; i < 6; ++i)
|
---|
1602 | {
|
---|
1603 | char c1 = *macStr++ - '0';
|
---|
1604 | if (c1 > 9)
|
---|
1605 | c1 -= 7;
|
---|
1606 | char c2 = *macStr++ - '0';
|
---|
1607 | if (c2 > 9)
|
---|
1608 | c2 -= 7;
|
---|
1609 | *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
|
---|
1610 | }
|
---|
1611 | InsertConfigBytes(pCfg, "MAC", &Mac, sizeof(Mac));
|
---|
1612 |
|
---|
1613 | /*
|
---|
1614 | * Check if the cable is supposed to be unplugged
|
---|
1615 | */
|
---|
1616 | BOOL fCableConnected;
|
---|
1617 | hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
|
---|
1618 | InsertConfigInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0);
|
---|
1619 |
|
---|
1620 | /*
|
---|
1621 | * Line speed to report from custom drivers
|
---|
1622 | */
|
---|
1623 | ULONG ulLineSpeed;
|
---|
1624 | hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
|
---|
1625 | InsertConfigInteger(pCfg, "LineSpeed", ulLineSpeed);
|
---|
1626 |
|
---|
1627 | /*
|
---|
1628 | * Attach the status driver.
|
---|
1629 | */
|
---|
1630 | InsertConfigNode(pInst, "LUN#999", &pLunL0);
|
---|
1631 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1632 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1633 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]);
|
---|
1634 |
|
---|
1635 | /*
|
---|
1636 | * Configure the network card now
|
---|
1637 | */
|
---|
1638 | rc = pConsole->configNetwork(pszAdapterName,
|
---|
1639 | ulInstance,
|
---|
1640 | 0,
|
---|
1641 | networkAdapter,
|
---|
1642 | pCfg,
|
---|
1643 | pLunL0,
|
---|
1644 | pInst,
|
---|
1645 | false /*fAttachDetach*/);
|
---|
1646 | if (RT_FAILURE(rc))
|
---|
1647 | return rc;
|
---|
1648 | }
|
---|
1649 |
|
---|
1650 | /*
|
---|
1651 | * Build network boot information and transfer it to the BIOS.
|
---|
1652 | */
|
---|
1653 | if (pNetBootCfg && !llBootNics.empty()) /* NetBoot node doesn't exist for EFI! */
|
---|
1654 | {
|
---|
1655 | llBootNics.sort(); /* Sort the list by boot priority. */
|
---|
1656 |
|
---|
1657 | char achBootIdx[] = "0";
|
---|
1658 | unsigned uBootIdx = 0;
|
---|
1659 |
|
---|
1660 | for (std::list<BootNic>::iterator it = llBootNics.begin(); it != llBootNics.end(); ++it)
|
---|
1661 | {
|
---|
1662 | /* A NIC with priority 0 is only used if it's first in the list. */
|
---|
1663 | if (it->mBootPrio == 0 && uBootIdx != 0)
|
---|
1664 | break;
|
---|
1665 |
|
---|
1666 | PCFGMNODE pNetBtDevCfg;
|
---|
1667 | achBootIdx[0] = '0' + uBootIdx++; /* Boot device order. */
|
---|
1668 | InsertConfigNode(pNetBootCfg, achBootIdx, &pNetBtDevCfg);
|
---|
1669 | InsertConfigInteger(pNetBtDevCfg, "NIC", it->mInstance);
|
---|
1670 | InsertConfigInteger(pNetBtDevCfg, "PCIDeviceNo", it->mPciDev);
|
---|
1671 | InsertConfigInteger(pNetBtDevCfg, "PCIFunctionNo", it->mPciFn);
|
---|
1672 | }
|
---|
1673 | }
|
---|
1674 |
|
---|
1675 | /*
|
---|
1676 | * Serial (UART) Ports
|
---|
1677 | */
|
---|
1678 | InsertConfigNode(pDevices, "serial", &pDev);
|
---|
1679 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ++ulInstance)
|
---|
1680 | {
|
---|
1681 | ComPtr<ISerialPort> serialPort;
|
---|
1682 | hrc = pMachine->GetSerialPort(ulInstance, serialPort.asOutParam()); H();
|
---|
1683 | BOOL fEnabled = FALSE;
|
---|
1684 | if (serialPort)
|
---|
1685 | hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1686 | if (!fEnabled)
|
---|
1687 | continue;
|
---|
1688 |
|
---|
1689 | InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
|
---|
1690 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1691 |
|
---|
1692 | ULONG ulIRQ;
|
---|
1693 | hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
|
---|
1694 | InsertConfigInteger(pCfg, "IRQ", ulIRQ);
|
---|
1695 | ULONG ulIOBase;
|
---|
1696 | hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
|
---|
1697 | InsertConfigInteger(pCfg, "IOBase", ulIOBase);
|
---|
1698 | BOOL fServer;
|
---|
1699 | hrc = serialPort->COMGETTER(Server)(&fServer); H();
|
---|
1700 | hrc = serialPort->COMGETTER(Path)(bstr.asOutParam()); H();
|
---|
1701 | PortMode_T eHostMode;
|
---|
1702 | hrc = serialPort->COMGETTER(HostMode)(&eHostMode); H();
|
---|
1703 | if (eHostMode != PortMode_Disconnected)
|
---|
1704 | {
|
---|
1705 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
1706 | if (eHostMode == PortMode_HostPipe)
|
---|
1707 | {
|
---|
1708 | InsertConfigString(pLunL0, "Driver", "Char");
|
---|
1709 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
1710 | InsertConfigString(pLunL1, "Driver", "NamedPipe");
|
---|
1711 | InsertConfigNode(pLunL1, "Config", &pLunL2);
|
---|
1712 | InsertConfigString(pLunL2, "Location", bstr);
|
---|
1713 | InsertConfigInteger(pLunL2, "IsServer", fServer);
|
---|
1714 | }
|
---|
1715 | else if (eHostMode == PortMode_HostDevice)
|
---|
1716 | {
|
---|
1717 | InsertConfigString(pLunL0, "Driver", "Host Serial");
|
---|
1718 | InsertConfigNode(pLunL0, "Config", &pLunL1);
|
---|
1719 | InsertConfigString(pLunL1, "DevicePath", bstr);
|
---|
1720 | }
|
---|
1721 | else if (eHostMode == PortMode_RawFile)
|
---|
1722 | {
|
---|
1723 | InsertConfigString(pLunL0, "Driver", "Char");
|
---|
1724 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
1725 | InsertConfigString(pLunL1, "Driver", "RawFile");
|
---|
1726 | InsertConfigNode(pLunL1, "Config", &pLunL2);
|
---|
1727 | InsertConfigString(pLunL2, "Location", bstr);
|
---|
1728 | }
|
---|
1729 | }
|
---|
1730 | }
|
---|
1731 |
|
---|
1732 | /*
|
---|
1733 | * Parallel (LPT) Ports
|
---|
1734 | */
|
---|
1735 | InsertConfigNode(pDevices, "parallel", &pDev);
|
---|
1736 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ++ulInstance)
|
---|
1737 | {
|
---|
1738 | ComPtr<IParallelPort> parallelPort;
|
---|
1739 | hrc = pMachine->GetParallelPort(ulInstance, parallelPort.asOutParam()); H();
|
---|
1740 | BOOL fEnabled = FALSE;
|
---|
1741 | if (parallelPort)
|
---|
1742 | {
|
---|
1743 | hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1744 | }
|
---|
1745 | if (!fEnabled)
|
---|
1746 | continue;
|
---|
1747 |
|
---|
1748 | InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
|
---|
1749 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1750 |
|
---|
1751 | ULONG ulIRQ;
|
---|
1752 | hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
|
---|
1753 | InsertConfigInteger(pCfg, "IRQ", ulIRQ);
|
---|
1754 | ULONG ulIOBase;
|
---|
1755 | hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
|
---|
1756 | InsertConfigInteger(pCfg, "IOBase", ulIOBase);
|
---|
1757 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
1758 | InsertConfigString(pLunL0, "Driver", "HostParallel");
|
---|
1759 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
1760 | hrc = parallelPort->COMGETTER(Path)(bstr.asOutParam()); H();
|
---|
1761 | InsertConfigString(pLunL1, "DevicePath", bstr);
|
---|
1762 | }
|
---|
1763 |
|
---|
1764 | /*
|
---|
1765 | * VMM Device
|
---|
1766 | */
|
---|
1767 | InsertConfigNode(pDevices, "VMMDev", &pDev);
|
---|
1768 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1769 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1770 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1771 | InsertConfigInteger(pInst, "PCIDeviceNo", 4);
|
---|
1772 | Assert(!afPciDeviceNo[4]);
|
---|
1773 | afPciDeviceNo[4] = true;
|
---|
1774 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
1775 | Bstr hwVersion;
|
---|
1776 | hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
|
---|
1777 | InsertConfigInteger(pCfg, "RamSize", cbRam);
|
---|
1778 | if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
|
---|
1779 | InsertConfigInteger(pCfg, "HeapEnabled", 0);
|
---|
1780 |
|
---|
1781 | /* the VMM device's Main driver */
|
---|
1782 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
1783 | InsertConfigString(pLunL0, "Driver", "HGCM");
|
---|
1784 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1785 | VMMDev *pVMMDev = pConsole->mVMMDev;
|
---|
1786 | InsertConfigInteger(pCfg, "Object", (uintptr_t)pVMMDev);
|
---|
1787 |
|
---|
1788 | /*
|
---|
1789 | * Attach the status driver.
|
---|
1790 | */
|
---|
1791 | InsertConfigNode(pInst, "LUN#999", &pLunL0);
|
---|
1792 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1793 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1794 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed);
|
---|
1795 | InsertConfigInteger(pCfg, "First", 0);
|
---|
1796 | InsertConfigInteger(pCfg, "Last", 0);
|
---|
1797 |
|
---|
1798 | /*
|
---|
1799 | * Audio Sniffer Device
|
---|
1800 | */
|
---|
1801 | InsertConfigNode(pDevices, "AudioSniffer", &pDev);
|
---|
1802 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1803 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1804 |
|
---|
1805 | /* the Audio Sniffer device's Main driver */
|
---|
1806 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
1807 | InsertConfigString(pLunL0, "Driver", "MainAudioSniffer");
|
---|
1808 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1809 | AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
|
---|
1810 | InsertConfigInteger(pCfg, "Object", (uintptr_t)pAudioSniffer);
|
---|
1811 |
|
---|
1812 | /*
|
---|
1813 | * AC'97 ICH / SoundBlaster16 audio / Intel HD Audio
|
---|
1814 | */
|
---|
1815 | BOOL enabled;
|
---|
1816 | ComPtr<IAudioAdapter> audioAdapter;
|
---|
1817 | hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
|
---|
1818 | if (audioAdapter)
|
---|
1819 | hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
|
---|
1820 |
|
---|
1821 | if (enabled)
|
---|
1822 | {
|
---|
1823 | AudioControllerType_T audioController;
|
---|
1824 | hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
|
---|
1825 | switch (audioController)
|
---|
1826 | {
|
---|
1827 | case AudioControllerType_AC97:
|
---|
1828 | {
|
---|
1829 | /* default: ICH AC97 */
|
---|
1830 | InsertConfigNode(pDevices, "ichac97", &pDev);
|
---|
1831 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1832 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1833 | InsertConfigInteger(pInst, "PCIDeviceNo", 5);
|
---|
1834 | Assert(!afPciDeviceNo[5]);
|
---|
1835 | afPciDeviceNo[5] = true;
|
---|
1836 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
1837 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1838 | break;
|
---|
1839 | }
|
---|
1840 | case AudioControllerType_SB16:
|
---|
1841 | {
|
---|
1842 | /* legacy SoundBlaster16 */
|
---|
1843 | InsertConfigNode(pDevices, "sb16", &pDev);
|
---|
1844 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1845 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1846 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1847 | InsertConfigInteger(pCfg, "IRQ", 5);
|
---|
1848 | InsertConfigInteger(pCfg, "DMA", 1);
|
---|
1849 | InsertConfigInteger(pCfg, "DMA16", 5);
|
---|
1850 | InsertConfigInteger(pCfg, "Port", 0x220);
|
---|
1851 | InsertConfigInteger(pCfg, "Version", 0x0405);
|
---|
1852 | break;
|
---|
1853 | }
|
---|
1854 | case AudioControllerType_HDA:
|
---|
1855 | {
|
---|
1856 | /* Intel HD Audio */
|
---|
1857 | InsertConfigNode(pDevices, "hda", &pDev);
|
---|
1858 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1859 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1860 | InsertConfigInteger(pInst, "PCIDeviceNo", 5);
|
---|
1861 | Assert(!afPciDeviceNo[5]);
|
---|
1862 | afPciDeviceNo[5] = true;
|
---|
1863 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
1864 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1865 | }
|
---|
1866 | }
|
---|
1867 |
|
---|
1868 | /* the Audio driver */
|
---|
1869 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
1870 | InsertConfigString(pLunL0, "Driver", "AUDIO");
|
---|
1871 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1872 |
|
---|
1873 | AudioDriverType_T audioDriver;
|
---|
1874 | hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
|
---|
1875 | switch (audioDriver)
|
---|
1876 | {
|
---|
1877 | case AudioDriverType_Null:
|
---|
1878 | {
|
---|
1879 | InsertConfigString(pCfg, "AudioDriver", "null");
|
---|
1880 | break;
|
---|
1881 | }
|
---|
1882 | #ifdef RT_OS_WINDOWS
|
---|
1883 | #ifdef VBOX_WITH_WINMM
|
---|
1884 | case AudioDriverType_WinMM:
|
---|
1885 | {
|
---|
1886 | InsertConfigString(pCfg, "AudioDriver", "winmm");
|
---|
1887 | break;
|
---|
1888 | }
|
---|
1889 | #endif
|
---|
1890 | case AudioDriverType_DirectSound:
|
---|
1891 | {
|
---|
1892 | InsertConfigString(pCfg, "AudioDriver", "dsound");
|
---|
1893 | break;
|
---|
1894 | }
|
---|
1895 | #endif /* RT_OS_WINDOWS */
|
---|
1896 | #ifdef RT_OS_SOLARIS
|
---|
1897 | case AudioDriverType_SolAudio:
|
---|
1898 | {
|
---|
1899 | InsertConfigString(pCfg, "AudioDriver", "solaudio");
|
---|
1900 | break;
|
---|
1901 | }
|
---|
1902 | #endif
|
---|
1903 | #ifdef RT_OS_LINUX
|
---|
1904 | # ifdef VBOX_WITH_ALSA
|
---|
1905 | case AudioDriverType_ALSA:
|
---|
1906 | {
|
---|
1907 | InsertConfigString(pCfg, "AudioDriver", "alsa");
|
---|
1908 | break;
|
---|
1909 | }
|
---|
1910 | # endif
|
---|
1911 | # ifdef VBOX_WITH_PULSE
|
---|
1912 | case AudioDriverType_Pulse:
|
---|
1913 | {
|
---|
1914 | InsertConfigString(pCfg, "AudioDriver", "pulse");
|
---|
1915 | break;
|
---|
1916 | }
|
---|
1917 | # endif
|
---|
1918 | #endif /* RT_OS_LINUX */
|
---|
1919 | #if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
|
---|
1920 | case AudioDriverType_OSS:
|
---|
1921 | {
|
---|
1922 | InsertConfigString(pCfg, "AudioDriver", "oss");
|
---|
1923 | break;
|
---|
1924 | }
|
---|
1925 | #endif
|
---|
1926 | #ifdef RT_OS_FREEBSD
|
---|
1927 | # ifdef VBOX_WITH_PULSE
|
---|
1928 | case AudioDriverType_Pulse:
|
---|
1929 | {
|
---|
1930 | InsertConfigString(pCfg, "AudioDriver", "pulse");
|
---|
1931 | break;
|
---|
1932 | }
|
---|
1933 | # endif
|
---|
1934 | #endif
|
---|
1935 | #ifdef RT_OS_DARWIN
|
---|
1936 | case AudioDriverType_CoreAudio:
|
---|
1937 | {
|
---|
1938 | InsertConfigString(pCfg, "AudioDriver", "coreaudio");
|
---|
1939 | break;
|
---|
1940 | }
|
---|
1941 | #endif
|
---|
1942 | }
|
---|
1943 | hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
|
---|
1944 | InsertConfigString(pCfg, "StreamName", bstr);
|
---|
1945 | }
|
---|
1946 |
|
---|
1947 | /*
|
---|
1948 | * The USB Controller.
|
---|
1949 | */
|
---|
1950 | ComPtr<IUSBController> USBCtlPtr;
|
---|
1951 | hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
|
---|
1952 | if (USBCtlPtr)
|
---|
1953 | {
|
---|
1954 | BOOL fOhciEnabled;
|
---|
1955 | hrc = USBCtlPtr->COMGETTER(Enabled)(&fOhciEnabled); H();
|
---|
1956 | if (fOhciEnabled)
|
---|
1957 | {
|
---|
1958 | InsertConfigNode(pDevices, "usb-ohci", &pDev);
|
---|
1959 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1960 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1961 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1962 | InsertConfigInteger(pInst, "PCIDeviceNo", 6);
|
---|
1963 | Assert(!afPciDeviceNo[6]);
|
---|
1964 | afPciDeviceNo[6] = true;
|
---|
1965 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
1966 |
|
---|
1967 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
1968 | InsertConfigString(pLunL0, "Driver", "VUSBRootHub");
|
---|
1969 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1970 |
|
---|
1971 | /*
|
---|
1972 | * Attach the status driver.
|
---|
1973 | */
|
---|
1974 | InsertConfigNode(pInst, "LUN#999", &pLunL0);
|
---|
1975 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
1976 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1977 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);
|
---|
1978 | InsertConfigInteger(pCfg, "First", 0);
|
---|
1979 | InsertConfigInteger(pCfg, "Last", 0);
|
---|
1980 |
|
---|
1981 | #ifdef VBOX_WITH_EHCI
|
---|
1982 | BOOL fEhciEnabled;
|
---|
1983 | hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEhciEnabled); H();
|
---|
1984 | if (fEhciEnabled)
|
---|
1985 | {
|
---|
1986 | InsertConfigNode(pDevices, "usb-ehci", &pDev);
|
---|
1987 | InsertConfigNode(pDev, "0", &pInst);
|
---|
1988 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
1989 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
1990 | InsertConfigInteger(pInst, "PCIDeviceNo", 11);
|
---|
1991 | Assert(!afPciDeviceNo[11]);
|
---|
1992 | afPciDeviceNo[11] = true;
|
---|
1993 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
1994 |
|
---|
1995 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
1996 | InsertConfigString(pLunL0, "Driver", "VUSBRootHub");
|
---|
1997 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
1998 |
|
---|
1999 | /*
|
---|
2000 | * Attach the status driver.
|
---|
2001 | */
|
---|
2002 | InsertConfigNode(pInst, "LUN#999", &pLunL0);
|
---|
2003 | InsertConfigString(pLunL0, "Driver", "MainStatus");
|
---|
2004 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2005 | InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);
|
---|
2006 | InsertConfigInteger(pCfg, "First", 0);
|
---|
2007 | InsertConfigInteger(pCfg, "Last", 0);
|
---|
2008 | }
|
---|
2009 | #endif
|
---|
2010 |
|
---|
2011 | /*
|
---|
2012 | * Virtual USB Devices.
|
---|
2013 | */
|
---|
2014 | PCFGMNODE pUsbDevices = NULL;
|
---|
2015 | InsertConfigNode(pRoot, "USB", &pUsbDevices);
|
---|
2016 |
|
---|
2017 | #ifdef VBOX_WITH_USB
|
---|
2018 | {
|
---|
2019 | /*
|
---|
2020 | * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
|
---|
2021 | * on a per device level now.
|
---|
2022 | */
|
---|
2023 | InsertConfigNode(pUsbDevices, "USBProxy", &pCfg);
|
---|
2024 | InsertConfigNode(pCfg, "GlobalConfig", &pCfg);
|
---|
2025 | // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
|
---|
2026 | //InsertConfigInteger(pCfg, "Force11Device", true);
|
---|
2027 | // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
|
---|
2028 | // that it's documented somewhere.) Users needing it can use:
|
---|
2029 | // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
|
---|
2030 | //InsertConfigInteger(pCfg, "Force11PacketSize", true);
|
---|
2031 | }
|
---|
2032 | #endif
|
---|
2033 |
|
---|
2034 | # if 0 /* Virtual MSD*/
|
---|
2035 |
|
---|
2036 | InsertConfigNode(pUsbDevices, "Msd", &pDev);
|
---|
2037 | InsertConfigNode(pDev, "0", &pInst);
|
---|
2038 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
2039 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
2040 |
|
---|
2041 | InsertConfigString(pLunL0, "Driver", "SCSI");
|
---|
2042 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2043 |
|
---|
2044 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
2045 | InsertConfigString(pLunL1, "Driver", "Block");
|
---|
2046 | InsertConfigNode(pLunL1, "Config", &pCfg);
|
---|
2047 | InsertConfigString(pCfg, "Type", "HardDisk");
|
---|
2048 | InsertConfigInteger(pCfg, "Mountable", 0);
|
---|
2049 |
|
---|
2050 | InsertConfigNode(pLunL1, "AttachedDriver", &pLunL2);
|
---|
2051 | InsertConfigString(pLunL2, "Driver", "VD");
|
---|
2052 | InsertConfigNode(pLunL2, "Config", &pCfg);
|
---|
2053 | InsertConfigString(pCfg, "Path", "/Volumes/DataHFS/bird/VDIs/linux.vdi");
|
---|
2054 | InsertConfigString(pCfg, "Format", "VDI");
|
---|
2055 | # endif
|
---|
2056 |
|
---|
2057 | /* Virtual USB Mouse/Tablet */
|
---|
2058 | PointingHidType_T aPointingHid;
|
---|
2059 | hrc = pMachine->COMGETTER(PointingHidType)(&aPointingHid); H();
|
---|
2060 | if (aPointingHid == PointingHidType_USBMouse || aPointingHid == PointingHidType_USBTablet)
|
---|
2061 | {
|
---|
2062 | InsertConfigNode(pUsbDevices, "HidMouse", &pDev);
|
---|
2063 | InsertConfigNode(pDev, "0", &pInst);
|
---|
2064 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
2065 |
|
---|
2066 | if (aPointingHid == PointingHidType_USBTablet)
|
---|
2067 | {
|
---|
2068 | InsertConfigInteger(pCfg, "Absolute", 1);
|
---|
2069 | }
|
---|
2070 | else
|
---|
2071 | {
|
---|
2072 | InsertConfigInteger(pCfg, "Absolute", 0);
|
---|
2073 | }
|
---|
2074 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
2075 | InsertConfigString(pLunL0, "Driver", "MouseQueue");
|
---|
2076 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2077 | InsertConfigInteger(pCfg, "QueueSize", 128);
|
---|
2078 |
|
---|
2079 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
2080 | InsertConfigString(pLunL1, "Driver", "MainMouse");
|
---|
2081 | InsertConfigNode(pLunL1, "Config", &pCfg);
|
---|
2082 | pMouse = pConsole->mMouse;
|
---|
2083 | InsertConfigInteger(pCfg, "Object", (uintptr_t)pMouse);
|
---|
2084 | }
|
---|
2085 |
|
---|
2086 | /* Virtual USB Keyboard */
|
---|
2087 | KeyboardHidType_T aKbdHid;
|
---|
2088 | hrc = pMachine->COMGETTER(KeyboardHidType)(&aKbdHid); H();
|
---|
2089 | if (aKbdHid == KeyboardHidType_USBKeyboard)
|
---|
2090 | {
|
---|
2091 | InsertConfigNode(pUsbDevices, "HidKeyboard", &pDev);
|
---|
2092 | InsertConfigNode(pDev, "0", &pInst);
|
---|
2093 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
2094 |
|
---|
2095 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
2096 | InsertConfigString(pLunL0, "Driver", "KeyboardQueue");
|
---|
2097 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2098 | InsertConfigInteger(pCfg, "QueueSize", 64);
|
---|
2099 |
|
---|
2100 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
2101 | InsertConfigString(pLunL1, "Driver", "MainKeyboard");
|
---|
2102 | InsertConfigNode(pLunL1, "Config", &pCfg);
|
---|
2103 | pKeyboard = pConsole->mKeyboard;
|
---|
2104 | InsertConfigInteger(pCfg, "Object", (uintptr_t)pKeyboard);
|
---|
2105 | }
|
---|
2106 | }
|
---|
2107 | }
|
---|
2108 |
|
---|
2109 | /*
|
---|
2110 | * Clipboard
|
---|
2111 | */
|
---|
2112 | {
|
---|
2113 | ClipboardMode_T mode = ClipboardMode_Disabled;
|
---|
2114 | hrc = pMachine->COMGETTER(ClipboardMode)(&mode); H();
|
---|
2115 |
|
---|
2116 | if (mode != ClipboardMode_Disabled)
|
---|
2117 | {
|
---|
2118 | /* Load the service */
|
---|
2119 | rc = pConsole->mVMMDev->hgcmLoadService("VBoxSharedClipboard", "VBoxSharedClipboard");
|
---|
2120 |
|
---|
2121 | if (RT_FAILURE(rc))
|
---|
2122 | {
|
---|
2123 | LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
|
---|
2124 | /* That is not a fatal failure. */
|
---|
2125 | rc = VINF_SUCCESS;
|
---|
2126 | }
|
---|
2127 | else
|
---|
2128 | {
|
---|
2129 | /* Setup the service. */
|
---|
2130 | VBOXHGCMSVCPARM parm;
|
---|
2131 |
|
---|
2132 | parm.type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
2133 |
|
---|
2134 | switch (mode)
|
---|
2135 | {
|
---|
2136 | default:
|
---|
2137 | case ClipboardMode_Disabled:
|
---|
2138 | {
|
---|
2139 | LogRel(("VBoxSharedClipboard mode: Off\n"));
|
---|
2140 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
|
---|
2141 | break;
|
---|
2142 | }
|
---|
2143 | case ClipboardMode_GuestToHost:
|
---|
2144 | {
|
---|
2145 | LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
|
---|
2146 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
|
---|
2147 | break;
|
---|
2148 | }
|
---|
2149 | case ClipboardMode_HostToGuest:
|
---|
2150 | {
|
---|
2151 | LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
|
---|
2152 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
|
---|
2153 | break;
|
---|
2154 | }
|
---|
2155 | case ClipboardMode_Bidirectional:
|
---|
2156 | {
|
---|
2157 | LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
|
---|
2158 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
|
---|
2159 | break;
|
---|
2160 | }
|
---|
2161 | }
|
---|
2162 |
|
---|
2163 | pConsole->mVMMDev->hgcmHostCall("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
|
---|
2164 |
|
---|
2165 | Log(("Set VBoxSharedClipboard mode\n"));
|
---|
2166 | }
|
---|
2167 | }
|
---|
2168 | }
|
---|
2169 |
|
---|
2170 | #ifdef VBOX_WITH_CROGL
|
---|
2171 | /*
|
---|
2172 | * crOpenGL
|
---|
2173 | */
|
---|
2174 | {
|
---|
2175 | BOOL fEnabled = false;
|
---|
2176 | hrc = pMachine->COMGETTER(Accelerate3DEnabled)(&fEnabled); H();
|
---|
2177 |
|
---|
2178 | if (fEnabled)
|
---|
2179 | {
|
---|
2180 | /* Load the service */
|
---|
2181 | rc = pConsole->mVMMDev->hgcmLoadService("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
|
---|
2182 | if (RT_FAILURE(rc))
|
---|
2183 | {
|
---|
2184 | LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
|
---|
2185 | /* That is not a fatal failure. */
|
---|
2186 | rc = VINF_SUCCESS;
|
---|
2187 | }
|
---|
2188 | else
|
---|
2189 | {
|
---|
2190 | LogRel(("Shared crOpenGL service loaded.\n"));
|
---|
2191 |
|
---|
2192 | /* Setup the service. */
|
---|
2193 | VBOXHGCMSVCPARM parm;
|
---|
2194 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2195 |
|
---|
2196 | parm.u.pointer.addr = (IConsole*) (Console*) pConsole;
|
---|
2197 | parm.u.pointer.size = sizeof(IConsole *);
|
---|
2198 |
|
---|
2199 | rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_CONSOLE,
|
---|
2200 | SHCRGL_CPARMS_SET_CONSOLE, &parm);
|
---|
2201 | if (!RT_SUCCESS(rc))
|
---|
2202 | AssertMsgFailed(("SHCRGL_HOST_FN_SET_CONSOLE failed with %Rrc\n", rc));
|
---|
2203 |
|
---|
2204 | parm.u.pointer.addr = pVM;
|
---|
2205 | parm.u.pointer.size = sizeof(pVM);
|
---|
2206 | rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VM,
|
---|
2207 | SHCRGL_CPARMS_SET_VM, &parm);
|
---|
2208 | if (!RT_SUCCESS(rc))
|
---|
2209 | AssertMsgFailed(("SHCRGL_HOST_FN_SET_VM failed with %Rrc\n", rc));
|
---|
2210 | }
|
---|
2211 |
|
---|
2212 | }
|
---|
2213 | }
|
---|
2214 | #endif
|
---|
2215 |
|
---|
2216 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
2217 | /*
|
---|
2218 | * Guest property service
|
---|
2219 | */
|
---|
2220 |
|
---|
2221 | rc = configGuestProperties(pConsole);
|
---|
2222 | #endif /* VBOX_WITH_GUEST_PROPS defined */
|
---|
2223 |
|
---|
2224 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
2225 | /*
|
---|
2226 | * Guest control service
|
---|
2227 | */
|
---|
2228 |
|
---|
2229 | rc = configGuestControl(pConsole);
|
---|
2230 | #endif /* VBOX_WITH_GUEST_CONTROL defined */
|
---|
2231 |
|
---|
2232 | /*
|
---|
2233 | * ACPI
|
---|
2234 | */
|
---|
2235 | BOOL fACPI;
|
---|
2236 | hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
|
---|
2237 | if (fACPI)
|
---|
2238 | {
|
---|
2239 | BOOL fCpuHotPlug = false;
|
---|
2240 | BOOL fShowCpu = fOsXGuest;
|
---|
2241 | /* Always show the CPU leafs when we have multiple VCPUs or when the IO-APIC is enabled.
|
---|
2242 | * The Windows SMP kernel needs a CPU leaf or else its idle loop will burn cpu cycles; the
|
---|
2243 | * intelppm driver refuses to register an idle state handler.
|
---|
2244 | */
|
---|
2245 | if ((cCpus > 1) || fIOAPIC)
|
---|
2246 | fShowCpu = true;
|
---|
2247 |
|
---|
2248 | hrc = pMachine->COMGETTER(CPUHotPlugEnabled)(&fCpuHotPlug); H();
|
---|
2249 |
|
---|
2250 | InsertConfigNode(pDevices, "acpi", &pDev);
|
---|
2251 | InsertConfigNode(pDev, "0", &pInst);
|
---|
2252 | InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
|
---|
2253 | InsertConfigNode(pInst, "Config", &pCfg);
|
---|
2254 | InsertConfigInteger(pCfg, "RamSize", cbRam);
|
---|
2255 | InsertConfigInteger(pCfg, "RamHoleSize", cbRamHole);
|
---|
2256 | InsertConfigInteger(pCfg, "NumCPUs", cCpus);
|
---|
2257 |
|
---|
2258 | InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
|
---|
2259 | InsertConfigInteger(pCfg, "FdcEnabled", fFdcEnabled);
|
---|
2260 | InsertConfigInteger(pCfg, "HpetEnabled", fHpetEnabled);
|
---|
2261 | InsertConfigInteger(pCfg, "SmcEnabled", fSmcEnabled);
|
---|
2262 | InsertConfigInteger(pCfg, "ShowRtc", fOsXGuest);
|
---|
2263 | if (fOsXGuest && !llBootNics.empty())
|
---|
2264 | {
|
---|
2265 | BootNic aNic = llBootNics.front();
|
---|
2266 | uint32_t u32NicPciAddr = (aNic.mPciDev << 16) | aNic.mPciFn;
|
---|
2267 | InsertConfigInteger(pCfg, "NicPciAddress", u32NicPciAddr);
|
---|
2268 | }
|
---|
2269 | InsertConfigInteger(pCfg, "ShowCpu", fShowCpu);
|
---|
2270 | InsertConfigInteger(pCfg, "CpuHotPlug", fCpuHotPlug);
|
---|
2271 | InsertConfigInteger(pInst, "PCIDeviceNo", 7);
|
---|
2272 | Assert(!afPciDeviceNo[7]);
|
---|
2273 | afPciDeviceNo[7] = true;
|
---|
2274 | InsertConfigInteger(pInst, "PCIFunctionNo", 0);
|
---|
2275 |
|
---|
2276 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
2277 | InsertConfigString(pLunL0, "Driver", "ACPIHost");
|
---|
2278 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2279 |
|
---|
2280 | /* Attach the dummy CPU drivers */
|
---|
2281 | for (ULONG iCpuCurr = 1; iCpuCurr < cCpus; iCpuCurr++)
|
---|
2282 | {
|
---|
2283 | BOOL fCpuAttached = true;
|
---|
2284 |
|
---|
2285 | if (fCpuHotPlug)
|
---|
2286 | {
|
---|
2287 | hrc = pMachine->GetCPUStatus(iCpuCurr, &fCpuAttached); H();
|
---|
2288 | }
|
---|
2289 |
|
---|
2290 | if (fCpuAttached)
|
---|
2291 | {
|
---|
2292 | InsertConfigNode(pInst, Utf8StrFmt("LUN#%u", iCpuCurr).c_str(), &pLunL0);
|
---|
2293 | InsertConfigString(pLunL0, "Driver", "ACPICpu");
|
---|
2294 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2295 | }
|
---|
2296 | }
|
---|
2297 | }
|
---|
2298 |
|
---|
2299 | /*
|
---|
2300 | * CFGM overlay handling.
|
---|
2301 | *
|
---|
2302 | * Here we check the extra data entries for CFGM values
|
---|
2303 | * and create the nodes and insert the values on the fly. Existing
|
---|
2304 | * values will be removed and reinserted. CFGM is typed, so by default
|
---|
2305 | * we will guess whether it's a string or an integer (byte arrays are
|
---|
2306 | * not currently supported). It's possible to override this autodetection
|
---|
2307 | * by adding "string:", "integer:" or "bytes:" (future).
|
---|
2308 | *
|
---|
2309 | * We first perform a run on global extra data, then on the machine
|
---|
2310 | * extra data to support global settings with local overrides.
|
---|
2311 | */
|
---|
2312 | /** @todo add support for removing nodes and byte blobs. */
|
---|
2313 | SafeArray<BSTR> aGlobalExtraDataKeys;
|
---|
2314 | SafeArray<BSTR> aMachineExtraDataKeys;
|
---|
2315 | /*
|
---|
2316 | * Get the next key
|
---|
2317 | */
|
---|
2318 | if (FAILED(hrc = virtualBox->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys))))
|
---|
2319 | AssertMsgFailed(("VirtualBox::GetExtraDataKeys failed with %Rrc\n", hrc));
|
---|
2320 |
|
---|
2321 | // remember the no. of global values so we can call the correct method below
|
---|
2322 | size_t cGlobalValues = aGlobalExtraDataKeys.size();
|
---|
2323 |
|
---|
2324 | if (FAILED(hrc = pMachine->GetExtraDataKeys(ComSafeArrayAsOutParam(aMachineExtraDataKeys))))
|
---|
2325 | AssertMsgFailed(("IMachine::GetExtraDataKeys failed with %Rrc\n", hrc));
|
---|
2326 |
|
---|
2327 | // build a combined list from global keys...
|
---|
2328 | std::list<Utf8Str> llExtraDataKeys;
|
---|
2329 |
|
---|
2330 | for (size_t i = 0; i < aGlobalExtraDataKeys.size(); ++i)
|
---|
2331 | llExtraDataKeys.push_back(Utf8Str(aGlobalExtraDataKeys[i]));
|
---|
2332 | // ... and machine keys
|
---|
2333 | for (size_t i = 0; i < aMachineExtraDataKeys.size(); ++i)
|
---|
2334 | llExtraDataKeys.push_back(Utf8Str(aMachineExtraDataKeys[i]));
|
---|
2335 |
|
---|
2336 | size_t i2 = 0;
|
---|
2337 | for (std::list<Utf8Str>::const_iterator it = llExtraDataKeys.begin();
|
---|
2338 | it != llExtraDataKeys.end();
|
---|
2339 | ++it, ++i2)
|
---|
2340 | {
|
---|
2341 | const Utf8Str &strKey = *it;
|
---|
2342 |
|
---|
2343 | /*
|
---|
2344 | * We only care about keys starting with "VBoxInternal/" (skip "G:" or "M:")
|
---|
2345 | */
|
---|
2346 | if (!strKey.startsWith("VBoxInternal/"))
|
---|
2347 | continue;
|
---|
2348 |
|
---|
2349 | const char *pszExtraDataKey = strKey.raw() + sizeof("VBoxInternal/") - 1;
|
---|
2350 |
|
---|
2351 | // get the value
|
---|
2352 | Bstr bstrExtraDataValue;
|
---|
2353 | if (i2 < cGlobalValues)
|
---|
2354 | // this is still one of the global values:
|
---|
2355 | hrc = virtualBox->GetExtraData(Bstr(strKey), bstrExtraDataValue.asOutParam());
|
---|
2356 | else
|
---|
2357 | hrc = pMachine->GetExtraData(Bstr(strKey), bstrExtraDataValue.asOutParam());
|
---|
2358 | if (FAILED(hrc))
|
---|
2359 | LogRel(("Warning: Cannot get extra data key %s, rc = %Rrc\n", strKey.raw(), hrc));
|
---|
2360 |
|
---|
2361 | /*
|
---|
2362 | * The key will be in the format "Node1/Node2/Value" or simply "Value".
|
---|
2363 | * Split the two and get the node, delete the value and create the node
|
---|
2364 | * if necessary.
|
---|
2365 | */
|
---|
2366 | PCFGMNODE pNode;
|
---|
2367 | const char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
|
---|
2368 | if (pszCFGMValueName)
|
---|
2369 | {
|
---|
2370 | /* terminate the node and advance to the value (Utf8Str might not
|
---|
2371 | offically like this but wtf) */
|
---|
2372 | *(char*)pszCFGMValueName = '\0';
|
---|
2373 | ++pszCFGMValueName;
|
---|
2374 |
|
---|
2375 | /* does the node already exist? */
|
---|
2376 | pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
|
---|
2377 | if (pNode)
|
---|
2378 | CFGMR3RemoveValue(pNode, pszCFGMValueName);
|
---|
2379 | else
|
---|
2380 | {
|
---|
2381 | /* create the node */
|
---|
2382 | rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
|
---|
2383 | if (RT_FAILURE(rc))
|
---|
2384 | {
|
---|
2385 | AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
|
---|
2386 | continue;
|
---|
2387 | }
|
---|
2388 | Assert(pNode);
|
---|
2389 | }
|
---|
2390 | }
|
---|
2391 | else
|
---|
2392 | {
|
---|
2393 | /* root value (no node path). */
|
---|
2394 | pNode = pRoot;
|
---|
2395 | pszCFGMValueName = pszExtraDataKey;
|
---|
2396 | pszExtraDataKey--;
|
---|
2397 | CFGMR3RemoveValue(pNode, pszCFGMValueName);
|
---|
2398 | }
|
---|
2399 |
|
---|
2400 | /*
|
---|
2401 | * Now let's have a look at the value.
|
---|
2402 | * Empty strings means that we should remove the value, which we've
|
---|
2403 | * already done above.
|
---|
2404 | */
|
---|
2405 | Utf8Str strCFGMValueUtf8(bstrExtraDataValue);
|
---|
2406 | if (!strCFGMValueUtf8.isEmpty())
|
---|
2407 | {
|
---|
2408 | uint64_t u64Value;
|
---|
2409 |
|
---|
2410 | /* check for type prefix first. */
|
---|
2411 | if (!strncmp(strCFGMValueUtf8.c_str(), "string:", sizeof("string:") - 1))
|
---|
2412 | InsertConfigString(pNode, pszCFGMValueName, strCFGMValueUtf8.c_str() + sizeof("string:") - 1);
|
---|
2413 | else if (!strncmp(strCFGMValueUtf8.c_str(), "integer:", sizeof("integer:") - 1))
|
---|
2414 | {
|
---|
2415 | rc = RTStrToUInt64Full(strCFGMValueUtf8.c_str() + sizeof("integer:") - 1, 0, &u64Value);
|
---|
2416 | if (RT_SUCCESS(rc))
|
---|
2417 | rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
|
---|
2418 | }
|
---|
2419 | else if (!strncmp(strCFGMValueUtf8.c_str(), "bytes:", sizeof("bytes:") - 1))
|
---|
2420 | rc = VERR_NOT_IMPLEMENTED;
|
---|
2421 | /* auto detect type. */
|
---|
2422 | else if (RT_SUCCESS(RTStrToUInt64Full(strCFGMValueUtf8.c_str(), 0, &u64Value)))
|
---|
2423 | rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
|
---|
2424 | else
|
---|
2425 | InsertConfigString(pNode, pszCFGMValueName, strCFGMValueUtf8);
|
---|
2426 | AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", strCFGMValueUtf8.c_str(), pszExtraDataKey));
|
---|
2427 | }
|
---|
2428 | }
|
---|
2429 | }
|
---|
2430 | catch (ConfigError &x)
|
---|
2431 | {
|
---|
2432 | // InsertConfig threw something:
|
---|
2433 | return x.m_vrc;
|
---|
2434 | }
|
---|
2435 |
|
---|
2436 | #undef H
|
---|
2437 |
|
---|
2438 | /* Register VM state change handler */
|
---|
2439 | int rc2 = VMR3AtStateRegister(pVM, Console::vmstateChangeCallback, pConsole);
|
---|
2440 | AssertRC(rc2);
|
---|
2441 | if (RT_SUCCESS(rc))
|
---|
2442 | rc = rc2;
|
---|
2443 |
|
---|
2444 | /* Register VM runtime error handler */
|
---|
2445 | rc2 = VMR3AtRuntimeErrorRegister(pVM, Console::setVMRuntimeErrorCallback, pConsole);
|
---|
2446 | AssertRC(rc2);
|
---|
2447 | if (RT_SUCCESS(rc))
|
---|
2448 | rc = rc2;
|
---|
2449 |
|
---|
2450 | LogFlowFunc(("vrc = %Rrc\n", rc));
|
---|
2451 | LogFlowFuncLeave();
|
---|
2452 |
|
---|
2453 | return rc;
|
---|
2454 | }
|
---|
2455 |
|
---|
2456 | /**
|
---|
2457 | * Ellipsis to va_list wrapper for calling setVMRuntimeErrorCallback.
|
---|
2458 | */
|
---|
2459 | /*static*/
|
---|
2460 | void Console::setVMRuntimeErrorCallbackF(PVM pVM, void *pvConsole, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
|
---|
2461 | {
|
---|
2462 | va_list va;
|
---|
2463 | va_start(va, pszFormat);
|
---|
2464 | setVMRuntimeErrorCallback(pVM, pvConsole, fFlags, pszErrorId, pszFormat, va);
|
---|
2465 | va_end(va);
|
---|
2466 | }
|
---|
2467 |
|
---|
2468 | /* XXX introduce RT format specifier */
|
---|
2469 | static uint64_t formatDiskSize(uint64_t u64Size, const char **pszUnit)
|
---|
2470 | {
|
---|
2471 | if (u64Size > INT64_C(5000)*_1G)
|
---|
2472 | {
|
---|
2473 | *pszUnit = "TB";
|
---|
2474 | return u64Size / _1T;
|
---|
2475 | }
|
---|
2476 | else if (u64Size > INT64_C(5000)*_1M)
|
---|
2477 | {
|
---|
2478 | *pszUnit = "GB";
|
---|
2479 | return u64Size / _1G;
|
---|
2480 | }
|
---|
2481 | else
|
---|
2482 | {
|
---|
2483 | *pszUnit = "MB";
|
---|
2484 | return u64Size / _1M;
|
---|
2485 | }
|
---|
2486 | }
|
---|
2487 |
|
---|
2488 | int Console::configMediumAttachment(PCFGMNODE pCtlInst,
|
---|
2489 | const char *pcszDevice,
|
---|
2490 | unsigned uInstance,
|
---|
2491 | StorageBus_T enmBus,
|
---|
2492 | bool fUseHostIOCache,
|
---|
2493 | bool fSetupMerge,
|
---|
2494 | unsigned uMergeSource,
|
---|
2495 | unsigned uMergeTarget,
|
---|
2496 | IMediumAttachment *pMediumAtt,
|
---|
2497 | MachineState_T aMachineState,
|
---|
2498 | HRESULT *phrc,
|
---|
2499 | bool fAttachDetach,
|
---|
2500 | bool fForceUnmount,
|
---|
2501 | PVM pVM,
|
---|
2502 | DeviceType_T *paLedDevType)
|
---|
2503 | {
|
---|
2504 | // InsertConfig* throws
|
---|
2505 | try
|
---|
2506 | {
|
---|
2507 | int rc = VINF_SUCCESS;
|
---|
2508 | HRESULT hrc;
|
---|
2509 | Bstr bstr;
|
---|
2510 |
|
---|
2511 | // #define RC_CHECK() AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc)
|
---|
2512 | #define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
|
---|
2513 |
|
---|
2514 | LONG lDev;
|
---|
2515 | hrc = pMediumAtt->COMGETTER(Device)(&lDev); H();
|
---|
2516 | LONG lPort;
|
---|
2517 | hrc = pMediumAtt->COMGETTER(Port)(&lPort); H();
|
---|
2518 | DeviceType_T lType;
|
---|
2519 | hrc = pMediumAtt->COMGETTER(Type)(&lType); H();
|
---|
2520 |
|
---|
2521 | unsigned uLUN;
|
---|
2522 | PCFGMNODE pLunL0 = NULL;
|
---|
2523 | PCFGMNODE pCfg = NULL;
|
---|
2524 | hrc = Console::convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN); H();
|
---|
2525 |
|
---|
2526 | /* First check if the LUN already exists. */
|
---|
2527 | pLunL0 = CFGMR3GetChildF(pCtlInst, "LUN#%u", uLUN);
|
---|
2528 | if (pLunL0)
|
---|
2529 | {
|
---|
2530 | if (fAttachDetach)
|
---|
2531 | {
|
---|
2532 | if (lType != DeviceType_HardDisk)
|
---|
2533 | {
|
---|
2534 | /* Unmount existing media only for floppy and DVD drives. */
|
---|
2535 | PPDMIBASE pBase;
|
---|
2536 | rc = PDMR3QueryLun(pVM, pcszDevice, uInstance, uLUN, &pBase);
|
---|
2537 | if (RT_FAILURE(rc))
|
---|
2538 | {
|
---|
2539 | if (rc == VERR_PDM_LUN_NOT_FOUND || rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
|
---|
2540 | rc = VINF_SUCCESS;
|
---|
2541 | AssertRC(rc);
|
---|
2542 | }
|
---|
2543 | else
|
---|
2544 | {
|
---|
2545 | PPDMIMOUNT pIMount = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMOUNT);
|
---|
2546 | AssertReturn(pIMount, VERR_INVALID_POINTER);
|
---|
2547 |
|
---|
2548 | /* Unmount the media. */
|
---|
2549 | rc = pIMount->pfnUnmount(pIMount, fForceUnmount);
|
---|
2550 | if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
|
---|
2551 | rc = VINF_SUCCESS;
|
---|
2552 | }
|
---|
2553 | }
|
---|
2554 |
|
---|
2555 | rc = PDMR3DeviceDetach(pVM, pcszDevice, 0, uLUN, PDM_TACH_FLAGS_NOT_HOT_PLUG);
|
---|
2556 | if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
|
---|
2557 | rc = VINF_SUCCESS;
|
---|
2558 | AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
|
---|
2559 |
|
---|
2560 | CFGMR3RemoveNode(pLunL0);
|
---|
2561 | }
|
---|
2562 | else
|
---|
2563 | AssertFailedReturn(VERR_INTERNAL_ERROR);
|
---|
2564 | }
|
---|
2565 |
|
---|
2566 | InsertConfigNode(pCtlInst, Utf8StrFmt("LUN#%u", uLUN).c_str(), &pLunL0);
|
---|
2567 |
|
---|
2568 | /* SCSI has a another driver between device and block. */
|
---|
2569 | if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS)
|
---|
2570 | {
|
---|
2571 | InsertConfigString(pLunL0, "Driver", "SCSI");
|
---|
2572 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2573 |
|
---|
2574 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
2575 | }
|
---|
2576 |
|
---|
2577 | ComPtr<IMedium> pMedium;
|
---|
2578 | hrc = pMediumAtt->COMGETTER(Medium)(pMedium.asOutParam()); H();
|
---|
2579 |
|
---|
2580 | if (lType == DeviceType_HardDisk)
|
---|
2581 | {
|
---|
2582 | /*
|
---|
2583 | * Some sanity checks.
|
---|
2584 | */
|
---|
2585 | ComPtr<IMediumFormat> pMediumFormat;
|
---|
2586 | hrc = pMedium->COMGETTER(MediumFormat)(pMediumFormat.asOutParam()); H();
|
---|
2587 | ULONG uCaps;
|
---|
2588 | hrc = pMediumFormat->COMGETTER(Capabilities)(&uCaps); H();
|
---|
2589 | if (uCaps & MediumFormatCapabilities_File)
|
---|
2590 | {
|
---|
2591 | Bstr strFile;
|
---|
2592 | hrc = pMedium->COMGETTER(Location)(strFile.asOutParam()); H();
|
---|
2593 | Utf8Str utfFile = Utf8Str(strFile);
|
---|
2594 | Bstr strSnap;
|
---|
2595 | ComPtr<IMachine> pMachine = machine();
|
---|
2596 | hrc = pMachine->COMGETTER(SnapshotFolder)(strSnap.asOutParam()); H();
|
---|
2597 | Utf8Str utfSnap = Utf8Str(strSnap);
|
---|
2598 | RTFSTYPE enmFsTypeFile = RTFSTYPE_UNKNOWN;
|
---|
2599 | RTFSTYPE enmFsTypeSnap = RTFSTYPE_UNKNOWN;
|
---|
2600 | int rc2 = RTFsQueryType(utfFile.c_str(), &enmFsTypeFile);
|
---|
2601 | AssertMsgRCReturn(rc2, ("Querying the file type of '%s' failed!\n", utfFile.c_str()), rc2);
|
---|
2602 | /* Ignore the error code. On error, the file system type is still 'unknown' so
|
---|
2603 | * none of the following pathes is taken. This can happen for new VMs which
|
---|
2604 | * still don't have a snapshot folder. */
|
---|
2605 | (void)RTFsQueryType(utfSnap.c_str(), &enmFsTypeSnap);
|
---|
2606 | LogRel(("File system of '%s' is %s\n", utfFile.c_str(), RTFsTypeName(enmFsTypeFile)));
|
---|
2607 | ULONG64 u64Size;
|
---|
2608 | hrc = pMedium->COMGETTER(LogicalSize)(&u64Size); H();
|
---|
2609 | u64Size *= _1M;
|
---|
2610 | #ifdef RT_OS_WINDOWS
|
---|
2611 | if ( enmFsTypeFile == RTFSTYPE_FAT
|
---|
2612 | && u64Size >= _4G)
|
---|
2613 | {
|
---|
2614 | const char *pszUnit;
|
---|
2615 | uint64_t u64Print = formatDiskSize(u64Size, &pszUnit);
|
---|
2616 | setVMRuntimeErrorCallbackF(pVM, this, 0,
|
---|
2617 | "FatPartitionDetected",
|
---|
2618 | N_("The medium '%ls' has a logical size of %RU64%s "
|
---|
2619 | "but the file system the medium is located on seems "
|
---|
2620 | "to be FAT(32) which cannot handle files bigger than 4GB.\n"
|
---|
2621 | "We strongly recommend to put all your virtual disk images and "
|
---|
2622 | "the snapshot folder onto an NTFS partition"),
|
---|
2623 | strFile.raw(), u64Print, pszUnit);
|
---|
2624 | }
|
---|
2625 | #else /* !RT_OS_WINDOWS */
|
---|
2626 | if ( enmFsTypeFile == RTFSTYPE_FAT
|
---|
2627 | || enmFsTypeFile == RTFSTYPE_EXT
|
---|
2628 | || enmFsTypeFile == RTFSTYPE_EXT2
|
---|
2629 | || enmFsTypeFile == RTFSTYPE_EXT3
|
---|
2630 | || enmFsTypeFile == RTFSTYPE_EXT4)
|
---|
2631 | {
|
---|
2632 | RTFILE file;
|
---|
2633 | rc = RTFileOpen(&file, utfFile.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
|
---|
2634 | if (RT_SUCCESS(rc))
|
---|
2635 | {
|
---|
2636 | RTFOFF maxSize;
|
---|
2637 | /* Careful: This function will work only on selected local file systems! */
|
---|
2638 | rc = RTFileGetMaxSizeEx(file, &maxSize);
|
---|
2639 | RTFileClose(file);
|
---|
2640 | if ( RT_SUCCESS(rc)
|
---|
2641 | && maxSize > 0
|
---|
2642 | && u64Size > (ULONG64)maxSize)
|
---|
2643 | {
|
---|
2644 | const char *pszUnitSiz;
|
---|
2645 | const char *pszUnitMax;
|
---|
2646 | uint64_t u64PrintSiz = formatDiskSize(u64Size, &pszUnitSiz);
|
---|
2647 | uint64_t u64PrintMax = formatDiskSize(maxSize, &pszUnitMax);
|
---|
2648 | setVMRuntimeErrorCallbackF(pVM, this, 0,
|
---|
2649 | "FatPartitionDetected", /* <= not exact but ... */
|
---|
2650 | N_("The medium '%ls' has a logical size of %RU64%s "
|
---|
2651 | "but the file system the medium is located on can "
|
---|
2652 | "only handle files up to %RU64%s in theory.\n"
|
---|
2653 | "We strongly recommend to put all your virtual disk "
|
---|
2654 | "images and the snapshot folder onto a proper "
|
---|
2655 | "file system (e.g. ext3) with a sufficient size"),
|
---|
2656 | strFile.raw(), u64PrintSiz, pszUnitSiz, u64PrintMax, pszUnitMax);
|
---|
2657 | }
|
---|
2658 | }
|
---|
2659 | }
|
---|
2660 | #endif /* !RT_OS_WINDOWS */
|
---|
2661 |
|
---|
2662 | /*
|
---|
2663 | * Snapshot folder:
|
---|
2664 | * Here we test only for a FAT partition as we had to create a dummy file otherwise
|
---|
2665 | */
|
---|
2666 | if ( enmFsTypeSnap == RTFSTYPE_FAT
|
---|
2667 | && u64Size >= _4G
|
---|
2668 | && !mfSnapshotFolderSizeWarningShown)
|
---|
2669 | {
|
---|
2670 | const char *pszUnit;
|
---|
2671 | uint64_t u64Print = formatDiskSize(u64Size, &pszUnit);
|
---|
2672 | setVMRuntimeErrorCallbackF(pVM, this, 0,
|
---|
2673 | "FatPartitionDetected",
|
---|
2674 | #ifdef RT_OS_WINDOWS
|
---|
2675 | N_("The snapshot folder of this VM '%ls' seems to be located on "
|
---|
2676 | "a FAT(32) file system. The logical size of the medium '%ls' "
|
---|
2677 | "(%RU64%s) is bigger than the maximum file size this file "
|
---|
2678 | "system can handle (4GB).\n"
|
---|
2679 | "We strongly recommend to put all your virtual disk images and "
|
---|
2680 | "the snapshot folder onto an NTFS partition"),
|
---|
2681 | #else
|
---|
2682 | N_("The snapshot folder of this VM '%ls' seems to be located on "
|
---|
2683 | "a FAT(32) file system. The logical size of the medium '%ls' "
|
---|
2684 | "(%RU64%s) is bigger than the maximum file size this file "
|
---|
2685 | "system can handle (4GB).\n"
|
---|
2686 | "We strongly recommend to put all your virtual disk images and "
|
---|
2687 | "the snapshot folder onto a proper file system (e.g. ext3)"),
|
---|
2688 | #endif
|
---|
2689 | strSnap.raw(), strFile.raw(), u64Print, pszUnit);
|
---|
2690 | /* Show this particular warning only once */
|
---|
2691 | mfSnapshotFolderSizeWarningShown = true;
|
---|
2692 | }
|
---|
2693 |
|
---|
2694 | #ifdef RT_OS_LINUX
|
---|
2695 | /*
|
---|
2696 | * Ext4 bug: Check if the host I/O cache is disabled and the disk image is located
|
---|
2697 | * on an ext4 partition. Later we have to check the Linux kernel version!
|
---|
2698 | * This bug apparently applies to the XFS file system as well.
|
---|
2699 | */
|
---|
2700 | if ( (uCaps & MediumFormatCapabilities_Asynchronous)
|
---|
2701 | && !fUseHostIOCache
|
---|
2702 | && ( enmFsTypeFile == RTFSTYPE_EXT4
|
---|
2703 | || enmFsTypeFile == RTFSTYPE_XFS))
|
---|
2704 | {
|
---|
2705 | setVMRuntimeErrorCallbackF(pVM, this, 0,
|
---|
2706 | "Ext4PartitionDetected",
|
---|
2707 | N_("The host I/O cache for at least one controller is disabled "
|
---|
2708 | "and the medium '%ls' for this VM "
|
---|
2709 | "is located on an %s partition. There is a known Linux "
|
---|
2710 | "kernel bug which can lead to the corruption of the virtual "
|
---|
2711 | "disk image under these conditions.\n"
|
---|
2712 | "Either enable the host I/O cache permanently in the VM "
|
---|
2713 | "settings or put the disk image and the snapshot folder "
|
---|
2714 | "onto a different file system.\n"
|
---|
2715 | "The host I/O cache will now be enabled for this medium"),
|
---|
2716 | strFile.raw(), enmFsTypeFile == RTFSTYPE_EXT4 ? "ext4" : "xfs");
|
---|
2717 | fUseHostIOCache = true;
|
---|
2718 | }
|
---|
2719 | else if ( (uCaps & MediumFormatCapabilities_Asynchronous)
|
---|
2720 | && !fUseHostIOCache
|
---|
2721 | && ( enmFsTypeSnap == RTFSTYPE_EXT4
|
---|
2722 | || enmFsTypeSnap == RTFSTYPE_XFS)
|
---|
2723 | && !mfSnapshotFolderExt4WarningShown)
|
---|
2724 | {
|
---|
2725 | setVMRuntimeErrorCallbackF(pVM, this, 0,
|
---|
2726 | "Ext4PartitionDetected",
|
---|
2727 | N_("The host I/O cache for at least one controller is disabled "
|
---|
2728 | "and the snapshot folder for this VM "
|
---|
2729 | "is located on an %s partition. There is a known Linux "
|
---|
2730 | "kernel bug which can lead to the corruption of the virtual "
|
---|
2731 | "disk image under these conditions.\n"
|
---|
2732 | "Either enable the host I/O cache permanently in the VM "
|
---|
2733 | "settings or put the disk image and the snapshot folder "
|
---|
2734 | "onto a different file system.\n"
|
---|
2735 | "The host I/O cache will now be enabled for this medium"),
|
---|
2736 | enmFsTypeSnap == RTFSTYPE_EXT4 ? "ext4" : "xfs");
|
---|
2737 | fUseHostIOCache = true;
|
---|
2738 | mfSnapshotFolderExt4WarningShown = true;
|
---|
2739 | }
|
---|
2740 | #endif
|
---|
2741 | }
|
---|
2742 | }
|
---|
2743 |
|
---|
2744 | BOOL fPassthrough;
|
---|
2745 | hrc = pMediumAtt->COMGETTER(Passthrough)(&fPassthrough); H();
|
---|
2746 | rc = configMedium(pLunL0,
|
---|
2747 | !!fPassthrough,
|
---|
2748 | lType,
|
---|
2749 | fUseHostIOCache,
|
---|
2750 | fSetupMerge,
|
---|
2751 | uMergeSource,
|
---|
2752 | uMergeTarget,
|
---|
2753 | pMedium,
|
---|
2754 | aMachineState,
|
---|
2755 | phrc);
|
---|
2756 | if (RT_FAILURE(rc))
|
---|
2757 | return rc;
|
---|
2758 |
|
---|
2759 | if (fAttachDetach)
|
---|
2760 | {
|
---|
2761 | /* Attach the new driver. */
|
---|
2762 | rc = PDMR3DeviceAttach(pVM, pcszDevice, 0, uLUN,
|
---|
2763 | PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
|
---|
2764 | AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
|
---|
2765 |
|
---|
2766 | /* There is no need to handle removable medium mounting, as we
|
---|
2767 | * unconditionally replace everthing including the block driver level.
|
---|
2768 | * This means the new medium will be picked up automatically. */
|
---|
2769 | }
|
---|
2770 |
|
---|
2771 | if (paLedDevType)
|
---|
2772 | paLedDevType[uLUN] = lType;
|
---|
2773 | }
|
---|
2774 | catch (ConfigError &x)
|
---|
2775 | {
|
---|
2776 | // InsertConfig threw something:
|
---|
2777 | return x.m_vrc;
|
---|
2778 | }
|
---|
2779 |
|
---|
2780 | #undef H
|
---|
2781 |
|
---|
2782 | return VINF_SUCCESS;;
|
---|
2783 | }
|
---|
2784 |
|
---|
2785 | int Console::configMedium(PCFGMNODE pLunL0,
|
---|
2786 | bool fPassthrough,
|
---|
2787 | DeviceType_T enmType,
|
---|
2788 | bool fUseHostIOCache,
|
---|
2789 | bool fSetupMerge,
|
---|
2790 | unsigned uMergeSource,
|
---|
2791 | unsigned uMergeTarget,
|
---|
2792 | IMedium *pMedium,
|
---|
2793 | MachineState_T aMachineState,
|
---|
2794 | HRESULT *phrc)
|
---|
2795 | {
|
---|
2796 | // InsertConfig* throws
|
---|
2797 | try
|
---|
2798 | {
|
---|
2799 | int rc = VINF_SUCCESS;
|
---|
2800 | HRESULT hrc;
|
---|
2801 | Bstr bstr;
|
---|
2802 |
|
---|
2803 | #define H() AssertMsgReturnStmt(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), if (phrc) *phrc = hrc, VERR_GENERAL_FAILURE)
|
---|
2804 |
|
---|
2805 | PCFGMNODE pLunL1 = NULL;
|
---|
2806 | PCFGMNODE pCfg = NULL;
|
---|
2807 |
|
---|
2808 | BOOL fHostDrive = FALSE;
|
---|
2809 | if (pMedium)
|
---|
2810 | {
|
---|
2811 | hrc = pMedium->COMGETTER(HostDrive)(&fHostDrive); H();
|
---|
2812 | }
|
---|
2813 |
|
---|
2814 | if (fHostDrive)
|
---|
2815 | {
|
---|
2816 | Assert(pMedium);
|
---|
2817 | if (enmType == DeviceType_DVD)
|
---|
2818 | {
|
---|
2819 | InsertConfigString(pLunL0, "Driver", "HostDVD");
|
---|
2820 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2821 |
|
---|
2822 | hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
|
---|
2823 | InsertConfigString(pCfg, "Path", bstr);
|
---|
2824 |
|
---|
2825 | InsertConfigInteger(pCfg, "Passthrough", fPassthrough);
|
---|
2826 | }
|
---|
2827 | else if (enmType == DeviceType_Floppy)
|
---|
2828 | {
|
---|
2829 | InsertConfigString(pLunL0, "Driver", "HostFloppy");
|
---|
2830 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2831 |
|
---|
2832 | hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
|
---|
2833 | InsertConfigString(pCfg, "Path", bstr);
|
---|
2834 | }
|
---|
2835 | }
|
---|
2836 | else
|
---|
2837 | {
|
---|
2838 | InsertConfigString(pLunL0, "Driver", "Block");
|
---|
2839 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2840 | switch (enmType)
|
---|
2841 | {
|
---|
2842 | case DeviceType_DVD:
|
---|
2843 | InsertConfigString(pCfg, "Type", "DVD");
|
---|
2844 | InsertConfigInteger(pCfg, "Mountable", 1);
|
---|
2845 | break;
|
---|
2846 | case DeviceType_Floppy:
|
---|
2847 | InsertConfigString(pCfg, "Type", "Floppy 1.44");
|
---|
2848 | InsertConfigInteger(pCfg, "Mountable", 1);
|
---|
2849 | break;
|
---|
2850 | case DeviceType_HardDisk:
|
---|
2851 | default:
|
---|
2852 | InsertConfigString(pCfg, "Type", "HardDisk");
|
---|
2853 | InsertConfigInteger(pCfg, "Mountable", 0);
|
---|
2854 | }
|
---|
2855 |
|
---|
2856 | if ( pMedium
|
---|
2857 | && ( enmType == DeviceType_DVD
|
---|
2858 | || enmType == DeviceType_Floppy
|
---|
2859 | ))
|
---|
2860 | {
|
---|
2861 | // if this medium represents an ISO image and this image is inaccessible,
|
---|
2862 | // the ignore it instead of causing a failure; this can happen when we
|
---|
2863 | // restore a VM state and the ISO has disappeared, e.g. because the Guest
|
---|
2864 | // Additions were mounted and the user upgraded VirtualBox. Previously
|
---|
2865 | // we failed on startup, but that's not good because the only way out then
|
---|
2866 | // would be to discard the VM state...
|
---|
2867 | MediumState_T mediumState;
|
---|
2868 | rc = pMedium->RefreshState(&mediumState);
|
---|
2869 | AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
|
---|
2870 |
|
---|
2871 | if (mediumState == MediumState_Inaccessible)
|
---|
2872 | {
|
---|
2873 | Bstr loc;
|
---|
2874 | rc = pMedium->COMGETTER(Location)(loc.asOutParam());
|
---|
2875 | if (FAILED(rc)) return rc;
|
---|
2876 |
|
---|
2877 | setVMRuntimeErrorCallbackF(mpVM,
|
---|
2878 | this,
|
---|
2879 | 0,
|
---|
2880 | "DvdOrFloppyImageInaccessible",
|
---|
2881 | "The image file '%ls' is inaccessible and is being ignored. Please select a different image file for the virtual %s drive.",
|
---|
2882 | loc.raw(),
|
---|
2883 | (enmType == DeviceType_DVD) ? "DVD" : "floppy");
|
---|
2884 | pMedium = NULL;
|
---|
2885 | }
|
---|
2886 | }
|
---|
2887 |
|
---|
2888 | if (pMedium)
|
---|
2889 | {
|
---|
2890 | /* Start with length of parent chain, as the list is reversed */
|
---|
2891 | unsigned uImage = 0;
|
---|
2892 | IMedium *pTmp = pMedium;
|
---|
2893 | while (pTmp)
|
---|
2894 | {
|
---|
2895 | uImage++;
|
---|
2896 | hrc = pTmp->COMGETTER(Parent)(&pTmp); H();
|
---|
2897 | }
|
---|
2898 | /* Index of last image */
|
---|
2899 | uImage--;
|
---|
2900 |
|
---|
2901 | #if 0 /* Enable for I/O debugging */
|
---|
2902 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
2903 | InsertConfigString(pLunL0, "Driver", "DiskIntegrity");
|
---|
2904 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
2905 | InsertConfigInteger(pCfg, "CheckConsistency", 0);
|
---|
2906 | InsertConfigInteger(pCfg, "CheckDoubleCompletions", 1);
|
---|
2907 | #endif
|
---|
2908 |
|
---|
2909 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
|
---|
2910 | InsertConfigString(pLunL1, "Driver", "VD");
|
---|
2911 | InsertConfigNode(pLunL1, "Config", &pCfg);
|
---|
2912 |
|
---|
2913 | hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
|
---|
2914 | InsertConfigString(pCfg, "Path", bstr);
|
---|
2915 |
|
---|
2916 | hrc = pMedium->COMGETTER(Format)(bstr.asOutParam()); H();
|
---|
2917 | InsertConfigString(pCfg, "Format", bstr);
|
---|
2918 |
|
---|
2919 | /* DVDs are always readonly */
|
---|
2920 | if (enmType == DeviceType_DVD)
|
---|
2921 | {
|
---|
2922 | InsertConfigInteger(pCfg, "ReadOnly", 1);
|
---|
2923 | }
|
---|
2924 |
|
---|
2925 | /* Start without exclusive write access to the images. */
|
---|
2926 | /** @todo Live Migration: I don't quite like this, we risk screwing up when
|
---|
2927 | * we're resuming the VM if some 3rd dude have any of the VDIs open
|
---|
2928 | * with write sharing denied. However, if the two VMs are sharing a
|
---|
2929 | * image it really is necessary....
|
---|
2930 | *
|
---|
2931 | * So, on the "lock-media" command, the target teleporter should also
|
---|
2932 | * make DrvVD undo TempReadOnly. It gets interesting if we fail after
|
---|
2933 | * that. Grumble. */
|
---|
2934 | else if (aMachineState == MachineState_TeleportingIn)
|
---|
2935 | {
|
---|
2936 | InsertConfigInteger(pCfg, "TempReadOnly", 1);
|
---|
2937 | }
|
---|
2938 |
|
---|
2939 | if (!fUseHostIOCache)
|
---|
2940 | {
|
---|
2941 | InsertConfigInteger(pCfg, "UseNewIo", 1);
|
---|
2942 | }
|
---|
2943 |
|
---|
2944 | if (fSetupMerge)
|
---|
2945 | {
|
---|
2946 | InsertConfigInteger(pCfg, "SetupMerge", 1);
|
---|
2947 | if (uImage == uMergeSource)
|
---|
2948 | {
|
---|
2949 | InsertConfigInteger(pCfg, "MergeSource", 1);
|
---|
2950 | }
|
---|
2951 | else if (uImage == uMergeTarget)
|
---|
2952 | {
|
---|
2953 | InsertConfigInteger(pCfg, "MergeTarget", 1);
|
---|
2954 | }
|
---|
2955 | }
|
---|
2956 |
|
---|
2957 | /* Pass all custom parameters. */
|
---|
2958 | bool fHostIP = true;
|
---|
2959 | SafeArray<BSTR> names;
|
---|
2960 | SafeArray<BSTR> values;
|
---|
2961 | hrc = pMedium->GetProperties(NULL,
|
---|
2962 | ComSafeArrayAsOutParam(names),
|
---|
2963 | ComSafeArrayAsOutParam(values)); H();
|
---|
2964 |
|
---|
2965 | if (names.size() != 0)
|
---|
2966 | {
|
---|
2967 | PCFGMNODE pVDC;
|
---|
2968 | InsertConfigNode(pCfg, "VDConfig", &pVDC);
|
---|
2969 | for (size_t ii = 0; ii < names.size(); ++ii)
|
---|
2970 | {
|
---|
2971 | if (values[ii] && *values[ii])
|
---|
2972 | {
|
---|
2973 | Utf8Str name = names[ii];
|
---|
2974 | Utf8Str value = values[ii];
|
---|
2975 | InsertConfigString(pVDC, name.c_str(), value);
|
---|
2976 | if ( name.compare("HostIPStack") == 0
|
---|
2977 | && value.compare("0") == 0)
|
---|
2978 | fHostIP = false;
|
---|
2979 | }
|
---|
2980 | }
|
---|
2981 | }
|
---|
2982 |
|
---|
2983 | /* Create an inversed list of parents. */
|
---|
2984 | uImage--;
|
---|
2985 | IMedium *pParentMedium = pMedium;
|
---|
2986 | for (PCFGMNODE pParent = pCfg;; uImage--)
|
---|
2987 | {
|
---|
2988 | hrc = pParentMedium->COMGETTER(Parent)(&pMedium); H();
|
---|
2989 | if (!pMedium)
|
---|
2990 | break;
|
---|
2991 |
|
---|
2992 | PCFGMNODE pCur;
|
---|
2993 | InsertConfigNode(pParent, "Parent", &pCur);
|
---|
2994 | hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
|
---|
2995 | InsertConfigString(pCur, "Path", bstr);
|
---|
2996 |
|
---|
2997 | hrc = pMedium->COMGETTER(Format)(bstr.asOutParam()); H();
|
---|
2998 | InsertConfigString(pCur, "Format", bstr);
|
---|
2999 |
|
---|
3000 | if (fSetupMerge)
|
---|
3001 | {
|
---|
3002 | if (uImage == uMergeSource)
|
---|
3003 | {
|
---|
3004 | InsertConfigInteger(pCur, "MergeSource", 1);
|
---|
3005 | }
|
---|
3006 | else if (uImage == uMergeTarget)
|
---|
3007 | {
|
---|
3008 | InsertConfigInteger(pCur, "MergeTarget", 1);
|
---|
3009 | }
|
---|
3010 | }
|
---|
3011 |
|
---|
3012 | /* Pass all custom parameters. */
|
---|
3013 | SafeArray<BSTR> aNames;
|
---|
3014 | SafeArray<BSTR> aValues;
|
---|
3015 | hrc = pMedium->GetProperties(NULL,
|
---|
3016 | ComSafeArrayAsOutParam(aNames),
|
---|
3017 | ComSafeArrayAsOutParam(aValues)); H();
|
---|
3018 |
|
---|
3019 | if (aNames.size() != 0)
|
---|
3020 | {
|
---|
3021 | PCFGMNODE pVDC;
|
---|
3022 | InsertConfigNode(pCur, "VDConfig", &pVDC);
|
---|
3023 | for (size_t ii = 0; ii < aNames.size(); ++ii)
|
---|
3024 | {
|
---|
3025 | if (aValues[ii] && *aValues[ii])
|
---|
3026 | {
|
---|
3027 | Utf8Str name = aNames[ii];
|
---|
3028 | Utf8Str value = aValues[ii];
|
---|
3029 | InsertConfigString(pVDC, name.c_str(), value);
|
---|
3030 | if ( name.compare("HostIPStack") == 0
|
---|
3031 | && value.compare("0") == 0)
|
---|
3032 | fHostIP = false;
|
---|
3033 | }
|
---|
3034 | }
|
---|
3035 | }
|
---|
3036 |
|
---|
3037 | /* Custom code: put marker to not use host IP stack to driver
|
---|
3038 | * configuration node. Simplifies life of DrvVD a bit. */
|
---|
3039 | if (!fHostIP)
|
---|
3040 | {
|
---|
3041 | InsertConfigInteger(pCfg, "HostIPStack", 0);
|
---|
3042 | }
|
---|
3043 |
|
---|
3044 | /* next */
|
---|
3045 | pParent = pCur;
|
---|
3046 | pParentMedium = pMedium;
|
---|
3047 | }
|
---|
3048 | }
|
---|
3049 | }
|
---|
3050 | }
|
---|
3051 | catch (ConfigError &x)
|
---|
3052 | {
|
---|
3053 | // InsertConfig threw something:
|
---|
3054 | return x.m_vrc;
|
---|
3055 | }
|
---|
3056 |
|
---|
3057 | #undef H
|
---|
3058 |
|
---|
3059 | return VINF_SUCCESS;
|
---|
3060 | }
|
---|
3061 |
|
---|
3062 | /**
|
---|
3063 | * Construct the Network configuration tree
|
---|
3064 | *
|
---|
3065 | * @returns VBox status code.
|
---|
3066 | *
|
---|
3067 | * @param pszDevice The PDM device name.
|
---|
3068 | * @param uInstance The PDM device instance.
|
---|
3069 | * @param uLun The PDM LUN number of the drive.
|
---|
3070 | * @param aNetworkAdapter The network adapter whose attachment needs to be changed
|
---|
3071 | * @param pCfg Configuration node for the device
|
---|
3072 | * @param pLunL0 To store the pointer to the LUN#0.
|
---|
3073 | * @param pInst The instance CFGM node
|
---|
3074 | * @param fAttachDetach To determine if the network attachment should
|
---|
3075 | * be attached/detached after/before
|
---|
3076 | * configuration.
|
---|
3077 | *
|
---|
3078 | * @note Locks this object for writing.
|
---|
3079 | */
|
---|
3080 | int Console::configNetwork(const char *pszDevice,
|
---|
3081 | unsigned uInstance,
|
---|
3082 | unsigned uLun,
|
---|
3083 | INetworkAdapter *aNetworkAdapter,
|
---|
3084 | PCFGMNODE pCfg,
|
---|
3085 | PCFGMNODE pLunL0,
|
---|
3086 | PCFGMNODE pInst,
|
---|
3087 | bool fAttachDetach)
|
---|
3088 | {
|
---|
3089 | AutoCaller autoCaller(this);
|
---|
3090 | AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
|
---|
3091 |
|
---|
3092 | // InsertConfig* throws
|
---|
3093 | try
|
---|
3094 | {
|
---|
3095 | int rc = VINF_SUCCESS;
|
---|
3096 | HRESULT hrc;
|
---|
3097 | Bstr bstr;
|
---|
3098 |
|
---|
3099 | #define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
|
---|
3100 |
|
---|
3101 | /*
|
---|
3102 | * Locking the object before doing VMR3* calls is quite safe here, since
|
---|
3103 | * we're on EMT. Write lock is necessary because we indirectly modify the
|
---|
3104 | * meAttachmentType member.
|
---|
3105 | */
|
---|
3106 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3107 |
|
---|
3108 | PVM pVM = mpVM;
|
---|
3109 |
|
---|
3110 | ComPtr<IMachine> pMachine = machine();
|
---|
3111 |
|
---|
3112 | ComPtr<IVirtualBox> virtualBox;
|
---|
3113 | hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam());
|
---|
3114 | H();
|
---|
3115 |
|
---|
3116 | ComPtr<IHost> host;
|
---|
3117 | hrc = virtualBox->COMGETTER(Host)(host.asOutParam());
|
---|
3118 | H();
|
---|
3119 |
|
---|
3120 | BOOL fSniffer;
|
---|
3121 | hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
|
---|
3122 | H();
|
---|
3123 |
|
---|
3124 | if (fAttachDetach && fSniffer)
|
---|
3125 | {
|
---|
3126 | const char *pszNetDriver = "IntNet";
|
---|
3127 | if (meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
|
---|
3128 | pszNetDriver = "NAT";
|
---|
3129 | #if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
|
---|
3130 | if (meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
|
---|
3131 | pszNetDriver = "HostInterface";
|
---|
3132 | #endif
|
---|
3133 |
|
---|
3134 | rc = PDMR3DriverDetach(pVM, pszDevice, uInstance, uLun, pszNetDriver, 0, 0 /*fFlags*/);
|
---|
3135 | if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
|
---|
3136 | rc = VINF_SUCCESS;
|
---|
3137 | AssertLogRelRCReturn(rc, rc);
|
---|
3138 |
|
---|
3139 | pLunL0 = CFGMR3GetChildF(pInst, "LUN#%u", uLun);
|
---|
3140 | PCFGMNODE pLunAD = CFGMR3GetChildF(pLunL0, "AttachedDriver");
|
---|
3141 | if (pLunAD)
|
---|
3142 | {
|
---|
3143 | CFGMR3RemoveNode(pLunAD);
|
---|
3144 | }
|
---|
3145 | else
|
---|
3146 | {
|
---|
3147 | CFGMR3RemoveNode(pLunL0);
|
---|
3148 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
3149 | InsertConfigString(pLunL0, "Driver", "NetSniffer");
|
---|
3150 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3151 | hrc = aNetworkAdapter->COMGETTER(TraceFile)(bstr.asOutParam()); H();
|
---|
3152 | if (!bstr.isEmpty()) /* check convention for indicating default file. */
|
---|
3153 | InsertConfigString(pCfg, "File", bstr);
|
---|
3154 | }
|
---|
3155 | }
|
---|
3156 | else if (fAttachDetach && !fSniffer)
|
---|
3157 | {
|
---|
3158 | rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
|
---|
3159 | if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
|
---|
3160 | rc = VINF_SUCCESS;
|
---|
3161 | AssertLogRelRCReturn(rc, rc);
|
---|
3162 |
|
---|
3163 | /* nuke anything which might have been left behind. */
|
---|
3164 | CFGMR3RemoveNode(CFGMR3GetChildF(pInst, "LUN#%u", uLun));
|
---|
3165 | }
|
---|
3166 | else if (!fAttachDetach && fSniffer)
|
---|
3167 | {
|
---|
3168 | /* insert the sniffer filter driver. */
|
---|
3169 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
3170 | InsertConfigString(pLunL0, "Driver", "NetSniffer");
|
---|
3171 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3172 | hrc = aNetworkAdapter->COMGETTER(TraceFile)(bstr.asOutParam()); H();
|
---|
3173 | if (!bstr.isEmpty()) /* check convention for indicating default file. */
|
---|
3174 | InsertConfigString(pCfg, "File", bstr);
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 | Bstr networkName, trunkName, trunkType;
|
---|
3178 | NetworkAttachmentType_T eAttachmentType;
|
---|
3179 | hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType); H();
|
---|
3180 | switch (eAttachmentType)
|
---|
3181 | {
|
---|
3182 | case NetworkAttachmentType_Null:
|
---|
3183 | break;
|
---|
3184 |
|
---|
3185 | case NetworkAttachmentType_NAT:
|
---|
3186 | {
|
---|
3187 | ComPtr<INATEngine> natDriver;
|
---|
3188 | hrc = aNetworkAdapter->COMGETTER(NatDriver)(natDriver.asOutParam()); H();
|
---|
3189 | if (fSniffer)
|
---|
3190 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
3191 | else
|
---|
3192 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
3193 | InsertConfigString(pLunL0, "Driver", "NAT");
|
---|
3194 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3195 |
|
---|
3196 | /* Configure TFTP prefix and boot filename. */
|
---|
3197 | hrc = virtualBox->COMGETTER(HomeFolder)(bstr.asOutParam()); H();
|
---|
3198 | if (!bstr.isEmpty())
|
---|
3199 | InsertConfigString(pCfg, "TFTPPrefix", Utf8StrFmt("%ls%c%s", bstr.raw(), RTPATH_DELIMITER, "TFTP"));
|
---|
3200 | hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
|
---|
3201 | InsertConfigString(pCfg, "BootFile", Utf8StrFmt("%ls.pxe", bstr.raw()));
|
---|
3202 |
|
---|
3203 | hrc = natDriver->COMGETTER(Network)(bstr.asOutParam()); H();
|
---|
3204 | if (!bstr.isEmpty())
|
---|
3205 | InsertConfigString(pCfg, "Network", bstr);
|
---|
3206 | else
|
---|
3207 | {
|
---|
3208 | ULONG uSlot;
|
---|
3209 | hrc = aNetworkAdapter->COMGETTER(Slot)(&uSlot); H();
|
---|
3210 | InsertConfigString(pCfg, "Network", Utf8StrFmt("10.0.%d.0/24", uSlot+2));
|
---|
3211 | }
|
---|
3212 | hrc = natDriver->COMGETTER(HostIP)(bstr.asOutParam()); H();
|
---|
3213 | if (!bstr.isEmpty())
|
---|
3214 | InsertConfigString(pCfg, "BindIP", bstr);
|
---|
3215 | ULONG mtu = 0;
|
---|
3216 | ULONG sockSnd = 0;
|
---|
3217 | ULONG sockRcv = 0;
|
---|
3218 | ULONG tcpSnd = 0;
|
---|
3219 | ULONG tcpRcv = 0;
|
---|
3220 | hrc = natDriver->GetNetworkSettings(&mtu, &sockSnd, &sockRcv, &tcpSnd, &tcpRcv); H();
|
---|
3221 | if (mtu)
|
---|
3222 | InsertConfigInteger(pCfg, "SlirpMTU", mtu);
|
---|
3223 | if (sockRcv)
|
---|
3224 | InsertConfigInteger(pCfg, "SockRcv", sockRcv);
|
---|
3225 | if (sockSnd)
|
---|
3226 | InsertConfigInteger(pCfg, "SockSnd", sockSnd);
|
---|
3227 | if (tcpRcv)
|
---|
3228 | InsertConfigInteger(pCfg, "TcpRcv", tcpRcv);
|
---|
3229 | if (tcpSnd)
|
---|
3230 | InsertConfigInteger(pCfg, "TcpSnd", tcpSnd);
|
---|
3231 | hrc = natDriver->COMGETTER(TftpPrefix)(bstr.asOutParam()); H();
|
---|
3232 | if (!bstr.isEmpty())
|
---|
3233 | {
|
---|
3234 | RemoveConfigValue(pCfg, "TFTPPrefix");
|
---|
3235 | InsertConfigString(pCfg, "TFTPPrefix", bstr);
|
---|
3236 | }
|
---|
3237 | hrc = natDriver->COMGETTER(TftpBootFile)(bstr.asOutParam()); H();
|
---|
3238 | if (!bstr.isEmpty())
|
---|
3239 | {
|
---|
3240 | RemoveConfigValue(pCfg, "BootFile");
|
---|
3241 | InsertConfigString(pCfg, "BootFile", bstr);
|
---|
3242 | }
|
---|
3243 | hrc = natDriver->COMGETTER(TftpNextServer)(bstr.asOutParam()); H();
|
---|
3244 | if (!bstr.isEmpty())
|
---|
3245 | InsertConfigString(pCfg, "NextServer", bstr);
|
---|
3246 | BOOL fDnsFlag;
|
---|
3247 | hrc = natDriver->COMGETTER(DnsPassDomain)(&fDnsFlag); H();
|
---|
3248 | InsertConfigInteger(pCfg, "PassDomain", fDnsFlag);
|
---|
3249 | hrc = natDriver->COMGETTER(DnsProxy)(&fDnsFlag); H();
|
---|
3250 | InsertConfigInteger(pCfg, "DNSProxy", fDnsFlag);
|
---|
3251 | hrc = natDriver->COMGETTER(DnsUseHostResolver)(&fDnsFlag); H();
|
---|
3252 | InsertConfigInteger(pCfg, "UseHostResolver", fDnsFlag);
|
---|
3253 |
|
---|
3254 | ULONG aliasMode;
|
---|
3255 | hrc = natDriver->COMGETTER(AliasMode)(&aliasMode); H();
|
---|
3256 | InsertConfigInteger(pCfg, "AliasMode", aliasMode);
|
---|
3257 |
|
---|
3258 | /* port-forwarding */
|
---|
3259 | SafeArray<BSTR> pfs;
|
---|
3260 | hrc = natDriver->COMGETTER(Redirects)(ComSafeArrayAsOutParam(pfs)); H();
|
---|
3261 | PCFGMNODE pPF = NULL; /* /Devices/Dev/.../Config/PF#0/ */
|
---|
3262 | for (unsigned int i = 0; i < pfs.size(); ++i)
|
---|
3263 | {
|
---|
3264 | uint16_t port = 0;
|
---|
3265 | BSTR r = pfs[i];
|
---|
3266 | Utf8Str utf = Utf8Str(r);
|
---|
3267 | Utf8Str strName;
|
---|
3268 | Utf8Str strProto;
|
---|
3269 | Utf8Str strHostPort;
|
---|
3270 | Utf8Str strHostIP;
|
---|
3271 | Utf8Str strGuestPort;
|
---|
3272 | Utf8Str strGuestIP;
|
---|
3273 | size_t pos, ppos;
|
---|
3274 | pos = ppos = 0;
|
---|
3275 | #define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \
|
---|
3276 | do { \
|
---|
3277 | pos = str.find(",", ppos); \
|
---|
3278 | if (pos == Utf8Str::npos) \
|
---|
3279 | { \
|
---|
3280 | Log(( #res " extracting from %s is failed\n", str.raw())); \
|
---|
3281 | continue; \
|
---|
3282 | } \
|
---|
3283 | res = str.substr(ppos, pos - ppos); \
|
---|
3284 | Log2((#res " %s pos:%d, ppos:%d\n", res.raw(), pos, ppos)); \
|
---|
3285 | ppos = pos + 1; \
|
---|
3286 | } while (0)
|
---|
3287 | ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos);
|
---|
3288 | ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos);
|
---|
3289 | ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos);
|
---|
3290 | ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos);
|
---|
3291 | ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos);
|
---|
3292 | strGuestPort = utf.substr(ppos, utf.length() - ppos);
|
---|
3293 | #undef ITERATE_TO_NEXT_TERM
|
---|
3294 |
|
---|
3295 | uint32_t proto = strProto.toUInt32();
|
---|
3296 | bool fValid = true;
|
---|
3297 | switch (proto)
|
---|
3298 | {
|
---|
3299 | case NATProtocol_UDP:
|
---|
3300 | strProto = "UDP";
|
---|
3301 | break;
|
---|
3302 | case NATProtocol_TCP:
|
---|
3303 | strProto = "TCP";
|
---|
3304 | break;
|
---|
3305 | default:
|
---|
3306 | fValid = false;
|
---|
3307 | }
|
---|
3308 | /* continue with next rule if no valid proto was passed */
|
---|
3309 | if (!fValid)
|
---|
3310 | continue;
|
---|
3311 |
|
---|
3312 | InsertConfigNode(pCfg, strName.raw(), &pPF);
|
---|
3313 | InsertConfigString(pPF, "Protocol", strProto);
|
---|
3314 |
|
---|
3315 | if (!strHostIP.isEmpty())
|
---|
3316 | InsertConfigString(pPF, "BindIP", strHostIP);
|
---|
3317 |
|
---|
3318 | if (!strGuestIP.isEmpty())
|
---|
3319 | InsertConfigString(pPF, "GuestIP", strGuestIP);
|
---|
3320 |
|
---|
3321 | port = RTStrToUInt16(strHostPort.raw());
|
---|
3322 | if (port)
|
---|
3323 | InsertConfigInteger(pPF, "HostPort", port);
|
---|
3324 |
|
---|
3325 | port = RTStrToUInt16(strGuestPort.raw());
|
---|
3326 | if (port)
|
---|
3327 | InsertConfigInteger(pPF, "GuestPort", port);
|
---|
3328 | }
|
---|
3329 | break;
|
---|
3330 | }
|
---|
3331 |
|
---|
3332 | case NetworkAttachmentType_Bridged:
|
---|
3333 | {
|
---|
3334 | #if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
|
---|
3335 | hrc = attachToTapInterface(aNetworkAdapter);
|
---|
3336 | if (FAILED(hrc))
|
---|
3337 | {
|
---|
3338 | switch (hrc)
|
---|
3339 | {
|
---|
3340 | case VERR_ACCESS_DENIED:
|
---|
3341 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
3342 | "Failed to open '/dev/net/tun' for read/write access. Please check the "
|
---|
3343 | "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
|
---|
3344 | "change the group of that node and make yourself a member of that group. Make "
|
---|
3345 | "sure that these changes are permanent, especially if you are "
|
---|
3346 | "using udev"));
|
---|
3347 | default:
|
---|
3348 | AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
|
---|
3349 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
3350 | "Failed to initialize Host Interface Networking"));
|
---|
3351 | }
|
---|
3352 | }
|
---|
3353 |
|
---|
3354 | Assert((int)maTapFD[uInstance] >= 0);
|
---|
3355 | if ((int)maTapFD[uInstance] >= 0)
|
---|
3356 | {
|
---|
3357 | if (fSniffer)
|
---|
3358 | {
|
---|
3359 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
3360 | }
|
---|
3361 | else
|
---|
3362 | {
|
---|
3363 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
3364 | }
|
---|
3365 | InsertConfigString(pLunL0, "Driver", "HostInterface");
|
---|
3366 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3367 | InsertConfigInteger(pCfg, "FileHandle", maTapFD[uInstance]);
|
---|
3368 | }
|
---|
3369 |
|
---|
3370 | #elif defined(VBOX_WITH_NETFLT)
|
---|
3371 | /*
|
---|
3372 | * This is the new VBoxNetFlt+IntNet stuff.
|
---|
3373 | */
|
---|
3374 | if (fSniffer)
|
---|
3375 | {
|
---|
3376 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
3377 | }
|
---|
3378 | else
|
---|
3379 | {
|
---|
3380 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
3381 | }
|
---|
3382 |
|
---|
3383 | Bstr HifName;
|
---|
3384 | hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
|
---|
3385 | if (FAILED(hrc))
|
---|
3386 | {
|
---|
3387 | LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
|
---|
3388 | H();
|
---|
3389 | }
|
---|
3390 |
|
---|
3391 | Utf8Str HifNameUtf8(HifName);
|
---|
3392 | const char *pszHifName = HifNameUtf8.raw();
|
---|
3393 |
|
---|
3394 | # if defined(RT_OS_DARWIN)
|
---|
3395 | /* The name is on the form 'ifX: long name', chop it off at the colon. */
|
---|
3396 | char szTrunk[8];
|
---|
3397 | strncpy(szTrunk, pszHifName, sizeof(szTrunk));
|
---|
3398 | char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
|
---|
3399 | if (!pszColon)
|
---|
3400 | {
|
---|
3401 | /*
|
---|
3402 | * Dynamic changing of attachment causes an attempt to configure
|
---|
3403 | * network with invalid host adapter (as it is must be changed before
|
---|
3404 | * the attachment), calling Detach here will cause a deadlock.
|
---|
3405 | * See #4750.
|
---|
3406 | * hrc = aNetworkAdapter->Detach(); H();
|
---|
3407 | */
|
---|
3408 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3409 | N_("Malformed host interface networking name '%ls'"),
|
---|
3410 | HifName.raw());
|
---|
3411 | }
|
---|
3412 | *pszColon = '\0';
|
---|
3413 | const char *pszTrunk = szTrunk;
|
---|
3414 |
|
---|
3415 | # elif defined(RT_OS_SOLARIS)
|
---|
3416 | /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
|
---|
3417 | char szTrunk[256];
|
---|
3418 | strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
|
---|
3419 | char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
|
---|
3420 |
|
---|
3421 | /*
|
---|
3422 | * Currently don't bother about malformed names here for the sake of people using
|
---|
3423 | * VBoxManage and setting only the NIC name from there. If there is a space we
|
---|
3424 | * chop it off and proceed, otherwise just use whatever we've got.
|
---|
3425 | */
|
---|
3426 | if (pszSpace)
|
---|
3427 | *pszSpace = '\0';
|
---|
3428 |
|
---|
3429 | /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
|
---|
3430 | char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
|
---|
3431 | if (pszColon)
|
---|
3432 | *pszColon = '\0';
|
---|
3433 |
|
---|
3434 | const char *pszTrunk = szTrunk;
|
---|
3435 |
|
---|
3436 | # elif defined(RT_OS_WINDOWS)
|
---|
3437 | ComPtr<IHostNetworkInterface> hostInterface;
|
---|
3438 | hrc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
|
---|
3439 | if (!SUCCEEDED(hrc))
|
---|
3440 | {
|
---|
3441 | AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
|
---|
3442 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3443 | N_("Inexistent host networking interface, name '%ls'"),
|
---|
3444 | HifName.raw());
|
---|
3445 | }
|
---|
3446 |
|
---|
3447 | HostNetworkInterfaceType_T eIfType;
|
---|
3448 | hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
|
---|
3449 | if (FAILED(hrc))
|
---|
3450 | {
|
---|
3451 | LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
|
---|
3452 | H();
|
---|
3453 | }
|
---|
3454 |
|
---|
3455 | if (eIfType != HostNetworkInterfaceType_Bridged)
|
---|
3456 | {
|
---|
3457 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3458 | N_("Interface ('%ls') is not a Bridged Adapter interface"),
|
---|
3459 | HifName.raw());
|
---|
3460 | }
|
---|
3461 |
|
---|
3462 | hrc = hostInterface->COMGETTER(Id)(bstr.asOutParam());
|
---|
3463 | if (FAILED(hrc))
|
---|
3464 | {
|
---|
3465 | LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
|
---|
3466 | H();
|
---|
3467 | }
|
---|
3468 | Guid hostIFGuid(bstr);
|
---|
3469 |
|
---|
3470 | INetCfg *pNc;
|
---|
3471 | ComPtr<INetCfgComponent> pAdaptorComponent;
|
---|
3472 | LPWSTR pszApp;
|
---|
3473 | int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
|
---|
3474 |
|
---|
3475 | hrc = VBoxNetCfgWinQueryINetCfg(FALSE /*fGetWriteLock*/,
|
---|
3476 | L"VirtualBox",
|
---|
3477 | &pNc,
|
---|
3478 | &pszApp);
|
---|
3479 | Assert(hrc == S_OK);
|
---|
3480 | if (hrc == S_OK)
|
---|
3481 | {
|
---|
3482 | /* get the adapter's INetCfgComponent*/
|
---|
3483 | hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
|
---|
3484 | if (hrc != S_OK)
|
---|
3485 | {
|
---|
3486 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3487 | LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
|
---|
3488 | H();
|
---|
3489 | }
|
---|
3490 | }
|
---|
3491 | #define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
|
---|
3492 | char szTrunkName[INTNET_MAX_TRUNK_NAME];
|
---|
3493 | char *pszTrunkName = szTrunkName;
|
---|
3494 | wchar_t * pswzBindName;
|
---|
3495 | hrc = pAdaptorComponent->GetBindName(&pswzBindName);
|
---|
3496 | Assert(hrc == S_OK);
|
---|
3497 | if (hrc == S_OK)
|
---|
3498 | {
|
---|
3499 | int cwBindName = (int)wcslen(pswzBindName) + 1;
|
---|
3500 | int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
|
---|
3501 | if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
|
---|
3502 | {
|
---|
3503 | strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
|
---|
3504 | pszTrunkName += cbFullBindNamePrefix-1;
|
---|
3505 | if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
|
---|
3506 | sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
|
---|
3507 | {
|
---|
3508 | DWORD err = GetLastError();
|
---|
3509 | hrc = HRESULT_FROM_WIN32(err);
|
---|
3510 | AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
|
---|
3511 | AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
|
---|
3512 | }
|
---|
3513 | }
|
---|
3514 | else
|
---|
3515 | {
|
---|
3516 | AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
|
---|
3517 | /** @todo set appropriate error code */
|
---|
3518 | hrc = E_FAIL;
|
---|
3519 | }
|
---|
3520 |
|
---|
3521 | if (hrc != S_OK)
|
---|
3522 | {
|
---|
3523 | AssertFailed();
|
---|
3524 | CoTaskMemFree(pswzBindName);
|
---|
3525 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3526 | H();
|
---|
3527 | }
|
---|
3528 |
|
---|
3529 | /* we're not freeing the bind name since we'll use it later for detecting wireless*/
|
---|
3530 | }
|
---|
3531 | else
|
---|
3532 | {
|
---|
3533 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3534 | AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
|
---|
3535 | H();
|
---|
3536 | }
|
---|
3537 | const char *pszTrunk = szTrunkName;
|
---|
3538 | /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
|
---|
3539 |
|
---|
3540 | # elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
|
---|
3541 | # if defined(RT_OS_FREEBSD)
|
---|
3542 | /*
|
---|
3543 | * If we bridge to a tap interface open it the `old' direct way.
|
---|
3544 | * This works and performs better than bridging a physical
|
---|
3545 | * interface via the current FreeBSD vboxnetflt implementation.
|
---|
3546 | */
|
---|
3547 | if (!strncmp(pszHifName, "tap", sizeof "tap" - 1)) {
|
---|
3548 | hrc = attachToTapInterface(aNetworkAdapter);
|
---|
3549 | if (FAILED(hrc))
|
---|
3550 | {
|
---|
3551 | switch (hrc)
|
---|
3552 | {
|
---|
3553 | case VERR_ACCESS_DENIED:
|
---|
3554 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
3555 | "Failed to open '/dev/%s' for read/write access. Please check the "
|
---|
3556 | "permissions of that node, and that the net.link.tap.user_open "
|
---|
3557 | "sysctl is set. Either run 'chmod 0666 /dev/%s' or "
|
---|
3558 | "change the group of that node to vboxusers and make yourself "
|
---|
3559 | "a member of that group. Make sure that these changes are permanent."), pszHifName, pszHifName);
|
---|
3560 | default:
|
---|
3561 | AssertMsgFailed(("Could not attach to tap interface! Bad!\n"));
|
---|
3562 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
3563 | "Failed to initialize Host Interface Networking"));
|
---|
3564 | }
|
---|
3565 | }
|
---|
3566 |
|
---|
3567 | Assert((int)maTapFD[uInstance] >= 0);
|
---|
3568 | if ((int)maTapFD[uInstance] >= 0)
|
---|
3569 | {
|
---|
3570 | InsertConfigString(pLunL0, "Driver", "HostInterface");
|
---|
3571 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3572 | InsertConfigInteger(pCfg, "FileHandle", maTapFD[uInstance]);
|
---|
3573 | }
|
---|
3574 | break;
|
---|
3575 | }
|
---|
3576 | # endif
|
---|
3577 | /** @todo Check for malformed names. */
|
---|
3578 | const char *pszTrunk = pszHifName;
|
---|
3579 |
|
---|
3580 | /* Issue a warning if the interface is down */
|
---|
3581 | {
|
---|
3582 | int iSock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
3583 | if (iSock >= 0)
|
---|
3584 | {
|
---|
3585 | struct ifreq Req;
|
---|
3586 |
|
---|
3587 | memset(&Req, 0, sizeof(Req));
|
---|
3588 | strncpy(Req.ifr_name, pszHifName, sizeof(Req.ifr_name) - 1);
|
---|
3589 | if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0)
|
---|
3590 | if ((Req.ifr_flags & IFF_UP) == 0)
|
---|
3591 | {
|
---|
3592 | setVMRuntimeErrorCallbackF(pVM, this, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);
|
---|
3593 | }
|
---|
3594 |
|
---|
3595 | close(iSock);
|
---|
3596 | }
|
---|
3597 | }
|
---|
3598 |
|
---|
3599 | # else
|
---|
3600 | # error "PORTME (VBOX_WITH_NETFLT)"
|
---|
3601 | # endif
|
---|
3602 |
|
---|
3603 | InsertConfigString(pLunL0, "Driver", "IntNet");
|
---|
3604 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3605 | InsertConfigString(pCfg, "Trunk", pszTrunk);
|
---|
3606 | InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
|
---|
3607 | char szNetwork[INTNET_MAX_NETWORK_NAME];
|
---|
3608 | RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
|
---|
3609 | InsertConfigString(pCfg, "Network", szNetwork);
|
---|
3610 | networkName = Bstr(szNetwork);
|
---|
3611 | trunkName = Bstr(pszTrunk);
|
---|
3612 | trunkType = Bstr(TRUNKTYPE_NETFLT);
|
---|
3613 |
|
---|
3614 | # if defined(RT_OS_DARWIN)
|
---|
3615 | /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
|
---|
3616 | if ( strstr(pszHifName, "Wireless")
|
---|
3617 | || strstr(pszHifName, "AirPort" ))
|
---|
3618 | InsertConfigInteger(pCfg, "SharedMacOnWire", true);
|
---|
3619 | # elif defined(RT_OS_LINUX)
|
---|
3620 | int iSock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
3621 | if (iSock >= 0)
|
---|
3622 | {
|
---|
3623 | struct iwreq WRq;
|
---|
3624 |
|
---|
3625 | memset(&WRq, 0, sizeof(WRq));
|
---|
3626 | strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
|
---|
3627 | bool fSharedMacOnWire = ioctl(iSock, SIOCGIWNAME, &WRq) >= 0;
|
---|
3628 | close(iSock);
|
---|
3629 | if (fSharedMacOnWire)
|
---|
3630 | {
|
---|
3631 | InsertConfigInteger(pCfg, "SharedMacOnWire", true);
|
---|
3632 | Log(("Set SharedMacOnWire\n"));
|
---|
3633 | }
|
---|
3634 | else
|
---|
3635 | Log(("Failed to get wireless name\n"));
|
---|
3636 | }
|
---|
3637 | else
|
---|
3638 | Log(("Failed to open wireless socket\n"));
|
---|
3639 | # elif defined(RT_OS_FREEBSD)
|
---|
3640 | int iSock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
3641 | if (iSock >= 0)
|
---|
3642 | {
|
---|
3643 | struct ieee80211req WReq;
|
---|
3644 | uint8_t abData[32];
|
---|
3645 |
|
---|
3646 | memset(&WReq, 0, sizeof(WReq));
|
---|
3647 | strncpy(WReq.i_name, pszHifName, sizeof(WReq.i_name));
|
---|
3648 | WReq.i_type = IEEE80211_IOC_SSID;
|
---|
3649 | WReq.i_val = -1;
|
---|
3650 | WReq.i_data = abData;
|
---|
3651 | WReq.i_len = sizeof(abData);
|
---|
3652 |
|
---|
3653 | bool fSharedMacOnWire = ioctl(iSock, SIOCG80211, &WReq) >= 0;
|
---|
3654 | close(iSock);
|
---|
3655 | if (fSharedMacOnWire)
|
---|
3656 | {
|
---|
3657 | InsertConfigInteger(pCfg, "SharedMacOnWire", true);
|
---|
3658 | Log(("Set SharedMacOnWire\n"));
|
---|
3659 | }
|
---|
3660 | else
|
---|
3661 | Log(("Failed to get wireless name\n"));
|
---|
3662 | }
|
---|
3663 | else
|
---|
3664 | Log(("Failed to open wireless socket\n"));
|
---|
3665 | # elif defined(RT_OS_WINDOWS)
|
---|
3666 | # define DEVNAME_PREFIX L"\\\\.\\"
|
---|
3667 | /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
|
---|
3668 | * there is a pretty long way till there though since we need to obtain the symbolic link name
|
---|
3669 | * for the adapter device we are going to query given the device Guid */
|
---|
3670 |
|
---|
3671 |
|
---|
3672 | /* prepend the "\\\\.\\" to the bind name to obtain the link name */
|
---|
3673 |
|
---|
3674 | wchar_t FileName[MAX_PATH];
|
---|
3675 | wcscpy(FileName, DEVNAME_PREFIX);
|
---|
3676 | wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
|
---|
3677 |
|
---|
3678 | /* open the device */
|
---|
3679 | HANDLE hDevice = CreateFile(FileName,
|
---|
3680 | GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
---|
3681 | NULL,
|
---|
3682 | OPEN_EXISTING,
|
---|
3683 | FILE_ATTRIBUTE_NORMAL,
|
---|
3684 | NULL);
|
---|
3685 |
|
---|
3686 | if (hDevice != INVALID_HANDLE_VALUE)
|
---|
3687 | {
|
---|
3688 | bool fSharedMacOnWire = false;
|
---|
3689 |
|
---|
3690 | /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
|
---|
3691 | DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
|
---|
3692 | NDIS_PHYSICAL_MEDIUM PhMedium;
|
---|
3693 | DWORD cbResult;
|
---|
3694 | if (DeviceIoControl(hDevice,
|
---|
3695 | IOCTL_NDIS_QUERY_GLOBAL_STATS,
|
---|
3696 | &Oid,
|
---|
3697 | sizeof(Oid),
|
---|
3698 | &PhMedium,
|
---|
3699 | sizeof(PhMedium),
|
---|
3700 | &cbResult,
|
---|
3701 | NULL))
|
---|
3702 | {
|
---|
3703 | /* that was simple, now examine PhMedium */
|
---|
3704 | if ( PhMedium == NdisPhysicalMediumWirelessWan
|
---|
3705 | || PhMedium == NdisPhysicalMediumWirelessLan
|
---|
3706 | || PhMedium == NdisPhysicalMediumNative802_11
|
---|
3707 | || PhMedium == NdisPhysicalMediumBluetooth)
|
---|
3708 | fSharedMacOnWire = true;
|
---|
3709 | }
|
---|
3710 | else
|
---|
3711 | {
|
---|
3712 | int winEr = GetLastError();
|
---|
3713 | LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
|
---|
3714 | Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
|
---|
3715 | }
|
---|
3716 | CloseHandle(hDevice);
|
---|
3717 |
|
---|
3718 | if (fSharedMacOnWire)
|
---|
3719 | {
|
---|
3720 | Log(("this is a wireless adapter"));
|
---|
3721 | InsertConfigInteger(pCfg, "SharedMacOnWire", true);
|
---|
3722 | Log(("Set SharedMacOnWire\n"));
|
---|
3723 | }
|
---|
3724 | else
|
---|
3725 | Log(("this is NOT a wireless adapter"));
|
---|
3726 | }
|
---|
3727 | else
|
---|
3728 | {
|
---|
3729 | int winEr = GetLastError();
|
---|
3730 | AssertLogRelMsgFailed(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
|
---|
3731 | }
|
---|
3732 |
|
---|
3733 | CoTaskMemFree(pswzBindName);
|
---|
3734 |
|
---|
3735 | pAdaptorComponent.setNull();
|
---|
3736 | /* release the pNc finally */
|
---|
3737 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3738 | # else
|
---|
3739 | /** @todo PORTME: wireless detection */
|
---|
3740 | # endif
|
---|
3741 |
|
---|
3742 | # if defined(RT_OS_SOLARIS)
|
---|
3743 | # if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
|
---|
3744 | /* Zone access restriction, don't allow snopping the global zone. */
|
---|
3745 | zoneid_t ZoneId = getzoneid();
|
---|
3746 | if (ZoneId != GLOBAL_ZONEID)
|
---|
3747 | {
|
---|
3748 | InsertConfigInteger(pCfg, "IgnoreAllPromisc", true);
|
---|
3749 | }
|
---|
3750 | # endif
|
---|
3751 | # endif
|
---|
3752 |
|
---|
3753 | #elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
|
---|
3754 | /* NOTHING TO DO HERE */
|
---|
3755 | #elif defined(RT_OS_LINUX)
|
---|
3756 | /// @todo aleksey: is there anything to be done here?
|
---|
3757 | #elif defined(RT_OS_FREEBSD)
|
---|
3758 | /** @todo FreeBSD: Check out this later (HIF networking). */
|
---|
3759 | #else
|
---|
3760 | # error "Port me"
|
---|
3761 | #endif
|
---|
3762 | break;
|
---|
3763 | }
|
---|
3764 |
|
---|
3765 | case NetworkAttachmentType_Internal:
|
---|
3766 | {
|
---|
3767 | hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(bstr.asOutParam()); H();
|
---|
3768 | if (!bstr.isEmpty())
|
---|
3769 | {
|
---|
3770 | if (fSniffer)
|
---|
3771 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
3772 | else
|
---|
3773 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
3774 | InsertConfigString(pLunL0, "Driver", "IntNet");
|
---|
3775 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3776 | InsertConfigString(pCfg, "Network", bstr);
|
---|
3777 | InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone);
|
---|
3778 | networkName = bstr;
|
---|
3779 | trunkType = Bstr(TRUNKTYPE_WHATEVER);
|
---|
3780 | }
|
---|
3781 | break;
|
---|
3782 | }
|
---|
3783 |
|
---|
3784 | case NetworkAttachmentType_HostOnly:
|
---|
3785 | {
|
---|
3786 | if (fSniffer)
|
---|
3787 | InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
3788 | else
|
---|
3789 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
3790 |
|
---|
3791 | InsertConfigString(pLunL0, "Driver", "IntNet");
|
---|
3792 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3793 |
|
---|
3794 | Bstr HifName;
|
---|
3795 | hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
|
---|
3796 | if (FAILED(hrc))
|
---|
3797 | {
|
---|
3798 | LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)\n", hrc));
|
---|
3799 | H();
|
---|
3800 | }
|
---|
3801 |
|
---|
3802 | Utf8Str HifNameUtf8(HifName);
|
---|
3803 | const char *pszHifName = HifNameUtf8.raw();
|
---|
3804 | ComPtr<IHostNetworkInterface> hostInterface;
|
---|
3805 | rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
|
---|
3806 | if (!SUCCEEDED(rc))
|
---|
3807 | {
|
---|
3808 | LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
|
---|
3809 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3810 | N_("Inexistent host networking interface, name '%ls'"),
|
---|
3811 | HifName.raw());
|
---|
3812 | }
|
---|
3813 |
|
---|
3814 | char szNetwork[INTNET_MAX_NETWORK_NAME];
|
---|
3815 | RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
|
---|
3816 |
|
---|
3817 | #if defined(RT_OS_WINDOWS)
|
---|
3818 | # ifndef VBOX_WITH_NETFLT
|
---|
3819 | hrc = E_NOTIMPL;
|
---|
3820 | LogRel(("NetworkAttachmentType_HostOnly: Not Implemented\n"));
|
---|
3821 | H();
|
---|
3822 | # else /* defined VBOX_WITH_NETFLT*/
|
---|
3823 | /** @todo r=bird: Put this in a function. */
|
---|
3824 |
|
---|
3825 | HostNetworkInterfaceType_T eIfType;
|
---|
3826 | hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
|
---|
3827 | if (FAILED(hrc))
|
---|
3828 | {
|
---|
3829 | LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)\n", hrc));
|
---|
3830 | H();
|
---|
3831 | }
|
---|
3832 |
|
---|
3833 | if (eIfType != HostNetworkInterfaceType_HostOnly)
|
---|
3834 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3835 | N_("Interface ('%ls') is not a Host-Only Adapter interface"),
|
---|
3836 | HifName.raw());
|
---|
3837 |
|
---|
3838 | hrc = hostInterface->COMGETTER(Id)(bstr.asOutParam());
|
---|
3839 | if (FAILED(hrc))
|
---|
3840 | {
|
---|
3841 | LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)\n", hrc));
|
---|
3842 | H();
|
---|
3843 | }
|
---|
3844 | Guid hostIFGuid(bstr);
|
---|
3845 |
|
---|
3846 | INetCfg *pNc;
|
---|
3847 | ComPtr<INetCfgComponent> pAdaptorComponent;
|
---|
3848 | LPWSTR pszApp;
|
---|
3849 | rc = VERR_INTNET_FLT_IF_NOT_FOUND;
|
---|
3850 |
|
---|
3851 | hrc = VBoxNetCfgWinQueryINetCfg(FALSE,
|
---|
3852 | L"VirtualBox",
|
---|
3853 | &pNc,
|
---|
3854 | &pszApp);
|
---|
3855 | Assert(hrc == S_OK);
|
---|
3856 | if (hrc == S_OK)
|
---|
3857 | {
|
---|
3858 | /* get the adapter's INetCfgComponent*/
|
---|
3859 | hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
|
---|
3860 | if (hrc != S_OK)
|
---|
3861 | {
|
---|
3862 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3863 | LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
|
---|
3864 | H();
|
---|
3865 | }
|
---|
3866 | }
|
---|
3867 | #define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
|
---|
3868 | char szTrunkName[INTNET_MAX_TRUNK_NAME];
|
---|
3869 | char *pszTrunkName = szTrunkName;
|
---|
3870 | wchar_t * pswzBindName;
|
---|
3871 | hrc = pAdaptorComponent->GetBindName(&pswzBindName);
|
---|
3872 | Assert(hrc == S_OK);
|
---|
3873 | if (hrc == S_OK)
|
---|
3874 | {
|
---|
3875 | int cwBindName = (int)wcslen(pswzBindName) + 1;
|
---|
3876 | int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
|
---|
3877 | if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
|
---|
3878 | {
|
---|
3879 | strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
|
---|
3880 | pszTrunkName += cbFullBindNamePrefix-1;
|
---|
3881 | if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
|
---|
3882 | sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
|
---|
3883 | {
|
---|
3884 | DWORD err = GetLastError();
|
---|
3885 | hrc = HRESULT_FROM_WIN32(err);
|
---|
3886 | AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
|
---|
3887 | }
|
---|
3888 | }
|
---|
3889 | else
|
---|
3890 | {
|
---|
3891 | AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
|
---|
3892 | /** @todo set appropriate error code */
|
---|
3893 | hrc = E_FAIL;
|
---|
3894 | }
|
---|
3895 |
|
---|
3896 | if (hrc != S_OK)
|
---|
3897 | {
|
---|
3898 | AssertFailed();
|
---|
3899 | CoTaskMemFree(pswzBindName);
|
---|
3900 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3901 | H();
|
---|
3902 | }
|
---|
3903 | }
|
---|
3904 | else
|
---|
3905 | {
|
---|
3906 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3907 | AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
|
---|
3908 | H();
|
---|
3909 | }
|
---|
3910 |
|
---|
3911 |
|
---|
3912 | CoTaskMemFree(pswzBindName);
|
---|
3913 |
|
---|
3914 | pAdaptorComponent.setNull();
|
---|
3915 | /* release the pNc finally */
|
---|
3916 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3917 |
|
---|
3918 | const char *pszTrunk = szTrunkName;
|
---|
3919 |
|
---|
3920 | InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
|
---|
3921 | InsertConfigString(pCfg, "Trunk", pszTrunk);
|
---|
3922 | InsertConfigString(pCfg, "Network", szNetwork);
|
---|
3923 | networkName = Bstr(szNetwork);
|
---|
3924 | trunkName = Bstr(pszTrunk);
|
---|
3925 | trunkType = TRUNKTYPE_NETADP;
|
---|
3926 | # endif /* defined VBOX_WITH_NETFLT*/
|
---|
3927 | #elif defined(RT_OS_DARWIN)
|
---|
3928 | InsertConfigString(pCfg, "Trunk", pszHifName);
|
---|
3929 | InsertConfigString(pCfg, "Network", szNetwork);
|
---|
3930 | InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
|
---|
3931 | networkName = Bstr(szNetwork);
|
---|
3932 | trunkName = Bstr(pszHifName);
|
---|
3933 | trunkType = TRUNKTYPE_NETADP;
|
---|
3934 | #else
|
---|
3935 | InsertConfigString(pCfg, "Trunk", pszHifName);
|
---|
3936 | InsertConfigString(pCfg, "Network", szNetwork);
|
---|
3937 | InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
|
---|
3938 | networkName = Bstr(szNetwork);
|
---|
3939 | trunkName = Bstr(pszHifName);
|
---|
3940 | trunkType = TRUNKTYPE_NETFLT;
|
---|
3941 | #endif
|
---|
3942 | #if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
|
---|
3943 |
|
---|
3944 | Bstr tmpAddr, tmpMask;
|
---|
3945 |
|
---|
3946 | hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPAddress", pszHifName), tmpAddr.asOutParam());
|
---|
3947 | if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
|
---|
3948 | {
|
---|
3949 | hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPNetMask", pszHifName), tmpMask.asOutParam());
|
---|
3950 | if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
|
---|
3951 | hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
|
---|
3952 | else
|
---|
3953 | hrc = hostInterface->EnableStaticIpConfig(tmpAddr,
|
---|
3954 | Bstr(VBOXNET_IPV4MASK_DEFAULT));
|
---|
3955 | }
|
---|
3956 | else
|
---|
3957 | {
|
---|
3958 | /* Grab the IP number from the 'vboxnetX' instance number (see netif.h) */
|
---|
3959 | hrc = hostInterface->EnableStaticIpConfig(getDefaultIPv4Address(Bstr(pszHifName)),
|
---|
3960 | Bstr(VBOXNET_IPV4MASK_DEFAULT));
|
---|
3961 | }
|
---|
3962 |
|
---|
3963 | ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
|
---|
3964 |
|
---|
3965 | hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6Address", pszHifName), tmpAddr.asOutParam());
|
---|
3966 | if (SUCCEEDED(hrc))
|
---|
3967 | hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6NetMask", pszHifName), tmpMask.asOutParam());
|
---|
3968 | if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
|
---|
3969 | {
|
---|
3970 | hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
|
---|
3971 | ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
|
---|
3972 | }
|
---|
3973 | #endif
|
---|
3974 | break;
|
---|
3975 | }
|
---|
3976 |
|
---|
3977 | #if defined(VBOX_WITH_VDE)
|
---|
3978 | case NetworkAttachmentType_VDE:
|
---|
3979 | {
|
---|
3980 | hrc = aNetworkAdapter->COMGETTER(VDENetwork)(bstr.asOutParam()); H();
|
---|
3981 | InsertConfigNode(pInst, "LUN#0", &pLunL0);
|
---|
3982 | InsertConfigString(pLunL0, "Driver", "VDE");
|
---|
3983 | InsertConfigNode(pLunL0, "Config", &pCfg);
|
---|
3984 | if (!bstr.isEmpty())
|
---|
3985 | {
|
---|
3986 | InsertConfigString(pCfg, "Network", bstr);
|
---|
3987 | networkName = bstr;
|
---|
3988 | }
|
---|
3989 | break;
|
---|
3990 | }
|
---|
3991 | #endif
|
---|
3992 |
|
---|
3993 | default:
|
---|
3994 | AssertMsgFailed(("should not get here!\n"));
|
---|
3995 | break;
|
---|
3996 | }
|
---|
3997 |
|
---|
3998 | /*
|
---|
3999 | * Attempt to attach the driver.
|
---|
4000 | */
|
---|
4001 | switch (eAttachmentType)
|
---|
4002 | {
|
---|
4003 | case NetworkAttachmentType_Null:
|
---|
4004 | break;
|
---|
4005 |
|
---|
4006 | case NetworkAttachmentType_Bridged:
|
---|
4007 | case NetworkAttachmentType_Internal:
|
---|
4008 | case NetworkAttachmentType_HostOnly:
|
---|
4009 | case NetworkAttachmentType_NAT:
|
---|
4010 | #if defined(VBOX_WITH_VDE)
|
---|
4011 | case NetworkAttachmentType_VDE:
|
---|
4012 | #endif
|
---|
4013 | {
|
---|
4014 | if (SUCCEEDED(hrc) && SUCCEEDED(rc))
|
---|
4015 | {
|
---|
4016 | if (fAttachDetach)
|
---|
4017 | {
|
---|
4018 | rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
|
---|
4019 | //AssertRC(rc);
|
---|
4020 | }
|
---|
4021 |
|
---|
4022 | {
|
---|
4023 | /** @todo pritesh: get the dhcp server name from the
|
---|
4024 | * previous network configuration and then stop the server
|
---|
4025 | * else it may conflict with the dhcp server running with
|
---|
4026 | * the current attachment type
|
---|
4027 | */
|
---|
4028 | /* Stop the hostonly DHCP Server */
|
---|
4029 | }
|
---|
4030 |
|
---|
4031 | if (!networkName.isEmpty())
|
---|
4032 | {
|
---|
4033 | /*
|
---|
4034 | * Until we implement service reference counters DHCP Server will be stopped
|
---|
4035 | * by DHCPServerRunner destructor.
|
---|
4036 | */
|
---|
4037 | ComPtr<IDHCPServer> dhcpServer;
|
---|
4038 | hrc = virtualBox->FindDHCPServerByNetworkName(networkName, dhcpServer.asOutParam());
|
---|
4039 | if (SUCCEEDED(hrc))
|
---|
4040 | {
|
---|
4041 | /* there is a DHCP server available for this network */
|
---|
4042 | BOOL fEnabled;
|
---|
4043 | hrc = dhcpServer->COMGETTER(Enabled)(&fEnabled);
|
---|
4044 | if (FAILED(hrc))
|
---|
4045 | {
|
---|
4046 | LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (%Rhrc)", hrc));
|
---|
4047 | H();
|
---|
4048 | }
|
---|
4049 |
|
---|
4050 | if (fEnabled)
|
---|
4051 | hrc = dhcpServer->Start(networkName, trunkName, trunkType);
|
---|
4052 | }
|
---|
4053 | else
|
---|
4054 | hrc = S_OK;
|
---|
4055 | }
|
---|
4056 | }
|
---|
4057 |
|
---|
4058 | break;
|
---|
4059 | }
|
---|
4060 |
|
---|
4061 | default:
|
---|
4062 | AssertMsgFailed(("should not get here!\n"));
|
---|
4063 | break;
|
---|
4064 | }
|
---|
4065 |
|
---|
4066 | meAttachmentType[uInstance] = eAttachmentType;
|
---|
4067 | }
|
---|
4068 | catch (ConfigError &x)
|
---|
4069 | {
|
---|
4070 | // InsertConfig threw something:
|
---|
4071 | return x.m_vrc;
|
---|
4072 | }
|
---|
4073 |
|
---|
4074 | #undef H
|
---|
4075 |
|
---|
4076 | return VINF_SUCCESS;
|
---|
4077 | }
|
---|
4078 |
|
---|
4079 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
4080 | /**
|
---|
4081 | * Set an array of guest properties
|
---|
4082 | */
|
---|
4083 | static void configSetProperties(VMMDev * const pVMMDev,
|
---|
4084 | void *names,
|
---|
4085 | void *values,
|
---|
4086 | void *timestamps,
|
---|
4087 | void *flags)
|
---|
4088 | {
|
---|
4089 | VBOXHGCMSVCPARM parms[4];
|
---|
4090 |
|
---|
4091 | parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
4092 | parms[0].u.pointer.addr = names;
|
---|
4093 | parms[0].u.pointer.size = 0; /* We don't actually care. */
|
---|
4094 | parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
4095 | parms[1].u.pointer.addr = values;
|
---|
4096 | parms[1].u.pointer.size = 0; /* We don't actually care. */
|
---|
4097 | parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
4098 | parms[2].u.pointer.addr = timestamps;
|
---|
4099 | parms[2].u.pointer.size = 0; /* We don't actually care. */
|
---|
4100 | parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
4101 | parms[3].u.pointer.addr = flags;
|
---|
4102 | parms[3].u.pointer.size = 0; /* We don't actually care. */
|
---|
4103 |
|
---|
4104 | pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4,
|
---|
4105 | &parms[0]);
|
---|
4106 | }
|
---|
4107 |
|
---|
4108 | /**
|
---|
4109 | * Set a single guest property
|
---|
4110 | */
|
---|
4111 | static void configSetProperty(VMMDev * const pVMMDev, const char *pszName,
|
---|
4112 | const char *pszValue, const char *pszFlags)
|
---|
4113 | {
|
---|
4114 | VBOXHGCMSVCPARM parms[4];
|
---|
4115 |
|
---|
4116 | AssertPtrReturnVoid(pszName);
|
---|
4117 | AssertPtrReturnVoid(pszValue);
|
---|
4118 | AssertPtrReturnVoid(pszFlags);
|
---|
4119 | parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
4120 | parms[0].u.pointer.addr = (void *)pszName;
|
---|
4121 | parms[0].u.pointer.size = strlen(pszName) + 1;
|
---|
4122 | parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
4123 | parms[1].u.pointer.addr = (void *)pszValue;
|
---|
4124 | parms[1].u.pointer.size = strlen(pszValue) + 1;
|
---|
4125 | parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
4126 | parms[2].u.pointer.addr = (void *)pszFlags;
|
---|
4127 | parms[2].u.pointer.size = strlen(pszFlags) + 1;
|
---|
4128 | pVMMDev->hgcmHostCall("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
|
---|
4129 | &parms[0]);
|
---|
4130 | }
|
---|
4131 |
|
---|
4132 | /**
|
---|
4133 | * Set the global flags value by calling the service
|
---|
4134 | * @returns the status returned by the call to the service
|
---|
4135 | *
|
---|
4136 | * @param pTable the service instance handle
|
---|
4137 | * @param eFlags the flags to set
|
---|
4138 | */
|
---|
4139 | int configSetGlobalPropertyFlags(VMMDev * const pVMMDev,
|
---|
4140 | guestProp::ePropFlags eFlags)
|
---|
4141 | {
|
---|
4142 | VBOXHGCMSVCPARM paParm;
|
---|
4143 | paParm.setUInt32(eFlags);
|
---|
4144 | int rc = pVMMDev->hgcmHostCall("VBoxGuestPropSvc",
|
---|
4145 | guestProp::SET_GLOBAL_FLAGS_HOST, 1,
|
---|
4146 | &paParm);
|
---|
4147 | if (RT_FAILURE(rc))
|
---|
4148 | {
|
---|
4149 | char szFlags[guestProp::MAX_FLAGS_LEN];
|
---|
4150 | if (RT_FAILURE(writeFlags(eFlags, szFlags)))
|
---|
4151 | Log(("Failed to set the global flags.\n"));
|
---|
4152 | else
|
---|
4153 | Log(("Failed to set the global flags \"%s\".\n", szFlags));
|
---|
4154 | }
|
---|
4155 | return rc;
|
---|
4156 | }
|
---|
4157 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
4158 |
|
---|
4159 | /**
|
---|
4160 | * Set up the Guest Property service, populate it with properties read from
|
---|
4161 | * the machine XML and set a couple of initial properties.
|
---|
4162 | */
|
---|
4163 | /* static */ int Console::configGuestProperties(void *pvConsole)
|
---|
4164 | {
|
---|
4165 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
4166 | AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
|
---|
4167 | ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
|
---|
4168 |
|
---|
4169 | /* Load the service */
|
---|
4170 | int rc = pConsole->mVMMDev->hgcmLoadService("VBoxGuestPropSvc", "VBoxGuestPropSvc");
|
---|
4171 |
|
---|
4172 | if (RT_FAILURE(rc))
|
---|
4173 | {
|
---|
4174 | LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
|
---|
4175 | /* That is not a fatal failure. */
|
---|
4176 | rc = VINF_SUCCESS;
|
---|
4177 | }
|
---|
4178 | else
|
---|
4179 | {
|
---|
4180 | /*
|
---|
4181 | * Initialize built-in properties that can be changed and saved.
|
---|
4182 | *
|
---|
4183 | * These are typically transient properties that the guest cannot
|
---|
4184 | * change.
|
---|
4185 | */
|
---|
4186 |
|
---|
4187 | /* Sysprep execution by VBoxService. */
|
---|
4188 | configSetProperty(pConsole->mVMMDev,
|
---|
4189 | "/VirtualBox/HostGuest/SysprepExec", "",
|
---|
4190 | "TRANSIENT, RDONLYGUEST");
|
---|
4191 | configSetProperty(pConsole->mVMMDev,
|
---|
4192 | "/VirtualBox/HostGuest/SysprepArgs", "",
|
---|
4193 | "TRANSIENT, RDONLYGUEST");
|
---|
4194 |
|
---|
4195 | /*
|
---|
4196 | * Pull over the properties from the server.
|
---|
4197 | */
|
---|
4198 | SafeArray<BSTR> namesOut;
|
---|
4199 | SafeArray<BSTR> valuesOut;
|
---|
4200 | SafeArray<ULONG64> timestampsOut;
|
---|
4201 | SafeArray<BSTR> flagsOut;
|
---|
4202 | HRESULT hrc;
|
---|
4203 | hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
|
---|
4204 | ComSafeArrayAsOutParam(valuesOut),
|
---|
4205 | ComSafeArrayAsOutParam(timestampsOut),
|
---|
4206 | ComSafeArrayAsOutParam(flagsOut));
|
---|
4207 | AssertMsgReturn(SUCCEEDED(hrc), ("hrc=%Rrc\n", hrc), VERR_GENERAL_FAILURE);
|
---|
4208 | size_t cProps = namesOut.size();
|
---|
4209 | size_t cAlloc = cProps + 1;
|
---|
4210 | if ( valuesOut.size() != cProps
|
---|
4211 | || timestampsOut.size() != cProps
|
---|
4212 | || flagsOut.size() != cProps
|
---|
4213 | )
|
---|
4214 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
4215 |
|
---|
4216 | char **papszNames, **papszValues, **papszFlags;
|
---|
4217 | char szEmpty[] = "";
|
---|
4218 | ULONG64 *pau64Timestamps;
|
---|
4219 | papszNames = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
|
---|
4220 | papszValues = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
|
---|
4221 | pau64Timestamps = (ULONG64 *)RTMemTmpAllocZ(sizeof(ULONG64) * cAlloc);
|
---|
4222 | papszFlags = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
|
---|
4223 | if (papszNames && papszValues && pau64Timestamps && papszFlags)
|
---|
4224 | {
|
---|
4225 | for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
|
---|
4226 | {
|
---|
4227 | AssertPtrReturn(namesOut[i], VERR_INVALID_PARAMETER);
|
---|
4228 | rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
|
---|
4229 | if (RT_FAILURE(rc))
|
---|
4230 | break;
|
---|
4231 | if (valuesOut[i])
|
---|
4232 | rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
|
---|
4233 | else
|
---|
4234 | papszValues[i] = szEmpty;
|
---|
4235 | if (RT_FAILURE(rc))
|
---|
4236 | break;
|
---|
4237 | pau64Timestamps[i] = timestampsOut[i];
|
---|
4238 | if (flagsOut[i])
|
---|
4239 | rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
|
---|
4240 | else
|
---|
4241 | papszFlags[i] = szEmpty;
|
---|
4242 | }
|
---|
4243 | if (RT_SUCCESS(rc))
|
---|
4244 | configSetProperties(pConsole->mVMMDev,
|
---|
4245 | (void *)papszNames,
|
---|
4246 | (void *)papszValues,
|
---|
4247 | (void *)pau64Timestamps,
|
---|
4248 | (void *)papszFlags);
|
---|
4249 | for (unsigned i = 0; i < cProps; ++i)
|
---|
4250 | {
|
---|
4251 | RTStrFree(papszNames[i]);
|
---|
4252 | if (valuesOut[i])
|
---|
4253 | RTStrFree(papszValues[i]);
|
---|
4254 | if (flagsOut[i])
|
---|
4255 | RTStrFree(papszFlags[i]);
|
---|
4256 | }
|
---|
4257 | }
|
---|
4258 | else
|
---|
4259 | rc = VERR_NO_MEMORY;
|
---|
4260 | RTMemTmpFree(papszNames);
|
---|
4261 | RTMemTmpFree(papszValues);
|
---|
4262 | RTMemTmpFree(pau64Timestamps);
|
---|
4263 | RTMemTmpFree(papszFlags);
|
---|
4264 | AssertRCReturn(rc, rc);
|
---|
4265 |
|
---|
4266 | /*
|
---|
4267 | * These properties have to be set before pulling over the properties
|
---|
4268 | * from the machine XML, to ensure that properties saved in the XML
|
---|
4269 | * will override them.
|
---|
4270 | */
|
---|
4271 | /* Set the VBox version string as a guest property */
|
---|
4272 | configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxVer",
|
---|
4273 | VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
|
---|
4274 | /* Set the VBox SVN revision as a guest property */
|
---|
4275 | configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxRev",
|
---|
4276 | RTBldCfgRevisionStr(), "TRANSIENT, RDONLYGUEST");
|
---|
4277 |
|
---|
4278 | /*
|
---|
4279 | * Register the host notification callback
|
---|
4280 | */
|
---|
4281 | HGCMSVCEXTHANDLE hDummy;
|
---|
4282 | HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestPropSvc",
|
---|
4283 | Console::doGuestPropNotification,
|
---|
4284 | pvConsole);
|
---|
4285 |
|
---|
4286 | #ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
|
---|
4287 | rc = configSetGlobalPropertyFlags(pConsole->mVMMDev,
|
---|
4288 | guestProp::RDONLYGUEST);
|
---|
4289 | AssertRCReturn(rc, rc);
|
---|
4290 | #endif
|
---|
4291 |
|
---|
4292 | Log(("Set VBoxGuestPropSvc property store\n"));
|
---|
4293 | }
|
---|
4294 | return VINF_SUCCESS;
|
---|
4295 | #else /* !VBOX_WITH_GUEST_PROPS */
|
---|
4296 | return VERR_NOT_SUPPORTED;
|
---|
4297 | #endif /* !VBOX_WITH_GUEST_PROPS */
|
---|
4298 | }
|
---|
4299 |
|
---|
4300 | /**
|
---|
4301 | * Set up the Guest Control service.
|
---|
4302 | */
|
---|
4303 | /* static */ int Console::configGuestControl(void *pvConsole)
|
---|
4304 | {
|
---|
4305 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
4306 | AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
|
---|
4307 | ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
|
---|
4308 |
|
---|
4309 | /* Load the service */
|
---|
4310 | int rc = pConsole->mVMMDev->hgcmLoadService("VBoxGuestControlSvc", "VBoxGuestControlSvc");
|
---|
4311 |
|
---|
4312 | if (RT_FAILURE(rc))
|
---|
4313 | {
|
---|
4314 | LogRel(("VBoxGuestControlSvc is not available. rc = %Rrc\n", rc));
|
---|
4315 | /* That is not a fatal failure. */
|
---|
4316 | rc = VINF_SUCCESS;
|
---|
4317 | }
|
---|
4318 | else
|
---|
4319 | {
|
---|
4320 | HGCMSVCEXTHANDLE hDummy;
|
---|
4321 | rc = HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestControlSvc",
|
---|
4322 | &Guest::doGuestCtrlNotification,
|
---|
4323 | pConsole->getGuest());
|
---|
4324 | if (RT_FAILURE(rc))
|
---|
4325 | Log(("Cannot register VBoxGuestControlSvc extension!\n"));
|
---|
4326 | else
|
---|
4327 | Log(("VBoxGuestControlSvc loaded\n"));
|
---|
4328 | }
|
---|
4329 |
|
---|
4330 | return rc;
|
---|
4331 | #else /* !VBOX_WITH_GUEST_CONTROL */
|
---|
4332 | return VERR_NOT_SUPPORTED;
|
---|
4333 | #endif /* !VBOX_WITH_GUEST_CONTROL */
|
---|
4334 | }
|
---|