VirtualBox

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

Last change on this file since 25583 was 25149, checked in by vboxsync, 15 years ago

Main: cleanup: remove all CheckComRC* macros (no functional change)

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