VirtualBox

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

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

Introduced the Synthetic CPU attribute and a get/set method for CPU properties.

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