VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp@ 40107

Last change on this file since 40107 was 39882, checked in by vboxsync, 13 years ago

Config.kmk,VMMDev,Main,QtGui,VBoxManage: Refactored IGuest::additionsVersion and associated acts, splitting it up into additionsVersion and additionsRevision like IVirtualBox and IExtPack handles versioning. Fixed missing saved state in VMMDev where the VMMDevReq_ReportGuestInfo2 info was not saved and Main+Frontends led to believe we were running guest additions older than 3.2. The changes have be subjected to limited testing. Added TODOs for another missing save in VMMDev.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 97.7 KB
Line 
1/* $Id: VBoxManageInfo.cpp 39882 2012-01-26 00:54:50Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'showvminfo' command and helper routines.
4 */
5
6/*
7 * Copyright (C) 2006-2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VBOX_ONLY_DOCS
19
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <VBox/com/com.h>
24#include <VBox/com/string.h>
25#include <VBox/com/Guid.h>
26#include <VBox/com/array.h>
27#include <VBox/com/ErrorInfo.h>
28#include <VBox/com/errorprint.h>
29
30#include <VBox/com/VirtualBox.h>
31
32#ifdef VBOX_WITH_PCI_PASSTHROUGH
33#include <VBox/pci.h>
34#endif
35
36#include <VBox/log.h>
37#include <iprt/stream.h>
38#include <iprt/time.h>
39#include <iprt/string.h>
40#include <iprt/getopt.h>
41#include <iprt/ctype.h>
42
43#include "VBoxManage.h"
44using namespace com;
45
46
47// funcs
48///////////////////////////////////////////////////////////////////////////////
49
50HRESULT showSnapshots(ComPtr<ISnapshot> &rootSnapshot,
51 ComPtr<ISnapshot> &currentSnapshot,
52 VMINFO_DETAILS details,
53 const Bstr &prefix /* = ""*/,
54 int level /*= 0*/)
55{
56 /* start with the root */
57 Bstr name;
58 Bstr uuid;
59 CHECK_ERROR2_RET(rootSnapshot,COMGETTER(Name)(name.asOutParam()), hrcCheck);
60 CHECK_ERROR2_RET(rootSnapshot,COMGETTER(Id)(uuid.asOutParam()), hrcCheck);
61 if (details == VMINFO_MACHINEREADABLE)
62 {
63 /* print with hierarchical numbering */
64 RTPrintf("SnapshotName%ls=\"%ls\"\n", prefix.raw(), name.raw());
65 RTPrintf("SnapshotUUID%ls=\"%s\"\n", prefix.raw(), Utf8Str(uuid).c_str());
66 }
67 else
68 {
69 /* print with indentation */
70 bool fCurrent = (rootSnapshot == currentSnapshot);
71 RTPrintf(" %lsName: %ls (UUID: %s)%s\n",
72 prefix.raw(),
73 name.raw(),
74 Utf8Str(uuid).c_str(),
75 (fCurrent) ? " *" : "");
76 }
77
78 /* get the children */
79 HRESULT hrc = S_OK;
80 SafeIfaceArray <ISnapshot> coll;
81 CHECK_ERROR2_RET(rootSnapshot,COMGETTER(Children)(ComSafeArrayAsOutParam(coll)), hrcCheck);
82 if (!coll.isNull())
83 {
84 for (size_t index = 0; index < coll.size(); ++index)
85 {
86 ComPtr<ISnapshot> snapshot = coll[index];
87 if (snapshot)
88 {
89 Bstr newPrefix;
90 if (details == VMINFO_MACHINEREADABLE)
91 newPrefix = Utf8StrFmt("%ls-%d", prefix.raw(), index + 1);
92 else
93 {
94 newPrefix = Utf8StrFmt("%ls ", prefix.raw());
95 }
96
97 /* recursive call */
98 HRESULT hrc2 = showSnapshots(snapshot, currentSnapshot, details, newPrefix, level + 1);
99 if (FAILED(hrc2))
100 hrc = hrc2;
101 }
102 }
103 }
104 return hrc;
105}
106
107static void makeTimeStr(char *s, int cb, int64_t millies)
108{
109 RTTIME t;
110 RTTIMESPEC ts;
111
112 RTTimeSpecSetMilli(&ts, millies);
113
114 RTTimeExplode(&t, &ts);
115
116 RTStrPrintf(s, cb, "%04d/%02d/%02d %02d:%02d:%02d UTC",
117 t.i32Year, t.u8Month, t.u8MonthDay,
118 t.u8Hour, t.u8Minute, t.u8Second);
119}
120
121const char *machineStateToName(MachineState_T machineState, bool fShort)
122{
123 switch (machineState)
124 {
125 case MachineState_PoweredOff:
126 return fShort ? "poweroff" : "powered off";
127 case MachineState_Saved:
128 return "saved";
129 case MachineState_Aborted:
130 return "aborted";
131 case MachineState_Teleported:
132 return "teleported";
133 case MachineState_Running:
134 return "running";
135 case MachineState_Paused:
136 return "paused";
137 case MachineState_Stuck:
138 return fShort ? "gurumeditation" : "guru meditation";
139 case MachineState_LiveSnapshotting:
140 return fShort ? "livesnapshotting" : "live snapshotting";
141 case MachineState_Teleporting:
142 return "teleporting";
143 case MachineState_Starting:
144 return "starting";
145 case MachineState_Stopping:
146 return "stopping";
147 case MachineState_Saving:
148 return "saving";
149 case MachineState_Restoring:
150 return "restoring";
151 case MachineState_TeleportingPausedVM:
152 return fShort ? "teleportingpausedvm" : "teleporting paused vm";
153 case MachineState_TeleportingIn:
154 return fShort ? "teleportingin" : "teleporting (incoming)";
155 case MachineState_RestoringSnapshot:
156 return fShort ? "restoringsnapshot" : "restoring snapshot";
157 case MachineState_DeletingSnapshot:
158 return fShort ? "deletingsnapshot" : "deleting snapshot";
159 case MachineState_DeletingSnapshotOnline:
160 return fShort ? "deletingsnapshotlive" : "deleting snapshot live";
161 case MachineState_DeletingSnapshotPaused:
162 return fShort ? "deletingsnapshotlivepaused" : "deleting snapshot live paused";
163 case MachineState_SettingUp:
164 return fShort ? "settingup" : "setting up";
165 default:
166 break;
167 }
168 return "unknown";
169}
170
171const char *facilityStateToName(AdditionsFacilityStatus_T faStatus, bool fShort)
172{
173 switch (faStatus)
174 {
175 case AdditionsFacilityStatus_Inactive:
176 return fShort ? "inactive" : "not active";
177 case AdditionsFacilityStatus_Paused:
178 return "paused";
179 case AdditionsFacilityStatus_PreInit:
180 return fShort ? "preinit" : "pre-initializing";
181 case AdditionsFacilityStatus_Init:
182 return fShort ? "init" : "initializing";
183 case AdditionsFacilityStatus_Active:
184 return fShort ? "active" : "active/running";
185 case AdditionsFacilityStatus_Terminating:
186 return "terminating";
187 case AdditionsFacilityStatus_Terminated:
188 return "terminated";
189 case AdditionsFacilityStatus_Failed:
190 return "failed";
191 case AdditionsFacilityStatus_Unknown:
192 default:
193 break;
194 }
195 return "unknown";
196}
197
198/* Disable global optimizations for MSC 8.0/64 to make it compile in reasonable
199 time. MSC 7.1/32 doesn't have quite as much trouble with it, but still
200 sufficient to qualify for this hack as well since this code isn't performance
201 critical and probably won't gain much from the extra optimizing in real life. */
202#if defined(_MSC_VER)
203# pragma optimize("g", off)
204#endif
205
206HRESULT showVMInfo(ComPtr<IVirtualBox> virtualBox,
207 ComPtr<IMachine> machine,
208 VMINFO_DETAILS details /*= VMINFO_NONE*/,
209 ComPtr<IConsole> console /*= ComPtr <IConsole> ()*/)
210{
211 HRESULT rc;
212
213 /*
214 * The rules for output in -argdump format:
215 * 1) the key part (the [0-9a-zA-Z_]+ string before the '=' delimiter)
216 * is all lowercase for "VBoxManage modifyvm" parameters. Any
217 * other values printed are in CamelCase.
218 * 2) strings (anything non-decimal) are printed surrounded by
219 * double quotes '"'. If the strings themselves contain double
220 * quotes, these characters are escaped by '\'. Any '\' character
221 * in the original string is also escaped by '\'.
222 * 3) numbers (containing just [0-9\-]) are written out unchanged.
223 */
224
225 /** @todo the quoting is not yet implemented! */
226 /** @todo error checking! */
227
228 BOOL accessible = FALSE;
229 CHECK_ERROR(machine, COMGETTER(Accessible)(&accessible));
230 if (FAILED(rc)) return rc;
231
232 Bstr uuid;
233 rc = machine->COMGETTER(Id)(uuid.asOutParam());
234
235 if (!accessible)
236 {
237 if (details == VMINFO_COMPACT)
238 RTPrintf("\"<inaccessible>\" {%s}\n", Utf8Str(uuid).c_str());
239 else
240 {
241 if (details == VMINFO_MACHINEREADABLE)
242 RTPrintf("name=\"<inaccessible>\"\n");
243 else
244 RTPrintf("Name: <inaccessible!>\n");
245 if (details == VMINFO_MACHINEREADABLE)
246 RTPrintf("UUID=\"%s\"\n", Utf8Str(uuid).c_str());
247 else
248 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
249 if (details != VMINFO_MACHINEREADABLE)
250 {
251 Bstr settingsFilePath;
252 rc = machine->COMGETTER(SettingsFilePath)(settingsFilePath.asOutParam());
253 RTPrintf("Config file: %ls\n", settingsFilePath.raw());
254 ComPtr<IVirtualBoxErrorInfo> accessError;
255 rc = machine->COMGETTER(AccessError)(accessError.asOutParam());
256 RTPrintf("Access error details:\n");
257 ErrorInfo ei(accessError);
258 GluePrintErrorInfo(ei);
259 RTPrintf("\n");
260 }
261 }
262 return S_OK;
263 }
264
265 Bstr machineName;
266 rc = machine->COMGETTER(Name)(machineName.asOutParam());
267
268 if (details == VMINFO_COMPACT)
269 {
270 RTPrintf("\"%ls\" {%s}\n", machineName.raw(), Utf8Str(uuid).c_str());
271 return S_OK;
272 }
273
274 if (details == VMINFO_MACHINEREADABLE)
275 RTPrintf("name=\"%ls\"\n", machineName.raw());
276 else
277 RTPrintf("Name: %ls\n", machineName.raw());
278
279 Bstr osTypeId;
280 rc = machine->COMGETTER(OSTypeId)(osTypeId.asOutParam());
281 ComPtr<IGuestOSType> osType;
282 rc = virtualBox->GetGuestOSType(osTypeId.raw(), osType.asOutParam());
283 Bstr osName;
284 rc = osType->COMGETTER(Description)(osName.asOutParam());
285 if (details == VMINFO_MACHINEREADABLE)
286 RTPrintf("ostype=\"%ls\"\n", osTypeId.raw());
287 else
288 RTPrintf("Guest OS: %ls\n", osName.raw());
289
290 if (details == VMINFO_MACHINEREADABLE)
291 RTPrintf("UUID=\"%s\"\n", Utf8Str(uuid).c_str());
292 else
293 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
294
295 Bstr settingsFilePath;
296 rc = machine->COMGETTER(SettingsFilePath)(settingsFilePath.asOutParam());
297 if (details == VMINFO_MACHINEREADABLE)
298 RTPrintf("CfgFile=\"%ls\"\n", settingsFilePath.raw());
299 else
300 RTPrintf("Config file: %ls\n", settingsFilePath.raw());
301
302 Bstr snapshotFolder;
303 rc = machine->COMGETTER(SnapshotFolder)(snapshotFolder.asOutParam());
304 if (details == VMINFO_MACHINEREADABLE)
305 RTPrintf("SnapFldr=\"%ls\"\n", snapshotFolder.raw());
306 else
307 RTPrintf("Snapshot folder: %ls\n", snapshotFolder.raw());
308
309 Bstr logFolder;
310 rc = machine->COMGETTER(LogFolder)(logFolder.asOutParam());
311 if (details == VMINFO_MACHINEREADABLE)
312 RTPrintf("LogFldr=\"%ls\"\n", logFolder.raw());
313 else
314 RTPrintf("Log folder: %ls\n", logFolder.raw());
315
316 Bstr strHardwareUuid;
317 rc = machine->COMGETTER(HardwareUUID)(strHardwareUuid.asOutParam());
318 if (details == VMINFO_MACHINEREADABLE)
319 RTPrintf("hardwareuuid=\"%ls\"\n", strHardwareUuid.raw());
320 else
321 RTPrintf("Hardware UUID: %ls\n", strHardwareUuid.raw());
322
323 ULONG memorySize;
324 rc = machine->COMGETTER(MemorySize)(&memorySize);
325 if (details == VMINFO_MACHINEREADABLE)
326 RTPrintf("memory=%u\n", memorySize);
327 else
328 RTPrintf("Memory size: %uMB\n", memorySize);
329
330 BOOL fPageFusionEnabled;
331 rc = machine->COMGETTER(PageFusionEnabled)(&fPageFusionEnabled);
332 if (details == VMINFO_MACHINEREADABLE)
333 RTPrintf("pagefusion=\"%s\"\n", fPageFusionEnabled ? "on" : "off");
334 else
335 RTPrintf("Page Fusion: %s\n", fPageFusionEnabled ? "on" : "off");
336
337 ULONG vramSize;
338 rc = machine->COMGETTER(VRAMSize)(&vramSize);
339 if (details == VMINFO_MACHINEREADABLE)
340 RTPrintf("vram=%u\n", vramSize);
341 else
342 RTPrintf("VRAM size: %uMB\n", vramSize);
343
344 ULONG cpuCap;
345 rc = machine->COMGETTER(CPUExecutionCap)(&cpuCap);
346 if (details == VMINFO_MACHINEREADABLE)
347 RTPrintf("cpuexecutioncap=%u\n", cpuCap);
348 else
349 RTPrintf("CPU exec cap: %u%%\n", cpuCap);
350
351 BOOL fHpetEnabled;
352 machine->COMGETTER(HpetEnabled)(&fHpetEnabled);
353 if (details == VMINFO_MACHINEREADABLE)
354 RTPrintf("hpet=\"%s\"\n", fHpetEnabled ? "on" : "off");
355 else
356 RTPrintf("HPET: %s\n", fHpetEnabled ? "on" : "off");
357
358 ChipsetType_T chipsetType = ChipsetType_Null;
359 const char *pszChipsetType = NULL;
360 machine->COMGETTER(ChipsetType)(&chipsetType);
361 switch (chipsetType)
362 {
363 case ChipsetType_Null:
364 pszChipsetType = "invalid";
365 break;
366 case ChipsetType_PIIX3:
367 pszChipsetType = "piix3";
368 break;
369 case ChipsetType_ICH9:
370 pszChipsetType = "ich9";
371 break;
372 default:
373 Assert(false);
374 pszChipsetType = "unknown";
375 }
376 if (details == VMINFO_MACHINEREADABLE)
377 RTPrintf("chipset=\"%s\"\n", pszChipsetType);
378 else
379 RTPrintf("Chipset: %s\n", pszChipsetType);
380
381 FirmwareType_T firmwareType = FirmwareType_BIOS;
382 const char *pszFirmwareType = NULL;
383 machine->COMGETTER(FirmwareType)(&firmwareType);
384 switch (firmwareType)
385 {
386 case FirmwareType_BIOS:
387 pszFirmwareType = "BIOS";
388 break;
389 case FirmwareType_EFI:
390 pszFirmwareType = "EFI";
391 break;
392 case FirmwareType_EFI32:
393 pszFirmwareType = "EFI32";
394 break;
395 case FirmwareType_EFI64:
396 pszFirmwareType = "EFI64";
397 break;
398 case FirmwareType_EFIDUAL:
399 pszFirmwareType = "EFIDUAL";
400 break;
401 default:
402 Assert(false);
403 pszFirmwareType = "unknown";
404 }
405 if (details == VMINFO_MACHINEREADABLE)
406 RTPrintf("firmware=\"%s\"\n", pszFirmwareType);
407 else
408 RTPrintf("Firmware: %s\n", pszFirmwareType);
409
410
411 ULONG numCpus;
412 rc = machine->COMGETTER(CPUCount)(&numCpus);
413 if (details == VMINFO_MACHINEREADABLE)
414 RTPrintf("cpus=%u\n", numCpus);
415 else
416 RTPrintf("Number of CPUs: %u\n", numCpus);
417
418 BOOL fSyntheticCpu;
419 machine->GetCPUProperty(CPUPropertyType_Synthetic, &fSyntheticCpu);
420 if (details == VMINFO_MACHINEREADABLE)
421 RTPrintf("synthcpu=\"%s\"\n", fSyntheticCpu ? "on" : "off");
422 else
423 RTPrintf("Synthetic Cpu: %s\n", fSyntheticCpu ? "on" : "off");
424
425 if (details != VMINFO_MACHINEREADABLE)
426 RTPrintf("CPUID overrides: ");
427 ULONG cFound = 0;
428 static uint32_t const s_auCpuIdRanges[] =
429 {
430 UINT32_C(0x00000000), UINT32_C(0x0000000a),
431 UINT32_C(0x80000000), UINT32_C(0x8000000a)
432 };
433 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
434 for (uint32_t uLeaf = s_auCpuIdRanges[i]; uLeaf < s_auCpuIdRanges[i + 1]; uLeaf++)
435 {
436 ULONG uEAX, uEBX, uECX, uEDX;
437 rc = machine->GetCPUIDLeaf(uLeaf, &uEAX, &uEBX, &uECX, &uEDX);
438 if (SUCCEEDED(rc))
439 {
440 if (details == VMINFO_MACHINEREADABLE)
441 RTPrintf("cpuid=%08x,%08x,%08x,%08x,%08x", uLeaf, uEAX, uEBX, uECX, uEDX);
442 else
443 {
444 if (!cFound)
445 RTPrintf("Leaf no. EAX EBX ECX EDX\n");
446 RTPrintf(" %08x %08x %08x %08x %08x\n", uLeaf, uEAX, uEBX, uECX, uEDX);
447 }
448 cFound++;
449 }
450 }
451 if (!cFound && details != VMINFO_MACHINEREADABLE)
452 RTPrintf("None\n");
453
454 ComPtr <IBIOSSettings> biosSettings;
455 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
456
457 BIOSBootMenuMode_T bootMenuMode;
458 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
459 const char *pszBootMenu = NULL;
460 switch (bootMenuMode)
461 {
462 case BIOSBootMenuMode_Disabled:
463 pszBootMenu = "disabled";
464 break;
465 case BIOSBootMenuMode_MenuOnly:
466 if (details == VMINFO_MACHINEREADABLE)
467 pszBootMenu = "menuonly";
468 else
469 pszBootMenu = "menu only";
470 break;
471 default:
472 if (details == VMINFO_MACHINEREADABLE)
473 pszBootMenu = "messageandmenu";
474 else
475 pszBootMenu = "message and menu";
476 }
477 if (details == VMINFO_MACHINEREADABLE)
478 RTPrintf("bootmenu=\"%s\"\n", pszBootMenu);
479 else
480 RTPrintf("Boot menu mode: %s\n", pszBootMenu);
481
482 ULONG maxBootPosition = 0;
483 ComPtr<ISystemProperties> systemProperties;
484 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
485 systemProperties->COMGETTER(MaxBootPosition)(&maxBootPosition);
486 for (ULONG i = 1; i <= maxBootPosition; i++)
487 {
488 DeviceType_T bootOrder;
489 machine->GetBootOrder(i, &bootOrder);
490 if (bootOrder == DeviceType_Floppy)
491 {
492 if (details == VMINFO_MACHINEREADABLE)
493 RTPrintf("boot%d=\"floppy\"\n", i);
494 else
495 RTPrintf("Boot Device (%d): Floppy\n", i);
496 }
497 else if (bootOrder == DeviceType_DVD)
498 {
499 if (details == VMINFO_MACHINEREADABLE)
500 RTPrintf("boot%d=\"dvd\"\n", i);
501 else
502 RTPrintf("Boot Device (%d): DVD\n", i);
503 }
504 else if (bootOrder == DeviceType_HardDisk)
505 {
506 if (details == VMINFO_MACHINEREADABLE)
507 RTPrintf("boot%d=\"disk\"\n", i);
508 else
509 RTPrintf("Boot Device (%d): HardDisk\n", i);
510 }
511 else if (bootOrder == DeviceType_Network)
512 {
513 if (details == VMINFO_MACHINEREADABLE)
514 RTPrintf("boot%d=\"net\"\n", i);
515 else
516 RTPrintf("Boot Device (%d): Network\n", i);
517 }
518 else if (bootOrder == DeviceType_USB)
519 {
520 if (details == VMINFO_MACHINEREADABLE)
521 RTPrintf("boot%d=\"usb\"\n", i);
522 else
523 RTPrintf("Boot Device (%d): USB\n", i);
524 }
525 else if (bootOrder == DeviceType_SharedFolder)
526 {
527 if (details == VMINFO_MACHINEREADABLE)
528 RTPrintf("boot%d=\"sharedfolder\"\n", i);
529 else
530 RTPrintf("Boot Device (%d): Shared Folder\n", i);
531 }
532 else
533 {
534 if (details == VMINFO_MACHINEREADABLE)
535 RTPrintf("boot%d=\"none\"\n", i);
536 else
537 RTPrintf("Boot Device (%d): Not Assigned\n", i);
538 }
539 }
540
541 BOOL acpiEnabled;
542 biosSettings->COMGETTER(ACPIEnabled)(&acpiEnabled);
543 if (details == VMINFO_MACHINEREADABLE)
544 RTPrintf("acpi=\"%s\"\n", acpiEnabled ? "on" : "off");
545 else
546 RTPrintf("ACPI: %s\n", acpiEnabled ? "on" : "off");
547
548 BOOL ioapicEnabled;
549 biosSettings->COMGETTER(IOAPICEnabled)(&ioapicEnabled);
550 if (details == VMINFO_MACHINEREADABLE)
551 RTPrintf("ioapic=\"%s\"\n", ioapicEnabled ? "on" : "off");
552 else
553 RTPrintf("IOAPIC: %s\n", ioapicEnabled ? "on" : "off");
554
555 BOOL PAEEnabled;
556 machine->GetCPUProperty(CPUPropertyType_PAE, &PAEEnabled);
557 if (details == VMINFO_MACHINEREADABLE)
558 RTPrintf("pae=\"%s\"\n", PAEEnabled ? "on" : "off");
559 else
560 RTPrintf("PAE: %s\n", PAEEnabled ? "on" : "off");
561
562 LONG64 timeOffset;
563 biosSettings->COMGETTER(TimeOffset)(&timeOffset);
564 if (details == VMINFO_MACHINEREADABLE)
565 RTPrintf("biossystemtimeoffset=%lld\n", timeOffset);
566 else
567 RTPrintf("Time offset: %lld ms\n", timeOffset);
568
569 BOOL RTCUseUTC;
570 machine->COMGETTER(RTCUseUTC)(&RTCUseUTC);
571 if (details == VMINFO_MACHINEREADABLE)
572 RTPrintf("rtcuseutc=\"%s\"\n", RTCUseUTC ? "on" : "off");
573 else
574 RTPrintf("RTC: %s\n", RTCUseUTC ? "UTC" : "local time");
575
576 BOOL hwVirtExEnabled;
577 machine->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &hwVirtExEnabled);
578 if (details == VMINFO_MACHINEREADABLE)
579 RTPrintf("hwvirtex=\"%s\"\n", hwVirtExEnabled ? "on" : "off");
580 else
581 RTPrintf("Hardw. virt.ext: %s\n", hwVirtExEnabled ? "on" : "off");
582
583 BOOL hwVirtExExclusive;
584 machine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &hwVirtExExclusive);
585 if (details == VMINFO_MACHINEREADABLE)
586 RTPrintf("hwvirtexexcl=\"%s\"\n", hwVirtExExclusive ? "on" : "off");
587 else
588 RTPrintf("Hardw. virt.ext exclusive: %s\n", hwVirtExExclusive ? "on" : "off");
589
590 BOOL HWVirtExNestedPagingEnabled;
591 machine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &HWVirtExNestedPagingEnabled);
592 if (details == VMINFO_MACHINEREADABLE)
593 RTPrintf("nestedpaging=\"%s\"\n", HWVirtExNestedPagingEnabled ? "on" : "off");
594 else
595 RTPrintf("Nested Paging: %s\n", HWVirtExNestedPagingEnabled ? "on" : "off");
596
597 BOOL HWVirtExLargePagesEnabled;
598 machine->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &HWVirtExLargePagesEnabled);
599 if (details == VMINFO_MACHINEREADABLE)
600 RTPrintf("largepages=\"%s\"\n", HWVirtExLargePagesEnabled ? "on" : "off");
601 else
602 RTPrintf("Large Pages: %s\n", HWVirtExLargePagesEnabled ? "on" : "off");
603
604 BOOL HWVirtExVPIDEnabled;
605 machine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &HWVirtExVPIDEnabled);
606 if (details == VMINFO_MACHINEREADABLE)
607 RTPrintf("vtxvpid=\"%s\"\n", HWVirtExVPIDEnabled ? "on" : "off");
608 else
609 RTPrintf("VT-x VPID: %s\n", HWVirtExVPIDEnabled ? "on" : "off");
610
611 MachineState_T machineState;
612 rc = machine->COMGETTER(State)(&machineState);
613 const char *pszState = machineStateToName(machineState, details == VMINFO_MACHINEREADABLE /*=fShort*/);
614
615 LONG64 stateSince;
616 machine->COMGETTER(LastStateChange)(&stateSince);
617 RTTIMESPEC timeSpec;
618 RTTimeSpecSetMilli(&timeSpec, stateSince);
619 char pszTime[30] = {0};
620 RTTimeSpecToString(&timeSpec, pszTime, sizeof(pszTime));
621 Bstr stateFile;
622 machine->COMGETTER(StateFilePath)(stateFile.asOutParam());
623 if (details == VMINFO_MACHINEREADABLE)
624 {
625 RTPrintf("VMState=\"%s\"\n", pszState);
626 RTPrintf("VMStateChangeTime=\"%s\"\n", pszTime);
627 if (!stateFile.isEmpty())
628 RTPrintf("VMStateFile=\"%ls\"\n", stateFile.raw());
629 }
630 else
631 RTPrintf("State: %s (since %s)\n", pszState, pszTime);
632
633 ULONG numMonitors;
634 machine->COMGETTER(MonitorCount)(&numMonitors);
635 if (details == VMINFO_MACHINEREADABLE)
636 RTPrintf("monitorcount=%d\n", numMonitors);
637 else
638 RTPrintf("Monitor count: %d\n", numMonitors);
639
640 BOOL accelerate3d;
641 machine->COMGETTER(Accelerate3DEnabled)(&accelerate3d);
642 if (details == VMINFO_MACHINEREADABLE)
643 RTPrintf("accelerate3d=\"%s\"\n", accelerate3d ? "on" : "off");
644 else
645 RTPrintf("3D Acceleration: %s\n", accelerate3d ? "on" : "off");
646
647#ifdef VBOX_WITH_VIDEOHWACCEL
648 BOOL accelerate2dVideo;
649 machine->COMGETTER(Accelerate2DVideoEnabled)(&accelerate2dVideo);
650 if (details == VMINFO_MACHINEREADABLE)
651 RTPrintf("accelerate2dvideo=\"%s\"\n", accelerate2dVideo ? "on" : "off");
652 else
653 RTPrintf("2D Video Acceleration: %s\n", accelerate2dVideo ? "on" : "off");
654#endif
655
656 BOOL teleporterEnabled;
657 machine->COMGETTER(TeleporterEnabled)(&teleporterEnabled);
658 if (details == VMINFO_MACHINEREADABLE)
659 RTPrintf("teleporterenabled=\"%s\"\n", teleporterEnabled ? "on" : "off");
660 else
661 RTPrintf("Teleporter Enabled: %s\n", teleporterEnabled ? "on" : "off");
662
663 ULONG teleporterPort;
664 machine->COMGETTER(TeleporterPort)(&teleporterPort);
665 if (details == VMINFO_MACHINEREADABLE)
666 RTPrintf("teleporterport=%u\n", teleporterPort);
667 else
668 RTPrintf("Teleporter Port: %u\n", teleporterPort);
669
670 Bstr teleporterAddress;
671 machine->COMGETTER(TeleporterAddress)(teleporterAddress.asOutParam());
672 if (details == VMINFO_MACHINEREADABLE)
673 RTPrintf("teleporteraddress=\"%ls\"\n", teleporterAddress.raw());
674 else
675 RTPrintf("Teleporter Address: %ls\n", teleporterAddress.raw());
676
677 Bstr teleporterPassword;
678 machine->COMGETTER(TeleporterPassword)(teleporterPassword.asOutParam());
679 if (details == VMINFO_MACHINEREADABLE)
680 RTPrintf("teleporterpassword=\"%ls\"\n", teleporterPassword.raw());
681 else
682 RTPrintf("Teleporter Password: %ls\n", teleporterPassword.raw());
683
684 /*
685 * Storage Controllers and their attached Mediums.
686 */
687 com::SafeIfaceArray<IStorageController> storageCtls;
688 CHECK_ERROR(machine, COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(storageCtls)));
689 for (size_t i = 0; i < storageCtls.size(); ++ i)
690 {
691 ComPtr<IStorageController> storageCtl = storageCtls[i];
692 StorageControllerType_T enmCtlType = StorageControllerType_Null;
693 const char *pszCtl = NULL;
694 ULONG ulValue = 0;
695 BOOL fBootable = FALSE;
696 Bstr storageCtlName;
697
698 storageCtl->COMGETTER(Name)(storageCtlName.asOutParam());
699 if (details == VMINFO_MACHINEREADABLE)
700 RTPrintf("storagecontrollername%u=\"%ls\"\n", i, storageCtlName.raw());
701 else
702 RTPrintf("Storage Controller Name (%u): %ls\n", i, storageCtlName.raw());
703
704 storageCtl->COMGETTER(ControllerType)(&enmCtlType);
705 switch (enmCtlType)
706 {
707 case StorageControllerType_LsiLogic:
708 pszCtl = "LsiLogic";
709 break;
710 case StorageControllerType_BusLogic:
711 pszCtl = "BusLogic";
712 break;
713 case StorageControllerType_IntelAhci:
714 pszCtl = "IntelAhci";
715 break;
716 case StorageControllerType_PIIX3:
717 pszCtl = "PIIX3";
718 break;
719 case StorageControllerType_PIIX4:
720 pszCtl = "PIIX4";
721 break;
722 case StorageControllerType_ICH6:
723 pszCtl = "ICH6";
724 break;
725 case StorageControllerType_I82078:
726 pszCtl = "I82078";
727 break;
728
729 default:
730 pszCtl = "unknown";
731 }
732 if (details == VMINFO_MACHINEREADABLE)
733 RTPrintf("storagecontrollertype%u=\"%s\"\n", i, pszCtl);
734 else
735 RTPrintf("Storage Controller Type (%u): %s\n", i, pszCtl);
736
737 storageCtl->COMGETTER(Instance)(&ulValue);
738 if (details == VMINFO_MACHINEREADABLE)
739 RTPrintf("storagecontrollerinstance%u=\"%lu\"\n", i, ulValue);
740 else
741 RTPrintf("Storage Controller Instance Number (%u): %lu\n", i, ulValue);
742
743 storageCtl->COMGETTER(MaxPortCount)(&ulValue);
744 if (details == VMINFO_MACHINEREADABLE)
745 RTPrintf("storagecontrollermaxportcount%u=\"%lu\"\n", i, ulValue);
746 else
747 RTPrintf("Storage Controller Max Port Count (%u): %lu\n", i, ulValue);
748
749 storageCtl->COMGETTER(PortCount)(&ulValue);
750 if (details == VMINFO_MACHINEREADABLE)
751 RTPrintf("storagecontrollerportcount%u=\"%lu\"\n", i, ulValue);
752 else
753 RTPrintf("Storage Controller Port Count (%u): %lu\n", i, ulValue);
754
755 storageCtl->COMGETTER(Bootable)(&fBootable);
756 if (details == VMINFO_MACHINEREADABLE)
757 RTPrintf("storagecontrollerbootable%u=\"%s\"\n", i, fBootable ? "on" : "off");
758 else
759 RTPrintf("Storage Controller Bootable (%u): %s\n", i, fBootable ? "on" : "off");
760 }
761
762 for (size_t j = 0; j < storageCtls.size(); ++ j)
763 {
764 ComPtr<IStorageController> storageCtl = storageCtls[j];
765 ComPtr<IMedium> medium;
766 Bstr storageCtlName;
767 Bstr filePath;
768 ULONG cDevices;
769 ULONG cPorts;
770
771 storageCtl->COMGETTER(Name)(storageCtlName.asOutParam());
772 storageCtl->COMGETTER(MaxDevicesPerPortCount)(&cDevices);
773 storageCtl->COMGETTER(PortCount)(&cPorts);
774
775 for (ULONG i = 0; i < cPorts; ++ i)
776 {
777 for (ULONG k = 0; k < cDevices; ++ k)
778 {
779 ComPtr<IMediumAttachment> mediumAttach;
780 machine->GetMediumAttachment(storageCtlName.raw(),
781 i, k,
782 mediumAttach.asOutParam());
783 BOOL fIsEjected = FALSE;
784 BOOL fTempEject = FALSE;
785 DeviceType_T devType = DeviceType_Null;
786 if (mediumAttach)
787 {
788 mediumAttach->COMGETTER(TemporaryEject)(&fTempEject);
789 mediumAttach->COMGETTER(IsEjected)(&fIsEjected);
790 mediumAttach->COMGETTER(Type)(&devType);
791 }
792 rc = machine->GetMedium(storageCtlName.raw(), i, k,
793 medium.asOutParam());
794 if (SUCCEEDED(rc) && medium)
795 {
796 BOOL fPassthrough = FALSE;
797
798 if (mediumAttach)
799 mediumAttach->COMGETTER(Passthrough)(&fPassthrough);
800
801 medium->COMGETTER(Location)(filePath.asOutParam());
802 medium->COMGETTER(Id)(uuid.asOutParam());
803
804 if (details == VMINFO_MACHINEREADABLE)
805 {
806 RTPrintf("\"%ls-%d-%d\"=\"%ls\"\n", storageCtlName.raw(),
807 i, k, filePath.raw());
808 RTPrintf("\"%ls-ImageUUID-%d-%d\"=\"%s\"\n",
809 storageCtlName.raw(), i, k, Utf8Str(uuid).c_str());
810 if (fPassthrough)
811 RTPrintf("\"%ls-dvdpassthrough\"=\"%s\"\n", storageCtlName.raw(),
812 fPassthrough ? "on" : "off");
813 if (devType == DeviceType_DVD)
814 {
815 RTPrintf("\"%ls-tempeject\"=\"%s\"\n", storageCtlName.raw(),
816 fTempEject ? "on" : "off");
817 RTPrintf("\"%ls-IsEjected\"=\"%s\"\n", storageCtlName.raw(),
818 fIsEjected ? "on" : "off");
819 }
820 }
821 else
822 {
823 RTPrintf("%ls (%d, %d): %ls (UUID: %s)",
824 storageCtlName.raw(), i, k, filePath.raw(),
825 Utf8Str(uuid).c_str());
826 if (fPassthrough)
827 RTPrintf(" (passthrough enabled)");
828 if (fTempEject)
829 RTPrintf(" (temp eject)");
830 if (fIsEjected)
831 RTPrintf(" (ejected)");
832 RTPrintf("\n");
833 }
834 }
835 else if (SUCCEEDED(rc))
836 {
837 if (details == VMINFO_MACHINEREADABLE)
838 {
839 RTPrintf("\"%ls-%d-%d\"=\"emptydrive\"\n", storageCtlName.raw(), i, k);
840 if (devType == DeviceType_DVD)
841 RTPrintf("\"%ls-IsEjected\"=\"%s\"\n", storageCtlName.raw(),
842 fIsEjected ? "on" : "off");
843 }
844 else
845 {
846 RTPrintf("%ls (%d, %d): Empty", storageCtlName.raw(), i, k);
847 if (fTempEject)
848 RTPrintf(" (temp eject)");
849 if (fIsEjected)
850 RTPrintf(" (ejected)");
851 RTPrintf("\n");
852 }
853 }
854 else
855 {
856 if (details == VMINFO_MACHINEREADABLE)
857 RTPrintf("\"%ls-%d-%d\"=\"none\"\n", storageCtlName.raw(), i, k);
858 }
859 }
860 }
861 }
862
863 /* get the maximum amount of NICS */
864 ULONG maxNICs = getMaxNics(virtualBox, machine);
865
866 for (ULONG currentNIC = 0; currentNIC < maxNICs; currentNIC++)
867 {
868 ComPtr<INetworkAdapter> nic;
869 rc = machine->GetNetworkAdapter(currentNIC, nic.asOutParam());
870 if (SUCCEEDED(rc) && nic)
871 {
872 BOOL fEnabled;
873 nic->COMGETTER(Enabled)(&fEnabled);
874 if (!fEnabled)
875 {
876 if (details == VMINFO_MACHINEREADABLE)
877 RTPrintf("nic%d=\"none\"\n", currentNIC + 1);
878 else
879 RTPrintf("NIC %d: disabled\n", currentNIC + 1);
880 }
881 else
882 {
883 Bstr strMACAddress;
884 nic->COMGETTER(MACAddress)(strMACAddress.asOutParam());
885 Utf8Str strAttachment;
886 Utf8Str strNatSettings = "";
887 Utf8Str strNatForwardings = "";
888 NetworkAttachmentType_T attachment;
889 nic->COMGETTER(AttachmentType)(&attachment);
890 switch (attachment)
891 {
892 case NetworkAttachmentType_Null:
893 if (details == VMINFO_MACHINEREADABLE)
894 strAttachment = "null";
895 else
896 strAttachment = "none";
897 break;
898
899 case NetworkAttachmentType_NAT:
900 {
901 Bstr strNetwork;
902 ComPtr<INATEngine> driver;
903 nic->COMGETTER(NatDriver)(driver.asOutParam());
904 driver->COMGETTER(Network)(strNetwork.asOutParam());
905 com::SafeArray<BSTR> forwardings;
906 driver->COMGETTER(Redirects)(ComSafeArrayAsOutParam(forwardings));
907 strNatForwardings = "";
908 for (size_t i = 0; i < forwardings.size(); ++i)
909 {
910 bool fSkip = false;
911 uint16_t port = 0;
912 BSTR r = forwardings[i];
913 Utf8Str utf = Utf8Str(r);
914 Utf8Str strName;
915 Utf8Str strProto;
916 Utf8Str strHostPort;
917 Utf8Str strHostIP;
918 Utf8Str strGuestPort;
919 Utf8Str strGuestIP;
920 size_t pos, ppos;
921 pos = ppos = 0;
922 #define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \
923 do { \
924 pos = str.find(",", ppos); \
925 if (pos == Utf8Str::npos) \
926 { \
927 Log(( #res " extracting from %s is failed\n", str.c_str())); \
928 fSkip = true; \
929 } \
930 res = str.substr(ppos, pos - ppos); \
931 Log2((#res " %s pos:%d, ppos:%d\n", res.c_str(), pos, ppos)); \
932 ppos = pos + 1; \
933 } while (0)
934 ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos);
935 if (fSkip) continue;
936 ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos);
937 if (fSkip) continue;
938 ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos);
939 if (fSkip) continue;
940 ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos);
941 if (fSkip) continue;
942 ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos);
943 if (fSkip) continue;
944 strGuestPort = utf.substr(ppos, utf.length() - ppos);
945 #undef ITERATE_TO_NEXT_TERM
946 switch (strProto.toUInt32())
947 {
948 case NATProtocol_TCP:
949 strProto = "tcp";
950 break;
951 case NATProtocol_UDP:
952 strProto = "udp";
953 break;
954 default:
955 strProto = "unk";
956 break;
957 }
958 if (details == VMINFO_MACHINEREADABLE)
959 {
960 strNatForwardings = Utf8StrFmt("%sForwarding(%d)=\"%s,%s,%s,%s,%s,%s\"\n",
961 strNatForwardings.c_str(), i, strName.c_str(), strProto.c_str(),
962 strHostIP.c_str(), strHostPort.c_str(),
963 strGuestIP.c_str(), strGuestPort.c_str());
964 }
965 else
966 {
967 strNatForwardings = Utf8StrFmt("%sNIC %d Rule(%d): name = %s, protocol = %s,"
968 " host ip = %s, host port = %s, guest ip = %s, guest port = %s\n",
969 strNatForwardings.c_str(), currentNIC + 1, i, strName.c_str(), strProto.c_str(),
970 strHostIP.c_str(), strHostPort.c_str(),
971 strGuestIP.c_str(), strGuestPort.c_str());
972 }
973 }
974 ULONG mtu = 0;
975 ULONG sockSnd = 0;
976 ULONG sockRcv = 0;
977 ULONG tcpSnd = 0;
978 ULONG tcpRcv = 0;
979 driver->GetNetworkSettings(&mtu, &sockSnd, &sockRcv, &tcpSnd, &tcpRcv);
980
981 if (details == VMINFO_MACHINEREADABLE)
982 {
983 RTPrintf("natnet%d=\"%ls\"\n", currentNIC + 1, strNetwork.length() ? strNetwork.raw(): Bstr("nat").raw());
984 strAttachment = "nat";
985 strNatSettings = Utf8StrFmt("mtu=\"%d\"\nsockSnd=\"%d\"\nsockRcv=\"%d\"\ntcpWndSnd=\"%d\"\ntcpWndRcv=\"%d\"\n",
986 mtu, sockSnd ? sockSnd : 64, sockRcv ? sockRcv : 64 , tcpSnd ? tcpSnd : 64, tcpRcv ? tcpRcv : 64);
987 }
988 else
989 {
990 strAttachment = "NAT";
991 strNatSettings = Utf8StrFmt("NIC %d Settings: MTU: %d, Socket (send: %d, receive: %d), TCP Window (send:%d, receive: %d)\n",
992 currentNIC + 1, mtu, sockSnd ? sockSnd : 64, sockRcv ? sockRcv : 64 , tcpSnd ? tcpSnd : 64, tcpRcv ? tcpRcv : 64);
993 }
994 break;
995 }
996
997 case NetworkAttachmentType_Bridged:
998 {
999 Bstr strBridgeAdp;
1000 nic->COMGETTER(BridgedInterface)(strBridgeAdp.asOutParam());
1001 if (details == VMINFO_MACHINEREADABLE)
1002 {
1003 RTPrintf("bridgeadapter%d=\"%ls\"\n", currentNIC + 1, strBridgeAdp.raw());
1004 strAttachment = "bridged";
1005 }
1006 else
1007 strAttachment = Utf8StrFmt("Bridged Interface '%ls'", strBridgeAdp.raw());
1008 break;
1009 }
1010
1011 case NetworkAttachmentType_Internal:
1012 {
1013 Bstr strNetwork;
1014 nic->COMGETTER(InternalNetwork)(strNetwork.asOutParam());
1015 if (details == VMINFO_MACHINEREADABLE)
1016 {
1017 RTPrintf("intnet%d=\"%ls\"\n", currentNIC + 1, strNetwork.raw());
1018 strAttachment = "intnet";
1019 }
1020 else
1021 strAttachment = Utf8StrFmt("Internal Network '%s'", Utf8Str(strNetwork).c_str());
1022 break;
1023 }
1024
1025 case NetworkAttachmentType_HostOnly:
1026 {
1027 Bstr strHostonlyAdp;
1028 nic->COMGETTER(HostOnlyInterface)(strHostonlyAdp.asOutParam());
1029 if (details == VMINFO_MACHINEREADABLE)
1030 {
1031 RTPrintf("hostonlyadapter%d=\"%ls\"\n", currentNIC + 1, strHostonlyAdp.raw());
1032 strAttachment = "hostonly";
1033 }
1034 else
1035 strAttachment = Utf8StrFmt("Host-only Interface '%ls'", strHostonlyAdp.raw());
1036 break;
1037 }
1038 case NetworkAttachmentType_Generic:
1039 {
1040 Bstr strGenericDriver;
1041 nic->COMGETTER(GenericDriver)(strGenericDriver.asOutParam());
1042 if (details == VMINFO_MACHINEREADABLE)
1043 {
1044 RTPrintf("generic%d=\"%ls\"\n", currentNIC + 1, strGenericDriver.raw());
1045 strAttachment = "Generic";
1046 }
1047 else
1048 {
1049 strAttachment = Utf8StrFmt("Generic '%ls'", strGenericDriver.raw());
1050
1051 // show the generic properties
1052 com::SafeArray<BSTR> aProperties;
1053 com::SafeArray<BSTR> aValues;
1054 rc = nic->GetProperties(NULL,
1055 ComSafeArrayAsOutParam(aProperties),
1056 ComSafeArrayAsOutParam(aValues));
1057 if (SUCCEEDED(rc))
1058 {
1059 strAttachment += " { ";
1060 for (unsigned i = 0; i < aProperties.size(); ++i)
1061 strAttachment += Utf8StrFmt(!i ? "%ls='%ls'" : ", %ls='%ls'",
1062 aProperties[i], aValues[i]);
1063 strAttachment += " }";
1064 }
1065 }
1066 break;
1067 }
1068 default:
1069 strAttachment = "unknown";
1070 break;
1071 }
1072
1073 /* cable connected */
1074 BOOL fConnected;
1075 nic->COMGETTER(CableConnected)(&fConnected);
1076
1077 /* promisc policy */
1078 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
1079 CHECK_ERROR2_RET(nic, COMGETTER(PromiscModePolicy)(&enmPromiscModePolicy), hrcCheck);
1080 const char *pszPromiscuousGuestPolicy;
1081 switch (enmPromiscModePolicy)
1082 {
1083 case NetworkAdapterPromiscModePolicy_Deny: pszPromiscuousGuestPolicy = "deny"; break;
1084 case NetworkAdapterPromiscModePolicy_AllowNetwork: pszPromiscuousGuestPolicy = "allow-vms"; break;
1085 case NetworkAdapterPromiscModePolicy_AllowAll: pszPromiscuousGuestPolicy = "allow-all"; break;
1086 default: AssertFailedReturn(VERR_INTERNAL_ERROR_4);
1087 }
1088
1089 /* trace stuff */
1090 BOOL fTraceEnabled;
1091 nic->COMGETTER(TraceEnabled)(&fTraceEnabled);
1092 Bstr traceFile;
1093 nic->COMGETTER(TraceFile)(traceFile.asOutParam());
1094
1095 /* NIC type */
1096 NetworkAdapterType_T NICType;
1097 nic->COMGETTER(AdapterType)(&NICType);
1098 const char *pszNICType;
1099 switch (NICType)
1100 {
1101 case NetworkAdapterType_Am79C970A: pszNICType = "Am79C970A"; break;
1102 case NetworkAdapterType_Am79C973: pszNICType = "Am79C973"; break;
1103#ifdef VBOX_WITH_E1000
1104 case NetworkAdapterType_I82540EM: pszNICType = "82540EM"; break;
1105 case NetworkAdapterType_I82543GC: pszNICType = "82543GC"; break;
1106 case NetworkAdapterType_I82545EM: pszNICType = "82545EM"; break;
1107#endif
1108#ifdef VBOX_WITH_VIRTIO
1109 case NetworkAdapterType_Virtio: pszNICType = "virtio"; break;
1110#endif
1111 default: AssertFailed(); pszNICType = "unknown"; break;
1112 }
1113
1114 /* reported line speed */
1115 ULONG ulLineSpeed;
1116 nic->COMGETTER(LineSpeed)(&ulLineSpeed);
1117
1118 /* boot priority of the adapter */
1119 ULONG ulBootPriority;
1120 nic->COMGETTER(BootPriority)(&ulBootPriority);
1121
1122 if (details == VMINFO_MACHINEREADABLE)
1123 {
1124 RTPrintf("macaddress%d=\"%ls\"\n", currentNIC + 1, strMACAddress.raw());
1125 RTPrintf("cableconnected%d=\"%s\"\n", currentNIC + 1, fConnected ? "on" : "off");
1126 RTPrintf("nic%d=\"%s\"\n", currentNIC + 1, strAttachment.c_str());
1127 }
1128 else
1129 RTPrintf("NIC %u: MAC: %ls, Attachment: %s, Cable connected: %s, Trace: %s (file: %ls), Type: %s, Reported speed: %d Mbps, Boot priority: %d, Promisc Policy: %s\n",
1130 currentNIC + 1, strMACAddress.raw(), strAttachment.c_str(),
1131 fConnected ? "on" : "off",
1132 fTraceEnabled ? "on" : "off",
1133 traceFile.isEmpty() ? Bstr("none").raw() : traceFile.raw(),
1134 pszNICType,
1135 ulLineSpeed / 1000,
1136 (int)ulBootPriority,
1137 pszPromiscuousGuestPolicy);
1138 if (strNatSettings.length())
1139 RTPrintf(strNatSettings.c_str());
1140 if (strNatForwardings.length())
1141 RTPrintf(strNatForwardings.c_str());
1142 }
1143 }
1144 }
1145
1146 /* Pointing device information */
1147 PointingHidType_T aPointingHid;
1148 const char *pszHid = "Unknown";
1149 const char *pszMrHid = "unknown";
1150 machine->COMGETTER(PointingHidType)(&aPointingHid);
1151 switch (aPointingHid)
1152 {
1153 case PointingHidType_None:
1154 pszHid = "None";
1155 pszMrHid = "none";
1156 break;
1157 case PointingHidType_PS2Mouse:
1158 pszHid = "PS/2 Mouse";
1159 pszMrHid = "ps2mouse";
1160 break;
1161 case PointingHidType_USBMouse:
1162 pszHid = "USB Mouse";
1163 pszMrHid = "usbmouse";
1164 break;
1165 case PointingHidType_USBTablet:
1166 pszHid = "USB Tablet";
1167 pszMrHid = "usbtablet";
1168 break;
1169 case PointingHidType_ComboMouse:
1170 pszHid = "USB Tablet and PS/2 Mouse";
1171 pszMrHid = "combomouse";
1172 break;
1173 default:
1174 break;
1175 }
1176 if (details == VMINFO_MACHINEREADABLE)
1177 RTPrintf("hidpointing=\"%s\"\n", pszMrHid);
1178 else
1179 RTPrintf("Pointing Device: %s\n", pszHid);
1180
1181 /* Keyboard device information */
1182 KeyboardHidType_T aKeyboardHid;
1183 machine->COMGETTER(KeyboardHidType)(&aKeyboardHid);
1184 pszHid = "Unknown";
1185 pszMrHid = "unknown";
1186 switch (aKeyboardHid)
1187 {
1188 case KeyboardHidType_None:
1189 pszHid = "None";
1190 pszMrHid = "none";
1191 break;
1192 case KeyboardHidType_PS2Keyboard:
1193 pszHid = "PS/2 Keyboard";
1194 pszMrHid = "ps2kbd";
1195 break;
1196 case KeyboardHidType_USBKeyboard:
1197 pszHid = "USB Keyboard";
1198 pszMrHid = "usbkbd";
1199 break;
1200 case KeyboardHidType_ComboKeyboard:
1201 pszHid = "USB and PS/2 Keyboard";
1202 pszMrHid = "combokbd";
1203 break;
1204 default:
1205 break;
1206 }
1207 if (details == VMINFO_MACHINEREADABLE)
1208 RTPrintf("hidkeyboard=\"%s\"\n", pszMrHid);
1209 else
1210 RTPrintf("Keyboard Device: %s\n", pszHid);
1211
1212 /* get the maximum amount of UARTs */
1213 ComPtr<ISystemProperties> sysProps;
1214 virtualBox->COMGETTER(SystemProperties)(sysProps.asOutParam());
1215
1216 ULONG maxUARTs = 0;
1217 sysProps->COMGETTER(SerialPortCount)(&maxUARTs);
1218 for (ULONG currentUART = 0; currentUART < maxUARTs; currentUART++)
1219 {
1220 ComPtr<ISerialPort> uart;
1221 rc = machine->GetSerialPort(currentUART, uart.asOutParam());
1222 if (SUCCEEDED(rc) && uart)
1223 {
1224 BOOL fEnabled;
1225 uart->COMGETTER(Enabled)(&fEnabled);
1226 if (!fEnabled)
1227 {
1228 if (details == VMINFO_MACHINEREADABLE)
1229 RTPrintf("uart%d=\"off\"\n", currentUART + 1);
1230 else
1231 RTPrintf("UART %d: disabled\n", currentUART + 1);
1232 }
1233 else
1234 {
1235 ULONG ulIRQ, ulIOBase;
1236 PortMode_T HostMode;
1237 Bstr path;
1238 BOOL fServer;
1239 uart->COMGETTER(IRQ)(&ulIRQ);
1240 uart->COMGETTER(IOBase)(&ulIOBase);
1241 uart->COMGETTER(Path)(path.asOutParam());
1242 uart->COMGETTER(Server)(&fServer);
1243 uart->COMGETTER(HostMode)(&HostMode);
1244
1245 if (details == VMINFO_MACHINEREADABLE)
1246 RTPrintf("uart%d=\"%#06x,%d\"\n", currentUART + 1,
1247 ulIOBase, ulIRQ);
1248 else
1249 RTPrintf("UART %d: I/O base: %#06x, IRQ: %d",
1250 currentUART + 1, ulIOBase, ulIRQ);
1251 switch (HostMode)
1252 {
1253 default:
1254 case PortMode_Disconnected:
1255 if (details == VMINFO_MACHINEREADABLE)
1256 RTPrintf("uartmode%d=\"disconnected\"\n", currentUART + 1);
1257 else
1258 RTPrintf(", disconnected\n");
1259 break;
1260 case PortMode_RawFile:
1261 if (details == VMINFO_MACHINEREADABLE)
1262 RTPrintf("uartmode%d=\"%ls\"\n", currentUART + 1,
1263 path.raw());
1264 else
1265 RTPrintf(", attached to raw file '%ls'\n",
1266 path.raw());
1267 break;
1268 case PortMode_HostPipe:
1269 if (details == VMINFO_MACHINEREADABLE)
1270 RTPrintf("uartmode%d=\"%s,%ls\"\n", currentUART + 1,
1271 fServer ? "server" : "client", path.raw());
1272 else
1273 RTPrintf(", attached to pipe (%s) '%ls'\n",
1274 fServer ? "server" : "client", path.raw());
1275 break;
1276 case PortMode_HostDevice:
1277 if (details == VMINFO_MACHINEREADABLE)
1278 RTPrintf("uartmode%d=\"%ls\"\n", currentUART + 1,
1279 path.raw());
1280 else
1281 RTPrintf(", attached to device '%ls'\n", path.raw());
1282 break;
1283 }
1284 }
1285 }
1286 }
1287
1288 ComPtr<IAudioAdapter> AudioAdapter;
1289 rc = machine->COMGETTER(AudioAdapter)(AudioAdapter.asOutParam());
1290 if (SUCCEEDED(rc))
1291 {
1292 const char *pszDrv = "Unknown";
1293 const char *pszCtrl = "Unknown";
1294 BOOL fEnabled;
1295 rc = AudioAdapter->COMGETTER(Enabled)(&fEnabled);
1296 if (SUCCEEDED(rc) && fEnabled)
1297 {
1298 AudioDriverType_T enmDrvType;
1299 rc = AudioAdapter->COMGETTER(AudioDriver)(&enmDrvType);
1300 switch (enmDrvType)
1301 {
1302 case AudioDriverType_Null:
1303 if (details == VMINFO_MACHINEREADABLE)
1304 pszDrv = "null";
1305 else
1306 pszDrv = "Null";
1307 break;
1308 case AudioDriverType_WinMM:
1309 if (details == VMINFO_MACHINEREADABLE)
1310 pszDrv = "winmm";
1311 else
1312 pszDrv = "WINMM";
1313 break;
1314 case AudioDriverType_DirectSound:
1315 if (details == VMINFO_MACHINEREADABLE)
1316 pszDrv = "dsound";
1317 else
1318 pszDrv = "DSOUND";
1319 break;
1320 case AudioDriverType_OSS:
1321 if (details == VMINFO_MACHINEREADABLE)
1322 pszDrv = "oss";
1323 else
1324 pszDrv = "OSS";
1325 break;
1326 case AudioDriverType_ALSA:
1327 if (details == VMINFO_MACHINEREADABLE)
1328 pszDrv = "alsa";
1329 else
1330 pszDrv = "ALSA";
1331 break;
1332 case AudioDriverType_Pulse:
1333 if (details == VMINFO_MACHINEREADABLE)
1334 pszDrv = "pulse";
1335 else
1336 pszDrv = "PulseAudio";
1337 break;
1338 case AudioDriverType_CoreAudio:
1339 if (details == VMINFO_MACHINEREADABLE)
1340 pszDrv = "coreaudio";
1341 else
1342 pszDrv = "CoreAudio";
1343 break;
1344 case AudioDriverType_SolAudio:
1345 if (details == VMINFO_MACHINEREADABLE)
1346 pszDrv = "solaudio";
1347 else
1348 pszDrv = "SolAudio";
1349 break;
1350 default:
1351 if (details == VMINFO_MACHINEREADABLE)
1352 pszDrv = "unknown";
1353 break;
1354 }
1355 AudioControllerType_T enmCtrlType;
1356 rc = AudioAdapter->COMGETTER(AudioController)(&enmCtrlType);
1357 switch (enmCtrlType)
1358 {
1359 case AudioControllerType_AC97:
1360 if (details == VMINFO_MACHINEREADABLE)
1361 pszCtrl = "ac97";
1362 else
1363 pszCtrl = "AC97";
1364 break;
1365 case AudioControllerType_SB16:
1366 if (details == VMINFO_MACHINEREADABLE)
1367 pszCtrl = "sb16";
1368 else
1369 pszCtrl = "SB16";
1370 break;
1371 case AudioControllerType_HDA:
1372 if (details == VMINFO_MACHINEREADABLE)
1373 pszCtrl = "hda";
1374 else
1375 pszCtrl = "HDA";
1376 break;
1377 }
1378 }
1379 else
1380 fEnabled = FALSE;
1381 if (details == VMINFO_MACHINEREADABLE)
1382 {
1383 if (fEnabled)
1384 RTPrintf("audio=\"%s\"\n", pszDrv);
1385 else
1386 RTPrintf("audio=\"none\"\n");
1387 }
1388 else
1389 {
1390 RTPrintf("Audio: %s",
1391 fEnabled ? "enabled" : "disabled");
1392 if (fEnabled)
1393 RTPrintf(" (Driver: %s, Controller: %s)",
1394 pszDrv, pszCtrl);
1395 RTPrintf("\n");
1396 }
1397 }
1398
1399 /* Shared clipboard */
1400 {
1401 const char *psz = "Unknown";
1402 ClipboardMode_T enmMode;
1403 rc = machine->COMGETTER(ClipboardMode)(&enmMode);
1404 switch (enmMode)
1405 {
1406 case ClipboardMode_Disabled:
1407 if (details == VMINFO_MACHINEREADABLE)
1408 psz = "disabled";
1409 else
1410 psz = "disabled";
1411 break;
1412 case ClipboardMode_HostToGuest:
1413 if (details == VMINFO_MACHINEREADABLE)
1414 psz = "hosttoguest";
1415 else
1416 psz = "HostToGuest";
1417 break;
1418 case ClipboardMode_GuestToHost:
1419 if (details == VMINFO_MACHINEREADABLE)
1420 psz = "guesttohost";
1421 else
1422 psz = "GuestToHost";
1423 break;
1424 case ClipboardMode_Bidirectional:
1425 if (details == VMINFO_MACHINEREADABLE)
1426 psz = "bidirectional";
1427 else
1428 psz = "Bidirectional";
1429 break;
1430 default:
1431 if (details == VMINFO_MACHINEREADABLE)
1432 psz = "unknown";
1433 break;
1434 }
1435 if (details == VMINFO_MACHINEREADABLE)
1436 RTPrintf("clipboard=\"%s\"\n", psz);
1437 else
1438 RTPrintf("Clipboard Mode: %s\n", psz);
1439 }
1440
1441 if (console)
1442 {
1443 do
1444 {
1445 ComPtr<IDisplay> display;
1446 rc = console->COMGETTER(Display)(display.asOutParam());
1447 if (rc == E_ACCESSDENIED)
1448 break; /* VM not powered up */
1449 if (FAILED(rc))
1450 {
1451 com::GlueHandleComError(console, "COMGETTER(Display)(display.asOutParam())", rc, __FILE__, __LINE__);
1452 return rc;
1453 }
1454 ULONG xRes, yRes, bpp;
1455 rc = display->GetScreenResolution(0, &xRes, &yRes, &bpp);
1456 if (rc == E_ACCESSDENIED)
1457 break; /* VM not powered up */
1458 if (FAILED(rc))
1459 {
1460 com::ErrorInfo info(display, COM_IIDOF(IDisplay));
1461 GluePrintErrorInfo(info);
1462 return rc;
1463 }
1464 if (details == VMINFO_MACHINEREADABLE)
1465 RTPrintf("VideoMode=\"%d,%d,%d\"\n", xRes, yRes, bpp);
1466 else
1467 RTPrintf("Video mode: %dx%dx%d\n", xRes, yRes, bpp);
1468 }
1469 while (0);
1470 }
1471
1472 /*
1473 * Remote Desktop
1474 */
1475 ComPtr<IVRDEServer> vrdeServer;
1476 rc = machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1477 if (SUCCEEDED(rc) && vrdeServer)
1478 {
1479 BOOL fEnabled = false;
1480 vrdeServer->COMGETTER(Enabled)(&fEnabled);
1481 if (fEnabled)
1482 {
1483 LONG currentPort = -1;
1484 Bstr ports;
1485 vrdeServer->GetVRDEProperty(Bstr("TCP/Ports").raw(), ports.asOutParam());
1486 Bstr address;
1487 vrdeServer->GetVRDEProperty(Bstr("TCP/Address").raw(), address.asOutParam());
1488 BOOL fMultiCon;
1489 vrdeServer->COMGETTER(AllowMultiConnection)(&fMultiCon);
1490 BOOL fReuseCon;
1491 vrdeServer->COMGETTER(ReuseSingleConnection)(&fReuseCon);
1492 Bstr videoChannel;
1493 vrdeServer->GetVRDEProperty(Bstr("VideoChannel/Enabled").raw(), videoChannel.asOutParam());
1494 BOOL fVideoChannel = (videoChannel.compare(Bstr("true"), Bstr::CaseInsensitive)== 0)
1495 || (videoChannel == "1");
1496 Bstr videoChannelQuality;
1497 vrdeServer->GetVRDEProperty(Bstr("VideoChannel/Quality").raw(), videoChannelQuality.asOutParam());
1498 AuthType_T authType;
1499 const char *strAuthType;
1500 vrdeServer->COMGETTER(AuthType)(&authType);
1501 switch (authType)
1502 {
1503 case AuthType_Null:
1504 strAuthType = "null";
1505 break;
1506 case AuthType_External:
1507 strAuthType = "external";
1508 break;
1509 case AuthType_Guest:
1510 strAuthType = "guest";
1511 break;
1512 default:
1513 strAuthType = "unknown";
1514 break;
1515 }
1516 if (console)
1517 {
1518 ComPtr<IVRDEServerInfo> vrdeServerInfo;
1519 CHECK_ERROR_RET(console, COMGETTER(VRDEServerInfo)(vrdeServerInfo.asOutParam()), rc);
1520 rc = vrdeServerInfo->COMGETTER(Port)(&currentPort);
1521 if (rc == E_ACCESSDENIED)
1522 {
1523 currentPort = -1; /* VM not powered up */
1524 }
1525 if (FAILED(rc))
1526 {
1527 com::ErrorInfo info(vrdeServerInfo, COM_IIDOF(IVRDEServerInfo));
1528 GluePrintErrorInfo(info);
1529 return rc;
1530 }
1531 }
1532 if (details == VMINFO_MACHINEREADABLE)
1533 {
1534 RTPrintf("vrde=\"on\"\n");
1535 RTPrintf("vrdeport=%d\n", currentPort);
1536 RTPrintf("vrdeports=\"%ls\"\n", ports.raw());
1537 RTPrintf("vrdeaddress=\"%ls\"\n", address.raw());
1538 RTPrintf("vrdeauthtype=\"%s\"\n", strAuthType);
1539 RTPrintf("vrdemulticon=\"%s\"\n", fMultiCon ? "on" : "off");
1540 RTPrintf("vrdereusecon=\"%s\"\n", fReuseCon ? "on" : "off");
1541 RTPrintf("vrdevideochannel=\"%s\"\n", fVideoChannel ? "on" : "off");
1542 if (fVideoChannel)
1543 RTPrintf("vrdevideochannelquality=\"%ls\"\n", videoChannelQuality.raw());
1544 }
1545 else
1546 {
1547 if (address.isEmpty())
1548 address = "0.0.0.0";
1549 RTPrintf("VRDE: enabled (Address %ls, Ports %ls, MultiConn: %s, ReuseSingleConn: %s, Authentication type: %s)\n", address.raw(), ports.raw(), fMultiCon ? "on" : "off", fReuseCon ? "on" : "off", strAuthType);
1550 if (console && currentPort != -1 && currentPort != 0)
1551 RTPrintf("VRDE port: %d\n", currentPort);
1552 if (fVideoChannel)
1553 RTPrintf("Video redirection: enabled (Quality %ls)\n", videoChannelQuality.raw());
1554 else
1555 RTPrintf("Video redirection: disabled\n");
1556 }
1557 com::SafeArray<BSTR> aProperties;
1558 if (SUCCEEDED(vrdeServer->COMGETTER(VRDEProperties)(ComSafeArrayAsOutParam(aProperties))))
1559 {
1560 unsigned i;
1561 for (i = 0; i < aProperties.size(); ++i)
1562 {
1563 Bstr value;
1564 vrdeServer->GetVRDEProperty(aProperties[i], value.asOutParam());
1565 if (details == VMINFO_MACHINEREADABLE)
1566 {
1567 if (value.isEmpty())
1568 RTPrintf("vrdeproperty[%ls]=<not set>\n", aProperties[i]);
1569 else
1570 RTPrintf("vrdeproperty[%ls]=\"%ls\"\n", aProperties[i], value.raw());
1571 }
1572 else
1573 {
1574 if (value.isEmpty())
1575 RTPrintf("VRDE property: %-10lS = <not set>\n", aProperties[i]);
1576 else
1577 RTPrintf("VRDE property: %-10lS = \"%ls\"\n", aProperties[i], value.raw());
1578 }
1579 }
1580 }
1581 }
1582 else
1583 {
1584 if (details == VMINFO_MACHINEREADABLE)
1585 RTPrintf("vrde=\"off\"\n");
1586 else
1587 RTPrintf("VRDE: disabled\n");
1588 }
1589 }
1590
1591 /*
1592 * USB.
1593 */
1594 ComPtr<IUSBController> USBCtl;
1595 rc = machine->COMGETTER(USBController)(USBCtl.asOutParam());
1596 if (SUCCEEDED(rc))
1597 {
1598 BOOL fEnabled;
1599 BOOL fEhciEnabled;
1600 rc = USBCtl->COMGETTER(Enabled)(&fEnabled);
1601 if (FAILED(rc))
1602 fEnabled = false;
1603 if (details == VMINFO_MACHINEREADABLE)
1604 RTPrintf("usb=\"%s\"\n", fEnabled ? "on" : "off");
1605 else
1606 RTPrintf("USB: %s\n", fEnabled ? "enabled" : "disabled");
1607
1608 rc = USBCtl->COMGETTER(EnabledEhci)(&fEhciEnabled);
1609 if (FAILED(rc))
1610 fEhciEnabled = false;
1611 if (details == VMINFO_MACHINEREADABLE)
1612 RTPrintf("ehci=\"%s\"\n", fEhciEnabled ? "on" : "off");
1613 else
1614 RTPrintf("EHCI: %s\n", fEhciEnabled ? "enabled" : "disabled");
1615
1616 SafeIfaceArray <IUSBDeviceFilter> Coll;
1617 rc = USBCtl->COMGETTER(DeviceFilters)(ComSafeArrayAsOutParam(Coll));
1618 if (SUCCEEDED(rc))
1619 {
1620 if (details != VMINFO_MACHINEREADABLE)
1621 RTPrintf("\nUSB Device Filters:\n\n");
1622
1623 if (Coll.size() == 0)
1624 {
1625 if (details != VMINFO_MACHINEREADABLE)
1626 RTPrintf("<none>\n\n");
1627 }
1628 else
1629 {
1630 for (size_t index = 0; index < Coll.size(); ++index)
1631 {
1632 ComPtr<IUSBDeviceFilter> DevPtr = Coll[index];
1633
1634 /* Query info. */
1635
1636 if (details != VMINFO_MACHINEREADABLE)
1637 RTPrintf("Index: %zu\n", index);
1638
1639 BOOL bActive = FALSE;
1640 CHECK_ERROR_RET(DevPtr, COMGETTER(Active)(&bActive), rc);
1641 if (details == VMINFO_MACHINEREADABLE)
1642 RTPrintf("USBFilterActive%zu=\"%s\"\n", index + 1, bActive ? "on" : "off");
1643 else
1644 RTPrintf("Active: %s\n", bActive ? "yes" : "no");
1645
1646 Bstr bstr;
1647 CHECK_ERROR_RET(DevPtr, COMGETTER(Name)(bstr.asOutParam()), rc);
1648 if (details == VMINFO_MACHINEREADABLE)
1649 RTPrintf("USBFilterName%zu=\"%ls\"\n", index + 1, bstr.raw());
1650 else
1651 RTPrintf("Name: %ls\n", bstr.raw());
1652 CHECK_ERROR_RET(DevPtr, COMGETTER(VendorId)(bstr.asOutParam()), rc);
1653 if (details == VMINFO_MACHINEREADABLE)
1654 RTPrintf("USBFilterVendorId%zu=\"%ls\"\n", index + 1, bstr.raw());
1655 else
1656 RTPrintf("VendorId: %ls\n", bstr.raw());
1657 CHECK_ERROR_RET(DevPtr, COMGETTER(ProductId)(bstr.asOutParam()), rc);
1658 if (details == VMINFO_MACHINEREADABLE)
1659 RTPrintf("USBFilterProductId%zu=\"%ls\"\n", index + 1, bstr.raw());
1660 else
1661 RTPrintf("ProductId: %ls\n", bstr.raw());
1662 CHECK_ERROR_RET(DevPtr, COMGETTER(Revision)(bstr.asOutParam()), rc);
1663 if (details == VMINFO_MACHINEREADABLE)
1664 RTPrintf("USBFilterRevision%zu=\"%ls\"\n", index + 1, bstr.raw());
1665 else
1666 RTPrintf("Revision: %ls\n", bstr.raw());
1667 CHECK_ERROR_RET(DevPtr, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1668 if (details == VMINFO_MACHINEREADABLE)
1669 RTPrintf("USBFilterManufacturer%zu=\"%ls\"\n", index + 1, bstr.raw());
1670 else
1671 RTPrintf("Manufacturer: %ls\n", bstr.raw());
1672 CHECK_ERROR_RET(DevPtr, COMGETTER(Product)(bstr.asOutParam()), rc);
1673 if (details == VMINFO_MACHINEREADABLE)
1674 RTPrintf("USBFilterProduct%zu=\"%ls\"\n", index + 1, bstr.raw());
1675 else
1676 RTPrintf("Product: %ls\n", bstr.raw());
1677 CHECK_ERROR_RET(DevPtr, COMGETTER(Remote)(bstr.asOutParam()), rc);
1678 if (details == VMINFO_MACHINEREADABLE)
1679 RTPrintf("USBFilterRemote%zu=\"%ls\"\n", index + 1, bstr.raw());
1680 else
1681 RTPrintf("Remote: %ls\n", bstr.raw());
1682 CHECK_ERROR_RET(DevPtr, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1683 if (details == VMINFO_MACHINEREADABLE)
1684 RTPrintf("USBFilterSerialNumber%zu=\"%ls\"\n", index + 1, bstr.raw());
1685 else
1686 RTPrintf("Serial Number: %ls\n", bstr.raw());
1687 if (details != VMINFO_MACHINEREADABLE)
1688 {
1689 ULONG fMaskedIfs;
1690 CHECK_ERROR_RET(DevPtr, COMGETTER(MaskedInterfaces)(&fMaskedIfs), rc);
1691 if (fMaskedIfs)
1692 RTPrintf("Masked Interfaces: %#010x\n", fMaskedIfs);
1693 RTPrintf("\n");
1694 }
1695 }
1696 }
1697 }
1698
1699 if (console)
1700 {
1701 /* scope */
1702 {
1703 if (details != VMINFO_MACHINEREADABLE)
1704 RTPrintf("Available remote USB devices:\n\n");
1705
1706 SafeIfaceArray <IHostUSBDevice> coll;
1707 CHECK_ERROR_RET(console, COMGETTER(RemoteUSBDevices)(ComSafeArrayAsOutParam(coll)), rc);
1708
1709 if (coll.size() == 0)
1710 {
1711 if (details != VMINFO_MACHINEREADABLE)
1712 RTPrintf("<none>\n\n");
1713 }
1714 else
1715 {
1716 for (size_t index = 0; index < coll.size(); ++index)
1717 {
1718 ComPtr <IHostUSBDevice> dev = coll[index];
1719
1720 /* Query info. */
1721 Bstr id;
1722 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), rc);
1723 USHORT usVendorId;
1724 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), rc);
1725 USHORT usProductId;
1726 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), rc);
1727 USHORT bcdRevision;
1728 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), rc);
1729
1730 if (details == VMINFO_MACHINEREADABLE)
1731 RTPrintf("USBRemoteUUID%zu=\"%s\"\n"
1732 "USBRemoteVendorId%zu=\"%#06x\"\n"
1733 "USBRemoteProductId%zu=\"%#06x\"\n"
1734 "USBRemoteRevision%zu=\"%#04x%02x\"\n",
1735 index + 1, Utf8Str(id).c_str(),
1736 index + 1, usVendorId,
1737 index + 1, usProductId,
1738 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1739 else
1740 RTPrintf("UUID: %s\n"
1741 "VendorId: %#06x (%04X)\n"
1742 "ProductId: %#06x (%04X)\n"
1743 "Revision: %u.%u (%02u%02u)\n",
1744 Utf8Str(id).c_str(),
1745 usVendorId, usVendorId, usProductId, usProductId,
1746 bcdRevision >> 8, bcdRevision & 0xff,
1747 bcdRevision >> 8, bcdRevision & 0xff);
1748
1749 /* optional stuff. */
1750 Bstr bstr;
1751 CHECK_ERROR_RET(dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1752 if (!bstr.isEmpty())
1753 {
1754 if (details == VMINFO_MACHINEREADABLE)
1755 RTPrintf("USBRemoteManufacturer%zu=\"%ls\"\n", index + 1, bstr.raw());
1756 else
1757 RTPrintf("Manufacturer: %ls\n", bstr.raw());
1758 }
1759 CHECK_ERROR_RET(dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1760 if (!bstr.isEmpty())
1761 {
1762 if (details == VMINFO_MACHINEREADABLE)
1763 RTPrintf("USBRemoteProduct%zu=\"%ls\"\n", index + 1, bstr.raw());
1764 else
1765 RTPrintf("Product: %ls\n", bstr.raw());
1766 }
1767 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1768 if (!bstr.isEmpty())
1769 {
1770 if (details == VMINFO_MACHINEREADABLE)
1771 RTPrintf("USBRemoteSerialNumber%zu=\"%ls\"\n", index + 1, bstr.raw());
1772 else
1773 RTPrintf("SerialNumber: %ls\n", bstr.raw());
1774 }
1775 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1776 if (!bstr.isEmpty())
1777 {
1778 if (details == VMINFO_MACHINEREADABLE)
1779 RTPrintf("USBRemoteAddress%zu=\"%ls\"\n", index + 1, bstr.raw());
1780 else
1781 RTPrintf("Address: %ls\n", bstr.raw());
1782 }
1783
1784 if (details != VMINFO_MACHINEREADABLE)
1785 RTPrintf("\n");
1786 }
1787 }
1788 }
1789
1790 /* scope */
1791 {
1792 if (details != VMINFO_MACHINEREADABLE)
1793 RTPrintf("Currently Attached USB Devices:\n\n");
1794
1795 SafeIfaceArray <IUSBDevice> coll;
1796 CHECK_ERROR_RET(console, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(coll)), rc);
1797
1798 if (coll.size() == 0)
1799 {
1800 if (details != VMINFO_MACHINEREADABLE)
1801 RTPrintf("<none>\n\n");
1802 }
1803 else
1804 {
1805 for (size_t index = 0; index < coll.size(); ++index)
1806 {
1807 ComPtr <IUSBDevice> dev = coll[index];
1808
1809 /* Query info. */
1810 Bstr id;
1811 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), rc);
1812 USHORT usVendorId;
1813 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), rc);
1814 USHORT usProductId;
1815 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), rc);
1816 USHORT bcdRevision;
1817 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), rc);
1818
1819 if (details == VMINFO_MACHINEREADABLE)
1820 RTPrintf("USBAttachedUUID%zu=\"%s\"\n"
1821 "USBAttachedVendorId%zu=\"%#06x\"\n"
1822 "USBAttachedProductId%zu=\"%#06x\"\n"
1823 "USBAttachedRevision%zu=\"%#04x%02x\"\n",
1824 index + 1, Utf8Str(id).c_str(),
1825 index + 1, usVendorId,
1826 index + 1, usProductId,
1827 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1828 else
1829 RTPrintf("UUID: %s\n"
1830 "VendorId: %#06x (%04X)\n"
1831 "ProductId: %#06x (%04X)\n"
1832 "Revision: %u.%u (%02u%02u)\n",
1833 Utf8Str(id).c_str(),
1834 usVendorId, usVendorId, usProductId, usProductId,
1835 bcdRevision >> 8, bcdRevision & 0xff,
1836 bcdRevision >> 8, bcdRevision & 0xff);
1837
1838 /* optional stuff. */
1839 Bstr bstr;
1840 CHECK_ERROR_RET(dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1841 if (!bstr.isEmpty())
1842 {
1843 if (details == VMINFO_MACHINEREADABLE)
1844 RTPrintf("USBAttachedManufacturer%zu=\"%ls\"\n", index + 1, bstr.raw());
1845 else
1846 RTPrintf("Manufacturer: %ls\n", bstr.raw());
1847 }
1848 CHECK_ERROR_RET(dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1849 if (!bstr.isEmpty())
1850 {
1851 if (details == VMINFO_MACHINEREADABLE)
1852 RTPrintf("USBAttachedProduct%zu=\"%ls\"\n", index + 1, bstr.raw());
1853 else
1854 RTPrintf("Product: %ls\n", bstr.raw());
1855 }
1856 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1857 if (!bstr.isEmpty())
1858 {
1859 if (details == VMINFO_MACHINEREADABLE)
1860 RTPrintf("USBAttachedSerialNumber%zu=\"%ls\"\n", index + 1, bstr.raw());
1861 else
1862 RTPrintf("SerialNumber: %ls\n", bstr.raw());
1863 }
1864 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1865 if (!bstr.isEmpty())
1866 {
1867 if (details == VMINFO_MACHINEREADABLE)
1868 RTPrintf("USBAttachedAddress%zu=\"%ls\"\n", index + 1, bstr.raw());
1869 else
1870 RTPrintf("Address: %ls\n", bstr.raw());
1871 }
1872
1873 if (details != VMINFO_MACHINEREADABLE)
1874 RTPrintf("\n");
1875 }
1876 }
1877 }
1878 }
1879 } /* USB */
1880
1881#ifdef VBOX_WITH_PCI_PASSTHROUGH
1882 /* Host PCI passthrough devices */
1883 {
1884 SafeIfaceArray <IPciDeviceAttachment> assignments;
1885 rc = machine->COMGETTER(PciDeviceAssignments)(ComSafeArrayAsOutParam(assignments));
1886 if (SUCCEEDED(rc))
1887 {
1888 if (assignments.size() > 0 && (details != VMINFO_MACHINEREADABLE))
1889 {
1890 RTPrintf("\nAttached physical PCI devices:\n\n");
1891 }
1892
1893 for (size_t index = 0; index < assignments.size(); ++index)
1894 {
1895 ComPtr<IPciDeviceAttachment> Assignment = assignments[index];
1896 char szHostPciAddress[32], szGuestPciAddress[32];
1897 LONG iHostPciAddress = -1, iGuestPciAddress = -1;
1898 Bstr DevName;
1899
1900 Assignment->COMGETTER(Name)(DevName.asOutParam());
1901 Assignment->COMGETTER(HostAddress)(&iHostPciAddress);
1902 Assignment->COMGETTER(GuestAddress)(&iGuestPciAddress);
1903 PciBusAddress().fromLong(iHostPciAddress).format(szHostPciAddress, sizeof(szHostPciAddress));
1904 PciBusAddress().fromLong(iGuestPciAddress).format(szGuestPciAddress, sizeof(szGuestPciAddress));
1905
1906 if (details == VMINFO_MACHINEREADABLE)
1907 RTPrintf("AttachedHostPci=%s,%s\n", szHostPciAddress, szGuestPciAddress);
1908 else
1909 RTPrintf(" Host device %ls at %s attached as %s\n", DevName.raw(), szHostPciAddress, szGuestPciAddress);
1910 }
1911
1912 if (assignments.size() > 0 && (details != VMINFO_MACHINEREADABLE))
1913 {
1914 RTPrintf("\n");
1915 }
1916 }
1917 }
1918 /* Host PCI passthrough devices */
1919#endif
1920
1921 /*
1922 * Shared folders
1923 */
1924 if (details != VMINFO_MACHINEREADABLE)
1925 RTPrintf("Shared folders: ");
1926 uint32_t numSharedFolders = 0;
1927#if 0 // not yet implemented
1928 /* globally shared folders first */
1929 {
1930 SafeIfaceArray <ISharedFolder> sfColl;
1931 CHECK_ERROR_RET(virtualBox, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sfColl)), rc);
1932 for (size_t i = 0; i < sfColl.size(); ++i)
1933 {
1934 ComPtr<ISharedFolder> sf = sfColl[i];
1935 Bstr name, hostPath;
1936 sf->COMGETTER(Name)(name.asOutParam());
1937 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1938 RTPrintf("Name: '%ls', Host path: '%ls' (global mapping)\n", name.raw(), hostPath.raw());
1939 ++numSharedFolders;
1940 }
1941 }
1942#endif
1943 /* now VM mappings */
1944 {
1945 com::SafeIfaceArray <ISharedFolder> folders;
1946
1947 CHECK_ERROR_RET(machine, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1948
1949 for (size_t i = 0; i < folders.size(); ++i)
1950 {
1951 ComPtr <ISharedFolder> sf = folders[i];
1952
1953 Bstr name, hostPath;
1954 BOOL writable;
1955 sf->COMGETTER(Name)(name.asOutParam());
1956 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1957 sf->COMGETTER(Writable)(&writable);
1958 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1959 RTPrintf("\n\n");
1960 if (details == VMINFO_MACHINEREADABLE)
1961 {
1962 RTPrintf("SharedFolderNameMachineMapping%zu=\"%ls\"\n", i + 1,
1963 name.raw());
1964 RTPrintf("SharedFolderPathMachineMapping%zu=\"%ls\"\n", i + 1,
1965 hostPath.raw());
1966 }
1967 else
1968 RTPrintf("Name: '%ls', Host path: '%ls' (machine mapping), %s\n",
1969 name.raw(), hostPath.raw(), writable ? "writable" : "readonly");
1970 ++numSharedFolders;
1971 }
1972 }
1973 /* transient mappings */
1974 if (console)
1975 {
1976 com::SafeIfaceArray <ISharedFolder> folders;
1977
1978 CHECK_ERROR_RET(console, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1979
1980 for (size_t i = 0; i < folders.size(); ++i)
1981 {
1982 ComPtr <ISharedFolder> sf = folders[i];
1983
1984 Bstr name, hostPath;
1985 sf->COMGETTER(Name)(name.asOutParam());
1986 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1987 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1988 RTPrintf("\n\n");
1989 if (details == VMINFO_MACHINEREADABLE)
1990 {
1991 RTPrintf("SharedFolderNameTransientMapping%zu=\"%ls\"\n", i + 1,
1992 name.raw());
1993 RTPrintf("SharedFolderPathTransientMapping%zu=\"%ls\"\n", i + 1,
1994 hostPath.raw());
1995 }
1996 else
1997 RTPrintf("Name: '%ls', Host path: '%ls' (transient mapping)\n", name.raw(), hostPath.raw());
1998 ++numSharedFolders;
1999 }
2000 }
2001 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
2002 RTPrintf("<none>\n");
2003 if (details != VMINFO_MACHINEREADABLE)
2004 RTPrintf("\n");
2005
2006 if (console)
2007 {
2008 /*
2009 * Live VRDE info.
2010 */
2011 ComPtr<IVRDEServerInfo> vrdeServerInfo;
2012 CHECK_ERROR_RET(console, COMGETTER(VRDEServerInfo)(vrdeServerInfo.asOutParam()), rc);
2013 BOOL Active;
2014 ULONG NumberOfClients;
2015 LONG64 BeginTime;
2016 LONG64 EndTime;
2017 LONG64 BytesSent;
2018 LONG64 BytesSentTotal;
2019 LONG64 BytesReceived;
2020 LONG64 BytesReceivedTotal;
2021 Bstr User;
2022 Bstr Domain;
2023 Bstr ClientName;
2024 Bstr ClientIP;
2025 ULONG ClientVersion;
2026 ULONG EncryptionStyle;
2027
2028 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(Active)(&Active), rc);
2029 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(NumberOfClients)(&NumberOfClients), rc);
2030 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(BeginTime)(&BeginTime), rc);
2031 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(EndTime)(&EndTime), rc);
2032 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(BytesSent)(&BytesSent), rc);
2033 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(BytesSentTotal)(&BytesSentTotal), rc);
2034 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(BytesReceived)(&BytesReceived), rc);
2035 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(BytesReceivedTotal)(&BytesReceivedTotal), rc);
2036 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(User)(User.asOutParam()), rc);
2037 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(Domain)(Domain.asOutParam()), rc);
2038 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(ClientName)(ClientName.asOutParam()), rc);
2039 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(ClientIP)(ClientIP.asOutParam()), rc);
2040 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(ClientVersion)(&ClientVersion), rc);
2041 CHECK_ERROR_RET(vrdeServerInfo, COMGETTER(EncryptionStyle)(&EncryptionStyle), rc);
2042
2043 if (details == VMINFO_MACHINEREADABLE)
2044 RTPrintf("VRDEActiveConnection=\"%s\"\n", Active ? "on": "off");
2045 else
2046 RTPrintf("VRDE Connection: %s\n", Active? "active": "not active");
2047
2048 if (details == VMINFO_MACHINEREADABLE)
2049 RTPrintf("VRDEClients=%d\n", NumberOfClients);
2050 else
2051 RTPrintf("Clients so far: %d\n", NumberOfClients);
2052
2053 if (NumberOfClients > 0)
2054 {
2055 char timestr[128];
2056
2057 if (Active)
2058 {
2059 makeTimeStr(timestr, sizeof(timestr), BeginTime);
2060 if (details == VMINFO_MACHINEREADABLE)
2061 RTPrintf("VRDEStartTime=\"%s\"\n", timestr);
2062 else
2063 RTPrintf("Start time: %s\n", timestr);
2064 }
2065 else
2066 {
2067 makeTimeStr(timestr, sizeof(timestr), BeginTime);
2068 if (details == VMINFO_MACHINEREADABLE)
2069 RTPrintf("VRDELastStartTime=\"%s\"\n", timestr);
2070 else
2071 RTPrintf("Last started: %s\n", timestr);
2072 makeTimeStr(timestr, sizeof(timestr), EndTime);
2073 if (details == VMINFO_MACHINEREADABLE)
2074 RTPrintf("VRDELastEndTime=\"%s\"\n", timestr);
2075 else
2076 RTPrintf("Last ended: %s\n", timestr);
2077 }
2078
2079 int64_t ThroughputSend = 0;
2080 int64_t ThroughputReceive = 0;
2081 if (EndTime != BeginTime)
2082 {
2083 ThroughputSend = (BytesSent * 1000) / (EndTime - BeginTime);
2084 ThroughputReceive = (BytesReceived * 1000) / (EndTime - BeginTime);
2085 }
2086
2087 if (details == VMINFO_MACHINEREADABLE)
2088 {
2089 RTPrintf("VRDEBytesSent=%lld\n", BytesSent);
2090 RTPrintf("VRDEThroughputSend=%lld\n", ThroughputSend);
2091 RTPrintf("VRDEBytesSentTotal=%lld\n", BytesSentTotal);
2092
2093 RTPrintf("VRDEBytesReceived=%lld\n", BytesReceived);
2094 RTPrintf("VRDEThroughputReceive=%lld\n", ThroughputReceive);
2095 RTPrintf("VRDEBytesReceivedTotal=%lld\n", BytesReceivedTotal);
2096 }
2097 else
2098 {
2099 RTPrintf("Sent: %lld Bytes\n", BytesSent);
2100 RTPrintf("Average speed: %lld B/s\n", ThroughputSend);
2101 RTPrintf("Sent total: %lld Bytes\n", BytesSentTotal);
2102
2103 RTPrintf("Received: %lld Bytes\n", BytesReceived);
2104 RTPrintf("Speed: %lld B/s\n", ThroughputReceive);
2105 RTPrintf("Received total: %lld Bytes\n", BytesReceivedTotal);
2106 }
2107
2108 if (Active)
2109 {
2110 if (details == VMINFO_MACHINEREADABLE)
2111 {
2112 RTPrintf("VRDEUserName=\"%ls\"\n", User.raw());
2113 RTPrintf("VRDEDomain=\"%ls\"\n", Domain.raw());
2114 RTPrintf("VRDEClientName=\"%ls\"\n", ClientName.raw());
2115 RTPrintf("VRDEClientIP=\"%ls\"\n", ClientIP.raw());
2116 RTPrintf("VRDEClientVersion=%d\n", ClientVersion);
2117 RTPrintf("VRDEEncryption=\"%s\"\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
2118 }
2119 else
2120 {
2121 RTPrintf("User name: %ls\n", User.raw());
2122 RTPrintf("Domain: %ls\n", Domain.raw());
2123 RTPrintf("Client name: %ls\n", ClientName.raw());
2124 RTPrintf("Client IP: %ls\n", ClientIP.raw());
2125 RTPrintf("Client version: %d\n", ClientVersion);
2126 RTPrintf("Encryption: %s\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
2127 }
2128 }
2129 }
2130
2131 if (details != VMINFO_MACHINEREADABLE)
2132 RTPrintf("\n");
2133 }
2134
2135 if ( details == VMINFO_STANDARD
2136 || details == VMINFO_FULL
2137 || details == VMINFO_MACHINEREADABLE)
2138 {
2139 Bstr description;
2140 machine->COMGETTER(Description)(description.asOutParam());
2141 if (!description.isEmpty())
2142 {
2143 if (details == VMINFO_MACHINEREADABLE)
2144 RTPrintf("description=\"%ls\"\n", description.raw());
2145 else
2146 RTPrintf("Description:\n%ls\n", description.raw());
2147 }
2148 }
2149
2150
2151 if (details != VMINFO_MACHINEREADABLE)
2152 RTPrintf("Guest:\n\n");
2153
2154 ULONG guestVal;
2155 rc = machine->COMGETTER(MemoryBalloonSize)(&guestVal);
2156 if (SUCCEEDED(rc))
2157 {
2158 if (details == VMINFO_MACHINEREADABLE)
2159 RTPrintf("GuestMemoryBalloon=%d\n", guestVal);
2160 else
2161 RTPrintf("Configured memory balloon size: %d MB\n", guestVal);
2162 }
2163
2164 if (console)
2165 {
2166 ComPtr<IGuest> guest;
2167 rc = console->COMGETTER(Guest)(guest.asOutParam());
2168 if (SUCCEEDED(rc))
2169 {
2170 Bstr guestString;
2171 rc = guest->COMGETTER(OSTypeId)(guestString.asOutParam());
2172 if ( SUCCEEDED(rc)
2173 && !guestString.isEmpty())
2174 {
2175 if (details == VMINFO_MACHINEREADABLE)
2176 RTPrintf("GuestOSType=\"%ls\"\n", guestString.raw());
2177 else
2178 RTPrintf("OS type: %ls\n", guestString.raw());
2179 }
2180
2181 AdditionsRunLevelType_T guestRunLevel; /** @todo Add a runlevel-to-string (e.g. 0 = "None") method? */
2182 rc = guest->COMGETTER(AdditionsRunLevel)(&guestRunLevel);
2183 if (SUCCEEDED(rc))
2184 {
2185 if (details == VMINFO_MACHINEREADABLE)
2186 RTPrintf("GuestAdditionsRunLevel=%u\n", guestRunLevel);
2187 else
2188 RTPrintf("Additions run level: %u\n", guestRunLevel);
2189 }
2190
2191 rc = guest->COMGETTER(AdditionsVersion)(guestString.asOutParam());
2192 if ( SUCCEEDED(rc)
2193 && !guestString.isEmpty())
2194 {
2195 ULONG uRevision;
2196 rc = guest->COMGETTER(AdditionsRevision)(&uRevision);
2197 if (FAILED(rc))
2198 uRevision = 0;
2199
2200 if (details == VMINFO_MACHINEREADABLE)
2201 RTPrintf("GuestAdditionsVersion=\"%ls r%u\"\n", guestString.raw(), uRevision);
2202 else
2203 RTPrintf("Additions version: %ls r%u\n\n", guestString.raw(), uRevision);
2204 }
2205
2206 if (details != VMINFO_MACHINEREADABLE)
2207 RTPrintf("\nGuest Facilities:\n\n");
2208
2209 /* Print information about known Guest Additions facilities: */
2210 SafeIfaceArray <IAdditionsFacility> collFac;
2211 CHECK_ERROR_RET(guest, COMGETTER(Facilities)(ComSafeArrayAsOutParam(collFac)), rc);
2212 LONG64 lLastUpdatedMS;
2213 char szLastUpdated[32];
2214 AdditionsFacilityStatus_T curStatus;
2215 for (size_t index = 0; index < collFac.size(); ++index)
2216 {
2217 ComPtr<IAdditionsFacility> fac = collFac[index];
2218 if (fac)
2219 {
2220 CHECK_ERROR_RET(fac, COMGETTER(Name)(guestString.asOutParam()), rc);
2221 if (!guestString.isEmpty())
2222 {
2223 CHECK_ERROR_RET(fac, COMGETTER(Status)(&curStatus), rc);
2224 CHECK_ERROR_RET(fac, COMGETTER(LastUpdated)(&lLastUpdatedMS), rc);
2225 if (details == VMINFO_MACHINEREADABLE)
2226 RTPrintf("GuestAdditionsFacility_%ls=%u,%lld\n",
2227 guestString.raw(), curStatus, lLastUpdatedMS);
2228 else
2229 {
2230 makeTimeStr(szLastUpdated, sizeof(szLastUpdated), lLastUpdatedMS);
2231 RTPrintf("Facility \"%ls\": %s (last update: %s)\n",
2232 guestString.raw(), facilityStateToName(curStatus, false /* No short naming */), szLastUpdated);
2233 }
2234 }
2235 else
2236 AssertMsgFailed(("Facility with undefined name retrieved!\n"));
2237 }
2238 else
2239 AssertMsgFailed(("Invalid facility returned!\n"));
2240 }
2241 if (!collFac.size() && details != VMINFO_MACHINEREADABLE)
2242 RTPrintf("No active facilities.\n");
2243 }
2244 }
2245
2246 if (details != VMINFO_MACHINEREADABLE)
2247 RTPrintf("\n");
2248
2249 /*
2250 * snapshots
2251 */
2252 ComPtr<ISnapshot> snapshot;
2253 rc = machine->FindSnapshot(Bstr().raw(), snapshot.asOutParam());
2254 if (SUCCEEDED(rc) && snapshot)
2255 {
2256 ComPtr<ISnapshot> currentSnapshot;
2257 rc = machine->COMGETTER(CurrentSnapshot)(currentSnapshot.asOutParam());
2258 if (SUCCEEDED(rc))
2259 {
2260 if (details != VMINFO_MACHINEREADABLE)
2261 RTPrintf("Snapshots:\n\n");
2262 showSnapshots(snapshot, currentSnapshot, details);
2263 }
2264 }
2265
2266 if (details != VMINFO_MACHINEREADABLE)
2267 RTPrintf("\n");
2268 return S_OK;
2269}
2270
2271#if defined(_MSC_VER)
2272# pragma optimize("", on)
2273#endif
2274
2275static const RTGETOPTDEF g_aShowVMInfoOptions[] =
2276{
2277 { "--details", 'D', RTGETOPT_REQ_NOTHING },
2278 { "-details", 'D', RTGETOPT_REQ_NOTHING }, // deprecated
2279 { "--machinereadable", 'M', RTGETOPT_REQ_NOTHING },
2280 { "-machinereadable", 'M', RTGETOPT_REQ_NOTHING }, // deprecated
2281 { "--log", 'l', RTGETOPT_REQ_UINT32 },
2282};
2283
2284int handleShowVMInfo(HandlerArg *a)
2285{
2286 HRESULT rc;
2287 const char *VMNameOrUuid = NULL;
2288 bool fLog = false;
2289 uint32_t uLogIdx = 0;
2290 bool fDetails = false;
2291 bool fMachinereadable = false;
2292
2293 int c;
2294 RTGETOPTUNION ValueUnion;
2295 RTGETOPTSTATE GetState;
2296 // start at 0 because main() has hacked both the argc and argv given to us
2297 RTGetOptInit(&GetState, a->argc, a->argv, g_aShowVMInfoOptions, RT_ELEMENTS(g_aShowVMInfoOptions),
2298 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
2299 while ((c = RTGetOpt(&GetState, &ValueUnion)))
2300 {
2301 switch (c)
2302 {
2303 case 'D': // --details
2304 fDetails = true;
2305 break;
2306
2307 case 'M': // --machinereadable
2308 fMachinereadable = true;
2309 break;
2310
2311 case 'l': // --log
2312 fLog = true;
2313 uLogIdx = ValueUnion.u32;
2314 break;
2315
2316 case VINF_GETOPT_NOT_OPTION:
2317 if (!VMNameOrUuid)
2318 VMNameOrUuid = ValueUnion.psz;
2319 else
2320 return errorSyntax(USAGE_SHOWVMINFO, "Invalid parameter '%s'", ValueUnion.psz);
2321 break;
2322
2323 default:
2324 if (c > 0)
2325 {
2326 if (RT_C_IS_PRINT(c))
2327 return errorSyntax(USAGE_SHOWVMINFO, "Invalid option -%c", c);
2328 else
2329 return errorSyntax(USAGE_SHOWVMINFO, "Invalid option case %i", c);
2330 }
2331 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
2332 return errorSyntax(USAGE_SHOWVMINFO, "unknown option: %s\n", ValueUnion.psz);
2333 else if (ValueUnion.pDef)
2334 return errorSyntax(USAGE_SHOWVMINFO, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
2335 else
2336 return errorSyntax(USAGE_SHOWVMINFO, "error: %Rrs", c);
2337 }
2338 }
2339
2340 /* check for required options */
2341 if (!VMNameOrUuid)
2342 return errorSyntax(USAGE_SHOWVMINFO, "VM name or UUID required");
2343
2344 /* try to find the given machine */
2345 ComPtr <IMachine> machine;
2346 CHECK_ERROR(a->virtualBox, FindMachine(Bstr(VMNameOrUuid).raw(),
2347 machine.asOutParam()));
2348 if (FAILED(rc))
2349 return 1;
2350
2351 /* Printing the log is exclusive. */
2352 if (fLog && (fMachinereadable || fDetails))
2353 return errorSyntax(USAGE_SHOWVMINFO, "Option --log is exclusive");
2354
2355 if (fLog)
2356 {
2357 ULONG64 uOffset = 0;
2358 SafeArray<BYTE> aLogData;
2359 ULONG cbLogData;
2360 while (true)
2361 {
2362 /* Reset the array */
2363 aLogData.setNull();
2364 /* Fetch a chunk of the log file */
2365 CHECK_ERROR_BREAK(machine, ReadLog(uLogIdx, uOffset, _1M,
2366 ComSafeArrayAsOutParam(aLogData)));
2367 cbLogData = aLogData.size();
2368 if (cbLogData == 0)
2369 break;
2370 /* aLogData has a platform dependent line ending, standardize on
2371 * Unix style, as RTStrmWrite does the LF -> CR/LF replacement on
2372 * Windows. Otherwise we end up with CR/CR/LF on Windows. */
2373 ULONG cbLogDataPrint = cbLogData;
2374 for (BYTE *s = aLogData.raw(), *d = s;
2375 s - aLogData.raw() < (ssize_t)cbLogData;
2376 s++, d++)
2377 {
2378 if (*s == '\r')
2379 {
2380 /* skip over CR, adjust destination */
2381 d--;
2382 cbLogDataPrint--;
2383 }
2384 else if (s != d)
2385 *d = *s;
2386 }
2387 RTStrmWrite(g_pStdOut, aLogData.raw(), cbLogDataPrint);
2388 uOffset += cbLogData;
2389 }
2390 }
2391 else
2392 {
2393 /* 2nd option can be -details or -argdump */
2394 VMINFO_DETAILS details = VMINFO_NONE;
2395 if (fMachinereadable)
2396 details = VMINFO_MACHINEREADABLE;
2397 else if (fDetails)
2398 details = VMINFO_FULL;
2399 else
2400 details = VMINFO_STANDARD;
2401
2402 ComPtr<IConsole> console;
2403
2404 /* open an existing session for the VM */
2405 rc = machine->LockMachine(a->session, LockType_Shared);
2406 if (SUCCEEDED(rc))
2407 /* get the session machine */
2408 rc = a->session->COMGETTER(Machine)(machine.asOutParam());
2409 if (SUCCEEDED(rc))
2410 /* get the session console */
2411 rc = a->session->COMGETTER(Console)(console.asOutParam());
2412
2413 rc = showVMInfo(a->virtualBox, machine, details, console);
2414
2415 if (console)
2416 a->session->UnlockMachine();
2417 }
2418
2419 return SUCCEEDED(rc) ? 0 : 1;
2420}
2421
2422#endif /* !VBOX_ONLY_DOCS */
2423/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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