VirtualBox

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

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

introduced VBoxManage modifyvm --rtcuseutc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 80.4 KB
Line 
1/* $Id: VBoxManageInfo.cpp 25672 2010-01-06 21:23:07Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'showvminfo' command and helper routines.
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef VBOX_ONLY_DOCS
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/com/com.h>
28#include <VBox/com/string.h>
29#include <VBox/com/Guid.h>
30#include <VBox/com/array.h>
31#include <VBox/com/ErrorInfo.h>
32#include <VBox/com/errorprint.h>
33
34#include <VBox/com/VirtualBox.h>
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).raw());
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).raw(),
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
117/* Disable global optimizations for MSC 8.0/64 to make it compile in reasonable
118 time. MSC 7.1/32 doesn't have quite as much trouble with it, but still
119 sufficient to qualify for this hack as well since this code isn't performance
120 critical and probably won't gain much from the extra optimizing in real life. */
121#if defined(_MSC_VER)
122# pragma optimize("g", off)
123#endif
124
125HRESULT showVMInfo (ComPtr<IVirtualBox> virtualBox,
126 ComPtr<IMachine> machine,
127 VMINFO_DETAILS details /*= VMINFO_NONE*/,
128 ComPtr<IConsole> console /*= ComPtr <IConsole> ()*/)
129{
130 HRESULT rc;
131
132 /*
133 * The rules for output in -argdump format:
134 * 1) the key part (the [0-9a-zA-Z_]+ string before the '=' delimiter)
135 * is all lowercase for "VBoxManage modifyvm" parameters. Any
136 * other values printed are in CamelCase.
137 * 2) strings (anything non-decimal) are printed surrounded by
138 * double quotes '"'. If the strings themselves contain double
139 * quotes, these characters are escaped by '\'. Any '\' character
140 * in the original string is also escaped by '\'.
141 * 3) numbers (containing just [0-9\-]) are written out unchanged.
142 */
143
144 /** @todo the quoting is not yet implemented! */
145 /** @todo error checking! */
146
147 BOOL accessible = FALSE;
148 CHECK_ERROR(machine, COMGETTER(Accessible)(&accessible));
149 if (FAILED(rc)) return rc;
150
151 Bstr uuid;
152 rc = machine->COMGETTER(Id)(uuid.asOutParam());
153
154 if (!accessible)
155 {
156 if (details == VMINFO_COMPACT)
157 RTPrintf("\"<inaccessible>\" {%s}\n", Utf8Str(uuid).raw());
158 else
159 {
160 if (details == VMINFO_MACHINEREADABLE)
161 RTPrintf("name=\"<inaccessible>\"\n");
162 else
163 RTPrintf("Name: <inaccessible!>\n");
164 if (details == VMINFO_MACHINEREADABLE)
165 RTPrintf("UUID=\"%s\"\n", Utf8Str(uuid).raw());
166 else
167 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
168 if (details != VMINFO_MACHINEREADABLE)
169 {
170 Bstr settingsFilePath;
171 rc = machine->COMGETTER(SettingsFilePath)(settingsFilePath.asOutParam());
172 RTPrintf("Config file: %lS\n", settingsFilePath.raw());
173 ComPtr<IVirtualBoxErrorInfo> accessError;
174 rc = machine->COMGETTER(AccessError)(accessError.asOutParam());
175 RTPrintf("Access error details:\n");
176 ErrorInfo ei(accessError);
177 GluePrintErrorInfo(ei);
178 RTPrintf("\n");
179 }
180 }
181 return S_OK;
182 }
183
184 Bstr machineName;
185 rc = machine->COMGETTER(Name)(machineName.asOutParam());
186
187 if (details == VMINFO_COMPACT)
188 {
189 RTPrintf("\"%lS\" {%s}\n", machineName.raw(), Utf8Str(uuid).raw());
190 return S_OK;
191 }
192
193 if (details == VMINFO_MACHINEREADABLE)
194 RTPrintf("name=\"%lS\"\n", machineName.raw());
195 else
196 RTPrintf("Name: %lS\n", machineName.raw());
197
198 Bstr osTypeId;
199 rc = machine->COMGETTER(OSTypeId)(osTypeId.asOutParam());
200 ComPtr<IGuestOSType> osType;
201 rc = virtualBox->GetGuestOSType (osTypeId, osType.asOutParam());
202 Bstr osName;
203 rc = osType->COMGETTER(Description)(osName.asOutParam());
204 if (details == VMINFO_MACHINEREADABLE)
205 RTPrintf("ostype=\"%lS\"\n", osTypeId.raw());
206 else
207 RTPrintf("Guest OS: %lS\n", osName.raw());
208
209 if (details == VMINFO_MACHINEREADABLE)
210 RTPrintf("UUID=\"%s\"\n", Utf8Str(uuid).raw());
211 else
212 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
213
214 Bstr settingsFilePath;
215 rc = machine->COMGETTER(SettingsFilePath)(settingsFilePath.asOutParam());
216 if (details == VMINFO_MACHINEREADABLE)
217 RTPrintf("CfgFile=\"%lS\"\n", settingsFilePath.raw());
218 else
219 RTPrintf("Config file: %lS\n", settingsFilePath.raw());
220
221 Bstr strHardwareUuid;
222 rc = machine->COMGETTER(HardwareUUID)(strHardwareUuid.asOutParam());
223 if (details == VMINFO_MACHINEREADABLE)
224 RTPrintf("hardwareuuid=\"%lS\"\n", strHardwareUuid.raw());
225 else
226 RTPrintf("Hardware UUID: %lS\n", strHardwareUuid.raw());
227
228 ULONG memorySize;
229 rc = machine->COMGETTER(MemorySize)(&memorySize);
230 if (details == VMINFO_MACHINEREADABLE)
231 RTPrintf("memory=%u\n", memorySize);
232 else
233 RTPrintf("Memory size: %uMB\n", memorySize);
234
235 ULONG vramSize;
236 rc = machine->COMGETTER(VRAMSize)(&vramSize);
237 if (details == VMINFO_MACHINEREADABLE)
238 RTPrintf("vram=%u\n", vramSize);
239 else
240 RTPrintf("VRAM size: %uMB\n", vramSize);
241
242 ULONG numCpus;
243 rc = machine->COMGETTER(CPUCount)(&numCpus);
244 if (details == VMINFO_MACHINEREADABLE)
245 RTPrintf("cpus=%u\n", numCpus);
246 else
247 RTPrintf("Number of CPUs: %u\n", numCpus);
248
249 BOOL fSyntheticCpu;
250 machine->GetCpuProperty(CpuPropertyType_Synthetic, &fSyntheticCpu);
251 if (details == VMINFO_MACHINEREADABLE)
252 RTPrintf("synthcpu=\"%s\"\n", fSyntheticCpu ? "on" : "off");
253 else
254 RTPrintf("Synthetic Cpu: %s\n", fSyntheticCpu ? "on" : "off");
255
256 if (details != VMINFO_MACHINEREADABLE)
257 RTPrintf("CPUID overrides: ");
258 ULONG cFound = 0;
259 static uint32_t const s_auCpuIdRanges[] =
260 {
261 UINT32_C(0x00000000), UINT32_C(0x0000000a),
262 UINT32_C(0x80000000), UINT32_C(0x8000000a)
263 };
264 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
265 for (uint32_t uLeaf = s_auCpuIdRanges[i]; uLeaf < s_auCpuIdRanges[i + 1]; uLeaf++)
266 {
267 ULONG uEAX, uEBX, uECX, uEDX;
268 rc = machine->GetCpuIdLeaf(uLeaf, &uEAX, &uEBX, &uECX, &uEDX);
269 if (SUCCEEDED(rc))
270 {
271 if (details == VMINFO_MACHINEREADABLE)
272 RTPrintf("cpuid=%08x,%08x,%08x,%08x,%08x", uLeaf, uEAX, uEBX, uECX, uEDX);
273 else
274 {
275 if (!cFound)
276 RTPrintf("Leaf no. EAX EBX ECX EDX\n");
277 RTPrintf(" %08x %08x %08x %08x %08x\n", uLeaf, uEAX, uEBX, uECX, uEDX);
278 }
279 cFound++;
280 }
281 }
282 if (!cFound && details != VMINFO_MACHINEREADABLE)
283 RTPrintf("None\n");
284
285 ComPtr <IBIOSSettings> biosSettings;
286 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
287
288 BIOSBootMenuMode_T bootMenuMode;
289 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
290 const char *pszBootMenu = NULL;
291 switch (bootMenuMode)
292 {
293 case BIOSBootMenuMode_Disabled:
294 pszBootMenu = "disabled";
295 break;
296 case BIOSBootMenuMode_MenuOnly:
297 if (details == VMINFO_MACHINEREADABLE)
298 pszBootMenu = "menuonly";
299 else
300 pszBootMenu = "menu only";
301 break;
302 default:
303 if (details == VMINFO_MACHINEREADABLE)
304 pszBootMenu = "messageandmenu";
305 else
306 pszBootMenu = "message and menu";
307 }
308 if (details == VMINFO_MACHINEREADABLE)
309 RTPrintf("bootmenu=\"%s\"\n", pszBootMenu);
310 else
311 RTPrintf("Boot menu mode: %s\n", pszBootMenu);
312
313 ULONG maxBootPosition = 0;
314 ComPtr<ISystemProperties> systemProperties;
315 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
316 systemProperties->COMGETTER(MaxBootPosition)(&maxBootPosition);
317 for (ULONG i = 1; i <= maxBootPosition; i++)
318 {
319 DeviceType_T bootOrder;
320 machine->GetBootOrder(i, &bootOrder);
321 if (bootOrder == DeviceType_Floppy)
322 {
323 if (details == VMINFO_MACHINEREADABLE)
324 RTPrintf("boot%d=\"floppy\"\n", i);
325 else
326 RTPrintf("Boot Device (%d): Floppy\n", i);
327 }
328 else if (bootOrder == DeviceType_DVD)
329 {
330 if (details == VMINFO_MACHINEREADABLE)
331 RTPrintf("boot%d=\"dvd\"\n", i);
332 else
333 RTPrintf("Boot Device (%d): DVD\n", i);
334 }
335 else if (bootOrder == DeviceType_HardDisk)
336 {
337 if (details == VMINFO_MACHINEREADABLE)
338 RTPrintf("boot%d=\"disk\"\n", i);
339 else
340 RTPrintf("Boot Device (%d): HardDisk\n", i);
341 }
342 else if (bootOrder == DeviceType_Network)
343 {
344 if (details == VMINFO_MACHINEREADABLE)
345 RTPrintf("boot%d=\"net\"\n", i);
346 else
347 RTPrintf("Boot Device (%d): Network\n", i);
348 }
349 else if (bootOrder == DeviceType_USB)
350 {
351 if (details == VMINFO_MACHINEREADABLE)
352 RTPrintf("boot%d=\"usb\"\n", i);
353 else
354 RTPrintf("Boot Device (%d): USB\n", i);
355 }
356 else if (bootOrder == DeviceType_SharedFolder)
357 {
358 if (details == VMINFO_MACHINEREADABLE)
359 RTPrintf("boot%d=\"sharedfolder\"\n", i);
360 else
361 RTPrintf("Boot Device (%d): Shared Folder\n", i);
362 }
363 else
364 {
365 if (details == VMINFO_MACHINEREADABLE)
366 RTPrintf("boot%d=\"none\"\n", i);
367 else
368 RTPrintf("Boot Device (%d): Not Assigned\n", i);
369 }
370 }
371
372 BOOL acpiEnabled;
373 biosSettings->COMGETTER(ACPIEnabled)(&acpiEnabled);
374 if (details == VMINFO_MACHINEREADABLE)
375 RTPrintf("acpi=\"%s\"\n", acpiEnabled ? "on" : "off");
376 else
377 RTPrintf("ACPI: %s\n", acpiEnabled ? "on" : "off");
378
379 BOOL ioapicEnabled;
380 biosSettings->COMGETTER(IOAPICEnabled)(&ioapicEnabled);
381 if (details == VMINFO_MACHINEREADABLE)
382 RTPrintf("ioapic=\"%s\"\n", ioapicEnabled ? "on" : "off");
383 else
384 RTPrintf("IOAPIC: %s\n", ioapicEnabled ? "on" : "off");
385
386 BOOL PAEEnabled;
387 machine->GetCpuProperty(CpuPropertyType_PAE, &PAEEnabled);
388 if (details == VMINFO_MACHINEREADABLE)
389 RTPrintf("pae=\"%s\"\n", PAEEnabled ? "on" : "off");
390 else
391 RTPrintf("PAE: %s\n", PAEEnabled ? "on" : "off");
392
393 LONG64 timeOffset;
394 biosSettings->COMGETTER(TimeOffset)(&timeOffset);
395 if (details == VMINFO_MACHINEREADABLE)
396 RTPrintf("biossystemtimeoffset=%lld\n", timeOffset);
397 else
398 RTPrintf("Time offset: %lld ms\n", timeOffset);
399
400 BOOL RTCUseUTC;
401 machine->COMGETTER(RTCUseUTC)(&RTCUseUTC);
402 if (details == VMINFO_MACHINEREADABLE)
403 RTPrintf("rtcuseutc=\"%s\"\n", RTCUseUTC ? "on" : "off");
404 else
405 RTPrintf("RTC: %s\n", RTCUseUTC ? "UTC" : "local time");
406
407 BOOL hwVirtExEnabled;
408 machine->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &hwVirtExEnabled);
409 if (details == VMINFO_MACHINEREADABLE)
410 RTPrintf("hwvirtex=\"%s\"\n", hwVirtExEnabled ? "on" : "off");
411 else
412 RTPrintf("Hardw. virt.ext: %s\n", hwVirtExEnabled ? "on" : "off");
413
414 BOOL hwVirtExExclusive;
415 machine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &hwVirtExExclusive);
416 if (details == VMINFO_MACHINEREADABLE)
417 RTPrintf("hwvirtexexcl=\"%s\"\n", hwVirtExExclusive ? "on" : "off");
418 else
419 RTPrintf("Hardw. virt.ext exclusive: %s\n", hwVirtExExclusive ? "on" : "off");
420
421 BOOL HWVirtExNestedPagingEnabled;
422 machine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &HWVirtExNestedPagingEnabled);
423 if (details == VMINFO_MACHINEREADABLE)
424 RTPrintf("nestedpaging=\"%s\"\n", HWVirtExNestedPagingEnabled ? "on" : "off");
425 else
426 RTPrintf("Nested Paging: %s\n", HWVirtExNestedPagingEnabled ? "on" : "off");
427
428 BOOL HWVirtExVPIDEnabled;
429 machine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &HWVirtExVPIDEnabled);
430 if (details == VMINFO_MACHINEREADABLE)
431 RTPrintf("vtxvpid=\"%s\"\n", HWVirtExVPIDEnabled ? "on" : "off");
432 else
433 RTPrintf("VT-x VPID: %s\n", HWVirtExVPIDEnabled ? "on" : "off");
434
435 MachineState_T machineState;
436 const char *pszState = NULL;
437 rc = machine->COMGETTER(State)(&machineState);
438 switch (machineState)
439 {
440 case MachineState_PoweredOff:
441 pszState = details == VMINFO_MACHINEREADABLE ? "poweroff" : "powered off";
442 break;
443 case MachineState_Saved:
444 pszState = "saved";
445 break;
446 case MachineState_Aborted:
447 pszState = "aborted";
448 break;
449 case MachineState_Teleported:
450 pszState = "teleported";
451 break;
452 case MachineState_Running:
453 pszState = "running";
454 break;
455 case MachineState_Paused:
456 pszState = "paused";
457 break;
458 case MachineState_Stuck:
459 pszState = details == VMINFO_MACHINEREADABLE ? "gurumeditation" : "guru meditation";
460 break;
461 case MachineState_LiveSnapshotting:
462 pszState = details == VMINFO_MACHINEREADABLE ? "livesnapshotting" : "live snapshotting";
463 break;
464 case MachineState_Teleporting:
465 pszState = "teleporting";
466 break;
467 case MachineState_Starting:
468 pszState = "starting";
469 break;
470 case MachineState_Stopping:
471 pszState = "stopping";
472 break;
473 case MachineState_Saving:
474 pszState = "saving";
475 break;
476 case MachineState_Restoring:
477 pszState = "restoring";
478 break;
479 case MachineState_TeleportingPausedVM:
480 pszState = details == VMINFO_MACHINEREADABLE ? "teleportingpausedvm" : "teleporting paused vm";
481 break;
482 case MachineState_TeleportingIn:
483 pszState = details == VMINFO_MACHINEREADABLE ? "teleportingin" : "teleporting (incoming)";
484 break;
485 case MachineState_RestoringSnapshot:
486 pszState = details == VMINFO_MACHINEREADABLE ? "restoringsnapshot" : "restoring snapshot";
487 case MachineState_DeletingSnapshot:
488 pszState = details == VMINFO_MACHINEREADABLE ? "deletingsnapshot" : "deleting snapshot";
489 case MachineState_SettingUp:
490 pszState = details == VMINFO_MACHINEREADABLE ? "settingup" : "setting up";
491 break;
492 default:
493 pszState = "unknown";
494 break;
495 }
496 LONG64 stateSince;
497 machine->COMGETTER(LastStateChange)(&stateSince);
498 RTTIMESPEC timeSpec;
499 RTTimeSpecSetMilli(&timeSpec, stateSince);
500 char pszTime[30] = {0};
501 RTTimeSpecToString(&timeSpec, pszTime, sizeof(pszTime));
502 Bstr stateFile;
503 machine->COMGETTER(StateFilePath)(stateFile.asOutParam());
504 if (details == VMINFO_MACHINEREADABLE)
505 {
506 RTPrintf("VMState=\"%s\"\n", pszState);
507 RTPrintf("VMStateChangeTime=\"%s\"\n", pszTime);
508 if (!stateFile.isEmpty())
509 RTPrintf("VMStateFile=\"%lS\"\n", stateFile.raw());
510 }
511 else
512 RTPrintf("State: %s (since %s)\n", pszState, pszTime);
513
514 ULONG numMonitors;
515 machine->COMGETTER(MonitorCount)(&numMonitors);
516 if (details == VMINFO_MACHINEREADABLE)
517 RTPrintf("monitorcount=%d\n", numMonitors);
518 else
519 RTPrintf("Monitor count: %d\n", numMonitors);
520
521 BOOL accelerate3d;
522 machine->COMGETTER(Accelerate3DEnabled)(&accelerate3d);
523 if (details == VMINFO_MACHINEREADABLE)
524 RTPrintf("accelerate3d=\"%s\"\n", accelerate3d ? "on" : "off");
525 else
526 RTPrintf("3D Acceleration: %s\n", accelerate3d ? "on" : "off");
527
528#ifdef VBOX_WITH_VIDEOHWACCEL
529 BOOL accelerate2dVideo;
530 machine->COMGETTER(Accelerate2DVideoEnabled)(&accelerate2dVideo);
531 if (details == VMINFO_MACHINEREADABLE)
532 RTPrintf("accelerate2dvideo=\"%s\"\n", accelerate2dVideo ? "on" : "off");
533 else
534 RTPrintf("2D Video Acceleration: %s\n", accelerate2dVideo ? "on" : "off");
535#endif
536
537 BOOL teleporterEnabled;
538 machine->COMGETTER(TeleporterEnabled)(&teleporterEnabled);
539 if (details == VMINFO_MACHINEREADABLE)
540 RTPrintf("teleporterenabled=\"%s\"\n", teleporterEnabled ? "on" : "off");
541 else
542 RTPrintf("Teleporter Enabled: %s\n", teleporterEnabled ? "on" : "off");
543
544 ULONG teleporterPort;
545 machine->COMGETTER(TeleporterPort)(&teleporterPort);
546 if (details == VMINFO_MACHINEREADABLE)
547 RTPrintf("teleporterport=%u\n", teleporterPort);
548 else
549 RTPrintf("Teleporter Port: %u\n", teleporterPort);
550
551 Bstr teleporterAddress;
552 machine->COMGETTER(TeleporterAddress)(teleporterAddress.asOutParam());
553 if (details == VMINFO_MACHINEREADABLE)
554 RTPrintf("teleporteraddress=\"%lS\"\n", teleporterAddress.raw());
555 else
556 RTPrintf("Teleporter Address: %lS\n", teleporterAddress.raw());
557
558 Bstr teleporterPassword;
559 machine->COMGETTER(TeleporterPassword)(teleporterPassword.asOutParam());
560 if (details == VMINFO_MACHINEREADABLE)
561 RTPrintf("teleporterpassword=\"%lS\"\n", teleporterPassword.raw());
562 else
563 RTPrintf("Teleporter Password: %lS\n", teleporterPassword.raw());
564
565 /*
566 * Storage Controllers and their attached Mediums.
567 */
568 com::SafeIfaceArray<IStorageController> storageCtls;
569 CHECK_ERROR(machine, COMGETTER(StorageControllers)(ComSafeArrayAsOutParam (storageCtls)));
570 for (size_t i = 0; i < storageCtls.size(); ++ i)
571 {
572 ComPtr<IStorageController> storageCtl = storageCtls[i];
573 StorageControllerType_T enmCtlType = StorageControllerType_Null;
574 const char *pszCtl = NULL;
575 ULONG ulValue = 0;
576 Bstr storageCtlName;
577
578 storageCtl->COMGETTER(Name)(storageCtlName.asOutParam());
579 if (details == VMINFO_MACHINEREADABLE)
580 RTPrintf("storagecontrollername%u=\"%lS\"\n", i, storageCtlName.raw());
581 else
582 RTPrintf("Storage Controller Name (%u): %lS\n", i, storageCtlName.raw());
583
584 storageCtl->COMGETTER(ControllerType)(&enmCtlType);
585 switch (enmCtlType)
586 {
587 case StorageControllerType_LsiLogic:
588 pszCtl = "LsiLogic";
589 break;
590 case StorageControllerType_BusLogic:
591 pszCtl = "BusLogic";
592 break;
593 case StorageControllerType_IntelAhci:
594 pszCtl = "IntelAhci";
595 break;
596 case StorageControllerType_PIIX3:
597 pszCtl = "PIIX3";
598 break;
599 case StorageControllerType_PIIX4:
600 pszCtl = "PIIX4";
601 break;
602 case StorageControllerType_ICH6:
603 pszCtl = "ICH6";
604 break;
605 case StorageControllerType_I82078:
606 pszCtl = "I82078";
607 break;
608
609 default:
610 pszCtl = "unknown";
611 }
612 if (details == VMINFO_MACHINEREADABLE)
613 RTPrintf("storagecontrollertype%u=\"%s\"\n", i, pszCtl);
614 else
615 RTPrintf("Storage Controller Type (%u): %s\n", i, pszCtl);
616
617 storageCtl->COMGETTER(Instance)(&ulValue);
618 if (details == VMINFO_MACHINEREADABLE)
619 RTPrintf("storagecontrollerinstance%u=\"%lu\"\n", i, ulValue);
620 else
621 RTPrintf("Storage Controller Instance Number (%u): %lu\n", i, ulValue);
622
623 storageCtl->COMGETTER(MaxPortCount)(&ulValue);
624 if (details == VMINFO_MACHINEREADABLE)
625 RTPrintf("storagecontrollermaxportcount%u=\"%lu\"\n", i, ulValue);
626 else
627 RTPrintf("Storage Controller Max Port Count (%u): %lu\n", i, ulValue);
628
629 storageCtl->COMGETTER(PortCount)(&ulValue);
630 if (details == VMINFO_MACHINEREADABLE)
631 RTPrintf("storagecontrollerportcount%u=\"%lu\"\n", i, ulValue);
632 else
633 RTPrintf("Storage Controller Port Count (%u): %lu\n", i, ulValue);
634 }
635
636 for (size_t j = 0; j < storageCtls.size(); ++ j)
637 {
638 ComPtr<IStorageController> storageCtl = storageCtls[j];
639 ComPtr<IMedium> medium;
640 Bstr storageCtlName;
641 Bstr filePath;
642 ULONG cDevices;
643 ULONG cPorts;
644
645 storageCtl->COMGETTER(Name)(storageCtlName.asOutParam());
646 storageCtl->COMGETTER(MaxDevicesPerPortCount)(&cDevices);
647 storageCtl->COMGETTER(PortCount)(&cPorts);
648
649 for (ULONG i = 0; i < cPorts; ++ i)
650 {
651 for (ULONG k = 0; k < cDevices; ++ k)
652 {
653 rc = machine->GetMedium(storageCtlName, i, k, medium.asOutParam());
654 if (SUCCEEDED(rc) && medium)
655 {
656 BOOL fPassthrough;
657 ComPtr<IMediumAttachment> mediumAttach;
658
659 rc = machine->GetMediumAttachment(storageCtlName, i, k, mediumAttach.asOutParam());
660 if (SUCCEEDED(rc) && mediumAttach)
661 mediumAttach->COMGETTER(Passthrough)(&fPassthrough);
662
663 medium->COMGETTER(Location)(filePath.asOutParam());
664 medium->COMGETTER(Id)(uuid.asOutParam());
665
666 if (details == VMINFO_MACHINEREADABLE)
667 {
668 RTPrintf("\"%lS-%d-%d\"=\"%lS\"\n", storageCtlName.raw(),
669 i, k, filePath.raw());
670 RTPrintf("\"%lS-ImageUUID-%d-%d\"=\"%s\"\n",
671 storageCtlName.raw(), i, k, Utf8Str(uuid).raw());
672 if (fPassthrough)
673 RTPrintf("\"%lS-dvdpassthrough\"=\"%s\"\n", storageCtlName.raw(),
674 fPassthrough ? "on" : "off");
675 }
676 else
677 {
678 RTPrintf("%lS (%d, %d): %lS (UUID: %s)",
679 storageCtlName.raw(), i, k, filePath.raw(),
680 Utf8Str(uuid).raw());
681 if (fPassthrough)
682 RTPrintf(" (passthrough enabled)");
683 RTPrintf("\n");
684 }
685 }
686 else if (SUCCEEDED(rc))
687 {
688 if (details == VMINFO_MACHINEREADABLE)
689 RTPrintf("\"%lS-%d-%d\"=\"emptydrive\"\n", storageCtlName.raw(), i, k);
690 else
691 RTPrintf("%lS (%d, %d): Empty\n", storageCtlName.raw(), i, k);
692 }
693 else
694 {
695 if (details == VMINFO_MACHINEREADABLE)
696 RTPrintf("\"%lS-%d-%d\"=\"none\"\n", storageCtlName.raw(), i, k);
697 }
698 }
699 }
700 }
701
702 /* get the maximum amount of NICS */
703 ComPtr<ISystemProperties> sysProps;
704 virtualBox->COMGETTER(SystemProperties)(sysProps.asOutParam());
705 ULONG maxNICs = 0;
706 sysProps->COMGETTER(NetworkAdapterCount)(&maxNICs);
707 for (ULONG currentNIC = 0; currentNIC < maxNICs; currentNIC++)
708 {
709 ComPtr<INetworkAdapter> nic;
710 rc = machine->GetNetworkAdapter(currentNIC, nic.asOutParam());
711 if (SUCCEEDED(rc) && nic)
712 {
713 BOOL fEnabled;
714 nic->COMGETTER(Enabled)(&fEnabled);
715 if (!fEnabled)
716 {
717 if (details == VMINFO_MACHINEREADABLE)
718 RTPrintf("nic%d=\"none\"\n", currentNIC + 1);
719 else
720 RTPrintf("NIC %d: disabled\n", currentNIC + 1);
721 }
722 else
723 {
724 Bstr strMACAddress;
725 nic->COMGETTER(MACAddress)(strMACAddress.asOutParam());
726 Utf8Str strAttachment;
727 NetworkAttachmentType_T attachment;
728 nic->COMGETTER(AttachmentType)(&attachment);
729 switch (attachment)
730 {
731 case NetworkAttachmentType_Null:
732 if (details == VMINFO_MACHINEREADABLE)
733 strAttachment = "null";
734 else
735 strAttachment = "none";
736 break;
737 case NetworkAttachmentType_NAT:
738 {
739 Bstr strNetwork;
740 nic->COMGETTER(NATNetwork)(strNetwork.asOutParam());
741 if (details == VMINFO_MACHINEREADABLE)
742 {
743 RTPrintf("natnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.raw());
744 strAttachment = "nat";
745 }
746 else if (!strNetwork.isEmpty())
747 strAttachment = Utf8StrFmt("NAT (%lS)", strNetwork.raw());
748 else
749 strAttachment = "NAT";
750 break;
751 }
752 case NetworkAttachmentType_Bridged:
753 {
754 Bstr strBridgeAdp;
755 nic->COMGETTER(HostInterface)(strBridgeAdp.asOutParam());
756 if (details == VMINFO_MACHINEREADABLE)
757 {
758 RTPrintf("bridgeadapter%d=\"%lS\"\n", currentNIC + 1, strBridgeAdp.raw());
759 strAttachment = "bridged";
760 }
761 else
762 strAttachment = Utf8StrFmt("Bridged Interface '%lS'", strBridgeAdp.raw());
763 break;
764 }
765 case NetworkAttachmentType_Internal:
766 {
767 Bstr strNetwork;
768 nic->COMGETTER(InternalNetwork)(strNetwork.asOutParam());
769 if (details == VMINFO_MACHINEREADABLE)
770 {
771 RTPrintf("intnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.raw());
772 strAttachment = "intnet";
773 }
774 else
775 strAttachment = Utf8StrFmt("Internal Network '%s'", Utf8Str(strNetwork).raw());
776 break;
777 }
778#if defined(VBOX_WITH_NETFLT)
779 case NetworkAttachmentType_HostOnly:
780 {
781 Bstr strHostonlyAdp;
782 nic->COMGETTER(HostInterface)(strHostonlyAdp.asOutParam());
783 if (details == VMINFO_MACHINEREADABLE)
784 {
785 RTPrintf("hostonlyadapter%d=\"%lS\"\n", currentNIC + 1, strHostonlyAdp.raw());
786 strAttachment = "hostonly";
787 }
788 else
789 strAttachment = Utf8StrFmt("Host-only Interface '%lS'", strHostonlyAdp.raw());
790 break;
791 }
792#endif
793 default:
794 strAttachment = "unknown";
795 break;
796 }
797
798 /* cable connected */
799 BOOL fConnected;
800 nic->COMGETTER(CableConnected)(&fConnected);
801
802 /* trace stuff */
803 BOOL fTraceEnabled;
804 nic->COMGETTER(TraceEnabled)(&fTraceEnabled);
805 Bstr traceFile;
806 nic->COMGETTER(TraceFile)(traceFile.asOutParam());
807
808 /* NIC type */
809 Utf8Str strNICType;
810 NetworkAdapterType_T NICType;
811 nic->COMGETTER(AdapterType)(&NICType);
812 switch (NICType) {
813 case NetworkAdapterType_Am79C970A:
814 strNICType = "Am79C970A";
815 break;
816 case NetworkAdapterType_Am79C973:
817 strNICType = "Am79C973";
818 break;
819#ifdef VBOX_WITH_E1000
820 case NetworkAdapterType_I82540EM:
821 strNICType = "82540EM";
822 break;
823 case NetworkAdapterType_I82543GC:
824 strNICType = "82543GC";
825 break;
826 case NetworkAdapterType_I82545EM:
827 strNICType = "82545EM";
828 break;
829#endif
830#ifdef VBOX_WITH_VIRTIO
831 case NetworkAdapterType_Virtio:
832 strNICType = "virtio";
833 break;
834#endif /* VBOX_WITH_VIRTIO */
835 default:
836 strNICType = "unknown";
837 break;
838 }
839
840 /* reported line speed */
841 ULONG ulLineSpeed;
842 nic->COMGETTER(LineSpeed)(&ulLineSpeed);
843
844 if (details == VMINFO_MACHINEREADABLE)
845 {
846 RTPrintf("macaddress%d=\"%lS\"\n", currentNIC + 1, strMACAddress.raw());
847 RTPrintf("cableconnected%d=\"%s\"\n", currentNIC + 1, fConnected ? "on" : "off");
848 RTPrintf("nic%d=\"%s\"\n", currentNIC + 1, strAttachment.raw());
849 }
850 else
851 RTPrintf("NIC %d: MAC: %lS, Attachment: %s, Cable connected: %s, Trace: %s (file: %lS), Type: %s, Reported speed: %d Mbps\n",
852 currentNIC + 1, strMACAddress.raw(), strAttachment.raw(),
853 fConnected ? "on" : "off",
854 fTraceEnabled ? "on" : "off",
855 traceFile.isEmpty() ? Bstr("none").raw() : traceFile.raw(),
856 strNICType.raw(),
857 ulLineSpeed / 1000);
858 }
859 }
860 }
861
862 /* get the maximum amount of UARTs */
863 ULONG maxUARTs = 0;
864 sysProps->COMGETTER(SerialPortCount)(&maxUARTs);
865 for (ULONG currentUART = 0; currentUART < maxUARTs; currentUART++)
866 {
867 ComPtr<ISerialPort> uart;
868 rc = machine->GetSerialPort(currentUART, uart.asOutParam());
869 if (SUCCEEDED(rc) && uart)
870 {
871 BOOL fEnabled;
872 uart->COMGETTER(Enabled)(&fEnabled);
873 if (!fEnabled)
874 {
875 if (details == VMINFO_MACHINEREADABLE)
876 RTPrintf("uart%d=\"off\"\n", currentUART + 1);
877 else
878 RTPrintf("UART %d: disabled\n", currentUART + 1);
879 }
880 else
881 {
882 ULONG ulIRQ, ulIOBase;
883 PortMode_T HostMode;
884 Bstr path;
885 BOOL fServer;
886 uart->COMGETTER(IRQ)(&ulIRQ);
887 uart->COMGETTER(IOBase)(&ulIOBase);
888 uart->COMGETTER(Path)(path.asOutParam());
889 uart->COMGETTER(Server)(&fServer);
890 uart->COMGETTER(HostMode)(&HostMode);
891
892 if (details == VMINFO_MACHINEREADABLE)
893 RTPrintf("uart%d=\"%#06x,%d\"\n", currentUART + 1,
894 ulIOBase, ulIRQ);
895 else
896 RTPrintf("UART %d: I/O base: 0x%04x, IRQ: %d",
897 currentUART + 1, ulIOBase, ulIRQ);
898 switch (HostMode)
899 {
900 default:
901 case PortMode_Disconnected:
902 if (details == VMINFO_MACHINEREADABLE)
903 RTPrintf("uartmode%d=\"disconnected\"\n", currentUART + 1);
904 else
905 RTPrintf(", disconnected\n");
906 break;
907 case PortMode_RawFile:
908 if (details == VMINFO_MACHINEREADABLE)
909 RTPrintf("uartmode%d=\"%lS\"\n", currentUART + 1,
910 path.raw());
911 else
912 RTPrintf(", attached to raw file '%lS'\n",
913 path.raw());
914 break;
915 case PortMode_HostPipe:
916 if (details == VMINFO_MACHINEREADABLE)
917 RTPrintf("uartmode%d=\"%s,%lS\"\n", currentUART + 1,
918 fServer ? "server" : "client", path.raw());
919 else
920 RTPrintf(", attached to pipe (%s) '%lS'\n",
921 fServer ? "server" : "client", path.raw());
922 break;
923 case PortMode_HostDevice:
924 if (details == VMINFO_MACHINEREADABLE)
925 RTPrintf("uartmode%d=\"%lS\"\n", currentUART + 1,
926 path.raw());
927 else
928 RTPrintf(", attached to device '%lS'\n", path.raw());
929 break;
930 }
931 }
932 }
933 }
934
935 ComPtr<IAudioAdapter> AudioAdapter;
936 rc = machine->COMGETTER(AudioAdapter)(AudioAdapter.asOutParam());
937 if (SUCCEEDED(rc))
938 {
939 const char *pszDrv = "Unknown";
940 const char *pszCtrl = "Unknown";
941 BOOL fEnabled;
942 rc = AudioAdapter->COMGETTER(Enabled)(&fEnabled);
943 if (SUCCEEDED(rc) && fEnabled)
944 {
945 AudioDriverType_T enmDrvType;
946 rc = AudioAdapter->COMGETTER(AudioDriver)(&enmDrvType);
947 switch (enmDrvType)
948 {
949 case AudioDriverType_Null:
950 if (details == VMINFO_MACHINEREADABLE)
951 pszDrv = "null";
952 else
953 pszDrv = "Null";
954 break;
955 case AudioDriverType_WinMM:
956 if (details == VMINFO_MACHINEREADABLE)
957 pszDrv = "winmm";
958 else
959 pszDrv = "WINMM";
960 break;
961 case AudioDriverType_DirectSound:
962 if (details == VMINFO_MACHINEREADABLE)
963 pszDrv = "dsound";
964 else
965 pszDrv = "DSOUND";
966 break;
967 case AudioDriverType_OSS:
968 if (details == VMINFO_MACHINEREADABLE)
969 pszDrv = "oss";
970 else
971 pszDrv = "OSS";
972 break;
973 case AudioDriverType_ALSA:
974 if (details == VMINFO_MACHINEREADABLE)
975 pszDrv = "alsa";
976 else
977 pszDrv = "ALSA";
978 break;
979 case AudioDriverType_Pulse:
980 if (details == VMINFO_MACHINEREADABLE)
981 pszDrv = "pulse";
982 else
983 pszDrv = "PulseAudio";
984 break;
985 case AudioDriverType_CoreAudio:
986 if (details == VMINFO_MACHINEREADABLE)
987 pszDrv = "coreaudio";
988 else
989 pszDrv = "CoreAudio";
990 break;
991 case AudioDriverType_SolAudio:
992 if (details == VMINFO_MACHINEREADABLE)
993 pszDrv = "solaudio";
994 else
995 pszDrv = "SolAudio";
996 break;
997 default:
998 if (details == VMINFO_MACHINEREADABLE)
999 pszDrv = "unknown";
1000 break;
1001 }
1002 AudioControllerType_T enmCtrlType;
1003 rc = AudioAdapter->COMGETTER(AudioController)(&enmCtrlType);
1004 switch (enmCtrlType)
1005 {
1006 case AudioControllerType_AC97:
1007 if (details == VMINFO_MACHINEREADABLE)
1008 pszCtrl = "ac97";
1009 else
1010 pszCtrl = "AC97";
1011 break;
1012 case AudioControllerType_SB16:
1013 if (details == VMINFO_MACHINEREADABLE)
1014 pszCtrl = "sb16";
1015 else
1016 pszCtrl = "SB16";
1017 break;
1018 }
1019 }
1020 else
1021 fEnabled = FALSE;
1022 if (details == VMINFO_MACHINEREADABLE)
1023 {
1024 if (fEnabled)
1025 RTPrintf("audio=\"%s\"\n", pszDrv);
1026 else
1027 RTPrintf("audio=\"none\"\n");
1028 }
1029 else
1030 {
1031 RTPrintf("Audio: %s",
1032 fEnabled ? "enabled" : "disabled");
1033 if (fEnabled)
1034 RTPrintf(" (Driver: %s, Controller: %s)",
1035 pszDrv, pszCtrl);
1036 RTPrintf("\n");
1037 }
1038 }
1039
1040 /* Shared clipboard */
1041 {
1042 const char *psz = "Unknown";
1043 ClipboardMode_T enmMode;
1044 rc = machine->COMGETTER(ClipboardMode)(&enmMode);
1045 switch (enmMode)
1046 {
1047 case ClipboardMode_Disabled:
1048 if (details == VMINFO_MACHINEREADABLE)
1049 psz = "disabled";
1050 else
1051 psz = "disabled";
1052 break;
1053 case ClipboardMode_HostToGuest:
1054 if (details == VMINFO_MACHINEREADABLE)
1055 psz = "hosttoguest";
1056 else
1057 psz = "HostToGuest";
1058 break;
1059 case ClipboardMode_GuestToHost:
1060 if (details == VMINFO_MACHINEREADABLE)
1061 psz = "guesttohost";
1062 else
1063 psz = "GuestToHost";
1064 break;
1065 case ClipboardMode_Bidirectional:
1066 if (details == VMINFO_MACHINEREADABLE)
1067 psz = "bidirectional";
1068 else
1069 psz = "Bidirectional";
1070 break;
1071 default:
1072 if (details == VMINFO_MACHINEREADABLE)
1073 psz = "unknown";
1074 break;
1075 }
1076 if (details == VMINFO_MACHINEREADABLE)
1077 RTPrintf("clipboard=\"%s\"\n", psz);
1078 else
1079 RTPrintf("Clipboard Mode: %s\n", psz);
1080 }
1081
1082 if (console)
1083 {
1084 ComPtr<IDisplay> display;
1085 CHECK_ERROR_RET(console, COMGETTER(Display)(display.asOutParam()), rc);
1086 do
1087 {
1088 ULONG xRes, yRes, bpp;
1089 rc = display->COMGETTER(Width)(&xRes);
1090 if (rc == E_ACCESSDENIED)
1091 break; /* VM not powered up */
1092 if (FAILED(rc))
1093 {
1094 com::ErrorInfo info (display);
1095 GluePrintErrorInfo(info);
1096 return rc;
1097 }
1098 rc = display->COMGETTER(Height)(&yRes);
1099 if (rc == E_ACCESSDENIED)
1100 break; /* VM not powered up */
1101 if (FAILED(rc))
1102 {
1103 com::ErrorInfo info (display);
1104 GluePrintErrorInfo(info);
1105 return rc;
1106 }
1107 rc = display->COMGETTER(BitsPerPixel)(&bpp);
1108 if (rc == E_ACCESSDENIED)
1109 break; /* VM not powered up */
1110 if (FAILED(rc))
1111 {
1112 com::ErrorInfo info (display);
1113 GluePrintErrorInfo(info);
1114 return rc;
1115 }
1116 if (details == VMINFO_MACHINEREADABLE)
1117 RTPrintf("VideoMode=\"%d,%d,%d\"\n", xRes, yRes, bpp);
1118 else
1119 RTPrintf("Video mode: %dx%dx%d\n", xRes, yRes, bpp);
1120 }
1121 while (0);
1122 }
1123
1124 /*
1125 * VRDP
1126 */
1127 ComPtr<IVRDPServer> vrdpServer;
1128 rc = machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1129 if (SUCCEEDED(rc) && vrdpServer)
1130 {
1131 BOOL fEnabled = false;
1132 vrdpServer->COMGETTER(Enabled)(&fEnabled);
1133 if (fEnabled)
1134 {
1135 LONG vrdpPort = -1;
1136 Bstr ports;
1137 vrdpServer->COMGETTER(Ports)(ports.asOutParam());
1138 Bstr address;
1139 vrdpServer->COMGETTER(NetAddress)(address.asOutParam());
1140 BOOL fMultiCon;
1141 vrdpServer->COMGETTER(AllowMultiConnection)(&fMultiCon);
1142 BOOL fReuseCon;
1143 vrdpServer->COMGETTER(ReuseSingleConnection)(&fReuseCon);
1144 VRDPAuthType_T vrdpAuthType;
1145 const char *strAuthType;
1146 vrdpServer->COMGETTER(AuthType)(&vrdpAuthType);
1147 switch (vrdpAuthType)
1148 {
1149 case VRDPAuthType_Null:
1150 strAuthType = "null";
1151 break;
1152 case VRDPAuthType_External:
1153 strAuthType = "external";
1154 break;
1155 case VRDPAuthType_Guest:
1156 strAuthType = "guest";
1157 break;
1158 default:
1159 strAuthType = "unknown";
1160 break;
1161 }
1162 if (console)
1163 {
1164 ComPtr<IRemoteDisplayInfo> remoteDisplayInfo;
1165 CHECK_ERROR_RET(console, COMGETTER(RemoteDisplayInfo)(remoteDisplayInfo.asOutParam()), rc);
1166 rc = remoteDisplayInfo->COMGETTER(Port)(&vrdpPort);
1167 if (rc == E_ACCESSDENIED)
1168 {
1169 vrdpPort = -1; /* VM not powered up */
1170 }
1171 if (FAILED(rc))
1172 {
1173 com::ErrorInfo info (remoteDisplayInfo);
1174 GluePrintErrorInfo(info);
1175 return rc;
1176 }
1177 }
1178 if (details == VMINFO_MACHINEREADABLE)
1179 {
1180 RTPrintf("vrdp=\"on\"\n");
1181 RTPrintf("vrdpport=%d\n", vrdpPort);
1182 RTPrintf("vrdpports=\"%lS\"\n", ports.raw());
1183 RTPrintf("vrdpaddress=\"%lS\"\n", address.raw());
1184 RTPrintf("vrdpauthtype=\"%s\"\n", strAuthType);
1185 RTPrintf("vrdpmulticon=\"%s\"\n", fMultiCon ? "on" : "off");
1186 RTPrintf("vrdpreusecon=\"%s\"\n", fReuseCon ? "on" : "off");
1187 }
1188 else
1189 {
1190 if (address.isEmpty())
1191 address = "0.0.0.0";
1192 RTPrintf("VRDP: enabled (Address %lS, Ports %lS, MultiConn: %s, ReuseSingleConn: %s, Authentication type: %s)\n", address.raw(), ports.raw(), fMultiCon ? "on" : "off", fReuseCon ? "on" : "off", strAuthType);
1193 if (console && vrdpPort != -1 && vrdpPort != 0)
1194 RTPrintf("VRDP port: %d\n", vrdpPort);
1195 }
1196 }
1197 else
1198 {
1199 if (details == VMINFO_MACHINEREADABLE)
1200 RTPrintf("vrdp=\"off\"\n");
1201 else
1202 RTPrintf("VRDP: disabled\n");
1203 }
1204 }
1205
1206 /*
1207 * USB.
1208 */
1209 ComPtr<IUSBController> USBCtl;
1210 rc = machine->COMGETTER(USBController)(USBCtl.asOutParam());
1211 if (SUCCEEDED(rc))
1212 {
1213 BOOL fEnabled;
1214 rc = USBCtl->COMGETTER(Enabled)(&fEnabled);
1215 if (FAILED(rc))
1216 fEnabled = false;
1217 if (details == VMINFO_MACHINEREADABLE)
1218 RTPrintf("usb=\"%s\"\n", fEnabled ? "on" : "off");
1219 else
1220 RTPrintf("USB: %s\n", fEnabled ? "enabled" : "disabled");
1221
1222 if (details != VMINFO_MACHINEREADABLE)
1223 RTPrintf("\nUSB Device Filters:\n\n");
1224
1225 SafeIfaceArray <IUSBDeviceFilter> Coll;
1226 CHECK_ERROR_RET (USBCtl, COMGETTER(DeviceFilters)(ComSafeArrayAsOutParam(Coll)), rc);
1227
1228 if (Coll.size() == 0)
1229 {
1230 if (details != VMINFO_MACHINEREADABLE)
1231 RTPrintf("<none>\n\n");
1232 }
1233 else
1234 {
1235 for (size_t index = 0; index < Coll.size(); ++index)
1236 {
1237 ComPtr<IUSBDeviceFilter> DevPtr = Coll[index];
1238
1239 /* Query info. */
1240
1241 if (details != VMINFO_MACHINEREADABLE)
1242 RTPrintf("Index: %zu\n", index);
1243
1244 BOOL bActive = FALSE;
1245 CHECK_ERROR_RET (DevPtr, COMGETTER (Active) (&bActive), rc);
1246 if (details == VMINFO_MACHINEREADABLE)
1247 RTPrintf("USBFilterActive%zu=\"%s\"\n", index + 1, bActive ? "on" : "off");
1248 else
1249 RTPrintf("Active: %s\n", bActive ? "yes" : "no");
1250
1251 Bstr bstr;
1252 CHECK_ERROR_RET (DevPtr, COMGETTER (Name) (bstr.asOutParam()), rc);
1253 if (details == VMINFO_MACHINEREADABLE)
1254 RTPrintf("USBFilterName%zu=\"%lS\"\n", index + 1, bstr.raw());
1255 else
1256 RTPrintf("Name: %lS\n", bstr.raw());
1257 CHECK_ERROR_RET (DevPtr, COMGETTER (VendorId) (bstr.asOutParam()), rc);
1258 if (details == VMINFO_MACHINEREADABLE)
1259 RTPrintf("USBFilterVendorId%zu=\"%lS\"\n", index + 1, bstr.raw());
1260 else
1261 RTPrintf("VendorId: %lS\n", bstr.raw());
1262 CHECK_ERROR_RET (DevPtr, COMGETTER (ProductId) (bstr.asOutParam()), rc);
1263 if (details == VMINFO_MACHINEREADABLE)
1264 RTPrintf("USBFilterProductId%zu=\"%lS\"\n", index + 1, bstr.raw());
1265 else
1266 RTPrintf("ProductId: %lS\n", bstr.raw());
1267 CHECK_ERROR_RET (DevPtr, COMGETTER (Revision) (bstr.asOutParam()), rc);
1268 if (details == VMINFO_MACHINEREADABLE)
1269 RTPrintf("USBFilterRevision%zu=\"%lS\"\n", index + 1, bstr.raw());
1270 else
1271 RTPrintf("Revision: %lS\n", bstr.raw());
1272 CHECK_ERROR_RET (DevPtr, COMGETTER (Manufacturer) (bstr.asOutParam()), rc);
1273 if (details == VMINFO_MACHINEREADABLE)
1274 RTPrintf("USBFilterManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1275 else
1276 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1277 CHECK_ERROR_RET (DevPtr, COMGETTER (Product) (bstr.asOutParam()), rc);
1278 if (details == VMINFO_MACHINEREADABLE)
1279 RTPrintf("USBFilterProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1280 else
1281 RTPrintf("Product: %lS\n", bstr.raw());
1282 CHECK_ERROR_RET (DevPtr, COMGETTER (Remote) (bstr.asOutParam()), rc);
1283 if (details == VMINFO_MACHINEREADABLE)
1284 RTPrintf("USBFilterRemote%zu=\"%lS\"\n", index + 1, bstr.raw());
1285 else
1286 RTPrintf("Remote: %lS\n", bstr.raw());
1287 CHECK_ERROR_RET (DevPtr, COMGETTER (SerialNumber) (bstr.asOutParam()), rc);
1288 if (details == VMINFO_MACHINEREADABLE)
1289 RTPrintf("USBFilterSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1290 else
1291 RTPrintf("Serial Number: %lS\n", bstr.raw());
1292 if (details != VMINFO_MACHINEREADABLE)
1293 {
1294 ULONG fMaskedIfs;
1295 CHECK_ERROR_RET (DevPtr, COMGETTER (MaskedInterfaces) (&fMaskedIfs), rc);
1296 if (fMaskedIfs)
1297 RTPrintf("Masked Interfaces: 0x%08x\n", fMaskedIfs);
1298 RTPrintf("\n");
1299 }
1300 }
1301 }
1302
1303 if (console)
1304 {
1305 /* scope */
1306 {
1307 if (details != VMINFO_MACHINEREADABLE)
1308 RTPrintf("Available remote USB devices:\n\n");
1309
1310 SafeIfaceArray <IHostUSBDevice> coll;
1311 CHECK_ERROR_RET (console, COMGETTER(RemoteUSBDevices) (ComSafeArrayAsOutParam(coll)), rc);
1312
1313 if (coll.size() == 0)
1314 {
1315 if (details != VMINFO_MACHINEREADABLE)
1316 RTPrintf("<none>\n\n");
1317 }
1318 else
1319 {
1320 for (size_t index = 0; index < coll.size(); ++index)
1321 {
1322 ComPtr <IHostUSBDevice> dev = coll[index];
1323
1324 /* Query info. */
1325 Bstr id;
1326 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1327 USHORT usVendorId;
1328 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1329 USHORT usProductId;
1330 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1331 USHORT bcdRevision;
1332 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1333
1334 if (details == VMINFO_MACHINEREADABLE)
1335 RTPrintf("USBRemoteUUID%zu=\"%S\"\n"
1336 "USBRemoteVendorId%zu=\"%#06x\"\n"
1337 "USBRemoteProductId%zu=\"%#06x\"\n"
1338 "USBRemoteRevision%zu=\"%#04x%02x\"\n",
1339 index + 1, Utf8Str(id).raw(),
1340 index + 1, usVendorId,
1341 index + 1, usProductId,
1342 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1343 else
1344 RTPrintf("UUID: %S\n"
1345 "VendorId: 0x%04x (%04X)\n"
1346 "ProductId: 0x%04x (%04X)\n"
1347 "Revision: %u.%u (%02u%02u)\n",
1348 Utf8Str(id).raw(),
1349 usVendorId, usVendorId, usProductId, usProductId,
1350 bcdRevision >> 8, bcdRevision & 0xff,
1351 bcdRevision >> 8, bcdRevision & 0xff);
1352
1353 /* optional stuff. */
1354 Bstr bstr;
1355 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1356 if (!bstr.isEmpty())
1357 {
1358 if (details == VMINFO_MACHINEREADABLE)
1359 RTPrintf("USBRemoteManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1360 else
1361 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1362 }
1363 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1364 if (!bstr.isEmpty())
1365 {
1366 if (details == VMINFO_MACHINEREADABLE)
1367 RTPrintf("USBRemoteProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1368 else
1369 RTPrintf("Product: %lS\n", bstr.raw());
1370 }
1371 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1372 if (!bstr.isEmpty())
1373 {
1374 if (details == VMINFO_MACHINEREADABLE)
1375 RTPrintf("USBRemoteSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1376 else
1377 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1378 }
1379 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1380 if (!bstr.isEmpty())
1381 {
1382 if (details == VMINFO_MACHINEREADABLE)
1383 RTPrintf("USBRemoteAddress%zu=\"%lS\"\n", index + 1, bstr.raw());
1384 else
1385 RTPrintf("Address: %lS\n", bstr.raw());
1386 }
1387
1388 if (details != VMINFO_MACHINEREADABLE)
1389 RTPrintf("\n");
1390 }
1391 }
1392 }
1393
1394 /* scope */
1395 {
1396 if (details != VMINFO_MACHINEREADABLE)
1397 RTPrintf ("Currently Attached USB Devices:\n\n");
1398
1399 SafeIfaceArray <IUSBDevice> coll;
1400 CHECK_ERROR_RET (console, COMGETTER(USBDevices) (ComSafeArrayAsOutParam(coll)), rc);
1401
1402 if (coll.size() == 0)
1403 {
1404 if (details != VMINFO_MACHINEREADABLE)
1405 RTPrintf("<none>\n\n");
1406 }
1407 else
1408 {
1409 for (size_t index = 0; index < coll.size(); ++index)
1410 {
1411 ComPtr <IUSBDevice> dev = coll[index];
1412
1413 /* Query info. */
1414 Bstr id;
1415 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1416 USHORT usVendorId;
1417 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1418 USHORT usProductId;
1419 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1420 USHORT bcdRevision;
1421 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1422
1423 if (details == VMINFO_MACHINEREADABLE)
1424 RTPrintf("USBAttachedUUID%zu=\"%S\"\n"
1425 "USBAttachedVendorId%zu=\"%#06x\"\n"
1426 "USBAttachedProductId%zu=\"%#06x\"\n"
1427 "USBAttachedRevision%zu=\"%#04x%02x\"\n",
1428 index + 1, Utf8Str(id).raw(),
1429 index + 1, usVendorId,
1430 index + 1, usProductId,
1431 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1432 else
1433 RTPrintf("UUID: %S\n"
1434 "VendorId: 0x%04x (%04X)\n"
1435 "ProductId: 0x%04x (%04X)\n"
1436 "Revision: %u.%u (%02u%02u)\n",
1437 Utf8Str(id).raw(),
1438 usVendorId, usVendorId, usProductId, usProductId,
1439 bcdRevision >> 8, bcdRevision & 0xff,
1440 bcdRevision >> 8, bcdRevision & 0xff);
1441
1442 /* optional stuff. */
1443 Bstr bstr;
1444 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1445 if (!bstr.isEmpty())
1446 {
1447 if (details == VMINFO_MACHINEREADABLE)
1448 RTPrintf("USBAttachedManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1449 else
1450 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1451 }
1452 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1453 if (!bstr.isEmpty())
1454 {
1455 if (details == VMINFO_MACHINEREADABLE)
1456 RTPrintf("USBAttachedProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1457 else
1458 RTPrintf("Product: %lS\n", bstr.raw());
1459 }
1460 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1461 if (!bstr.isEmpty())
1462 {
1463 if (details == VMINFO_MACHINEREADABLE)
1464 RTPrintf("USBAttachedSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1465 else
1466 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1467 }
1468 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1469 if (!bstr.isEmpty())
1470 {
1471 if (details == VMINFO_MACHINEREADABLE)
1472 RTPrintf("USBAttachedAddress%zu=\"%lS\"\n", index + 1, bstr.raw());
1473 else
1474 RTPrintf("Address: %lS\n", bstr.raw());
1475 }
1476
1477 if (details != VMINFO_MACHINEREADABLE)
1478 RTPrintf("\n");
1479 }
1480 }
1481 }
1482 }
1483 } /* USB */
1484
1485 /*
1486 * Shared folders
1487 */
1488 if (details != VMINFO_MACHINEREADABLE)
1489 RTPrintf("Shared folders: ");
1490 uint32_t numSharedFolders = 0;
1491#if 0 // not yet implemented
1492 /* globally shared folders first */
1493 {
1494 SafeIfaceArray <ISharedFolder> sfColl;
1495 CHECK_ERROR_RET(virtualBox, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sfColl)), rc);
1496 for (size_t i = 0; i < sfColl.size(); ++i)
1497 {
1498 ComPtr<ISharedFolder> sf = sfColl[i];
1499 Bstr name, hostPath;
1500 sf->COMGETTER(Name)(name.asOutParam());
1501 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1502 RTPrintf("Name: '%lS', Host path: '%lS' (global mapping)\n", name.raw(), hostPath.raw());
1503 ++numSharedFolders;
1504 }
1505 }
1506#endif
1507 /* now VM mappings */
1508 {
1509 com::SafeIfaceArray <ISharedFolder> folders;
1510
1511 CHECK_ERROR_RET(machine, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1512
1513 for (size_t i = 0; i < folders.size(); ++i)
1514 {
1515 ComPtr <ISharedFolder> sf = folders[i];
1516
1517 Bstr name, hostPath;
1518 BOOL writable;
1519 sf->COMGETTER(Name)(name.asOutParam());
1520 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1521 sf->COMGETTER(Writable)(&writable);
1522 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1523 RTPrintf("\n\n");
1524 if (details == VMINFO_MACHINEREADABLE)
1525 {
1526 RTPrintf("SharedFolderNameMachineMapping%zu=\"%lS\"\n", i + 1,
1527 name.raw());
1528 RTPrintf("SharedFolderPathMachineMapping%zu=\"%lS\"\n", i + 1,
1529 hostPath.raw());
1530 }
1531 else
1532 RTPrintf("Name: '%lS', Host path: '%lS' (machine mapping), %s\n",
1533 name.raw(), hostPath.raw(), writable ? "writable" : "readonly");
1534 ++numSharedFolders;
1535 }
1536 }
1537 /* transient mappings */
1538 if (console)
1539 {
1540 com::SafeIfaceArray <ISharedFolder> folders;
1541
1542 CHECK_ERROR_RET(console, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1543
1544 for (size_t i = 0; i < folders.size(); ++i)
1545 {
1546 ComPtr <ISharedFolder> sf = folders[i];
1547
1548 Bstr name, hostPath;
1549 sf->COMGETTER(Name)(name.asOutParam());
1550 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1551 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1552 RTPrintf("\n\n");
1553 if (details == VMINFO_MACHINEREADABLE)
1554 {
1555 RTPrintf("SharedFolderNameTransientMapping%zu=\"%lS\"\n", i + 1,
1556 name.raw());
1557 RTPrintf("SharedFolderPathTransientMapping%zu=\"%lS\"\n", i + 1,
1558 hostPath.raw());
1559 }
1560 else
1561 RTPrintf("Name: '%lS', Host path: '%lS' (transient mapping)\n", name.raw(), hostPath.raw());
1562 ++numSharedFolders;
1563 }
1564 }
1565 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1566 RTPrintf("<none>\n");
1567 if (details != VMINFO_MACHINEREADABLE)
1568 RTPrintf("\n");
1569
1570 if (console)
1571 {
1572 /*
1573 * Live VRDP info.
1574 */
1575 ComPtr<IRemoteDisplayInfo> remoteDisplayInfo;
1576 CHECK_ERROR_RET(console, COMGETTER(RemoteDisplayInfo)(remoteDisplayInfo.asOutParam()), rc);
1577 BOOL Active;
1578 ULONG NumberOfClients;
1579 LONG64 BeginTime;
1580 LONG64 EndTime;
1581 ULONG64 BytesSent;
1582 ULONG64 BytesSentTotal;
1583 ULONG64 BytesReceived;
1584 ULONG64 BytesReceivedTotal;
1585 Bstr User;
1586 Bstr Domain;
1587 Bstr ClientName;
1588 Bstr ClientIP;
1589 ULONG ClientVersion;
1590 ULONG EncryptionStyle;
1591
1592 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Active) (&Active), rc);
1593 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(NumberOfClients) (&NumberOfClients), rc);
1594 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BeginTime) (&BeginTime), rc);
1595 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EndTime) (&EndTime), rc);
1596 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSent) (&BytesSent), rc);
1597 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSentTotal) (&BytesSentTotal), rc);
1598 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceived) (&BytesReceived), rc);
1599 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceivedTotal) (&BytesReceivedTotal), rc);
1600 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(User) (User.asOutParam ()), rc);
1601 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Domain) (Domain.asOutParam ()), rc);
1602 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientName) (ClientName.asOutParam ()), rc);
1603 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientIP) (ClientIP.asOutParam ()), rc);
1604 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientVersion) (&ClientVersion), rc);
1605 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EncryptionStyle) (&EncryptionStyle), rc);
1606
1607 if (details == VMINFO_MACHINEREADABLE)
1608 RTPrintf("VRDPActiveConnection=\"%s\"\n", Active ? "on": "off");
1609 else
1610 RTPrintf("VRDP Connection: %s\n", Active? "active": "not active");
1611
1612 if (details == VMINFO_MACHINEREADABLE)
1613 RTPrintf("VRDPClients=%d\n", NumberOfClients);
1614 else
1615 RTPrintf("Clients so far: %d\n", NumberOfClients);
1616
1617 if (NumberOfClients > 0)
1618 {
1619 char timestr[128];
1620
1621 if (Active)
1622 {
1623 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1624 if (details == VMINFO_MACHINEREADABLE)
1625 RTPrintf("VRDPStartTime=\"%s\"\n", timestr);
1626 else
1627 RTPrintf("Start time: %s\n", timestr);
1628 }
1629 else
1630 {
1631 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1632 if (details == VMINFO_MACHINEREADABLE)
1633 RTPrintf("VRDPLastStartTime=\"%s\"\n", timestr);
1634 else
1635 RTPrintf("Last started: %s\n", timestr);
1636 makeTimeStr (timestr, sizeof (timestr), EndTime);
1637 if (details == VMINFO_MACHINEREADABLE)
1638 RTPrintf("VRDPLastEndTime=\"%s\"\n", timestr);
1639 else
1640 RTPrintf("Last ended: %s\n", timestr);
1641 }
1642
1643 uint64_t ThroughputSend = 0;
1644 uint64_t ThroughputReceive = 0;
1645 if (EndTime != BeginTime)
1646 {
1647 ThroughputSend = (BytesSent * 1000) / (EndTime - BeginTime);
1648 ThroughputReceive = (BytesReceived * 1000) / (EndTime - BeginTime);
1649 }
1650
1651 if (details == VMINFO_MACHINEREADABLE)
1652 {
1653 RTPrintf("VRDPBytesSent=%llu\n", BytesSent);
1654 RTPrintf("VRDPThroughputSend=%llu\n", ThroughputSend);
1655 RTPrintf("VRDPBytesSentTotal=%llu\n", BytesSentTotal);
1656
1657 RTPrintf("VRDPBytesReceived=%llu\n", BytesReceived);
1658 RTPrintf("VRDPThroughputReceive=%llu\n", ThroughputReceive);
1659 RTPrintf("VRDPBytesReceivedTotal=%llu\n", BytesReceivedTotal);
1660 }
1661 else
1662 {
1663 RTPrintf("Sent: %llu Bytes\n", BytesSent);
1664 RTPrintf("Average speed: %llu B/s\n", ThroughputSend);
1665 RTPrintf("Sent total: %llu Bytes\n", BytesSentTotal);
1666
1667 RTPrintf("Received: %llu Bytes\n", BytesReceived);
1668 RTPrintf("Speed: %llu B/s\n", ThroughputReceive);
1669 RTPrintf("Received total: %llu Bytes\n", BytesReceivedTotal);
1670 }
1671
1672 if (Active)
1673 {
1674 if (details == VMINFO_MACHINEREADABLE)
1675 {
1676 RTPrintf("VRDPUserName=\"%lS\"\n", User.raw());
1677 RTPrintf("VRDPDomain=\"%lS\"\n", Domain.raw());
1678 RTPrintf("VRDPClientName=\"%lS\"\n", ClientName.raw());
1679 RTPrintf("VRDPClientIP=\"%lS\"\n", ClientIP.raw());
1680 RTPrintf("VRDPClientVersion=%d\n", ClientVersion);
1681 RTPrintf("VRDPEncryption=\"%s\"\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1682 }
1683 else
1684 {
1685 RTPrintf("User name: %lS\n", User.raw());
1686 RTPrintf("Domain: %lS\n", Domain.raw());
1687 RTPrintf("Client name: %lS\n", ClientName.raw());
1688 RTPrintf("Client IP: %lS\n", ClientIP.raw());
1689 RTPrintf("Client version: %d\n", ClientVersion);
1690 RTPrintf("Encryption: %s\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1691 }
1692 }
1693 }
1694
1695 if (details != VMINFO_MACHINEREADABLE)
1696 RTPrintf("\n");
1697 }
1698
1699 if ( details == VMINFO_STANDARD
1700 || details == VMINFO_FULL
1701 || details == VMINFO_MACHINEREADABLE)
1702 {
1703 Bstr description;
1704 machine->COMGETTER(Description)(description.asOutParam());
1705 if (!description.isEmpty())
1706 {
1707 if (details == VMINFO_MACHINEREADABLE)
1708 RTPrintf("description=\"%lS\"\n", description.raw());
1709 else
1710 RTPrintf("Description:\n%lS\n", description.raw());
1711 }
1712 }
1713
1714 ULONG guestVal;
1715 if (details != VMINFO_MACHINEREADABLE)
1716 RTPrintf("Guest:\n\n");
1717
1718#ifdef VBOX_WITH_MEM_BALLOONING
1719 rc = machine->COMGETTER(MemoryBalloonSize)(&guestVal);
1720 if (SUCCEEDED(rc))
1721 {
1722 if (details == VMINFO_MACHINEREADABLE)
1723 RTPrintf("GuestMemoryBalloon=%d\n", guestVal);
1724 else
1725 RTPrintf("Configured memory balloon size: %d MB\n", guestVal);
1726 }
1727#endif
1728 rc = machine->COMGETTER(StatisticsUpdateInterval)(&guestVal);
1729 if (SUCCEEDED(rc))
1730 {
1731 if (details == VMINFO_MACHINEREADABLE)
1732 RTPrintf("GuestStatisticsUpdateInterval=%d\n", guestVal);
1733 else
1734 {
1735 if (guestVal == 0)
1736 RTPrintf("Statistics update: disabled\n");
1737 else
1738 RTPrintf("Statistics update interval: %d seconds\n", guestVal);
1739 }
1740 }
1741 if (details != VMINFO_MACHINEREADABLE)
1742 RTPrintf("\n");
1743
1744 if ( console
1745 && ( details == VMINFO_STATISTICS
1746 || details == VMINFO_FULL
1747 || details == VMINFO_MACHINEREADABLE))
1748 {
1749 ComPtr <IGuest> guest;
1750
1751 rc = console->COMGETTER(Guest)(guest.asOutParam());
1752 if (SUCCEEDED(rc))
1753 {
1754 ULONG statVal;
1755
1756 rc = guest->GetStatistic(0, GuestStatisticType_SampleNumber, &statVal);
1757 if (SUCCEEDED(rc))
1758 {
1759 if (details == VMINFO_MACHINEREADABLE)
1760 RTPrintf("StatGuestSample=%d\n", statVal);
1761 else
1762 RTPrintf("Guest statistics for sample %d:\n\n", statVal);
1763 }
1764
1765 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Idle, &statVal);
1766 if (SUCCEEDED(rc))
1767 {
1768 if (details == VMINFO_MACHINEREADABLE)
1769 RTPrintf("StatGuestLoadIdleCPU%d=%d\n", 0, statVal);
1770 else
1771 RTPrintf("CPU%d: CPU Load Idle %-3d%%\n", 0, statVal);
1772 }
1773
1774 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Kernel, &statVal);
1775 if (SUCCEEDED(rc))
1776 {
1777 if (details == VMINFO_MACHINEREADABLE)
1778 RTPrintf("StatGuestLoadKernelCPU%d=%d\n", 0, statVal);
1779 else
1780 RTPrintf("CPU%d: CPU Load Kernel %-3d%%\n", 0, statVal);
1781 }
1782
1783 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_User, &statVal);
1784 if (SUCCEEDED(rc))
1785 {
1786 if (details == VMINFO_MACHINEREADABLE)
1787 RTPrintf("StatGuestLoadUserCPU%d=%d\n", 0, statVal);
1788 else
1789 RTPrintf("CPU%d: CPU Load User %-3d%%\n", 0, statVal);
1790 }
1791
1792 rc = guest->GetStatistic(0, GuestStatisticType_Threads, &statVal);
1793 if (SUCCEEDED(rc))
1794 {
1795 if (details == VMINFO_MACHINEREADABLE)
1796 RTPrintf("StatGuestThreadsCPU%d=%d\n", 0, statVal);
1797 else
1798 RTPrintf("CPU%d: Threads %d\n", 0, statVal);
1799 }
1800
1801 rc = guest->GetStatistic(0, GuestStatisticType_Processes, &statVal);
1802 if (SUCCEEDED(rc))
1803 {
1804 if (details == VMINFO_MACHINEREADABLE)
1805 RTPrintf("StatGuestProcessesCPU%d=%d\n", 0, statVal);
1806 else
1807 RTPrintf("CPU%d: Processes %d\n", 0, statVal);
1808 }
1809
1810 rc = guest->GetStatistic(0, GuestStatisticType_Handles, &statVal);
1811 if (SUCCEEDED(rc))
1812 {
1813 if (details == VMINFO_MACHINEREADABLE)
1814 RTPrintf("StatGuestHandlesCPU%d=%d\n", 0, statVal);
1815 else
1816 RTPrintf("CPU%d: Handles %d\n", 0, statVal);
1817 }
1818
1819 rc = guest->GetStatistic(0, GuestStatisticType_MemoryLoad, &statVal);
1820 if (SUCCEEDED(rc))
1821 {
1822 if (details == VMINFO_MACHINEREADABLE)
1823 RTPrintf("StatGuestMemoryLoadCPU%d=%d\n", 0, statVal);
1824 else
1825 RTPrintf("CPU%d: Memory Load %d%%\n", 0, statVal);
1826 }
1827
1828 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemTotal, &statVal);
1829 if (SUCCEEDED(rc))
1830 {
1831 if (details == VMINFO_MACHINEREADABLE)
1832 RTPrintf("StatGuestMemoryTotalPhysCPU%d=%d\n", 0, statVal);
1833 else
1834 RTPrintf("CPU%d: Total physical memory %-4d MB\n", 0, statVal);
1835 }
1836
1837 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemAvailable, &statVal);
1838 if (SUCCEEDED(rc))
1839 {
1840 if (details == VMINFO_MACHINEREADABLE)
1841 RTPrintf("StatGuestMemoryFreePhysCPU%d=%d\n", 0, statVal);
1842 else
1843 RTPrintf("CPU%d: Free physical memory %-4d MB\n", 0, statVal);
1844 }
1845
1846#ifdef VBOX_WITH_MEM_BALLOONING
1847 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemBalloon, &statVal);
1848 if (SUCCEEDED(rc))
1849 {
1850 if (details == VMINFO_MACHINEREADABLE)
1851 RTPrintf("StatGuestMemoryBalloonCPU%d=%d\n", 0, statVal);
1852 else
1853 RTPrintf("CPU%d: Memory balloon size %-4d MB\n", 0, statVal);
1854 }
1855#endif
1856 rc = guest->GetStatistic(0, GuestStatisticType_MemCommitTotal, &statVal);
1857 if (SUCCEEDED(rc))
1858 {
1859 if (details == VMINFO_MACHINEREADABLE)
1860 RTPrintf("StatGuestMemoryCommittedCPU%d=%d\n", 0, statVal);
1861 else
1862 RTPrintf("CPU%d: Committed memory %-4d MB\n", 0, statVal);
1863 }
1864
1865 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelTotal, &statVal);
1866 if (SUCCEEDED(rc))
1867 {
1868 if (details == VMINFO_MACHINEREADABLE)
1869 RTPrintf("StatGuestMemoryTotalKernelCPU%d=%d\n", 0, statVal);
1870 else
1871 RTPrintf("CPU%d: Total kernel memory %-4d MB\n", 0, statVal);
1872 }
1873
1874 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelPaged, &statVal);
1875 if (SUCCEEDED(rc))
1876 {
1877 if (details == VMINFO_MACHINEREADABLE)
1878 RTPrintf("StatGuestMemoryPagedKernelCPU%d=%d\n", 0, statVal);
1879 else
1880 RTPrintf("CPU%d: Paged kernel memory %-4d MB\n", 0, statVal);
1881 }
1882
1883 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelNonpaged, &statVal);
1884 if (SUCCEEDED(rc))
1885 {
1886 if (details == VMINFO_MACHINEREADABLE)
1887 RTPrintf("StatGuestMemoryNonpagedKernelCPU%d=%d\n", 0, statVal);
1888 else
1889 RTPrintf("CPU%d: Nonpaged kernel memory %-4d MB\n", 0, statVal);
1890 }
1891
1892 rc = guest->GetStatistic(0, GuestStatisticType_MemSystemCache, &statVal);
1893 if (SUCCEEDED(rc))
1894 {
1895 if (details == VMINFO_MACHINEREADABLE)
1896 RTPrintf("StatGuestSystemCacheSizeCPU%d=%d\n", 0, statVal);
1897 else
1898 RTPrintf("CPU%d: System cache size %-4d MB\n", 0, statVal);
1899 }
1900
1901 rc = guest->GetStatistic(0, GuestStatisticType_PageFileSize, &statVal);
1902 if (SUCCEEDED(rc))
1903 {
1904 if (details == VMINFO_MACHINEREADABLE)
1905 RTPrintf("StatGuestPageFileSizeCPU%d=%d\n", 0, statVal);
1906 else
1907 RTPrintf("CPU%d: Page file size %-4d MB\n", 0, statVal);
1908 }
1909
1910 RTPrintf("\n");
1911 }
1912 else
1913 {
1914 if (details != VMINFO_MACHINEREADABLE)
1915 {
1916 RTPrintf("[!] FAILED calling console->getGuest at line %d!\n", __LINE__);
1917 GluePrintRCMessage(rc);
1918 }
1919 }
1920 }
1921
1922 /*
1923 * snapshots
1924 */
1925 ComPtr<ISnapshot> snapshot;
1926 rc = machine->GetSnapshot(Bstr(), snapshot.asOutParam());
1927 if (SUCCEEDED(rc) && snapshot)
1928 {
1929 ComPtr<ISnapshot> currentSnapshot;
1930 rc = machine->COMGETTER(CurrentSnapshot)(currentSnapshot.asOutParam());
1931 if (SUCCEEDED(rc))
1932 {
1933 if (details != VMINFO_MACHINEREADABLE)
1934 RTPrintf("Snapshots:\n\n");
1935 showSnapshots(snapshot, currentSnapshot, details);
1936 }
1937 }
1938
1939 if (details != VMINFO_MACHINEREADABLE)
1940 RTPrintf("\n");
1941 return S_OK;
1942}
1943
1944#if defined(_MSC_VER)
1945# pragma optimize("", on)
1946#endif
1947
1948static const RTGETOPTDEF g_aShowVMInfoOptions[] =
1949{
1950 { "--details", 'D', RTGETOPT_REQ_NOTHING },
1951 { "-details", 'D', RTGETOPT_REQ_NOTHING }, // deprecated
1952 { "--statistics", 'S', RTGETOPT_REQ_NOTHING },
1953 { "-statistics", 'S', RTGETOPT_REQ_NOTHING }, // deprecated
1954 { "--machinereadable", 'M', RTGETOPT_REQ_NOTHING },
1955 { "-machinereadable", 'M', RTGETOPT_REQ_NOTHING }, // deprecated
1956};
1957
1958int handleShowVMInfo(HandlerArg *a)
1959{
1960 HRESULT rc;
1961 const char *VMNameOrUuid = NULL;
1962 bool fDetails = false;
1963 bool fStatistics = false;
1964 bool fMachinereadable = false;
1965
1966 int c;
1967 RTGETOPTUNION ValueUnion;
1968 RTGETOPTSTATE GetState;
1969 // start at 0 because main() has hacked both the argc and argv given to us
1970 RTGetOptInit(&GetState, a->argc, a->argv, g_aShowVMInfoOptions, RT_ELEMENTS(g_aShowVMInfoOptions), 0, 0 /* fFlags */);
1971 while ((c = RTGetOpt(&GetState, &ValueUnion)))
1972 {
1973 switch (c)
1974 {
1975 case 'D': // --details
1976 fDetails = true;
1977 break;
1978
1979 case 'S': // --statistics
1980 fStatistics = true;
1981 break;
1982
1983 case 'M': // --machinereadable
1984 fMachinereadable = true;
1985 break;
1986
1987 case VINF_GETOPT_NOT_OPTION:
1988 if (!VMNameOrUuid)
1989 VMNameOrUuid = ValueUnion.psz;
1990 else
1991 return errorSyntax(USAGE_SHOWVMINFO, "Invalid parameter '%s'", ValueUnion.psz);
1992 break;
1993
1994 default:
1995 if (c > 0)
1996 {
1997 if (RT_C_IS_PRINT(c))
1998 return errorSyntax(USAGE_SHOWVMINFO, "Invalid option -%c", c);
1999 else
2000 return errorSyntax(USAGE_SHOWVMINFO, "Invalid option case %i", c);
2001 }
2002 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
2003 return errorSyntax(USAGE_SHOWVMINFO, "unknown option: %s\n", ValueUnion.psz);
2004 else if (ValueUnion.pDef)
2005 return errorSyntax(USAGE_SHOWVMINFO, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
2006 else
2007 return errorSyntax(USAGE_SHOWVMINFO, "error: %Rrs", c);
2008 }
2009 }
2010
2011 /* check for required options */
2012 if (!VMNameOrUuid)
2013 return errorSyntax(USAGE_SHOWVMINFO, "VM name or UUID required");
2014
2015 /* try to find the given machine */
2016 ComPtr <IMachine> machine;
2017 Bstr uuid (VMNameOrUuid);
2018 if (!Guid (VMNameOrUuid).isEmpty())
2019 {
2020 CHECK_ERROR (a->virtualBox, GetMachine (uuid, machine.asOutParam()));
2021 }
2022 else
2023 {
2024 CHECK_ERROR (a->virtualBox, FindMachine (Bstr(VMNameOrUuid), machine.asOutParam()));
2025 if (SUCCEEDED (rc))
2026 machine->COMGETTER(Id) (uuid.asOutParam());
2027 }
2028 if (FAILED (rc))
2029 return 1;
2030
2031 /* 2nd option can be -details, -statistics or -argdump */
2032 VMINFO_DETAILS details = VMINFO_NONE;
2033 if (fMachinereadable)
2034 details = VMINFO_MACHINEREADABLE;
2035 else
2036 if (fDetails && fStatistics)
2037 details = VMINFO_FULL;
2038 else
2039 if (fDetails)
2040 details = VMINFO_STANDARD;
2041 else
2042 if (fStatistics)
2043 details = VMINFO_STATISTICS;
2044
2045 ComPtr <IConsole> console;
2046
2047 /* open an existing session for the VM */
2048 rc = a->virtualBox->OpenExistingSession (a->session, uuid);
2049 if (SUCCEEDED(rc))
2050 /* get the session machine */
2051 rc = a->session->COMGETTER(Machine)(machine.asOutParam());
2052 if (SUCCEEDED(rc))
2053 /* get the session console */
2054 rc = a->session->COMGETTER(Console)(console.asOutParam());
2055
2056 rc = showVMInfo(a->virtualBox, machine, details, console);
2057
2058 if (console)
2059 a->session->Close();
2060
2061 return SUCCEEDED (rc) ? 0 : 1;
2062}
2063
2064#endif /* !VBOX_ONLY_DOCS */
2065/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use