VirtualBox

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

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

VBoxManage: Updated vminfo with the live migration bits.

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