VirtualBox

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

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

networking API renaming

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