VirtualBox

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

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

Main: Rework storage controller handling to allow an arbitrary number of different storage controllers and remove code duplication:

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