VirtualBox

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

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

IPRT: make RTGetOpt accept non-'--' parameters; use RTGetOpt for 'VBoxManage list'; default to short output for 'list vms' unless --long is specified

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