VirtualBox

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

Last change on this file since 36784 was 36631, checked in by vboxsync, 14 years ago

burn fix

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