VirtualBox

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

Last change on this file since 24358 was 24301, checked in by vboxsync, 16 years ago

Main,Frontends: Added two new running states: Teleporting and LiveSnapshotting. Also added TeleportingPausedVM. Renamed TeleportingFrom to TeleportingIn.

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

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