VirtualBox

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

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

VBoxManage showvminfo: cosmetical fix

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette