VirtualBox

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

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

Dropped obsolet HWVirtEx properties.

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