VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp@ 92710

Last change on this file since 92710 was 92594, checked in by vboxsync, 3 years ago

Main: bugref:1909: Added translation into VBoxManage excluding built-in docbook help. Fixed translation marks in the VBoxManage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 154.1 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 92594 2021-11-25 09:05:48Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of modifyvm command.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
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
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#ifndef VBOX_ONLY_DOCS
23#include <VBox/com/com.h>
24#include <VBox/com/array.h>
25#include <VBox/com/ErrorInfo.h>
26#include <VBox/com/errorprint.h>
27#include <VBox/com/VirtualBox.h>
28#endif /* !VBOX_ONLY_DOCS */
29
30#include <iprt/cidr.h>
31#include <iprt/ctype.h>
32#include <iprt/file.h>
33#include <iprt/param.h>
34#include <iprt/path.h>
35#include <iprt/stream.h>
36#include <iprt/string.h>
37#include <iprt/getopt.h>
38#include <VBox/log.h>
39#include "VBoxManage.h"
40#include "VBoxManageUtils.h"
41
42DECLARE_TRANSLATION_CONTEXT(ModifyVM);
43
44#ifndef VBOX_ONLY_DOCS
45using namespace com;
46/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
47#if defined(_MSC_VER)
48# pragma optimize("g", off)
49# if _MSC_VER < RT_MSC_VER_VC120
50# pragma warning(disable:4748)
51# endif
52#endif
53
54enum
55{
56 MODIFYVM_NAME = 1000,
57 MODIFYVM_GROUPS,
58 MODIFYVM_DESCRIPTION,
59 MODIFYVM_OSTYPE,
60 MODIFYVM_ICONFILE,
61 MODIFYVM_MEMORY,
62 MODIFYVM_PAGEFUSION,
63 MODIFYVM_VRAM,
64 MODIFYVM_FIRMWARE,
65 MODIFYVM_ACPI,
66 MODIFYVM_IOAPIC,
67 MODIFYVM_PAE,
68 MODIFYVM_LONGMODE,
69 MODIFYVM_CPUID_PORTABILITY,
70 MODIFYVM_TFRESET,
71 MODIFYVM_APIC,
72 MODIFYVM_X2APIC,
73 MODIFYVM_PARAVIRTPROVIDER,
74 MODIFYVM_PARAVIRTDEBUG,
75 MODIFYVM_HWVIRTEX,
76 MODIFYVM_NESTEDPAGING,
77 MODIFYVM_LARGEPAGES,
78 MODIFYVM_VTXVPID,
79 MODIFYVM_VTXUX,
80 MODIFYVM_VIRT_VMSAVE_VMLOAD,
81 MODIFYVM_IBPB_ON_VM_EXIT,
82 MODIFYVM_IBPB_ON_VM_ENTRY,
83 MODIFYVM_SPEC_CTRL,
84 MODIFYVM_L1D_FLUSH_ON_SCHED,
85 MODIFYVM_L1D_FLUSH_ON_VM_ENTRY,
86 MODIFYVM_MDS_CLEAR_ON_SCHED,
87 MODIFYVM_MDS_CLEAR_ON_VM_ENTRY,
88 MODIFYVM_NESTED_HW_VIRT,
89 MODIFYVM_CPUS,
90 MODIFYVM_CPUHOTPLUG,
91 MODIFYVM_CPU_PROFILE,
92 MODIFYVM_PLUGCPU,
93 MODIFYVM_UNPLUGCPU,
94 MODIFYVM_SETCPUID,
95 MODIFYVM_DELCPUID,
96 MODIFYVM_DELCPUID_OLD, // legacy, different syntax from MODIFYVM_DELCPUID
97 MODIFYVM_DELALLCPUID,
98 MODIFYVM_GRAPHICSCONTROLLER,
99 MODIFYVM_MONITORCOUNT,
100 MODIFYVM_ACCELERATE3D,
101#ifdef VBOX_WITH_VIDEOHWACCEL
102 MODIFYVM_ACCELERATE2DVIDEO,
103#endif
104 MODIFYVM_BIOSLOGOFADEIN,
105 MODIFYVM_BIOSLOGOFADEOUT,
106 MODIFYVM_BIOSLOGODISPLAYTIME,
107 MODIFYVM_BIOSLOGOIMAGEPATH,
108 MODIFYVM_BIOSBOOTMENU,
109 MODIFYVM_BIOSAPIC,
110 MODIFYVM_BIOSSYSTEMTIMEOFFSET,
111 MODIFYVM_BIOSPXEDEBUG,
112 MODIFYVM_SYSTEMUUIDLE,
113 MODIFYVM_BOOT,
114 MODIFYVM_HDA, // deprecated
115 MODIFYVM_HDB, // deprecated
116 MODIFYVM_HDD, // deprecated
117 MODIFYVM_IDECONTROLLER, // deprecated
118 MODIFYVM_SATAPORTCOUNT, // deprecated
119 MODIFYVM_SATAPORT, // deprecated
120 MODIFYVM_SATA, // deprecated
121 MODIFYVM_SCSIPORT, // deprecated
122 MODIFYVM_SCSITYPE, // deprecated
123 MODIFYVM_SCSI, // deprecated
124 MODIFYVM_DVDPASSTHROUGH, // deprecated
125 MODIFYVM_DVD, // deprecated
126 MODIFYVM_FLOPPY, // deprecated
127 MODIFYVM_NICTRACEFILE,
128 MODIFYVM_NICTRACE,
129 MODIFYVM_NICPROPERTY,
130 MODIFYVM_NICTYPE,
131 MODIFYVM_NICSPEED,
132 MODIFYVM_NICBOOTPRIO,
133 MODIFYVM_NICPROMISC,
134 MODIFYVM_NICBWGROUP,
135 MODIFYVM_NIC,
136 MODIFYVM_CABLECONNECTED,
137 MODIFYVM_BRIDGEADAPTER,
138 MODIFYVM_HOSTONLYADAPTER,
139#ifdef VBOX_WITH_VMNET
140 MODIFYVM_HOSTONLYNET,
141#endif /* VBOX_WITH_VMNET */
142 MODIFYVM_INTNET,
143 MODIFYVM_GENERICDRV,
144 MODIFYVM_NATNETWORKNAME,
145 MODIFYVM_NATNET,
146 MODIFYVM_NATBINDIP,
147 MODIFYVM_NATSETTINGS,
148 MODIFYVM_NATPF,
149 MODIFYVM_NATALIASMODE,
150 MODIFYVM_NATTFTPPREFIX,
151 MODIFYVM_NATTFTPFILE,
152 MODIFYVM_NATTFTPSERVER,
153 MODIFYVM_NATDNSPASSDOMAIN,
154 MODIFYVM_NATDNSPROXY,
155 MODIFYVM_NATDNSHOSTRESOLVER,
156 MODIFYVM_NATLOCALHOSTREACHABLE,
157 MODIFYVM_MACADDRESS,
158 MODIFYVM_HIDPTR,
159 MODIFYVM_HIDKBD,
160 MODIFYVM_UARTMODE,
161 MODIFYVM_UARTTYPE,
162 MODIFYVM_UART,
163#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
164 MODIFYVM_LPTMODE,
165 MODIFYVM_LPT,
166#endif
167 MODIFYVM_GUESTMEMORYBALLOON,
168 MODIFYVM_AUDIOCONTROLLER,
169 MODIFYVM_AUDIOCODEC,
170 MODIFYVM_AUDIO,
171 MODIFYVM_AUDIOIN,
172 MODIFYVM_AUDIOOUT,
173#ifdef VBOX_WITH_SHARED_CLIPBOARD
174 MODIFYVM_CLIPBOARD_MODE,
175# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
176 MODIFYVM_CLIPBOARD_FILE_TRANSFERS,
177# endif
178#endif
179 MODIFYVM_DRAGANDDROP,
180 MODIFYVM_VRDPPORT, /* VRDE: deprecated */
181 MODIFYVM_VRDPADDRESS, /* VRDE: deprecated */
182 MODIFYVM_VRDPAUTHTYPE, /* VRDE: deprecated */
183 MODIFYVM_VRDPMULTICON, /* VRDE: deprecated */
184 MODIFYVM_VRDPREUSECON, /* VRDE: deprecated */
185 MODIFYVM_VRDPVIDEOCHANNEL, /* VRDE: deprecated */
186 MODIFYVM_VRDPVIDEOCHANNELQUALITY, /* VRDE: deprecated */
187 MODIFYVM_VRDP, /* VRDE: deprecated */
188 MODIFYVM_VRDEPROPERTY,
189 MODIFYVM_VRDEPORT,
190 MODIFYVM_VRDEADDRESS,
191 MODIFYVM_VRDEAUTHTYPE,
192 MODIFYVM_VRDEAUTHLIBRARY,
193 MODIFYVM_VRDEMULTICON,
194 MODIFYVM_VRDEREUSECON,
195 MODIFYVM_VRDEVIDEOCHANNEL,
196 MODIFYVM_VRDEVIDEOCHANNELQUALITY,
197 MODIFYVM_VRDE_EXTPACK,
198 MODIFYVM_VRDE,
199 MODIFYVM_RTCUSEUTC,
200 MODIFYVM_USBRENAME,
201 MODIFYVM_USBXHCI,
202 MODIFYVM_USBEHCI,
203 MODIFYVM_USBOHCI,
204 MODIFYVM_SNAPSHOTFOLDER,
205 MODIFYVM_TELEPORTER_ENABLED,
206 MODIFYVM_TELEPORTER_PORT,
207 MODIFYVM_TELEPORTER_ADDRESS,
208 MODIFYVM_TELEPORTER_PASSWORD,
209 MODIFYVM_TELEPORTER_PASSWORD_FILE,
210 MODIFYVM_TRACING_ENABLED,
211 MODIFYVM_TRACING_CONFIG,
212 MODIFYVM_TRACING_ALLOW_VM_ACCESS,
213 MODIFYVM_HARDWARE_UUID,
214 MODIFYVM_HPET,
215 MODIFYVM_IOCACHE,
216 MODIFYVM_IOCACHESIZE,
217 MODIFYVM_CPU_EXECTUION_CAP,
218 MODIFYVM_AUTOSTART_ENABLED,
219 MODIFYVM_AUTOSTART_DELAY,
220 MODIFYVM_AUTOSTOP_TYPE,
221#ifdef VBOX_WITH_PCI_PASSTHROUGH
222 MODIFYVM_ATTACH_PCI,
223 MODIFYVM_DETACH_PCI,
224#endif
225#ifdef VBOX_WITH_USB_CARDREADER
226 MODIFYVM_USBCARDREADER,
227#endif
228#ifdef VBOX_WITH_RECORDING
229 MODIFYVM_RECORDING,
230 MODIFYVM_RECORDING_FEATURES,
231 MODIFYVM_RECORDING_SCREENS,
232 MODIFYVM_RECORDING_FILENAME,
233 MODIFYVM_RECORDING_VIDEO_WIDTH,
234 MODIFYVM_RECORDING_VIDEO_HEIGHT,
235 MODIFYVM_RECORDING_VIDEO_RES,
236 MODIFYVM_RECORDING_VIDEO_RATE,
237 MODIFYVM_RECORDING_VIDEO_FPS,
238 MODIFYVM_RECORDING_MAXTIME,
239 MODIFYVM_RECORDING_MAXSIZE,
240 MODIFYVM_RECORDING_OPTIONS,
241#endif
242 MODIFYVM_CHIPSET,
243#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
244 MODIFYVM_IOMMU,
245#endif
246#if defined(VBOX_WITH_TPM)
247 MODIFYVM_TPM_LOCATION,
248 MODIFYVM_TPM_TYPE,
249#endif
250 MODIFYVM_DEFAULTFRONTEND,
251 MODIFYVM_VMPROC_PRIORITY,
252 MODIFYVM_TESTING_ENABLED,
253 MODIFYVM_TESTING_MMIO,
254 MODIFYVM_TESTING_CFG_DWORD,
255};
256
257static const RTGETOPTDEF g_aModifyVMOptions[] =
258{
259 OPT1("--name", MODIFYVM_NAME, RTGETOPT_REQ_STRING),
260 OPT1("--groups", MODIFYVM_GROUPS, RTGETOPT_REQ_STRING),
261 OPT1("--description", MODIFYVM_DESCRIPTION, RTGETOPT_REQ_STRING),
262 OPT2("--os-type", "--ostype", MODIFYVM_OSTYPE, RTGETOPT_REQ_STRING),
263 OPT2("--icon-file", "--iconfile", MODIFYVM_ICONFILE, RTGETOPT_REQ_STRING),
264 OPT1("--memory", MODIFYVM_MEMORY, RTGETOPT_REQ_UINT32),
265 OPT2("--page-fusion", "--pagefusion", MODIFYVM_PAGEFUSION, RTGETOPT_REQ_BOOL_ONOFF),
266 OPT1("--vram", MODIFYVM_VRAM, RTGETOPT_REQ_UINT32),
267 OPT1("--firmware", MODIFYVM_FIRMWARE, RTGETOPT_REQ_STRING),
268 OPT1("--acpi", MODIFYVM_ACPI, RTGETOPT_REQ_BOOL_ONOFF),
269 OPT1("--ioapic", MODIFYVM_IOAPIC, RTGETOPT_REQ_BOOL_ONOFF),
270 OPT1("--pae", MODIFYVM_PAE, RTGETOPT_REQ_BOOL_ONOFF),
271 OPT2("--long-mode", "--longmode", MODIFYVM_LONGMODE, RTGETOPT_REQ_BOOL_ONOFF),
272 OPT1("--cpuid-portability-level", MODIFYVM_CPUID_PORTABILITY, RTGETOPT_REQ_UINT32),
273 OPT2("--triple-fault-reset", "--triplefaultreset", MODIFYVM_TFRESET, RTGETOPT_REQ_BOOL_ONOFF),
274 OPT1("--apic", MODIFYVM_APIC, RTGETOPT_REQ_BOOL_ONOFF),
275 OPT1("--x2apic", MODIFYVM_X2APIC, RTGETOPT_REQ_BOOL_ONOFF),
276 OPT2("--paravirt-provider", "--paravirtprovider", MODIFYVM_PARAVIRTPROVIDER, RTGETOPT_REQ_STRING),
277 OPT2("--paravirt-debug", "--paravirtdebug", MODIFYVM_PARAVIRTDEBUG, RTGETOPT_REQ_STRING),
278 OPT1("--hwvirtex", MODIFYVM_HWVIRTEX, RTGETOPT_REQ_BOOL_ONOFF),
279 OPT2("--nested-paging", "--nestedpaging", MODIFYVM_NESTEDPAGING, RTGETOPT_REQ_BOOL_ONOFF),
280 OPT2("--large-pages", "--largepages", MODIFYVM_LARGEPAGES, RTGETOPT_REQ_BOOL_ONOFF),
281 OPT2("--vtx-vpid", "--vtxvpid", MODIFYVM_VTXVPID, RTGETOPT_REQ_BOOL_ONOFF),
282 OPT2("--vtx-ux", "--vtxux", MODIFYVM_VTXUX, RTGETOPT_REQ_BOOL_ONOFF),
283 OPT1("--virt-vmsave-vmload", MODIFYVM_VIRT_VMSAVE_VMLOAD, RTGETOPT_REQ_BOOL_ONOFF),
284 OPT1("--ibpb-on-vm-exit", MODIFYVM_IBPB_ON_VM_EXIT, RTGETOPT_REQ_BOOL_ONOFF),
285 OPT1("--ibpb-on-vm-entry", MODIFYVM_IBPB_ON_VM_ENTRY, RTGETOPT_REQ_BOOL_ONOFF),
286 OPT1("--spec-ctrl", MODIFYVM_SPEC_CTRL, RTGETOPT_REQ_BOOL_ONOFF),
287 OPT1("--l1d-flush-on-sched", MODIFYVM_L1D_FLUSH_ON_SCHED, RTGETOPT_REQ_BOOL_ONOFF),
288 OPT1("--l1d-flush-on-vm-entry", MODIFYVM_L1D_FLUSH_ON_VM_ENTRY, RTGETOPT_REQ_BOOL_ONOFF),
289 OPT1("--mds-clear-on-sched", MODIFYVM_MDS_CLEAR_ON_SCHED, RTGETOPT_REQ_BOOL_ONOFF),
290 OPT1("--mds-clear-on-vm-entry", MODIFYVM_MDS_CLEAR_ON_VM_ENTRY, RTGETOPT_REQ_BOOL_ONOFF),
291 OPT1("--nested-hw-virt", MODIFYVM_NESTED_HW_VIRT, RTGETOPT_REQ_BOOL_ONOFF),
292 OPT2("--cpuid-set", "--cpuidset", MODIFYVM_SETCPUID, RTGETOPT_REQ_UINT32_OPTIONAL_PAIR | RTGETOPT_FLAG_HEX),
293 OPT1("--cpuid-remove", MODIFYVM_DELCPUID, RTGETOPT_REQ_UINT32_OPTIONAL_PAIR | RTGETOPT_FLAG_HEX),
294 OPT1("--cpuidremove", MODIFYVM_DELCPUID_OLD, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX), /* legacy - syntax differs */
295 OPT2("--cpuid-remove-all", "--cpuidremoveall", MODIFYVM_DELALLCPUID, RTGETOPT_REQ_NOTHING),
296 OPT1("--cpus", MODIFYVM_CPUS, RTGETOPT_REQ_UINT32),
297 OPT2("--cpu-hotplug", "--cpuhotplug", MODIFYVM_CPUHOTPLUG, RTGETOPT_REQ_BOOL_ONOFF),
298 OPT1("--cpu-profile", MODIFYVM_CPU_PROFILE, RTGETOPT_REQ_STRING),
299 OPT2("--plug-cpu", "--plugcpu", MODIFYVM_PLUGCPU, RTGETOPT_REQ_UINT32),
300 OPT2("--unplug-cpu", "--unplugcpu", MODIFYVM_UNPLUGCPU, RTGETOPT_REQ_UINT32),
301 OPT2("--cpu-execution-cap", "--cpuexecutioncap", MODIFYVM_CPU_EXECTUION_CAP, RTGETOPT_REQ_UINT32),
302 OPT2("--rtc-use-utc", "--rtcuseutc", MODIFYVM_RTCUSEUTC, RTGETOPT_REQ_BOOL_ONOFF),
303 OPT2("--graphicscontroller", "--graphicscontroller", MODIFYVM_GRAPHICSCONTROLLER, RTGETOPT_REQ_STRING),
304 OPT2("--monitor-count", "--monitorcount", MODIFYVM_MONITORCOUNT, RTGETOPT_REQ_UINT32),
305 OPT2("--accelerate-3d", "--accelerate3d", MODIFYVM_ACCELERATE3D, RTGETOPT_REQ_BOOL_ONOFF),
306#ifdef VBOX_WITH_VIDEOHWACCEL
307 OPT2("--accelerate-2d-video", "--accelerate2dvideo", MODIFYVM_ACCELERATE2DVIDEO, RTGETOPT_REQ_BOOL_ONOFF),
308#endif
309 OPT2("--bios-logo-fade-in", "--bioslogofadein", MODIFYVM_BIOSLOGOFADEIN, RTGETOPT_REQ_BOOL_ONOFF),
310 OPT2("--bios-logo-fade-out", "--bioslogofadeout", MODIFYVM_BIOSLOGOFADEOUT, RTGETOPT_REQ_BOOL_ONOFF),
311 OPT2("--bios-logo-display-time", "--bioslogodisplaytime", MODIFYVM_BIOSLOGODISPLAYTIME, RTGETOPT_REQ_UINT32),
312 OPT2("--bios-logo-image-path", "--bioslogoimagepath", MODIFYVM_BIOSLOGOIMAGEPATH, RTGETOPT_REQ_STRING),
313 OPT2("--bios-boot-menu", "--biosbootmenu", MODIFYVM_BIOSBOOTMENU, RTGETOPT_REQ_STRING),
314 OPT2("--bios-system-time-offset", "--biossystemtimeoffset", MODIFYVM_BIOSSYSTEMTIMEOFFSET, RTGETOPT_REQ_INT64),
315 OPT2("--bios-apic", "--biosapic", MODIFYVM_BIOSAPIC, RTGETOPT_REQ_STRING),
316 OPT2("--bios-pxe-debug", "--biospxedebug", MODIFYVM_BIOSPXEDEBUG, RTGETOPT_REQ_BOOL_ONOFF),
317 OPT2("--system-uuid-le", "--system-uuid-le", MODIFYVM_SYSTEMUUIDLE, RTGETOPT_REQ_BOOL_ONOFF),
318 OPT1("--boot", MODIFYVM_BOOT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
319 OPT1("--hda", MODIFYVM_HDA, RTGETOPT_REQ_STRING), /* deprecated */
320 OPT1("--hdb", MODIFYVM_HDB, RTGETOPT_REQ_STRING), /* deprecated */
321 OPT1("--hdd", MODIFYVM_HDD, RTGETOPT_REQ_STRING), /* deprecated */
322 OPT2("--idec-ontroller", "--idecontroller", MODIFYVM_IDECONTROLLER, RTGETOPT_REQ_STRING), /* deprecated */
323 OPT2("--sata-port-count", "--sataportcount", MODIFYVM_SATAPORTCOUNT, RTGETOPT_REQ_UINT32), /* deprecated */
324 OPT2("--sata-port", "--sataport", MODIFYVM_SATAPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX), /* deprecated */
325 OPT1("--sata", MODIFYVM_SATA, RTGETOPT_REQ_STRING), /* deprecated */
326 OPT2("--scsi-port", "--scsiport", MODIFYVM_SCSIPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX), /* deprecated */
327 OPT2("--scsi-type", "--scsitype", MODIFYVM_SCSITYPE, RTGETOPT_REQ_STRING), /* deprecated */
328 OPT1("--scsi", MODIFYVM_SCSI, RTGETOPT_REQ_STRING), /* deprecated */
329 OPT2("--dvd-pass-through", "--dvdpassthrough", MODIFYVM_DVDPASSTHROUGH, RTGETOPT_REQ_STRING), /* deprecated */
330 OPT1("--dvd", MODIFYVM_DVD, RTGETOPT_REQ_STRING), /* deprecated */
331 OPT1("--floppy", MODIFYVM_FLOPPY, RTGETOPT_REQ_STRING), /* deprecated */
332 OPT2("--nic-trace-file", "--nictracefile", MODIFYVM_NICTRACEFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
333 OPT2("--nic-trace", "--nictrace", MODIFYVM_NICTRACE, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX),
334 OPT2("--nic-property", "--nicproperty", MODIFYVM_NICPROPERTY, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
335 OPT2("--nic-type", "--nictype", MODIFYVM_NICTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
336 OPT2("--nic-speed", "--nicspeed", MODIFYVM_NICSPEED, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX),
337 OPT2("--nic-boot-prio", "--nicbootprio", MODIFYVM_NICBOOTPRIO, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX),
338 OPT2("--nic-promisc", "--nicpromisc", MODIFYVM_NICPROMISC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
339 OPT2("--nic-bandwidth-group", "--nicbandwidthgroup", MODIFYVM_NICBWGROUP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
340 OPT1("--nic", MODIFYVM_NIC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
341 OPT2("--cable-connected", "--cableconnected", MODIFYVM_CABLECONNECTED, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX),
342 OPT2("--bridge-adapter", "--bridgeadapter", MODIFYVM_BRIDGEADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
343 OPT2("--host-only-adapter", "--hostonlyadapter", MODIFYVM_HOSTONLYADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
344#ifdef VBOX_WITH_VMNET
345 OPT2("--host-only-net", "--hostonlynet", MODIFYVM_HOSTONLYNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
346#endif
347 OPT1("--intnet", MODIFYVM_INTNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
348 OPT2("--nic-generic-drv", "--nicgenericdrv", MODIFYVM_GENERICDRV, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
349 OPT2("--nat-network", "--natnetwork", MODIFYVM_NATNETWORKNAME, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
350 OPT2("--nat-net", "--natnet", MODIFYVM_NATNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
351 OPT2("--nat-bind-ip", "--natbindip", MODIFYVM_NATBINDIP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
352 OPT2("--nat-settings", "--natsettings", MODIFYVM_NATSETTINGS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
353 OPT2("--nat-pf", "--natpf", MODIFYVM_NATPF, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
354 OPT2("--nat-alias-mode", "--nataliasmode", MODIFYVM_NATALIASMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
355 OPT2("--nat-tftp-prefix", "--nattftpprefix", MODIFYVM_NATTFTPPREFIX, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
356 OPT2("--nat-tftp-file", "--nattftpfile", MODIFYVM_NATTFTPFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
357 OPT2("--nat-tftp-server", "--nattftpserver", MODIFYVM_NATTFTPSERVER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
358 OPT2("--nat-dns-pass-domain", "--natdnspassdomain", MODIFYVM_NATDNSPASSDOMAIN, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX),
359 OPT2("--nat-dns-proxy", "--natdnsproxy", MODIFYVM_NATDNSPROXY, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX),
360 OPT2("--nat-dns-host-resolver", "--natdnshostresolver", MODIFYVM_NATDNSHOSTRESOLVER, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX),
361 OPT2("--nat-localhostreachable", "--natlocalhostreachable", MODIFYVM_NATLOCALHOSTREACHABLE, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX),
362 OPT2("--mac-address", "--macaddress", MODIFYVM_MACADDRESS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
363 OPT1("--mouse", MODIFYVM_HIDPTR, RTGETOPT_REQ_STRING),
364 OPT1("--keyboard", MODIFYVM_HIDKBD, RTGETOPT_REQ_STRING),
365 OPT2("--uart-mode", "--uartmode", MODIFYVM_UARTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
366 OPT2("--uart-type", "--uarttype", MODIFYVM_UARTTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
367 OPT1("--uart", MODIFYVM_UART, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
368#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
369 OPT2("--lpt-mode", "--lptmode", MODIFYVM_LPTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
370 OPT1("--lpt", MODIFYVM_LPT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
371#endif
372 OPT2("--guest-memory-balloon", "--guestmemoryballoon", MODIFYVM_GUESTMEMORYBALLOON, RTGETOPT_REQ_UINT32),
373 OPT2("--audio-controller", "--audiocontroller", MODIFYVM_AUDIOCONTROLLER, RTGETOPT_REQ_STRING),
374 OPT2("--audio-codec", "--audiocodec", MODIFYVM_AUDIOCODEC, RTGETOPT_REQ_STRING),
375 OPT1("--audio", MODIFYVM_AUDIO, RTGETOPT_REQ_STRING),
376 OPT2("--audio-in", "--audioin", MODIFYVM_AUDIOIN, RTGETOPT_REQ_BOOL_ONOFF),
377 OPT2("--audio-out", "--audioout", MODIFYVM_AUDIOOUT, RTGETOPT_REQ_BOOL_ONOFF),
378#ifdef VBOX_WITH_SHARED_CLIPBOARD
379 OPT1("--clipboard-mode", MODIFYVM_CLIPBOARD_MODE, RTGETOPT_REQ_STRING),
380 OPT1("--clipboard", MODIFYVM_CLIPBOARD_MODE, RTGETOPT_REQ_STRING), /* deprecated */
381# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
382 OPT1("--clipboard-file-transfers", MODIFYVM_CLIPBOARD_FILE_TRANSFERS, RTGETOPT_REQ_STRING),
383# endif
384#endif
385 OPT2("--drag-and-drop", "--draganddrop", MODIFYVM_DRAGANDDROP, RTGETOPT_REQ_STRING),
386 OPT2("--vrdp-port", "--vrdpport", MODIFYVM_VRDPPORT, RTGETOPT_REQ_STRING), /* deprecated */
387 OPT2("--vrdp-address", "--vrdpaddress", MODIFYVM_VRDPADDRESS, RTGETOPT_REQ_STRING), /* deprecated */
388 OPT2("--vrdp-auth-type", "--vrdpauthtype", MODIFYVM_VRDPAUTHTYPE, RTGETOPT_REQ_STRING), /* deprecated */
389 OPT2("--vrdp-multi-con", "--vrdpmulticon", MODIFYVM_VRDPMULTICON, RTGETOPT_REQ_BOOL_ONOFF), /* deprecated */
390 OPT2("--vrdp-reuse-con", "--vrdpreusecon", MODIFYVM_VRDPREUSECON, RTGETOPT_REQ_BOOL_ONOFF), /* deprecated */
391 OPT2("--vrdp-video-channel", "--vrdpvideochannel", MODIFYVM_VRDPVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF), /* deprecated */
392 OPT2("--vrdp-video-channel-quality", "--vrdpvideochannelquality",MODIFYVM_VRDPVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING), /* deprecated */
393 OPT1("--vrdp", MODIFYVM_VRDP, RTGETOPT_REQ_BOOL_ONOFF), /* deprecated */
394 OPT2("--vrde-property", "--vrdeproperty", MODIFYVM_VRDEPROPERTY, RTGETOPT_REQ_STRING),
395 OPT2("--vrde-port", "--vrdeport", MODIFYVM_VRDEPORT, RTGETOPT_REQ_STRING),
396 OPT2("--vrde-address", "--vrdeaddress", MODIFYVM_VRDEADDRESS, RTGETOPT_REQ_STRING),
397 OPT2("--vrde-auth-type", "--vrdeauthtype", MODIFYVM_VRDEAUTHTYPE, RTGETOPT_REQ_STRING),
398 OPT2("--vrde-auth-library", "--vrdeauthlibrary", MODIFYVM_VRDEAUTHLIBRARY, RTGETOPT_REQ_STRING),
399 OPT2("--vrde-multi-con", "--vrdemulticon", MODIFYVM_VRDEMULTICON, RTGETOPT_REQ_BOOL_ONOFF),
400 OPT2("--vrde-reuse-con", "--vrdereusecon", MODIFYVM_VRDEREUSECON, RTGETOPT_REQ_BOOL_ONOFF),
401 OPT2("--vrde-video-channel", "--vrdevideochannel", MODIFYVM_VRDEVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF),
402 OPT2("--vrde-video-channel-quality", "--vrdevideochannelquality",MODIFYVM_VRDEVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING),
403 OPT2("--vrde-extpack", "--vrdeextpack", MODIFYVM_VRDE_EXTPACK, RTGETOPT_REQ_STRING),
404 OPT1("--vrde", MODIFYVM_VRDE, RTGETOPT_REQ_BOOL_ONOFF),
405 OPT2("--usb-rename", "--usbrename", MODIFYVM_USBRENAME, RTGETOPT_REQ_STRING),
406 OPT2("--usb-xhci", "--usbxhci", MODIFYVM_USBXHCI, RTGETOPT_REQ_BOOL_ONOFF),
407 OPT2("--usb-ehci", "--usbehci", MODIFYVM_USBEHCI, RTGETOPT_REQ_BOOL_ONOFF),
408 OPT2("--usb-ohci", "--usbohci", MODIFYVM_USBOHCI, RTGETOPT_REQ_BOOL_ONOFF),
409 OPT1("--usb", MODIFYVM_USBOHCI, RTGETOPT_REQ_BOOL_ONOFF), /* deprecated */
410 OPT2("--snapshot-folder", "--snapshotfolder", MODIFYVM_SNAPSHOTFOLDER, RTGETOPT_REQ_STRING),
411 OPT1("--teleporter", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF),
412 OPT2("--teleporter-enabled", "--teleporterenabled", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF), /* deprecated */
413 OPT2("--teleporter-port", "--teleporterport", MODIFYVM_TELEPORTER_PORT, RTGETOPT_REQ_UINT32),
414 OPT2("--teleporter-address", "--teleporteraddress", MODIFYVM_TELEPORTER_ADDRESS, RTGETOPT_REQ_STRING),
415 OPT2("--teleporter-password", "--teleporterpassword", MODIFYVM_TELEPORTER_PASSWORD, RTGETOPT_REQ_STRING),
416 OPT2("--teleporter-password-file", "--teleporterpasswordfile", MODIFYVM_TELEPORTER_PASSWORD_FILE, RTGETOPT_REQ_STRING),
417 OPT1("--tracing-enabled", MODIFYVM_TRACING_ENABLED, RTGETOPT_REQ_BOOL_ONOFF),
418 OPT1("--tracing-config", MODIFYVM_TRACING_CONFIG, RTGETOPT_REQ_STRING),
419 OPT1("--tracing-allow-vm-access", MODIFYVM_TRACING_ALLOW_VM_ACCESS, RTGETOPT_REQ_BOOL_ONOFF),
420 OPT2("--hardware-uuid", "--hardwareuuid", MODIFYVM_HARDWARE_UUID, RTGETOPT_REQ_STRING),
421 OPT1("--hpet", MODIFYVM_HPET, RTGETOPT_REQ_BOOL_ONOFF),
422 OPT1("--iocache", MODIFYVM_IOCACHE, RTGETOPT_REQ_BOOL_ONOFF),
423 OPT2("--iocache-size", "--iocachesize", MODIFYVM_IOCACHESIZE, RTGETOPT_REQ_UINT32),
424 OPT1("--chipset", MODIFYVM_CHIPSET, RTGETOPT_REQ_STRING),
425#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
426 OPT1("--iommu", MODIFYVM_IOMMU, RTGETOPT_REQ_STRING),
427#endif
428#if defined(VBOX_WITH_TPM)
429 OPT1("--tpm-type", MODIFYVM_TPM_TYPE, RTGETOPT_REQ_STRING),
430 OPT1("--tpm-location", MODIFYVM_TPM_LOCATION, RTGETOPT_REQ_STRING),
431#endif
432#ifdef VBOX_WITH_RECORDING
433 OPT1("--recording", MODIFYVM_RECORDING, RTGETOPT_REQ_BOOL_ONOFF),
434 OPT2("--recording-screens", "--recordingscreens", MODIFYVM_RECORDING_SCREENS, RTGETOPT_REQ_STRING),
435 OPT2("--recording-file", "--recordingfile", MODIFYVM_RECORDING_FILENAME, RTGETOPT_REQ_STRING),
436 OPT2("--recording-max-time", "--recordingmaxtime", MODIFYVM_RECORDING_MAXTIME, RTGETOPT_REQ_INT32),
437 OPT2("--recording-max-size", "--recordingmaxsize", MODIFYVM_RECORDING_MAXSIZE, RTGETOPT_REQ_INT32),
438 OPT2("--recording-opts", "--recordingopts", MODIFYVM_RECORDING_OPTIONS, RTGETOPT_REQ_STRING),
439 OPT2("--recording-options", "--recordingoptions", MODIFYVM_RECORDING_OPTIONS, RTGETOPT_REQ_STRING),
440 OPT2("--recording-video-res", "--recordingvideores", MODIFYVM_RECORDING_VIDEO_RES, RTGETOPT_REQ_STRING),
441 OPT2("--recording-video-resolution", "--recordingvideoresolution",MODIFYVM_RECORDING_VIDEO_RES, RTGETOPT_REQ_STRING),
442 OPT2("--recording-video-rate", "--recordingvideorate", MODIFYVM_RECORDING_VIDEO_RATE, RTGETOPT_REQ_UINT32),
443 OPT2("--recording-video-fps", "--recordingvideofps", MODIFYVM_RECORDING_VIDEO_FPS, RTGETOPT_REQ_UINT32),
444#endif
445 OPT1("--autostart-enabled", MODIFYVM_AUTOSTART_ENABLED, RTGETOPT_REQ_BOOL_ONOFF),
446 OPT1("--autostart-delay", MODIFYVM_AUTOSTART_DELAY, RTGETOPT_REQ_UINT32),
447 OPT1("--autostop-type", MODIFYVM_AUTOSTOP_TYPE, RTGETOPT_REQ_STRING),
448#ifdef VBOX_WITH_PCI_PASSTHROUGH
449 OPT2("--pci-attach", "--pciattach", MODIFYVM_ATTACH_PCI, RTGETOPT_REQ_STRING),
450 OPT2("--pci-detach", "--pcidetach", MODIFYVM_DETACH_PCI, RTGETOPT_REQ_STRING),
451#endif
452#ifdef VBOX_WITH_USB_CARDREADER
453 OPT2("--usb-card-reader", "--usbcardreader", MODIFYVM_USBCARDREADER, RTGETOPT_REQ_BOOL_ONOFF),
454#endif
455 OPT2("--default-frontend", "--defaultfrontend", MODIFYVM_DEFAULTFRONTEND, RTGETOPT_REQ_STRING),
456 OPT1("--vm-process-priority", MODIFYVM_VMPROC_PRIORITY, RTGETOPT_REQ_STRING),
457 OPT1("--testing-enabled", MODIFYVM_TESTING_ENABLED, RTGETOPT_REQ_BOOL_ONOFF),
458 OPT1("--testing-mmio", MODIFYVM_TESTING_MMIO, RTGETOPT_REQ_BOOL_ONOFF),
459 OPT1("--testing-cfg-dword", MODIFYVM_TESTING_CFG_DWORD, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX),
460};
461
462static void vrdeWarningDeprecatedOption(const char *pszOption)
463{
464 RTStrmPrintf(g_pStdErr, ModifyVM::tr("Warning: '--vrdp%s' is deprecated. Use '--vrde%s'.\n"), pszOption, pszOption);
465}
466
467
468/**
469 * Wrapper around IMachine::SetExtraData that does the error reporting.
470 *
471 * @returns COM result code.
472 * @param rSessionMachine The IMachine.
473 * @param pszVariable The variable to set.
474 * @param pszValue The value to set. To delete pass empty string, not
475 * NULL.
476 */
477static HRESULT setExtraData(ComPtr<IMachine> &rSessionMachine, const char *pszVariable, const char *pszValue)
478{
479 HRESULT hrc = rSessionMachine->SetExtraData(Bstr(pszVariable).raw(), Bstr(pszValue).raw());
480 if (FAILED(hrc))
481 {
482 char *pszContext = RTStrAPrintf2("IMachine::SetExtraData('%s', '%s')", pszVariable, pszValue);
483 com::GlueHandleComError(rSessionMachine, pszContext, hrc, __FILE__, __LINE__);
484 RTStrFree(pszContext);
485 }
486 return hrc;
487}
488
489
490#ifdef VBOX_WITH_PCI_PASSTHROUGH
491/** Parse PCI address in format 01:02.03 and convert it to the numeric representation. */
492static int32_t parsePci(const char* szPciAddr)
493{
494 char* pszNext = (char*)szPciAddr;
495 int rc;
496 uint8_t aVals[3] = {0, 0, 0};
497
498 rc = RTStrToUInt8Ex(pszNext, &pszNext, 16, &aVals[0]);
499 if (RT_FAILURE(rc) || pszNext == NULL || *pszNext != ':')
500 return -1;
501
502 rc = RTStrToUInt8Ex(pszNext+1, &pszNext, 16, &aVals[1]);
503 if (RT_FAILURE(rc) || pszNext == NULL || *pszNext != '.')
504 return -1;
505
506 rc = RTStrToUInt8Ex(pszNext+1, &pszNext, 16, &aVals[2]);
507 if (RT_FAILURE(rc) || pszNext == NULL)
508 return -1;
509
510 return (aVals[0] << 8) | (aVals[1] << 3) | (aVals[2] << 0);
511}
512#endif
513
514void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups)
515{
516 while (pcszGroups)
517 {
518 char *pComma = RTStrStr(pcszGroups, ",");
519 if (pComma)
520 {
521 Bstr(pcszGroups, pComma - pcszGroups).detachTo(pGroups->appendedRaw());
522 pcszGroups = pComma + 1;
523 }
524 else
525 {
526 Bstr(pcszGroups).detachTo(pGroups->appendedRaw());
527 pcszGroups = NULL;
528 }
529 }
530}
531
532#ifdef VBOX_WITH_RECORDING
533static int parseScreens(const char *pcszScreens, com::SafeArray<BOOL> *pScreens)
534{
535 while (pcszScreens && *pcszScreens)
536 {
537 char *pszNext;
538 uint32_t iScreen;
539 int rc = RTStrToUInt32Ex(pcszScreens, &pszNext, 0, &iScreen);
540 if (RT_FAILURE(rc))
541 return 1;
542 if (iScreen >= pScreens->size())
543 return 1;
544 if (pszNext && *pszNext)
545 {
546 pszNext = RTStrStripL(pszNext);
547 if (*pszNext != ',')
548 return 1;
549 pszNext++;
550 }
551 (*pScreens)[iScreen] = true;
552 pcszScreens = pszNext;
553 }
554 return 0;
555}
556#endif
557
558static int parseNum(uint32_t uIndex, unsigned cMaxIndex, const char *pszName)
559{
560 if ( uIndex >= 1
561 && uIndex <= cMaxIndex)
562 return uIndex;
563 errorArgument(ModifyVM::tr("Invalid %s number %u"), pszName, uIndex);
564 return 0;
565}
566
567VMProcPriority_T nameToVMProcPriority(const char *pszName)
568{
569 if (!RTStrICmp(pszName, "default"))
570 return VMProcPriority_Default;
571 if (!RTStrICmp(pszName, "flat"))
572 return VMProcPriority_Flat;
573 if (!RTStrICmp(pszName, "low"))
574 return VMProcPriority_Low;
575 if (!RTStrICmp(pszName, "normal"))
576 return VMProcPriority_Normal;
577 if (!RTStrICmp(pszName, "high"))
578 return VMProcPriority_High;
579
580 return VMProcPriority_Invalid;
581}
582
583RTEXITCODE handleModifyVM(HandlerArg *a)
584{
585 int c;
586 HRESULT rc;
587 Bstr name;
588
589 /* VM ID + at least one parameter. Parameter arguments are checked
590 * individually. */
591 if (a->argc < 2)
592 return errorSyntax(USAGE_MODIFYVM, ModifyVM::tr("Not enough parameters"));
593
594 /* try to find the given sessionMachine */
595 ComPtr<IMachine> machine;
596 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
597 machine.asOutParam()), RTEXITCODE_FAILURE);
598
599
600 /* Get the number of network adapters */
601 ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, machine);
602
603 /* open a session for the VM */
604 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), RTEXITCODE_FAILURE);
605
606 /* get the mutable session sessionMachine */
607 ComPtr<IMachine> sessionMachine;
608 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()), RTEXITCODE_FAILURE);
609
610 ComPtr<IBIOSSettings> biosSettings;
611 sessionMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
612
613 ComPtr<IGraphicsAdapter> pGraphicsAdapter;
614 sessionMachine->COMGETTER(GraphicsAdapter)(pGraphicsAdapter.asOutParam());
615
616 RTGETOPTSTATE GetOptState;
617 RTGetOptInit(&GetOptState, a->argc, a->argv, g_aModifyVMOptions,
618 RT_ELEMENTS(g_aModifyVMOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
619
620 RTGETOPTUNION ValueUnion;
621 while ( SUCCEEDED (rc)
622 && (c = RTGetOpt(&GetOptState, &ValueUnion)))
623 {
624 switch (c)
625 {
626 case MODIFYVM_NAME:
627 {
628 CHECK_ERROR(sessionMachine, COMSETTER(Name)(Bstr(ValueUnion.psz).raw()));
629 break;
630 }
631 case MODIFYVM_GROUPS:
632 {
633 com::SafeArray<BSTR> groups;
634 parseGroups(ValueUnion.psz, &groups);
635 CHECK_ERROR(sessionMachine, COMSETTER(Groups)(ComSafeArrayAsInParam(groups)));
636 break;
637 }
638 case MODIFYVM_DESCRIPTION:
639 {
640 CHECK_ERROR(sessionMachine, COMSETTER(Description)(Bstr(ValueUnion.psz).raw()));
641 break;
642 }
643 case MODIFYVM_OSTYPE:
644 {
645 CHECK_ERROR(sessionMachine, COMSETTER(OSTypeId)(Bstr(ValueUnion.psz).raw()));
646 break;
647 }
648
649 case MODIFYVM_ICONFILE:
650 {
651 RTFILE iconFile;
652 int vrc = RTFileOpen(&iconFile, ValueUnion.psz, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
653 if (RT_FAILURE(vrc))
654 {
655 RTMsgError(ModifyVM::tr("Cannot open file \"%s\": %Rrc"), ValueUnion.psz, vrc);
656 rc = E_FAIL;
657 break;
658 }
659 uint64_t cbSize;
660 vrc = RTFileQuerySize(iconFile, &cbSize);
661 if (RT_FAILURE(vrc))
662 {
663 RTMsgError(ModifyVM::tr("Cannot get size of file \"%s\": %Rrc"), ValueUnion.psz, vrc);
664 rc = E_FAIL;
665 break;
666 }
667 if (cbSize > _256K)
668 {
669 RTMsgError(ModifyVM::tr("File \"%s\" is bigger than 256KByte"), ValueUnion.psz);
670 rc = E_FAIL;
671 break;
672 }
673 SafeArray<BYTE> icon((size_t)cbSize);
674 rc = RTFileRead(iconFile, icon.raw(), (size_t)cbSize, NULL);
675 if (RT_FAILURE(vrc))
676 {
677 RTMsgError(ModifyVM::tr("Cannot read contents of file \"%s\": %Rrc"), ValueUnion.psz, vrc);
678 rc = E_FAIL;
679 break;
680 }
681 RTFileClose(iconFile);
682 CHECK_ERROR(sessionMachine, COMSETTER(Icon)(ComSafeArrayAsInParam(icon)));
683 break;
684 }
685
686 case MODIFYVM_MEMORY:
687 {
688 CHECK_ERROR(sessionMachine, COMSETTER(MemorySize)(ValueUnion.u32));
689 break;
690 }
691
692 case MODIFYVM_PAGEFUSION:
693 {
694 CHECK_ERROR(sessionMachine, COMSETTER(PageFusionEnabled)(ValueUnion.f));
695 break;
696 }
697
698 case MODIFYVM_VRAM:
699 {
700 CHECK_ERROR(pGraphicsAdapter, COMSETTER(VRAMSize)(ValueUnion.u32));
701 break;
702 }
703
704 case MODIFYVM_FIRMWARE:
705 {
706 if (!RTStrICmp(ValueUnion.psz, "efi"))
707 {
708 CHECK_ERROR(sessionMachine, COMSETTER(FirmwareType)(FirmwareType_EFI));
709 }
710 else if (!RTStrICmp(ValueUnion.psz, "efi32"))
711 {
712 CHECK_ERROR(sessionMachine, COMSETTER(FirmwareType)(FirmwareType_EFI32));
713 }
714 else if (!RTStrICmp(ValueUnion.psz, "efi64"))
715 {
716 CHECK_ERROR(sessionMachine, COMSETTER(FirmwareType)(FirmwareType_EFI64));
717 }
718 else if (!RTStrICmp(ValueUnion.psz, "efidual"))
719 {
720 CHECK_ERROR(sessionMachine, COMSETTER(FirmwareType)(FirmwareType_EFIDUAL));
721 }
722 else if (!RTStrICmp(ValueUnion.psz, "bios"))
723 {
724 CHECK_ERROR(sessionMachine, COMSETTER(FirmwareType)(FirmwareType_BIOS));
725 }
726 else
727 {
728 errorArgument(ModifyVM::tr("Invalid --firmware argument '%s'"), ValueUnion.psz);
729 rc = E_FAIL;
730 }
731 break;
732 }
733
734 case MODIFYVM_ACPI:
735 {
736 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(ValueUnion.f));
737 break;
738 }
739
740 case MODIFYVM_IOAPIC:
741 {
742 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(ValueUnion.f));
743 break;
744 }
745
746 case MODIFYVM_PAE:
747 {
748 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_PAE, ValueUnion.f));
749 break;
750 }
751
752 case MODIFYVM_LONGMODE:
753 {
754 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_LongMode, ValueUnion.f));
755 break;
756 }
757
758 case MODIFYVM_CPUID_PORTABILITY:
759 {
760 CHECK_ERROR(sessionMachine, COMSETTER(CPUIDPortabilityLevel)(ValueUnion.u32));
761 break;
762 }
763
764 case MODIFYVM_TFRESET:
765 {
766 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_TripleFaultReset, ValueUnion.f));
767 break;
768 }
769
770 case MODIFYVM_APIC:
771 {
772 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_APIC, ValueUnion.f));
773 break;
774 }
775
776 case MODIFYVM_X2APIC:
777 {
778 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_X2APIC, ValueUnion.f));
779 break;
780 }
781
782 case MODIFYVM_PARAVIRTPROVIDER:
783 {
784 if ( !RTStrICmp(ValueUnion.psz, "none")
785 || !RTStrICmp(ValueUnion.psz, "disabled"))
786 CHECK_ERROR(sessionMachine, COMSETTER(ParavirtProvider)(ParavirtProvider_None));
787 else if (!RTStrICmp(ValueUnion.psz, "default"))
788 CHECK_ERROR(sessionMachine, COMSETTER(ParavirtProvider)(ParavirtProvider_Default));
789 else if (!RTStrICmp(ValueUnion.psz, "legacy"))
790 CHECK_ERROR(sessionMachine, COMSETTER(ParavirtProvider)(ParavirtProvider_Legacy));
791 else if (!RTStrICmp(ValueUnion.psz, "minimal"))
792 CHECK_ERROR(sessionMachine, COMSETTER(ParavirtProvider)(ParavirtProvider_Minimal));
793 else if (!RTStrICmp(ValueUnion.psz, "hyperv"))
794 CHECK_ERROR(sessionMachine, COMSETTER(ParavirtProvider)(ParavirtProvider_HyperV));
795 else if (!RTStrICmp(ValueUnion.psz, "kvm"))
796 CHECK_ERROR(sessionMachine, COMSETTER(ParavirtProvider)(ParavirtProvider_KVM));
797 else
798 {
799 errorArgument(ModifyVM::tr("Invalid --paravirtprovider argument '%s'"), ValueUnion.psz);
800 rc = E_FAIL;
801 }
802 break;
803 }
804
805 case MODIFYVM_PARAVIRTDEBUG:
806 {
807 CHECK_ERROR(sessionMachine, COMSETTER(ParavirtDebug)(Bstr(ValueUnion.psz).raw()));
808 break;
809 }
810
811 case MODIFYVM_HWVIRTEX:
812 {
813 CHECK_ERROR(sessionMachine, SetHWVirtExProperty(HWVirtExPropertyType_Enabled, ValueUnion.f));
814 break;
815 }
816
817 case MODIFYVM_SETCPUID:
818 {
819 uint32_t const idx = c == MODIFYVM_SETCPUID ? ValueUnion.PairU32.uFirst : ValueUnion.u32;
820 uint32_t const idxSub = c == MODIFYVM_SETCPUID ? ValueUnion.PairU32.uSecond : UINT32_MAX;
821 uint32_t aValue[4];
822 for (unsigned i = 0; i < 4; i++)
823 {
824 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX);
825 if (RT_FAILURE(vrc))
826 return errorSyntax(USAGE_MODIFYVM, ModifyVM::tr("Missing or Invalid argument to '%s'"),
827 GetOptState.pDef->pszLong);
828 aValue[i] = ValueUnion.u32;
829 }
830 CHECK_ERROR(sessionMachine, SetCPUIDLeaf(idx, idxSub, aValue[0], aValue[1], aValue[2], aValue[3]));
831 break;
832 }
833
834 case MODIFYVM_DELCPUID:
835 CHECK_ERROR(sessionMachine, RemoveCPUIDLeaf(ValueUnion.PairU32.uFirst, ValueUnion.PairU32.uSecond));
836 break;
837
838 case MODIFYVM_DELCPUID_OLD:
839 CHECK_ERROR(sessionMachine, RemoveCPUIDLeaf(ValueUnion.u32, UINT32_MAX));
840 break;
841
842 case MODIFYVM_DELALLCPUID:
843 {
844 CHECK_ERROR(sessionMachine, RemoveAllCPUIDLeaves());
845 break;
846 }
847
848 case MODIFYVM_NESTEDPAGING:
849 {
850 CHECK_ERROR(sessionMachine, SetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, ValueUnion.f));
851 break;
852 }
853
854 case MODIFYVM_LARGEPAGES:
855 {
856 CHECK_ERROR(sessionMachine, SetHWVirtExProperty(HWVirtExPropertyType_LargePages, ValueUnion.f));
857 break;
858 }
859
860 case MODIFYVM_VTXVPID:
861 {
862 CHECK_ERROR(sessionMachine, SetHWVirtExProperty(HWVirtExPropertyType_VPID, ValueUnion.f));
863 break;
864 }
865
866 case MODIFYVM_VTXUX:
867 {
868 CHECK_ERROR(sessionMachine, SetHWVirtExProperty(HWVirtExPropertyType_UnrestrictedExecution, ValueUnion.f));
869 break;
870 }
871
872 case MODIFYVM_VIRT_VMSAVE_VMLOAD:
873 CHECK_ERROR(sessionMachine, SetHWVirtExProperty(HWVirtExPropertyType_VirtVmsaveVmload, ValueUnion.f));
874 break;
875
876 case MODIFYVM_IBPB_ON_VM_EXIT:
877 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_IBPBOnVMExit, ValueUnion.f));
878 break;
879
880 case MODIFYVM_IBPB_ON_VM_ENTRY:
881 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_IBPBOnVMEntry, ValueUnion.f));
882 break;
883
884 case MODIFYVM_SPEC_CTRL:
885 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_SpecCtrl, ValueUnion.f));
886 break;
887
888 case MODIFYVM_L1D_FLUSH_ON_SCHED:
889 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_L1DFlushOnEMTScheduling, ValueUnion.f));
890 break;
891
892 case MODIFYVM_L1D_FLUSH_ON_VM_ENTRY:
893 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_L1DFlushOnVMEntry, ValueUnion.f));
894 break;
895
896 case MODIFYVM_MDS_CLEAR_ON_SCHED:
897 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_MDSClearOnEMTScheduling, ValueUnion.f));
898 break;
899
900 case MODIFYVM_MDS_CLEAR_ON_VM_ENTRY:
901 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_MDSClearOnVMEntry, ValueUnion.f));
902 break;
903
904 case MODIFYVM_NESTED_HW_VIRT:
905 CHECK_ERROR(sessionMachine, SetCPUProperty(CPUPropertyType_HWVirt, ValueUnion.f));
906 break;
907
908 case MODIFYVM_CPUS:
909 {
910 CHECK_ERROR(sessionMachine, COMSETTER(CPUCount)(ValueUnion.u32));
911 break;
912 }
913
914 case MODIFYVM_RTCUSEUTC:
915 {
916 CHECK_ERROR(sessionMachine, COMSETTER(RTCUseUTC)(ValueUnion.f));
917 break;
918 }
919
920 case MODIFYVM_CPUHOTPLUG:
921 {
922 CHECK_ERROR(sessionMachine, COMSETTER(CPUHotPlugEnabled)(ValueUnion.f));
923 break;
924 }
925
926 case MODIFYVM_CPU_PROFILE:
927 {
928 CHECK_ERROR(sessionMachine, COMSETTER(CPUProfile)(Bstr(ValueUnion.psz).raw()));
929 break;
930 }
931
932 case MODIFYVM_PLUGCPU:
933 {
934 CHECK_ERROR(sessionMachine, HotPlugCPU(ValueUnion.u32));
935 break;
936 }
937
938 case MODIFYVM_UNPLUGCPU:
939 {
940 CHECK_ERROR(sessionMachine, HotUnplugCPU(ValueUnion.u32));
941 break;
942 }
943
944 case MODIFYVM_CPU_EXECTUION_CAP:
945 {
946 CHECK_ERROR(sessionMachine, COMSETTER(CPUExecutionCap)(ValueUnion.u32));
947 break;
948 }
949
950 case MODIFYVM_GRAPHICSCONTROLLER:
951 {
952 if ( !RTStrICmp(ValueUnion.psz, "none")
953 || !RTStrICmp(ValueUnion.psz, "disabled"))
954 CHECK_ERROR(pGraphicsAdapter, COMSETTER(GraphicsControllerType)(GraphicsControllerType_Null));
955 else if ( !RTStrICmp(ValueUnion.psz, "vboxvga")
956 || !RTStrICmp(ValueUnion.psz, "vbox")
957 || !RTStrICmp(ValueUnion.psz, "vga")
958 || !RTStrICmp(ValueUnion.psz, "vesa"))
959 CHECK_ERROR(pGraphicsAdapter, COMSETTER(GraphicsControllerType)(GraphicsControllerType_VBoxVGA));
960#ifdef VBOX_WITH_VMSVGA
961 else if ( !RTStrICmp(ValueUnion.psz, "vmsvga")
962 || !RTStrICmp(ValueUnion.psz, "vmware"))
963 CHECK_ERROR(pGraphicsAdapter, COMSETTER(GraphicsControllerType)(GraphicsControllerType_VMSVGA));
964 else if ( !RTStrICmp(ValueUnion.psz, "vboxsvga")
965 || !RTStrICmp(ValueUnion.psz, "svga"))
966 CHECK_ERROR(pGraphicsAdapter, COMSETTER(GraphicsControllerType)(GraphicsControllerType_VBoxSVGA));
967#endif
968 else
969 {
970 errorArgument(ModifyVM::tr("Invalid --graphicscontroller argument '%s'"), ValueUnion.psz);
971 rc = E_FAIL;
972 }
973 break;
974 }
975
976 case MODIFYVM_MONITORCOUNT:
977 {
978 CHECK_ERROR(pGraphicsAdapter, COMSETTER(MonitorCount)(ValueUnion.u32));
979 break;
980 }
981
982 case MODIFYVM_ACCELERATE3D:
983 {
984 CHECK_ERROR(pGraphicsAdapter, COMSETTER(Accelerate3DEnabled)(ValueUnion.f));
985 break;
986 }
987
988#ifdef VBOX_WITH_VIDEOHWACCEL
989 case MODIFYVM_ACCELERATE2DVIDEO:
990 {
991 CHECK_ERROR(pGraphicsAdapter, COMSETTER(Accelerate2DVideoEnabled)(ValueUnion.f));
992 break;
993 }
994#endif
995
996 case MODIFYVM_BIOSLOGOFADEIN:
997 {
998 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(ValueUnion.f));
999 break;
1000 }
1001
1002 case MODIFYVM_BIOSLOGOFADEOUT:
1003 {
1004 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(ValueUnion.f));
1005 break;
1006 }
1007
1008 case MODIFYVM_BIOSLOGODISPLAYTIME:
1009 {
1010 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(ValueUnion.u32));
1011 break;
1012 }
1013
1014 case MODIFYVM_BIOSLOGOIMAGEPATH:
1015 {
1016 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(ValueUnion.psz).raw()));
1017 break;
1018 }
1019
1020 case MODIFYVM_BIOSBOOTMENU:
1021 {
1022 if (!RTStrICmp(ValueUnion.psz, "disabled"))
1023 {
1024 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
1025 }
1026 else if (!RTStrICmp(ValueUnion.psz, "menuonly"))
1027 {
1028 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
1029 }
1030 else if (!RTStrICmp(ValueUnion.psz, "messageandmenu"))
1031 {
1032 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
1033 }
1034 else
1035 {
1036 errorArgument(ModifyVM::tr("Invalid --biosbootmenu argument '%s'"), ValueUnion.psz);
1037 rc = E_FAIL;
1038 }
1039 break;
1040 }
1041
1042 case MODIFYVM_BIOSAPIC:
1043 {
1044 if (!RTStrICmp(ValueUnion.psz, "disabled"))
1045 {
1046 CHECK_ERROR(biosSettings, COMSETTER(APICMode)(APICMode_Disabled));
1047 }
1048 else if ( !RTStrICmp(ValueUnion.psz, "apic")
1049 || !RTStrICmp(ValueUnion.psz, "lapic")
1050 || !RTStrICmp(ValueUnion.psz, "xapic"))
1051 {
1052 CHECK_ERROR(biosSettings, COMSETTER(APICMode)(APICMode_APIC));
1053 }
1054 else if (!RTStrICmp(ValueUnion.psz, "x2apic"))
1055 {
1056 CHECK_ERROR(biosSettings, COMSETTER(APICMode)(APICMode_X2APIC));
1057 }
1058 else
1059 {
1060 errorArgument(ModifyVM::tr("Invalid --biosapic argument '%s'"), ValueUnion.psz);
1061 rc = E_FAIL;
1062 }
1063 break;
1064 }
1065
1066 case MODIFYVM_BIOSSYSTEMTIMEOFFSET:
1067 {
1068 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(ValueUnion.i64));
1069 break;
1070 }
1071
1072 case MODIFYVM_BIOSPXEDEBUG:
1073 {
1074 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(ValueUnion.f));
1075 break;
1076 }
1077
1078 case MODIFYVM_SYSTEMUUIDLE:
1079 {
1080 CHECK_ERROR(biosSettings, COMSETTER(SMBIOSUuidLittleEndian)(ValueUnion.f));
1081 break;
1082 }
1083
1084 case MODIFYVM_BOOT:
1085 {
1086 if (!RTStrICmp(ValueUnion.psz, "none"))
1087 {
1088 CHECK_ERROR(sessionMachine, SetBootOrder(GetOptState.uIndex, DeviceType_Null));
1089 }
1090 else if (!RTStrICmp(ValueUnion.psz, "floppy"))
1091 {
1092 CHECK_ERROR(sessionMachine, SetBootOrder(GetOptState.uIndex, DeviceType_Floppy));
1093 }
1094 else if (!RTStrICmp(ValueUnion.psz, "dvd"))
1095 {
1096 CHECK_ERROR(sessionMachine, SetBootOrder(GetOptState.uIndex, DeviceType_DVD));
1097 }
1098 else if (!RTStrICmp(ValueUnion.psz, "disk"))
1099 {
1100 CHECK_ERROR(sessionMachine, SetBootOrder(GetOptState.uIndex, DeviceType_HardDisk));
1101 }
1102 else if (!RTStrICmp(ValueUnion.psz, "net"))
1103 {
1104 CHECK_ERROR(sessionMachine, SetBootOrder(GetOptState.uIndex, DeviceType_Network));
1105 }
1106 else
1107 return errorArgument(ModifyVM::tr("Invalid boot device '%s'"), ValueUnion.psz);
1108 break;
1109 }
1110
1111 case MODIFYVM_HDA: // deprecated
1112 case MODIFYVM_HDB: // deprecated
1113 case MODIFYVM_HDD: // deprecated
1114 case MODIFYVM_SATAPORT: // deprecated
1115 {
1116 uint32_t u1 = 0, u2 = 0;
1117 Bstr bstrController = L"IDE Controller";
1118
1119 switch (c)
1120 {
1121 case MODIFYVM_HDA: // deprecated
1122 u1 = 0;
1123 break;
1124
1125 case MODIFYVM_HDB: // deprecated
1126 u1 = 0;
1127 u2 = 1;
1128 break;
1129
1130 case MODIFYVM_HDD: // deprecated
1131 u1 = 1;
1132 u2 = 1;
1133 break;
1134
1135 case MODIFYVM_SATAPORT: // deprecated
1136 u1 = GetOptState.uIndex;
1137 bstrController = L"SATA";
1138 break;
1139 }
1140
1141 if (!RTStrICmp(ValueUnion.psz, "none"))
1142 {
1143 sessionMachine->DetachDevice(bstrController.raw(), u1, u2);
1144 }
1145 else
1146 {
1147 ComPtr<IMedium> hardDisk;
1148 rc = openMedium(a, ValueUnion.psz, DeviceType_HardDisk,
1149 AccessMode_ReadWrite, hardDisk,
1150 false /* fForceNewUuidOnOpen */,
1151 false /* fSilent */);
1152 if (FAILED(rc))
1153 break;
1154 if (hardDisk)
1155 {
1156 CHECK_ERROR(sessionMachine, AttachDevice(bstrController.raw(),
1157 u1, u2,
1158 DeviceType_HardDisk,
1159 hardDisk));
1160 }
1161 else
1162 rc = E_FAIL;
1163 }
1164 break;
1165 }
1166
1167 case MODIFYVM_IDECONTROLLER: // deprecated
1168 {
1169 ComPtr<IStorageController> storageController;
1170 CHECK_ERROR(sessionMachine, GetStorageControllerByName(Bstr("IDE Controller").raw(),
1171 storageController.asOutParam()));
1172
1173 if (!RTStrICmp(ValueUnion.psz, "PIIX3"))
1174 {
1175 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
1176 }
1177 else if (!RTStrICmp(ValueUnion.psz, "PIIX4"))
1178 {
1179 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
1180 }
1181 else if (!RTStrICmp(ValueUnion.psz, "ICH6"))
1182 {
1183 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_ICH6));
1184 }
1185 else
1186 {
1187 errorArgument(ModifyVM::tr("Invalid --idecontroller argument '%s'"), ValueUnion.psz);
1188 rc = E_FAIL;
1189 }
1190 break;
1191 }
1192
1193 case MODIFYVM_SATAPORTCOUNT: // deprecated
1194 {
1195 ComPtr<IStorageController> SataCtl;
1196 CHECK_ERROR(sessionMachine, GetStorageControllerByName(Bstr("SATA").raw(),
1197 SataCtl.asOutParam()));
1198
1199 if (SUCCEEDED(rc) && ValueUnion.u32 > 0)
1200 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(ValueUnion.u32));
1201 break;
1202 }
1203
1204 case MODIFYVM_SATA: // deprecated
1205 {
1206 if (!RTStrICmp(ValueUnion.psz, "on") || !RTStrICmp(ValueUnion.psz, "enable"))
1207 {
1208 ComPtr<IStorageController> ctl;
1209 CHECK_ERROR(sessionMachine, AddStorageController(Bstr("SATA").raw(),
1210 StorageBus_SATA,
1211 ctl.asOutParam()));
1212 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
1213 }
1214 else if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
1215 CHECK_ERROR(sessionMachine, RemoveStorageController(Bstr("SATA").raw()));
1216 else
1217 return errorArgument(ModifyVM::tr("Invalid --usb argument '%s'"), ValueUnion.psz);
1218 break;
1219 }
1220
1221 case MODIFYVM_SCSIPORT: // deprecated
1222 {
1223 if (!RTStrICmp(ValueUnion.psz, "none"))
1224 {
1225 rc = sessionMachine->DetachDevice(Bstr("LsiLogic").raw(),
1226 GetOptState.uIndex, 0);
1227 if (FAILED(rc))
1228 CHECK_ERROR(sessionMachine, DetachDevice(Bstr("BusLogic").raw(),
1229 GetOptState.uIndex, 0));
1230 }
1231 else
1232 {
1233 ComPtr<IMedium> hardDisk;
1234 rc = openMedium(a, ValueUnion.psz, DeviceType_HardDisk,
1235 AccessMode_ReadWrite, hardDisk,
1236 false /* fForceNewUuidOnOpen */,
1237 false /* fSilent */);
1238 if (FAILED(rc))
1239 break;
1240 if (hardDisk)
1241 {
1242 rc = sessionMachine->AttachDevice(Bstr("LsiLogic").raw(),
1243 GetOptState.uIndex, 0,
1244 DeviceType_HardDisk,
1245 hardDisk);
1246 if (FAILED(rc))
1247 CHECK_ERROR(sessionMachine,
1248 AttachDevice(Bstr("BusLogic").raw(),
1249 GetOptState.uIndex, 0,
1250 DeviceType_HardDisk,
1251 hardDisk));
1252 }
1253 else
1254 rc = E_FAIL;
1255 }
1256 break;
1257 }
1258
1259 case MODIFYVM_SCSITYPE: // deprecated
1260 {
1261 ComPtr<IStorageController> ctl;
1262
1263 if (!RTStrICmp(ValueUnion.psz, "LsiLogic"))
1264 {
1265 rc = sessionMachine->RemoveStorageController(Bstr("BusLogic").raw());
1266 if (FAILED(rc))
1267 CHECK_ERROR(sessionMachine, RemoveStorageController(Bstr("LsiLogic").raw()));
1268
1269 CHECK_ERROR(sessionMachine,
1270 AddStorageController(Bstr("LsiLogic").raw(),
1271 StorageBus_SCSI,
1272 ctl.asOutParam()));
1273
1274 if (SUCCEEDED(rc))
1275 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
1276 }
1277 else if (!RTStrICmp(ValueUnion.psz, "BusLogic"))
1278 {
1279 rc = sessionMachine->RemoveStorageController(Bstr("LsiLogic").raw());
1280 if (FAILED(rc))
1281 CHECK_ERROR(sessionMachine, RemoveStorageController(Bstr("BusLogic").raw()));
1282
1283 CHECK_ERROR(sessionMachine,
1284 AddStorageController(Bstr("BusLogic").raw(),
1285 StorageBus_SCSI,
1286 ctl.asOutParam()));
1287
1288 if (SUCCEEDED(rc))
1289 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
1290 }
1291 else
1292 return errorArgument(ModifyVM::tr("Invalid --scsitype argument '%s'"), ValueUnion.psz);
1293 break;
1294 }
1295
1296 case MODIFYVM_SCSI: // deprecated
1297 {
1298 if (!RTStrICmp(ValueUnion.psz, "on") || !RTStrICmp(ValueUnion.psz, "enable"))
1299 {
1300 ComPtr<IStorageController> ctl;
1301
1302 CHECK_ERROR(sessionMachine, AddStorageController(Bstr("BusLogic").raw(),
1303 StorageBus_SCSI,
1304 ctl.asOutParam()));
1305 if (SUCCEEDED(rc))
1306 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
1307 }
1308 else if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
1309 {
1310 rc = sessionMachine->RemoveStorageController(Bstr("BusLogic").raw());
1311 if (FAILED(rc))
1312 CHECK_ERROR(sessionMachine, RemoveStorageController(Bstr("LsiLogic").raw()));
1313 }
1314 break;
1315 }
1316
1317 case MODIFYVM_DVDPASSTHROUGH: // deprecated
1318 {
1319 CHECK_ERROR(sessionMachine, PassthroughDevice(Bstr("IDE Controller").raw(),
1320 1, 0,
1321 !RTStrICmp(ValueUnion.psz, "on")));
1322 break;
1323 }
1324
1325 case MODIFYVM_DVD: // deprecated
1326 {
1327 ComPtr<IMedium> dvdMedium;
1328
1329 /* unmount? */
1330 if (!RTStrICmp(ValueUnion.psz, "none"))
1331 {
1332 /* nothing to do, NULL object will cause unmount */
1333 }
1334 /* host drive? */
1335 else if (!RTStrNICmp(ValueUnion.psz, RT_STR_TUPLE("host:")))
1336 {
1337 ComPtr<IHost> host;
1338 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1339 rc = host->FindHostDVDDrive(Bstr(ValueUnion.psz + 5).raw(),
1340 dvdMedium.asOutParam());
1341 if (!dvdMedium)
1342 {
1343 /* 2nd try: try with the real name, important on Linux+libhal */
1344 char szPathReal[RTPATH_MAX];
1345 if (RT_FAILURE(RTPathReal(ValueUnion.psz + 5, szPathReal, sizeof(szPathReal))))
1346 {
1347 errorArgument(ModifyVM::tr("Invalid host DVD drive name \"%s\""), ValueUnion.psz + 5);
1348 rc = E_FAIL;
1349 break;
1350 }
1351 rc = host->FindHostDVDDrive(Bstr(szPathReal).raw(),
1352 dvdMedium.asOutParam());
1353 if (!dvdMedium)
1354 {
1355 errorArgument(ModifyVM::tr("Invalid host DVD drive name \"%s\""), ValueUnion.psz + 5);
1356 rc = E_FAIL;
1357 break;
1358 }
1359 }
1360 }
1361 else
1362 {
1363 rc = openMedium(a, ValueUnion.psz, DeviceType_DVD,
1364 AccessMode_ReadOnly, dvdMedium,
1365 false /* fForceNewUuidOnOpen */,
1366 false /* fSilent */);
1367 if (FAILED(rc))
1368 break;
1369 if (!dvdMedium)
1370 {
1371 rc = E_FAIL;
1372 break;
1373 }
1374 }
1375
1376 CHECK_ERROR(sessionMachine, MountMedium(Bstr("IDE Controller").raw(),
1377 1, 0,
1378 dvdMedium,
1379 FALSE /* aForce */));
1380 break;
1381 }
1382
1383 case MODIFYVM_FLOPPY: // deprecated
1384 {
1385 ComPtr<IMedium> floppyMedium;
1386 ComPtr<IMediumAttachment> floppyAttachment;
1387 sessionMachine->GetMediumAttachment(Bstr("Floppy Controller").raw(),
1388 0, 0, floppyAttachment.asOutParam());
1389
1390 /* disable? */
1391 if (!RTStrICmp(ValueUnion.psz, "disabled"))
1392 {
1393 /* disable the controller */
1394 if (floppyAttachment)
1395 CHECK_ERROR(sessionMachine, DetachDevice(Bstr("Floppy Controller").raw(),
1396 0, 0));
1397 }
1398 else
1399 {
1400 /* enable the controller */
1401 if (!floppyAttachment)
1402 CHECK_ERROR(sessionMachine, AttachDeviceWithoutMedium(Bstr("Floppy Controller").raw(),
1403 0, 0,
1404 DeviceType_Floppy));
1405
1406 /* unmount? */
1407 if ( !RTStrICmp(ValueUnion.psz, "none")
1408 || !RTStrICmp(ValueUnion.psz, "empty")) // deprecated
1409 {
1410 /* nothing to do, NULL object will cause unmount */
1411 }
1412 /* host drive? */
1413 else if (!RTStrNICmp(ValueUnion.psz, RT_STR_TUPLE("host:")))
1414 {
1415 ComPtr<IHost> host;
1416 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1417 rc = host->FindHostFloppyDrive(Bstr(ValueUnion.psz + 5).raw(),
1418 floppyMedium.asOutParam());
1419 if (!floppyMedium)
1420 {
1421 errorArgument(ModifyVM::tr("Invalid host floppy drive name \"%s\""), ValueUnion.psz + 5);
1422 rc = E_FAIL;
1423 break;
1424 }
1425 }
1426 else
1427 {
1428 rc = openMedium(a, ValueUnion.psz, DeviceType_Floppy,
1429 AccessMode_ReadWrite, floppyMedium,
1430 false /* fForceNewUuidOnOpen */,
1431 false /* fSilent */);
1432 if (FAILED(rc))
1433 break;
1434 if (!floppyMedium)
1435 {
1436 rc = E_FAIL;
1437 break;
1438 }
1439 }
1440 CHECK_ERROR(sessionMachine, MountMedium(Bstr("Floppy Controller").raw(),
1441 0, 0,
1442 floppyMedium,
1443 FALSE /* aForce */));
1444 }
1445 break;
1446 }
1447
1448 case MODIFYVM_NICTRACEFILE:
1449 {
1450
1451 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1452 break;
1453
1454 ComPtr<INetworkAdapter> nic;
1455 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1456 ASSERT(nic);
1457
1458 CHECK_ERROR(nic, COMSETTER(TraceFile)(Bstr(ValueUnion.psz).raw()));
1459 break;
1460 }
1461
1462 case MODIFYVM_NICTRACE:
1463 {
1464 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1465 break;
1466
1467 ComPtr<INetworkAdapter> nic;
1468 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1469 ASSERT(nic);
1470
1471 CHECK_ERROR(nic, COMSETTER(TraceEnabled)(ValueUnion.f));
1472 break;
1473 }
1474
1475 case MODIFYVM_NICPROPERTY:
1476 {
1477 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1478 break;
1479
1480 ComPtr<INetworkAdapter> nic;
1481 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1482 ASSERT(nic);
1483
1484 if (nic)
1485 {
1486 /* Parse 'name=value' */
1487 char *pszProperty = RTStrDup(ValueUnion.psz);
1488 if (pszProperty)
1489 {
1490 char *pDelimiter = strchr(pszProperty, '=');
1491 if (pDelimiter)
1492 {
1493 *pDelimiter = '\0';
1494
1495 Bstr bstrName = pszProperty;
1496 Bstr bstrValue = &pDelimiter[1];
1497 CHECK_ERROR(nic, SetProperty(bstrName.raw(), bstrValue.raw()));
1498 }
1499 else
1500 {
1501 errorArgument(ModifyVM::tr("Invalid --nicproperty%d argument '%s'"), GetOptState.uIndex, ValueUnion.psz);
1502 rc = E_FAIL;
1503 }
1504 RTStrFree(pszProperty);
1505 }
1506 else
1507 {
1508 RTStrmPrintf(g_pStdErr, ModifyVM::tr("Error: Failed to allocate memory for --nicproperty%d '%s'\n"),
1509 GetOptState.uIndex, ValueUnion.psz);
1510 rc = E_FAIL;
1511 }
1512 }
1513 break;
1514 }
1515 case MODIFYVM_NICTYPE:
1516 {
1517 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1518 break;
1519
1520 ComPtr<INetworkAdapter> nic;
1521 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1522 ASSERT(nic);
1523
1524 if (!RTStrICmp(ValueUnion.psz, "Am79C970A"))
1525 {
1526 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A));
1527 }
1528 else if (!RTStrICmp(ValueUnion.psz, "Am79C973"))
1529 {
1530 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973));
1531 }
1532 else if (!RTStrICmp(ValueUnion.psz, "Am79C960"))
1533 {
1534 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C960));
1535 }
1536#ifdef VBOX_WITH_E1000
1537 else if (!RTStrICmp(ValueUnion.psz, "82540EM"))
1538 {
1539 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM));
1540 }
1541 else if (!RTStrICmp(ValueUnion.psz, "82543GC"))
1542 {
1543 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC));
1544 }
1545 else if (!RTStrICmp(ValueUnion.psz, "82545EM"))
1546 {
1547 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82545EM));
1548 }
1549#endif
1550#ifdef VBOX_WITH_VIRTIO
1551 else if (!RTStrICmp(ValueUnion.psz, "virtio"))
1552 {
1553 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Virtio));
1554 }
1555#endif /* VBOX_WITH_VIRTIO */
1556#ifdef VBOX_WITH_VIRTIO_NET_1_0
1557 else if (!RTStrICmp(ValueUnion.psz, "virtio_1.0"))
1558 {
1559 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Virtio_1_0));
1560 }
1561#endif /* VBOX_WITH_VIRTIO_NET_1_0 */
1562 else
1563 {
1564 errorArgument(ModifyVM::tr("Invalid NIC type '%s' specified for NIC %u"),
1565 ValueUnion.psz, GetOptState.uIndex);
1566 rc = E_FAIL;
1567 }
1568 break;
1569 }
1570
1571 case MODIFYVM_NICSPEED:
1572 {
1573 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1574 break;
1575
1576 ComPtr<INetworkAdapter> nic;
1577 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1578 ASSERT(nic);
1579
1580 CHECK_ERROR(nic, COMSETTER(LineSpeed)(ValueUnion.u32));
1581 break;
1582 }
1583
1584 case MODIFYVM_NICBOOTPRIO:
1585 {
1586 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1587 break;
1588
1589 ComPtr<INetworkAdapter> nic;
1590 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1591 ASSERT(nic);
1592
1593 /* Somewhat arbitrary limitation - we can pass a list of up to 4 PCI devices
1594 * to the PXE ROM, hence only boot priorities 1-4 are allowed (in addition to
1595 * 0 for the default lowest priority).
1596 */
1597 if (ValueUnion.u32 > 4)
1598 {
1599 errorArgument(ModifyVM::tr("Invalid boot priority '%u' specfied for NIC %u"), ValueUnion.u32, GetOptState.uIndex);
1600 rc = E_FAIL;
1601 }
1602 else
1603 {
1604 CHECK_ERROR(nic, COMSETTER(BootPriority)(ValueUnion.u32));
1605 }
1606 break;
1607 }
1608
1609 case MODIFYVM_NICPROMISC:
1610 {
1611 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
1612 if (!RTStrICmp(ValueUnion.psz, "deny"))
1613 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
1614 else if ( !RTStrICmp(ValueUnion.psz, "allow-vms")
1615 || !RTStrICmp(ValueUnion.psz, "allow-network"))
1616 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
1617 else if (!RTStrICmp(ValueUnion.psz, "allow-all"))
1618 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
1619 else
1620 {
1621 errorArgument(ModifyVM::tr("Unknown promiscuous mode policy '%s'"), ValueUnion.psz);
1622 rc = E_INVALIDARG;
1623 break;
1624 }
1625
1626 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1627 break;
1628
1629 ComPtr<INetworkAdapter> nic;
1630 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1631 ASSERT(nic);
1632
1633 CHECK_ERROR(nic, COMSETTER(PromiscModePolicy)(enmPromiscModePolicy));
1634 break;
1635 }
1636
1637 case MODIFYVM_NICBWGROUP:
1638 {
1639 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1640 break;
1641
1642 ComPtr<INetworkAdapter> nic;
1643 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1644 ASSERT(nic);
1645
1646 if (!RTStrICmp(ValueUnion.psz, "none"))
1647 {
1648 /* Just remove the bandwidth group. */
1649 CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(NULL));
1650 }
1651 else
1652 {
1653 ComPtr<IBandwidthControl> bwCtrl;
1654 ComPtr<IBandwidthGroup> bwGroup;
1655
1656 CHECK_ERROR(sessionMachine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
1657
1658 if (SUCCEEDED(rc))
1659 {
1660 CHECK_ERROR(bwCtrl, GetBandwidthGroup(Bstr(ValueUnion.psz).raw(), bwGroup.asOutParam()));
1661 if (SUCCEEDED(rc))
1662 {
1663 CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(bwGroup));
1664 }
1665 }
1666 }
1667 break;
1668 }
1669
1670 case MODIFYVM_NIC:
1671 {
1672 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1673 break;
1674
1675 ComPtr<INetworkAdapter> nic;
1676 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1677 ASSERT(nic);
1678
1679 /*
1680 * Check if the NIC is already enabled. Do not try to
1681 * enable it if it already is. That makes a
1682 * difference for saved VMs for which you can change
1683 * the NIC attachment, but can't change the NIC
1684 * enabled status (yes, the setter also should not
1685 * freak out about a no-op request).
1686 */
1687 BOOL fEnabled;;
1688 CHECK_ERROR(nic, COMGETTER(Enabled)(&fEnabled));
1689
1690 if (!RTStrICmp(ValueUnion.psz, "none"))
1691 {
1692 if (RT_BOOL(fEnabled))
1693 CHECK_ERROR(nic, COMSETTER(Enabled)(FALSE));
1694 }
1695 else if (!RTStrICmp(ValueUnion.psz, "null"))
1696 {
1697 if (!fEnabled)
1698 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1699 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Null));
1700 }
1701 else if (!RTStrICmp(ValueUnion.psz, "nat"))
1702 {
1703 if (!fEnabled)
1704 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1705 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_NAT));
1706 }
1707 else if ( !RTStrICmp(ValueUnion.psz, "bridged")
1708 || !RTStrICmp(ValueUnion.psz, "hostif")) /* backward compatibility */
1709 {
1710 if (!fEnabled)
1711 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1712 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Bridged));
1713 }
1714 else if (!RTStrICmp(ValueUnion.psz, "intnet"))
1715 {
1716 if (!fEnabled)
1717 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1718 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Internal));
1719 }
1720 else if (!RTStrICmp(ValueUnion.psz, "hostonly"))
1721 {
1722 if (!fEnabled)
1723 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1724 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_HostOnly));
1725 }
1726#ifdef VBOX_WITH_VMNET
1727 else if (!RTStrICmp(ValueUnion.psz, "hostonlynet"))
1728 {
1729 if (!fEnabled)
1730 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1731 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_HostOnlyNetwork));
1732 }
1733#endif /* VBOX_WITH_VMNET */
1734 else if (!RTStrICmp(ValueUnion.psz, "generic"))
1735 {
1736 if (!fEnabled)
1737 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1738 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic));
1739 }
1740 else if (!RTStrICmp(ValueUnion.psz, "natnetwork"))
1741 {
1742 if (!fEnabled)
1743 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1744 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_NATNetwork));
1745 }
1746 else
1747 {
1748 errorArgument(ModifyVM::tr("Invalid type '%s' specfied for NIC %u"), ValueUnion.psz, GetOptState.uIndex);
1749 rc = E_FAIL;
1750 }
1751 break;
1752 }
1753
1754 case MODIFYVM_CABLECONNECTED:
1755 {
1756 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1757 break;
1758
1759 ComPtr<INetworkAdapter> nic;
1760 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1761 ASSERT(nic);
1762
1763 CHECK_ERROR(nic, COMSETTER(CableConnected)(ValueUnion.f));
1764 break;
1765 }
1766
1767 case MODIFYVM_BRIDGEADAPTER:
1768 {
1769 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1770 break;
1771
1772 ComPtr<INetworkAdapter> nic;
1773 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1774 ASSERT(nic);
1775
1776 /* remove it? */
1777 if (!RTStrICmp(ValueUnion.psz, "none"))
1778 {
1779 CHECK_ERROR(nic, COMSETTER(BridgedInterface)(Bstr().raw()));
1780 }
1781 else
1782 {
1783 CHECK_ERROR(nic, COMSETTER(BridgedInterface)(Bstr(ValueUnion.psz).raw()));
1784 verifyHostNetworkInterfaceName(a->virtualBox, ValueUnion.psz,
1785 HostNetworkInterfaceType_Bridged);
1786 }
1787 break;
1788 }
1789
1790 case MODIFYVM_HOSTONLYADAPTER:
1791 {
1792 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1793 break;
1794
1795 ComPtr<INetworkAdapter> nic;
1796 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1797 ASSERT(nic);
1798
1799 /* remove it? */
1800 if (!RTStrICmp(ValueUnion.psz, "none"))
1801 {
1802 CHECK_ERROR(nic, COMSETTER(HostOnlyInterface)(Bstr().raw()));
1803 }
1804 else
1805 {
1806 CHECK_ERROR(nic, COMSETTER(HostOnlyInterface)(Bstr(ValueUnion.psz).raw()));
1807 verifyHostNetworkInterfaceName(a->virtualBox, ValueUnion.psz,
1808 HostNetworkInterfaceType_HostOnly);
1809 }
1810 break;
1811 }
1812
1813#ifdef VBOX_WITH_VMNET
1814 case MODIFYVM_HOSTONLYNET:
1815 {
1816 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1817 break;
1818
1819 ComPtr<INetworkAdapter> nic;
1820 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1821 ASSERT(nic);
1822
1823 /* remove it? */
1824 if (!RTStrICmp(ValueUnion.psz, "none"))
1825 {
1826 CHECK_ERROR(nic, COMSETTER(HostOnlyNetwork)(Bstr().raw()));
1827 }
1828 else
1829 {
1830 CHECK_ERROR(nic, COMSETTER(HostOnlyNetwork)(Bstr(ValueUnion.psz).raw()));
1831 }
1832 break;
1833 }
1834#endif /* VBOX_WITH_VMNET */
1835
1836 case MODIFYVM_INTNET:
1837 {
1838 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1839 break;
1840
1841 ComPtr<INetworkAdapter> nic;
1842 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1843 ASSERT(nic);
1844
1845 /* remove it? */
1846 if (!RTStrICmp(ValueUnion.psz, "none"))
1847 {
1848 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr().raw()));
1849 }
1850 else
1851 {
1852 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr(ValueUnion.psz).raw()));
1853 }
1854 break;
1855 }
1856
1857 case MODIFYVM_GENERICDRV:
1858 {
1859 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1860 break;
1861
1862 ComPtr<INetworkAdapter> nic;
1863 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1864 ASSERT(nic);
1865
1866 CHECK_ERROR(nic, COMSETTER(GenericDriver)(Bstr(ValueUnion.psz).raw()));
1867 break;
1868 }
1869
1870 case MODIFYVM_NATNETWORKNAME:
1871 {
1872 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1873 break;
1874
1875 ComPtr<INetworkAdapter> nic;
1876 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1877 ASSERT(nic);
1878
1879 CHECK_ERROR(nic, COMSETTER(NATNetwork)(Bstr(ValueUnion.psz).raw()));
1880 break;
1881 }
1882
1883 case MODIFYVM_NATNET:
1884 {
1885 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1886 break;
1887
1888 ComPtr<INetworkAdapter> nic;
1889 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1890 ASSERT(nic);
1891
1892 ComPtr<INATEngine> engine;
1893 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1894
1895 const char *psz = ValueUnion.psz;
1896 if (!RTStrICmp("default", psz))
1897 psz = "";
1898
1899 CHECK_ERROR(engine, COMSETTER(Network)(Bstr(psz).raw()));
1900 break;
1901 }
1902
1903 case MODIFYVM_NATBINDIP:
1904 {
1905 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1906 break;
1907
1908 ComPtr<INetworkAdapter> nic;
1909 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1910 ASSERT(nic);
1911
1912 ComPtr<INATEngine> engine;
1913 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1914
1915 CHECK_ERROR(engine, COMSETTER(HostIP)(Bstr(ValueUnion.psz).raw()));
1916 break;
1917 }
1918
1919#define ITERATE_TO_NEXT_TERM(ch) \
1920 do { \
1921 while (*ch != ',') \
1922 { \
1923 if (*ch == 0) \
1924 { \
1925 return errorSyntax(USAGE_MODIFYVM, \
1926 ModifyVM::tr("Missing or Invalid argument to '%s'"), \
1927 GetOptState.pDef->pszLong); \
1928 } \
1929 ch++; \
1930 } \
1931 *ch = '\0'; \
1932 ch++; \
1933 } while(0)
1934
1935 case MODIFYVM_NATSETTINGS:
1936 {
1937 ComPtr<INetworkAdapter> nic;
1938 ComPtr<INATEngine> engine;
1939 char *strMtu;
1940 char *strSockSnd;
1941 char *strSockRcv;
1942 char *strTcpSnd;
1943 char *strTcpRcv;
1944 char *strRaw = RTStrDup(ValueUnion.psz);
1945 char *ch = strRaw;
1946 strMtu = RTStrStrip(ch);
1947 ITERATE_TO_NEXT_TERM(ch);
1948 strSockSnd = RTStrStrip(ch);
1949 ITERATE_TO_NEXT_TERM(ch);
1950 strSockRcv = RTStrStrip(ch);
1951 ITERATE_TO_NEXT_TERM(ch);
1952 strTcpSnd = RTStrStrip(ch);
1953 ITERATE_TO_NEXT_TERM(ch);
1954 strTcpRcv = RTStrStrip(ch);
1955
1956 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1957 break;
1958
1959 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1960 ASSERT(nic);
1961
1962 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1963 CHECK_ERROR(engine, SetNetworkSettings(RTStrToUInt32(strMtu), RTStrToUInt32(strSockSnd), RTStrToUInt32(strSockRcv),
1964 RTStrToUInt32(strTcpSnd), RTStrToUInt32(strTcpRcv)));
1965 break;
1966 }
1967
1968
1969 case MODIFYVM_NATPF:
1970 {
1971 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
1972 break;
1973
1974 ComPtr<INetworkAdapter> nic;
1975 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1976 ASSERT(nic);
1977
1978 ComPtr<INATEngine> engine;
1979 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1980
1981 /* format name:proto:hostip:hostport:guestip:guestport*/
1982 if (RTStrCmp(ValueUnion.psz, "delete") != 0)
1983 {
1984 char *strName;
1985 char *strProto;
1986 char *strHostIp;
1987 char *strHostPort;
1988 char *strGuestIp;
1989 char *strGuestPort;
1990 char *strRaw = RTStrDup(ValueUnion.psz);
1991 char *ch = strRaw;
1992 strName = RTStrStrip(ch);
1993 ITERATE_TO_NEXT_TERM(ch);
1994 strProto = RTStrStrip(ch);
1995 ITERATE_TO_NEXT_TERM(ch);
1996 strHostIp = RTStrStrip(ch);
1997 ITERATE_TO_NEXT_TERM(ch);
1998 strHostPort = RTStrStrip(ch);
1999 ITERATE_TO_NEXT_TERM(ch);
2000 strGuestIp = RTStrStrip(ch);
2001 ITERATE_TO_NEXT_TERM(ch);
2002 strGuestPort = RTStrStrip(ch);
2003 NATProtocol_T proto;
2004 if (RTStrICmp(strProto, "udp") == 0)
2005 proto = NATProtocol_UDP;
2006 else if (RTStrICmp(strProto, "tcp") == 0)
2007 proto = NATProtocol_TCP;
2008 else
2009 {
2010 errorArgument(ModifyVM::tr("Invalid proto '%s' specfied for NIC %u"), ValueUnion.psz, GetOptState.uIndex);
2011 rc = E_FAIL;
2012 break;
2013 }
2014 CHECK_ERROR(engine, AddRedirect(Bstr(strName).raw(), proto,
2015 Bstr(strHostIp).raw(),
2016 RTStrToUInt16(strHostPort),
2017 Bstr(strGuestIp).raw(),
2018 RTStrToUInt16(strGuestPort)));
2019 }
2020 else
2021 {
2022 /* delete NAT Rule operation */
2023 int vrc;
2024 vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
2025 if (RT_FAILURE(vrc))
2026 return errorSyntax(USAGE_MODIFYVM, ModifyVM::tr("Not enough parameters"));
2027 CHECK_ERROR(engine, RemoveRedirect(Bstr(ValueUnion.psz).raw()));
2028 }
2029 break;
2030 }
2031 #undef ITERATE_TO_NEXT_TERM
2032 case MODIFYVM_NATALIASMODE:
2033 {
2034 ComPtr<INetworkAdapter> nic;
2035 ComPtr<INATEngine> engine;
2036 uint32_t aliasMode = 0;
2037
2038 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2039 ASSERT(nic);
2040
2041 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
2042 if (RTStrCmp(ValueUnion.psz, "default") == 0)
2043 aliasMode = 0;
2044 else
2045 {
2046 char *token = (char *)ValueUnion.psz;
2047 while (token)
2048 {
2049 if (RTStrNCmp(token, RT_STR_TUPLE("log")) == 0)
2050 aliasMode |= NATAliasMode_AliasLog;
2051 else if (RTStrNCmp(token, RT_STR_TUPLE("proxyonly")) == 0)
2052 aliasMode |= NATAliasMode_AliasProxyOnly;
2053 else if (RTStrNCmp(token, RT_STR_TUPLE("sameports")) == 0)
2054 aliasMode |= NATAliasMode_AliasUseSamePorts;
2055 token = RTStrStr(token, ",");
2056 if (token == NULL)
2057 break;
2058 token++;
2059 }
2060 }
2061 CHECK_ERROR(engine, COMSETTER(AliasMode)(aliasMode));
2062 break;
2063 }
2064
2065 case MODIFYVM_NATTFTPPREFIX:
2066 {
2067 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
2068 break;
2069
2070 ComPtr<INetworkAdapter> nic;
2071 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2072 ASSERT(nic);
2073
2074 ComPtr<INATEngine> engine;
2075 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
2076
2077 CHECK_ERROR(engine, COMSETTER(TFTPPrefix)(Bstr(ValueUnion.psz).raw()));
2078 break;
2079 }
2080
2081 case MODIFYVM_NATTFTPFILE:
2082 {
2083 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
2084 break;
2085
2086 ComPtr<INetworkAdapter> nic;
2087 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2088 ASSERT(nic);
2089
2090 ComPtr<INATEngine> engine;
2091 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
2092
2093 CHECK_ERROR(engine, COMSETTER(TFTPBootFile)(Bstr(ValueUnion.psz).raw()));
2094 break;
2095 }
2096
2097 case MODIFYVM_NATTFTPSERVER:
2098 {
2099 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
2100 break;
2101
2102 ComPtr<INetworkAdapter> nic;
2103 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2104 ASSERT(nic);
2105
2106 ComPtr<INATEngine> engine;
2107 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
2108
2109 CHECK_ERROR(engine, COMSETTER(TFTPNextServer)(Bstr(ValueUnion.psz).raw()));
2110 break;
2111 }
2112 case MODIFYVM_NATDNSPASSDOMAIN:
2113 {
2114 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
2115 break;
2116
2117 ComPtr<INetworkAdapter> nic;
2118 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2119 ASSERT(nic);
2120
2121 ComPtr<INATEngine> engine;
2122 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
2123
2124 CHECK_ERROR(engine, COMSETTER(DNSPassDomain)(ValueUnion.f));
2125 break;
2126 }
2127
2128 case MODIFYVM_NATDNSPROXY:
2129 {
2130 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
2131 break;
2132
2133 ComPtr<INetworkAdapter> nic;
2134 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2135 ASSERT(nic);
2136
2137 ComPtr<INATEngine> engine;
2138 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
2139
2140 CHECK_ERROR(engine, COMSETTER(DNSProxy)(ValueUnion.f));
2141 break;
2142 }
2143
2144 case MODIFYVM_NATDNSHOSTRESOLVER:
2145 {
2146 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
2147 break;
2148
2149 ComPtr<INetworkAdapter> nic;
2150 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2151 ASSERT(nic);
2152
2153 ComPtr<INATEngine> engine;
2154 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
2155
2156 CHECK_ERROR(engine, COMSETTER(DNSUseHostResolver)(ValueUnion.f));
2157 break;
2158 }
2159
2160 case MODIFYVM_NATLOCALHOSTREACHABLE:
2161 {
2162 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
2163 break;
2164
2165 ComPtr<INetworkAdapter> nic;
2166 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2167 ASSERT(nic);
2168
2169 ComPtr<INATEngine> engine;
2170 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
2171
2172 CHECK_ERROR(engine, COMSETTER(LocalhostReachable)(ValueUnion.f));
2173 break;
2174 }
2175
2176 case MODIFYVM_MACADDRESS:
2177 {
2178 if (!parseNum(GetOptState.uIndex, NetworkAdapterCount, "NIC"))
2179 break;
2180
2181 ComPtr<INetworkAdapter> nic;
2182 CHECK_ERROR_BREAK(sessionMachine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
2183 ASSERT(nic);
2184
2185 /* generate one? */
2186 if (!RTStrICmp(ValueUnion.psz, "auto"))
2187 {
2188 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr().raw()));
2189 }
2190 else
2191 {
2192 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr(ValueUnion.psz).raw()));
2193 }
2194 break;
2195 }
2196
2197 case MODIFYVM_HIDPTR:
2198 {
2199 bool fEnableUsb = false;
2200 if (!RTStrICmp(ValueUnion.psz, "ps2"))
2201 {
2202 CHECK_ERROR(sessionMachine, COMSETTER(PointingHIDType)(PointingHIDType_PS2Mouse));
2203 }
2204 else if (!RTStrICmp(ValueUnion.psz, "usb"))
2205 {
2206 CHECK_ERROR(sessionMachine, COMSETTER(PointingHIDType)(PointingHIDType_USBMouse));
2207 if (SUCCEEDED(rc))
2208 fEnableUsb = true;
2209 }
2210 else if (!RTStrICmp(ValueUnion.psz, "usbtablet"))
2211 {
2212 CHECK_ERROR(sessionMachine, COMSETTER(PointingHIDType)(PointingHIDType_USBTablet));
2213 if (SUCCEEDED(rc))
2214 fEnableUsb = true;
2215 }
2216 else if (!RTStrICmp(ValueUnion.psz, "usbmultitouch"))
2217 {
2218 CHECK_ERROR(sessionMachine, COMSETTER(PointingHIDType)(PointingHIDType_USBMultiTouch));
2219 if (SUCCEEDED(rc))
2220 fEnableUsb = true;
2221 }
2222 else if (!RTStrICmp(ValueUnion.psz, "none"))
2223 {
2224 CHECK_ERROR(sessionMachine, COMSETTER(PointingHIDType)(PointingHIDType_None));
2225 }
2226 else
2227 {
2228 errorArgument(ModifyVM::tr("Invalid type '%s' specfied for pointing device"), ValueUnion.psz);
2229 rc = E_FAIL;
2230 }
2231 if (fEnableUsb)
2232 {
2233 /* Make sure either the OHCI or xHCI controller is enabled. */
2234 ULONG cOhciCtrls = 0;
2235 ULONG cXhciCtrls = 0;
2236 rc = sessionMachine->GetUSBControllerCountByType(USBControllerType_OHCI, &cOhciCtrls);
2237 if (SUCCEEDED(rc)) {
2238 rc = sessionMachine->GetUSBControllerCountByType(USBControllerType_XHCI, &cXhciCtrls);
2239 if ( SUCCEEDED(rc)
2240 && cOhciCtrls + cXhciCtrls == 0)
2241 {
2242 /* If there's nothing, enable OHCI (always available). */
2243 ComPtr<IUSBController> UsbCtl;
2244 CHECK_ERROR(sessionMachine, AddUSBController(Bstr("OHCI").raw(), USBControllerType_OHCI,
2245 UsbCtl.asOutParam()));
2246 }
2247 }
2248 }
2249 break;
2250 }
2251
2252 case MODIFYVM_HIDKBD:
2253 {
2254 bool fEnableUsb = false;
2255 if (!RTStrICmp(ValueUnion.psz, "ps2"))
2256 {
2257 CHECK_ERROR(sessionMachine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_PS2Keyboard));
2258 }
2259 else if (!RTStrICmp(ValueUnion.psz, "usb"))
2260 {
2261 CHECK_ERROR(sessionMachine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_USBKeyboard));
2262 if (SUCCEEDED(rc))
2263 fEnableUsb = true;
2264 }
2265 else if (!RTStrICmp(ValueUnion.psz, "none"))
2266 {
2267 CHECK_ERROR(sessionMachine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_None));
2268 if (SUCCEEDED(rc))
2269 fEnableUsb = true;
2270 }
2271 else
2272 {
2273 errorArgument(ModifyVM::tr("Invalid type '%s' specfied for keyboard"), ValueUnion.psz);
2274 rc = E_FAIL;
2275 }
2276 if (fEnableUsb)
2277 {
2278 /* Make sure either the OHCI or xHCI controller is enabled. */
2279 ULONG cOhciCtrls = 0;
2280 ULONG cXhciCtrls = 0;
2281 rc = sessionMachine->GetUSBControllerCountByType(USBControllerType_OHCI, &cOhciCtrls);
2282 if (SUCCEEDED(rc)) {
2283 rc = sessionMachine->GetUSBControllerCountByType(USBControllerType_XHCI, &cXhciCtrls);
2284 if ( SUCCEEDED(rc)
2285 && cOhciCtrls + cXhciCtrls == 0)
2286 {
2287 /* If there's nothing, enable OHCI (always available). */
2288 ComPtr<IUSBController> UsbCtl;
2289 CHECK_ERROR(sessionMachine, AddUSBController(Bstr("OHCI").raw(), USBControllerType_OHCI,
2290 UsbCtl.asOutParam()));
2291 }
2292 }
2293 }
2294 break;
2295 }
2296
2297 case MODIFYVM_UARTMODE:
2298 {
2299 ComPtr<ISerialPort> uart;
2300
2301 CHECK_ERROR_BREAK(sessionMachine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
2302 ASSERT(uart);
2303
2304 if (!RTStrICmp(ValueUnion.psz, "disconnected"))
2305 {
2306 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
2307 }
2308 else if ( !RTStrICmp(ValueUnion.psz, "server")
2309 || !RTStrICmp(ValueUnion.psz, "client")
2310 || !RTStrICmp(ValueUnion.psz, "tcpserver")
2311 || !RTStrICmp(ValueUnion.psz, "tcpclient")
2312 || !RTStrICmp(ValueUnion.psz, "file"))
2313 {
2314 const char *pszMode = ValueUnion.psz;
2315
2316 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
2317 if (RT_FAILURE(vrc))
2318 return errorSyntax(USAGE_MODIFYVM,
2319 ModifyVM::tr("Missing or Invalid argument to '%s'"),
2320 GetOptState.pDef->pszLong);
2321
2322 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
2323
2324 if (!RTStrICmp(pszMode, "server"))
2325 {
2326 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
2327 CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
2328 }
2329 else if (!RTStrICmp(pszMode, "client"))
2330 {
2331 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
2332 CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
2333 }
2334 else if (!RTStrICmp(pszMode, "tcpserver"))
2335 {
2336 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_TCP));
2337 CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
2338 }
2339 else if (!RTStrICmp(pszMode, "tcpclient"))
2340 {
2341 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_TCP));
2342 CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
2343 }
2344 else if (!RTStrICmp(pszMode, "file"))
2345 {
2346 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_RawFile));
2347 }
2348 }
2349 else
2350 {
2351 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
2352 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostDevice));
2353 }
2354 break;
2355 }
2356
2357 case MODIFYVM_UARTTYPE:
2358 {
2359 ComPtr<ISerialPort> uart;
2360
2361 CHECK_ERROR_BREAK(sessionMachine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
2362 ASSERT(uart);
2363
2364 if (!RTStrICmp(ValueUnion.psz, "16450"))
2365 {
2366 CHECK_ERROR(uart, COMSETTER(UartType)(UartType_U16450));
2367 }
2368 else if (!RTStrICmp(ValueUnion.psz, "16550A"))
2369 {
2370 CHECK_ERROR(uart, COMSETTER(UartType)(UartType_U16550A));
2371 }
2372 else if (!RTStrICmp(ValueUnion.psz, "16750"))
2373 {
2374 CHECK_ERROR(uart, COMSETTER(UartType)(UartType_U16750));
2375 }
2376 else
2377 return errorSyntax(USAGE_MODIFYVM,
2378 ModifyVM::tr("Invalid argument to '%s'"),
2379 GetOptState.pDef->pszLong);
2380 break;
2381 }
2382
2383 case MODIFYVM_UART:
2384 {
2385 ComPtr<ISerialPort> uart;
2386
2387 CHECK_ERROR_BREAK(sessionMachine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
2388 ASSERT(uart);
2389
2390 if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
2391 CHECK_ERROR(uart, COMSETTER(Enabled)(FALSE));
2392 else
2393 {
2394 const char *pszIOBase = ValueUnion.psz;
2395 uint32_t uVal = 0;
2396
2397 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_UART;
2398 if (RT_FAILURE(vrc))
2399 return errorSyntax(USAGE_MODIFYVM,
2400 ModifyVM::tr("Missing or Invalid argument to '%s'"),
2401 GetOptState.pDef->pszLong);
2402
2403 CHECK_ERROR(uart, COMSETTER(IRQ)(ValueUnion.u32));
2404
2405 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
2406 if (vrc != VINF_SUCCESS || uVal == 0)
2407 return errorArgument(ModifyVM::tr("Error parsing UART I/O base '%s'"), pszIOBase);
2408 CHECK_ERROR(uart, COMSETTER(IOBase)(uVal));
2409
2410 CHECK_ERROR(uart, COMSETTER(Enabled)(TRUE));
2411 }
2412 break;
2413 }
2414
2415#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
2416 case MODIFYVM_LPTMODE:
2417 {
2418 ComPtr<IParallelPort> lpt;
2419
2420 CHECK_ERROR_BREAK(sessionMachine, GetParallelPort(GetOptState.uIndex - 1, lpt.asOutParam()));
2421 ASSERT(lpt);
2422
2423 CHECK_ERROR(lpt, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
2424 break;
2425 }
2426
2427 case MODIFYVM_LPT:
2428 {
2429 ComPtr<IParallelPort> lpt;
2430
2431 CHECK_ERROR_BREAK(sessionMachine, GetParallelPort(GetOptState.uIndex - 1, lpt.asOutParam()));
2432 ASSERT(lpt);
2433
2434 if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
2435 CHECK_ERROR(lpt, COMSETTER(Enabled)(FALSE));
2436 else
2437 {
2438 const char *pszIOBase = ValueUnion.psz;
2439 uint32_t uVal = 0;
2440
2441 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_LPT;
2442 if (RT_FAILURE(vrc))
2443 return errorSyntax(USAGE_MODIFYVM,
2444 ModifyVM::tr("Missing or Invalid argument to '%s'"),
2445 GetOptState.pDef->pszLong);
2446
2447 CHECK_ERROR(lpt, COMSETTER(IRQ)(ValueUnion.u32));
2448
2449 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
2450 if (vrc != VINF_SUCCESS || uVal == 0)
2451 return errorArgument(ModifyVM::tr("Error parsing LPT I/O base '%s'"), pszIOBase);
2452 CHECK_ERROR(lpt, COMSETTER(IOBase)(uVal));
2453
2454 CHECK_ERROR(lpt, COMSETTER(Enabled)(TRUE));
2455 }
2456 break;
2457 }
2458#endif
2459
2460 case MODIFYVM_GUESTMEMORYBALLOON:
2461 {
2462 CHECK_ERROR(sessionMachine, COMSETTER(MemoryBalloonSize)(ValueUnion.u32));
2463 break;
2464 }
2465
2466 case MODIFYVM_AUDIOCONTROLLER:
2467 {
2468 ComPtr<IAudioAdapter> audioAdapter;
2469 sessionMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
2470 ASSERT(audioAdapter);
2471
2472 if (!RTStrICmp(ValueUnion.psz, "sb16"))
2473 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
2474 else if (!RTStrICmp(ValueUnion.psz, "ac97"))
2475 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
2476 else if (!RTStrICmp(ValueUnion.psz, "hda"))
2477 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_HDA));
2478 else
2479 {
2480 errorArgument(ModifyVM::tr("Invalid --audiocontroller argument '%s'"), ValueUnion.psz);
2481 rc = E_FAIL;
2482 }
2483 break;
2484 }
2485
2486 case MODIFYVM_AUDIOCODEC:
2487 {
2488 ComPtr<IAudioAdapter> audioAdapter;
2489 sessionMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
2490 ASSERT(audioAdapter);
2491
2492 if (!RTStrICmp(ValueUnion.psz, "sb16"))
2493 CHECK_ERROR(audioAdapter, COMSETTER(AudioCodec)(AudioCodecType_SB16));
2494 else if (!RTStrICmp(ValueUnion.psz, "stac9700"))
2495 CHECK_ERROR(audioAdapter, COMSETTER(AudioCodec)(AudioCodecType_STAC9700));
2496 else if (!RTStrICmp(ValueUnion.psz, "ad1980"))
2497 CHECK_ERROR(audioAdapter, COMSETTER(AudioCodec)(AudioCodecType_AD1980));
2498 else if (!RTStrICmp(ValueUnion.psz, "stac9221"))
2499 CHECK_ERROR(audioAdapter, COMSETTER(AudioCodec)(AudioCodecType_STAC9221));
2500 else
2501 {
2502 errorArgument(ModifyVM::tr("Invalid --audiocodec argument '%s'"), ValueUnion.psz);
2503 rc = E_FAIL;
2504 }
2505 break;
2506 }
2507
2508 case MODIFYVM_AUDIO:
2509 {
2510 ComPtr<IAudioAdapter> audioAdapter;
2511 sessionMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
2512 ASSERT(audioAdapter);
2513/** @todo r=klaus: don't unconditionally bolt together setting the audio driver
2514 * and enabling the device. Doing this more cleverly allows changing the audio
2515 * driver for VMs in saved state, which can be very useful when moving VMs
2516 * between systems with different setup. The driver doesn't leave any traces in
2517 * saved state. The GUI also might learn this trick if it doesn't use it
2518 * already. */
2519
2520 /* disable? */
2521 if (!RTStrICmp(ValueUnion.psz, "none"))
2522 {
2523 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
2524 }
2525 else if (!RTStrICmp(ValueUnion.psz, "null"))
2526 {
2527 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
2528 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2529 }
2530#ifdef RT_OS_WINDOWS
2531#ifdef VBOX_WITH_WINMM
2532 else if (!RTStrICmp(ValueUnion.psz, "winmm"))
2533 {
2534 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
2535 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2536 }
2537#endif
2538 else if (!RTStrICmp(ValueUnion.psz, "dsound"))
2539 {
2540 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
2541 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2542 }
2543#endif /* RT_OS_WINDOWS */
2544#ifdef VBOX_WITH_AUDIO_OSS
2545 else if (!RTStrICmp(ValueUnion.psz, "oss"))
2546 {
2547 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
2548 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2549 }
2550#endif
2551#ifdef VBOX_WITH_AUDIO_ALSA
2552 else if (!RTStrICmp(ValueUnion.psz, "alsa"))
2553 {
2554 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
2555 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2556 }
2557#endif
2558#ifdef VBOX_WITH_AUDIO_PULSE
2559 else if (!RTStrICmp(ValueUnion.psz, "pulse"))
2560 {
2561 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
2562 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2563 }
2564#endif
2565#ifdef RT_OS_DARWIN
2566 else if (!RTStrICmp(ValueUnion.psz, "coreaudio"))
2567 {
2568 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
2569 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2570 }
2571#endif /* !RT_OS_DARWIN */
2572 else
2573 {
2574 errorArgument(ModifyVM::tr("Invalid --audio argument '%s'"), ValueUnion.psz);
2575 rc = E_FAIL;
2576 }
2577 break;
2578 }
2579
2580 case MODIFYVM_AUDIOIN:
2581 {
2582 ComPtr<IAudioAdapter> audioAdapter;
2583 sessionMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
2584 ASSERT(audioAdapter);
2585
2586 CHECK_ERROR(audioAdapter, COMSETTER(EnabledIn)(ValueUnion.f));
2587 break;
2588 }
2589
2590 case MODIFYVM_AUDIOOUT:
2591 {
2592 ComPtr<IAudioAdapter> audioAdapter;
2593 sessionMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
2594 ASSERT(audioAdapter);
2595
2596 CHECK_ERROR(audioAdapter, COMSETTER(EnabledOut)(ValueUnion.f));
2597 break;
2598 }
2599
2600#ifdef VBOX_WITH_SHARED_CLIPBOARD
2601 case MODIFYVM_CLIPBOARD_MODE:
2602 {
2603 ClipboardMode_T mode = ClipboardMode_Disabled; /* Shut up MSC */
2604 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2605 mode = ClipboardMode_Disabled;
2606 else if (!RTStrICmp(ValueUnion.psz, "hosttoguest"))
2607 mode = ClipboardMode_HostToGuest;
2608 else if (!RTStrICmp(ValueUnion.psz, "guesttohost"))
2609 mode = ClipboardMode_GuestToHost;
2610 else if (!RTStrICmp(ValueUnion.psz, "bidirectional"))
2611 mode = ClipboardMode_Bidirectional;
2612 else
2613 {
2614 errorArgument(ModifyVM::tr("Invalid --clipboard-mode argument '%s'"), ValueUnion.psz);
2615 rc = E_FAIL;
2616 }
2617 if (SUCCEEDED(rc))
2618 {
2619 CHECK_ERROR(sessionMachine, COMSETTER(ClipboardMode)(mode));
2620 }
2621 break;
2622 }
2623
2624# ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
2625 case MODIFYVM_CLIPBOARD_FILE_TRANSFERS:
2626 {
2627 BOOL fEnabled = false; /* Shut up MSC */
2628 if (!RTStrICmp(ValueUnion.psz, "enabled"))
2629 fEnabled = true;
2630 else if (!RTStrICmp(ValueUnion.psz, "disabled"))
2631 fEnabled = false;
2632 else
2633 {
2634 errorArgument(ModifyVM::tr("Invalid --clipboard-file-transfers argument '%s'"), ValueUnion.psz);
2635 rc = E_FAIL;
2636 }
2637 if (SUCCEEDED(rc))
2638 {
2639 CHECK_ERROR(sessionMachine, COMSETTER(ClipboardFileTransfersEnabled)(fEnabled));
2640 }
2641 break;
2642 }
2643# endif /* VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS */
2644#endif /* VBOX_WITH_SHARED_CLIPBOARD */
2645
2646 case MODIFYVM_DRAGANDDROP:
2647 {
2648 DnDMode_T mode = DnDMode_Disabled; /* Shut up MSC */
2649 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2650 mode = DnDMode_Disabled;
2651 else if (!RTStrICmp(ValueUnion.psz, "hosttoguest"))
2652 mode = DnDMode_HostToGuest;
2653 else if (!RTStrICmp(ValueUnion.psz, "guesttohost"))
2654 mode = DnDMode_GuestToHost;
2655 else if (!RTStrICmp(ValueUnion.psz, "bidirectional"))
2656 mode = DnDMode_Bidirectional;
2657 else
2658 {
2659 errorArgument(ModifyVM::tr("Invalid --draganddrop argument '%s'"), ValueUnion.psz);
2660 rc = E_FAIL;
2661 }
2662 if (SUCCEEDED(rc))
2663 {
2664 CHECK_ERROR(sessionMachine, COMSETTER(DnDMode)(mode));
2665 }
2666 break;
2667 }
2668
2669 case MODIFYVM_VRDE_EXTPACK:
2670 {
2671 ComPtr<IVRDEServer> vrdeServer;
2672 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2673 ASSERT(vrdeServer);
2674
2675 if (vrdeServer)
2676 {
2677 if (RTStrICmp(ValueUnion.psz, "default") != 0)
2678 {
2679 Bstr bstr(ValueUnion.psz);
2680 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(bstr.raw()));
2681 }
2682 else
2683 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(Bstr().raw()));
2684 }
2685 break;
2686 }
2687
2688 case MODIFYVM_VRDEPROPERTY:
2689 {
2690 ComPtr<IVRDEServer> vrdeServer;
2691 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2692 ASSERT(vrdeServer);
2693
2694 if (vrdeServer)
2695 {
2696 /* Parse 'name=value' */
2697 char *pszProperty = RTStrDup(ValueUnion.psz);
2698 if (pszProperty)
2699 {
2700 char *pDelimiter = strchr(pszProperty, '=');
2701 if (pDelimiter)
2702 {
2703 *pDelimiter = '\0';
2704
2705 Bstr bstrName = pszProperty;
2706 Bstr bstrValue = &pDelimiter[1];
2707 CHECK_ERROR(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
2708 }
2709 else
2710 {
2711 RTStrFree(pszProperty);
2712
2713 errorArgument(ModifyVM::tr("Invalid --vrdeproperty argument '%s'"), ValueUnion.psz);
2714 rc = E_FAIL;
2715 break;
2716 }
2717 RTStrFree(pszProperty);
2718 }
2719 else
2720 {
2721 RTStrmPrintf(g_pStdErr, ModifyVM::tr("Error: Failed to allocate memory for VRDE property '%s'\n"),
2722 ValueUnion.psz);
2723 rc = E_FAIL;
2724 }
2725 }
2726 break;
2727 }
2728
2729 case MODIFYVM_VRDPPORT:
2730 vrdeWarningDeprecatedOption("port");
2731 RT_FALL_THRU();
2732
2733 case MODIFYVM_VRDEPORT:
2734 {
2735 ComPtr<IVRDEServer> vrdeServer;
2736 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2737 ASSERT(vrdeServer);
2738
2739 if (!RTStrICmp(ValueUnion.psz, "default"))
2740 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr("0").raw()));
2741 else
2742 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr(ValueUnion.psz).raw()));
2743 break;
2744 }
2745
2746 case MODIFYVM_VRDPADDRESS:
2747 vrdeWarningDeprecatedOption("address");
2748 RT_FALL_THRU();
2749
2750 case MODIFYVM_VRDEADDRESS:
2751 {
2752 ComPtr<IVRDEServer> vrdeServer;
2753 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2754 ASSERT(vrdeServer);
2755
2756 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Address").raw(), Bstr(ValueUnion.psz).raw()));
2757 break;
2758 }
2759
2760 case MODIFYVM_VRDPAUTHTYPE:
2761 vrdeWarningDeprecatedOption("authtype");
2762 RT_FALL_THRU();
2763 case MODIFYVM_VRDEAUTHTYPE:
2764 {
2765 ComPtr<IVRDEServer> vrdeServer;
2766 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2767 ASSERT(vrdeServer);
2768
2769 if (!RTStrICmp(ValueUnion.psz, "null"))
2770 {
2771 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Null));
2772 }
2773 else if (!RTStrICmp(ValueUnion.psz, "external"))
2774 {
2775 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_External));
2776 }
2777 else if (!RTStrICmp(ValueUnion.psz, "guest"))
2778 {
2779 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Guest));
2780 }
2781 else
2782 {
2783 errorArgument(ModifyVM::tr("Invalid --vrdeauthtype argument '%s'"), ValueUnion.psz);
2784 rc = E_FAIL;
2785 }
2786 break;
2787 }
2788
2789 case MODIFYVM_VRDEAUTHLIBRARY:
2790 {
2791 ComPtr<IVRDEServer> vrdeServer;
2792 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2793 ASSERT(vrdeServer);
2794
2795 if (vrdeServer)
2796 {
2797 if (RTStrICmp(ValueUnion.psz, "default") != 0)
2798 {
2799 Bstr bstr(ValueUnion.psz);
2800 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(bstr.raw()));
2801 }
2802 else
2803 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(Bstr().raw()));
2804 }
2805 break;
2806 }
2807
2808 case MODIFYVM_VRDPMULTICON:
2809 vrdeWarningDeprecatedOption("multicon");
2810 RT_FALL_THRU();
2811 case MODIFYVM_VRDEMULTICON:
2812 {
2813 ComPtr<IVRDEServer> vrdeServer;
2814 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2815 ASSERT(vrdeServer);
2816
2817 CHECK_ERROR(vrdeServer, COMSETTER(AllowMultiConnection)(ValueUnion.f));
2818 break;
2819 }
2820
2821 case MODIFYVM_VRDPREUSECON:
2822 vrdeWarningDeprecatedOption("reusecon");
2823 RT_FALL_THRU();
2824 case MODIFYVM_VRDEREUSECON:
2825 {
2826 ComPtr<IVRDEServer> vrdeServer;
2827 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2828 ASSERT(vrdeServer);
2829
2830 CHECK_ERROR(vrdeServer, COMSETTER(ReuseSingleConnection)(ValueUnion.f));
2831 break;
2832 }
2833
2834 case MODIFYVM_VRDPVIDEOCHANNEL:
2835 vrdeWarningDeprecatedOption("videochannel");
2836 RT_FALL_THRU();
2837 case MODIFYVM_VRDEVIDEOCHANNEL:
2838 {
2839 ComPtr<IVRDEServer> vrdeServer;
2840 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2841 ASSERT(vrdeServer);
2842
2843 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Enabled").raw(),
2844 ValueUnion.f? Bstr("true").raw(): Bstr("false").raw()));
2845 break;
2846 }
2847
2848 case MODIFYVM_VRDPVIDEOCHANNELQUALITY:
2849 vrdeWarningDeprecatedOption("videochannelquality");
2850 RT_FALL_THRU();
2851 case MODIFYVM_VRDEVIDEOCHANNELQUALITY:
2852 {
2853 ComPtr<IVRDEServer> vrdeServer;
2854 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2855 ASSERT(vrdeServer);
2856
2857 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Quality").raw(),
2858 Bstr(ValueUnion.psz).raw()));
2859 break;
2860 }
2861
2862 case MODIFYVM_VRDP:
2863 vrdeWarningDeprecatedOption("");
2864 RT_FALL_THRU();
2865 case MODIFYVM_VRDE:
2866 {
2867 ComPtr<IVRDEServer> vrdeServer;
2868 sessionMachine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2869 ASSERT(vrdeServer);
2870
2871 CHECK_ERROR(vrdeServer, COMSETTER(Enabled)(ValueUnion.f));
2872 break;
2873 }
2874
2875 case MODIFYVM_USBRENAME:
2876 {
2877 const char *pszName = ValueUnion.psz;
2878 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
2879 if (RT_FAILURE(vrc))
2880 return errorSyntax(USAGE_MODIFYVM,
2881 ModifyVM::tr("Missing or Invalid argument to '%s'"),
2882 GetOptState.pDef->pszLong);
2883 const char *pszNewName = ValueUnion.psz;
2884
2885 SafeIfaceArray<IUSBController> ctrls;
2886 CHECK_ERROR(sessionMachine, COMGETTER(USBControllers)(ComSafeArrayAsOutParam(ctrls)));
2887 bool fRenamed = false;
2888 for (size_t i = 0; i < ctrls.size(); i++)
2889 {
2890 ComPtr<IUSBController> pCtrl = ctrls[i];
2891 Bstr bstrName;
2892 CHECK_ERROR(pCtrl, COMGETTER(Name)(bstrName.asOutParam()));
2893 if (bstrName == pszName)
2894 {
2895 bstrName = pszNewName;
2896 CHECK_ERROR(pCtrl, COMSETTER(Name)(bstrName.raw()));
2897 fRenamed = true;
2898 }
2899 }
2900 if (!fRenamed)
2901 {
2902 errorArgument(ModifyVM::tr("Invalid --usbrename parameters, nothing renamed"));
2903 rc = E_FAIL;
2904 }
2905 break;
2906 }
2907
2908 case MODIFYVM_USBXHCI:
2909 {
2910 ULONG cXhciCtrls = 0;
2911 rc = sessionMachine->GetUSBControllerCountByType(USBControllerType_XHCI, &cXhciCtrls);
2912 if (SUCCEEDED(rc))
2913 {
2914 if (!cXhciCtrls && ValueUnion.f)
2915 {
2916 ComPtr<IUSBController> UsbCtl;
2917 CHECK_ERROR(sessionMachine, AddUSBController(Bstr("xHCI").raw(), USBControllerType_XHCI,
2918 UsbCtl.asOutParam()));
2919 }
2920 else if (cXhciCtrls && !ValueUnion.f)
2921 {
2922 SafeIfaceArray<IUSBController> ctrls;
2923 CHECK_ERROR(sessionMachine, COMGETTER(USBControllers)(ComSafeArrayAsOutParam(ctrls)));
2924 for (size_t i = 0; i < ctrls.size(); i++)
2925 {
2926 ComPtr<IUSBController> pCtrl = ctrls[i];
2927 USBControllerType_T enmType;
2928 CHECK_ERROR(pCtrl, COMGETTER(Type)(&enmType));
2929 if (enmType == USBControllerType_XHCI)
2930 {
2931 Bstr ctrlName;
2932 CHECK_ERROR(pCtrl, COMGETTER(Name)(ctrlName.asOutParam()));
2933 CHECK_ERROR(sessionMachine, RemoveUSBController(ctrlName.raw()));
2934 }
2935 }
2936 }
2937 }
2938 break;
2939 }
2940
2941 case MODIFYVM_USBEHCI:
2942 {
2943 ULONG cEhciCtrls = 0;
2944 rc = sessionMachine->GetUSBControllerCountByType(USBControllerType_EHCI, &cEhciCtrls);
2945 if (SUCCEEDED(rc))
2946 {
2947 if (!cEhciCtrls && ValueUnion.f)
2948 {
2949 ComPtr<IUSBController> UsbCtl;
2950 CHECK_ERROR(sessionMachine, AddUSBController(Bstr("EHCI").raw(), USBControllerType_EHCI,
2951 UsbCtl.asOutParam()));
2952 }
2953 else if (cEhciCtrls && !ValueUnion.f)
2954 {
2955 SafeIfaceArray<IUSBController> ctrls;
2956 CHECK_ERROR(sessionMachine, COMGETTER(USBControllers)(ComSafeArrayAsOutParam(ctrls)));
2957 for (size_t i = 0; i < ctrls.size(); i++)
2958 {
2959 ComPtr<IUSBController> pCtrl = ctrls[i];
2960 USBControllerType_T enmType;
2961 CHECK_ERROR(pCtrl, COMGETTER(Type)(&enmType));
2962 if (enmType == USBControllerType_EHCI)
2963 {
2964 Bstr ctrlName;
2965 CHECK_ERROR(pCtrl, COMGETTER(Name)(ctrlName.asOutParam()));
2966 CHECK_ERROR(sessionMachine, RemoveUSBController(ctrlName.raw()));
2967 }
2968 }
2969 }
2970 }
2971 break;
2972 }
2973
2974 case MODIFYVM_USBOHCI:
2975 {
2976 ULONG cOhciCtrls = 0;
2977 rc = sessionMachine->GetUSBControllerCountByType(USBControllerType_OHCI, &cOhciCtrls);
2978 if (SUCCEEDED(rc))
2979 {
2980 if (!cOhciCtrls && ValueUnion.f)
2981 {
2982 ComPtr<IUSBController> UsbCtl;
2983 CHECK_ERROR(sessionMachine, AddUSBController(Bstr("OHCI").raw(), USBControllerType_OHCI,
2984 UsbCtl.asOutParam()));
2985 }
2986 else if (cOhciCtrls && !ValueUnion.f)
2987 {
2988 SafeIfaceArray<IUSBController> ctrls;
2989 CHECK_ERROR(sessionMachine, COMGETTER(USBControllers)(ComSafeArrayAsOutParam(ctrls)));
2990 for (size_t i = 0; i < ctrls.size(); i++)
2991 {
2992 ComPtr<IUSBController> pCtrl = ctrls[i];
2993 USBControllerType_T enmType;
2994 CHECK_ERROR(pCtrl, COMGETTER(Type)(&enmType));
2995 if (enmType == USBControllerType_OHCI)
2996 {
2997 Bstr ctrlName;
2998 CHECK_ERROR(pCtrl, COMGETTER(Name)(ctrlName.asOutParam()));
2999 CHECK_ERROR(sessionMachine, RemoveUSBController(ctrlName.raw()));
3000 }
3001 }
3002 }
3003 }
3004 break;
3005 }
3006
3007 case MODIFYVM_SNAPSHOTFOLDER:
3008 {
3009 if (!RTStrICmp(ValueUnion.psz, "default"))
3010 CHECK_ERROR(sessionMachine, COMSETTER(SnapshotFolder)(Bstr().raw()));
3011 else
3012 CHECK_ERROR(sessionMachine, COMSETTER(SnapshotFolder)(Bstr(ValueUnion.psz).raw()));
3013 break;
3014 }
3015
3016 case MODIFYVM_TELEPORTER_ENABLED:
3017 {
3018 CHECK_ERROR(sessionMachine, COMSETTER(TeleporterEnabled)(ValueUnion.f));
3019 break;
3020 }
3021
3022 case MODIFYVM_TELEPORTER_PORT:
3023 {
3024 CHECK_ERROR(sessionMachine, COMSETTER(TeleporterPort)(ValueUnion.u32));
3025 break;
3026 }
3027
3028 case MODIFYVM_TELEPORTER_ADDRESS:
3029 {
3030 CHECK_ERROR(sessionMachine, COMSETTER(TeleporterAddress)(Bstr(ValueUnion.psz).raw()));
3031 break;
3032 }
3033
3034 case MODIFYVM_TELEPORTER_PASSWORD:
3035 {
3036 CHECK_ERROR(sessionMachine, COMSETTER(TeleporterPassword)(Bstr(ValueUnion.psz).raw()));
3037 break;
3038 }
3039
3040 case MODIFYVM_TELEPORTER_PASSWORD_FILE:
3041 {
3042 Utf8Str password;
3043 RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &password);
3044 if (rcExit != RTEXITCODE_SUCCESS)
3045 rc = E_FAIL;
3046 else
3047 CHECK_ERROR(sessionMachine, COMSETTER(TeleporterPassword)(Bstr(password).raw()));
3048 break;
3049 }
3050
3051 case MODIFYVM_TRACING_ENABLED:
3052 {
3053 CHECK_ERROR(sessionMachine, COMSETTER(TracingEnabled)(ValueUnion.f));
3054 break;
3055 }
3056
3057 case MODIFYVM_TRACING_CONFIG:
3058 {
3059 CHECK_ERROR(sessionMachine, COMSETTER(TracingConfig)(Bstr(ValueUnion.psz).raw()));
3060 break;
3061 }
3062
3063 case MODIFYVM_TRACING_ALLOW_VM_ACCESS:
3064 {
3065 CHECK_ERROR(sessionMachine, COMSETTER(AllowTracingToAccessVM)(ValueUnion.f));
3066 break;
3067 }
3068
3069 case MODIFYVM_HARDWARE_UUID:
3070 {
3071 CHECK_ERROR(sessionMachine, COMSETTER(HardwareUUID)(Bstr(ValueUnion.psz).raw()));
3072 break;
3073 }
3074
3075 case MODIFYVM_HPET:
3076 {
3077 CHECK_ERROR(sessionMachine, COMSETTER(HPETEnabled)(ValueUnion.f));
3078 break;
3079 }
3080
3081 case MODIFYVM_IOCACHE:
3082 {
3083 CHECK_ERROR(sessionMachine, COMSETTER(IOCacheEnabled)(ValueUnion.f));
3084 break;
3085 }
3086
3087 case MODIFYVM_IOCACHESIZE:
3088 {
3089 CHECK_ERROR(sessionMachine, COMSETTER(IOCacheSize)(ValueUnion.u32));
3090 break;
3091 }
3092
3093 case MODIFYVM_CHIPSET:
3094 {
3095 if (!RTStrICmp(ValueUnion.psz, "piix3"))
3096 {
3097 CHECK_ERROR(sessionMachine, COMSETTER(ChipsetType)(ChipsetType_PIIX3));
3098 }
3099 else if (!RTStrICmp(ValueUnion.psz, "ich9"))
3100 {
3101 CHECK_ERROR(sessionMachine, COMSETTER(ChipsetType)(ChipsetType_ICH9));
3102 BOOL fIoApic = FALSE;
3103 CHECK_ERROR(biosSettings, COMGETTER(IOAPICEnabled)(&fIoApic));
3104 if (!fIoApic)
3105 {
3106 RTStrmPrintf(g_pStdErr, ModifyVM::tr("*** I/O APIC must be enabled for ICH9, enabling. ***\n"));
3107 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(TRUE));
3108 }
3109 }
3110 else
3111 {
3112 errorArgument(ModifyVM::tr("Invalid --chipset argument '%s' (valid: piix3,ich9)"), ValueUnion.psz);
3113 rc = E_FAIL;
3114 }
3115 break;
3116 }
3117#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
3118 case MODIFYVM_IOMMU:
3119 {
3120 if ( !RTStrICmp(ValueUnion.psz, "none")
3121 || !RTStrICmp(ValueUnion.psz, "disabled"))
3122 CHECK_ERROR(sessionMachine, COMSETTER(IommuType)(IommuType_None));
3123 else if (!RTStrICmp(ValueUnion.psz, "amd"))
3124 CHECK_ERROR(sessionMachine, COMSETTER(IommuType)(IommuType_AMD));
3125 else if (!RTStrICmp(ValueUnion.psz, "intel"))
3126 {
3127#ifdef VBOX_WITH_IOMMU_INTEL
3128 CHECK_ERROR(sessionMachine, COMSETTER(IommuType)(IommuType_Intel));
3129#else
3130 errorArgument(ModifyVM::tr("Invalid --iommu argument '%s' (valid: none,amd,automatic)"), ValueUnion.psz);
3131 rc = E_FAIL;
3132#endif
3133 }
3134 else if (!RTStrICmp(ValueUnion.psz, "automatic"))
3135 {
3136 CHECK_ERROR(sessionMachine, COMSETTER(IommuType)(IommuType_Automatic));
3137#ifndef VBOX_WITH_IOMMU_INTEL
3138 RTStrmPrintf(g_pStdErr,
3139 ModifyVM::tr("Warning: On Intel hosts, 'automatic' will not enable an IOMMU since the Intel IOMMU device is not supported yet.\n"));
3140#endif
3141 }
3142 else
3143 {
3144 errorArgument(ModifyVM::tr("Invalid --iommu argument '%s'"), ValueUnion.psz);
3145 rc = E_FAIL;
3146 }
3147 break;
3148 }
3149#endif
3150#if defined(VBOX_WITH_TPM)
3151 case MODIFYVM_TPM_TYPE:
3152 {
3153 ComPtr<ITrustedPlatformModule> tpm;
3154 sessionMachine->COMGETTER(TrustedPlatformModule)(tpm.asOutParam());
3155
3156 if ( !RTStrICmp(ValueUnion.psz, "none")
3157 || !RTStrICmp(ValueUnion.psz, "disabled"))
3158 CHECK_ERROR(tpm, COMSETTER(Type)(TpmType_None));
3159 else if (!RTStrICmp(ValueUnion.psz, "1.2"))
3160 CHECK_ERROR(tpm, COMSETTER(Type)(TpmType_v1_2));
3161 else if (!RTStrICmp(ValueUnion.psz, "2.0"))
3162 CHECK_ERROR(tpm, COMSETTER(Type)(TpmType_v2_0));
3163 else if (!RTStrICmp(ValueUnion.psz, "host"))
3164 CHECK_ERROR(tpm, COMSETTER(Type)(TpmType_Host));
3165 else if (!RTStrICmp(ValueUnion.psz, "swtpm"))
3166 CHECK_ERROR(tpm, COMSETTER(Type)(TpmType_Swtpm));
3167 else
3168 {
3169 errorArgument(ModifyVM::tr("Invalid --tpm-type argument '%s'"), ValueUnion.psz);
3170 rc = E_FAIL;
3171 }
3172 break;
3173 }
3174
3175 case MODIFYVM_TPM_LOCATION:
3176 {
3177 ComPtr<ITrustedPlatformModule> tpm;
3178 sessionMachine->COMGETTER(TrustedPlatformModule)(tpm.asOutParam());
3179
3180 CHECK_ERROR(tpm, COMSETTER(Location)(Bstr(ValueUnion.psz).raw()));
3181 break;
3182 }
3183#endif
3184#ifdef VBOX_WITH_RECORDING
3185 case MODIFYVM_RECORDING:
3186 RT_FALL_THROUGH();
3187 case MODIFYVM_RECORDING_SCREENS:
3188 RT_FALL_THROUGH();
3189 case MODIFYVM_RECORDING_FILENAME:
3190 RT_FALL_THROUGH();
3191 case MODIFYVM_RECORDING_VIDEO_WIDTH:
3192 RT_FALL_THROUGH();
3193 case MODIFYVM_RECORDING_VIDEO_HEIGHT:
3194 RT_FALL_THROUGH();
3195 case MODIFYVM_RECORDING_VIDEO_RES:
3196 RT_FALL_THROUGH();
3197 case MODIFYVM_RECORDING_VIDEO_RATE:
3198 RT_FALL_THROUGH();
3199 case MODIFYVM_RECORDING_VIDEO_FPS:
3200 RT_FALL_THROUGH();
3201 case MODIFYVM_RECORDING_MAXTIME:
3202 RT_FALL_THROUGH();
3203 case MODIFYVM_RECORDING_MAXSIZE:
3204 RT_FALL_THROUGH();
3205 case MODIFYVM_RECORDING_OPTIONS:
3206 {
3207 ComPtr<IRecordingSettings> recordingSettings;
3208 CHECK_ERROR_BREAK(sessionMachine, COMGETTER(RecordingSettings)(recordingSettings.asOutParam()));
3209 SafeIfaceArray <IRecordingScreenSettings> saRecordingScreenScreens;
3210 CHECK_ERROR_BREAK(recordingSettings, COMGETTER(Screens)(ComSafeArrayAsOutParam(saRecordingScreenScreens)));
3211
3212 switch (c)
3213 {
3214 case MODIFYVM_RECORDING:
3215 {
3216 CHECK_ERROR(recordingSettings, COMSETTER(Enabled)(ValueUnion.f));
3217 break;
3218 }
3219 case MODIFYVM_RECORDING_SCREENS:
3220 {
3221 ULONG cMonitors = 64;
3222 CHECK_ERROR(pGraphicsAdapter, COMGETTER(MonitorCount)(&cMonitors));
3223 com::SafeArray<BOOL> screens(cMonitors);
3224 if (parseScreens(ValueUnion.psz, &screens))
3225 {
3226 errorArgument(ModifyVM::tr("Invalid list of screens specified\n"));
3227 rc = E_FAIL;
3228 break;
3229 }
3230
3231 if (cMonitors > saRecordingScreenScreens.size()) /* Paranoia. */
3232 cMonitors = (ULONG)saRecordingScreenScreens.size();
3233
3234 for (size_t i = 0; i < cMonitors; ++i)
3235 CHECK_ERROR_BREAK(saRecordingScreenScreens[i], COMSETTER(Enabled)(screens[i]));
3236 break;
3237 }
3238 case MODIFYVM_RECORDING_FILENAME:
3239 {
3240 Bstr bstr;
3241 /* empty string will fall through, leaving bstr empty */
3242 if (*ValueUnion.psz)
3243 {
3244 char szVCFileAbs[RTPATH_MAX] = "";
3245 int vrc = RTPathAbs(ValueUnion.psz, szVCFileAbs, sizeof(szVCFileAbs));
3246 if (RT_FAILURE(vrc))
3247 {
3248 errorArgument(ModifyVM::tr("Cannot convert filename \"%s\" to absolute path\n"), ValueUnion.psz);
3249 rc = E_FAIL;
3250 break;
3251 }
3252 bstr = szVCFileAbs;
3253 }
3254
3255 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3256 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(Filename)(bstr.raw()));
3257 break;
3258 }
3259 case MODIFYVM_RECORDING_VIDEO_WIDTH:
3260 {
3261 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3262 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(VideoWidth)(ValueUnion.u32));
3263 break;
3264 }
3265 case MODIFYVM_RECORDING_VIDEO_HEIGHT:
3266 {
3267 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3268 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(VideoHeight)(ValueUnion.u32));
3269 break;
3270 }
3271 case MODIFYVM_RECORDING_VIDEO_RES:
3272 {
3273 uint32_t uWidth = 0;
3274 char *pszNext;
3275 int vrc = RTStrToUInt32Ex(ValueUnion.psz, &pszNext, 0, &uWidth);
3276 if (RT_FAILURE(vrc) || vrc != VWRN_TRAILING_CHARS || !pszNext || *pszNext != 'x')
3277 {
3278 errorArgument(ModifyVM::tr("Error parsing video resolution '%s' (expected <width>x<height>)"),
3279 ValueUnion.psz);
3280 rc = E_FAIL;
3281 break;
3282 }
3283 uint32_t uHeight = 0;
3284 vrc = RTStrToUInt32Ex(pszNext+1, NULL, 0, &uHeight);
3285 if (vrc != VINF_SUCCESS)
3286 {
3287 errorArgument(ModifyVM::tr("Error parsing video resolution '%s' (expected <width>x<height>)"),
3288 ValueUnion.psz);
3289 rc = E_FAIL;
3290 break;
3291 }
3292
3293 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3294 {
3295 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(VideoWidth)(uWidth));
3296 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(VideoHeight)(uHeight));
3297 }
3298 break;
3299 }
3300 case MODIFYVM_RECORDING_VIDEO_RATE:
3301 {
3302 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3303 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(VideoRate)(ValueUnion.u32));
3304 break;
3305 }
3306 case MODIFYVM_RECORDING_VIDEO_FPS:
3307 {
3308 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3309 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(VideoFPS)(ValueUnion.u32));
3310 break;
3311 }
3312 case MODIFYVM_RECORDING_MAXTIME:
3313 {
3314 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3315 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(MaxTime)(ValueUnion.u32));
3316 break;
3317 }
3318 case MODIFYVM_RECORDING_MAXSIZE:
3319 {
3320 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3321 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(MaxFileSize)(ValueUnion.u32));
3322 break;
3323 }
3324 case MODIFYVM_RECORDING_OPTIONS:
3325 {
3326 Bstr bstr(ValueUnion.psz);
3327 for (size_t i = 0; i < saRecordingScreenScreens.size(); ++i)
3328 CHECK_ERROR(saRecordingScreenScreens[i], COMSETTER(Options)(bstr.raw()));
3329 break;
3330 }
3331 }
3332
3333 break;
3334 }
3335#endif
3336 case MODIFYVM_AUTOSTART_ENABLED:
3337 {
3338 CHECK_ERROR(sessionMachine, COMSETTER(AutostartEnabled)(ValueUnion.f));
3339 break;
3340 }
3341
3342 case MODIFYVM_AUTOSTART_DELAY:
3343 {
3344 CHECK_ERROR(sessionMachine, COMSETTER(AutostartDelay)(ValueUnion.u32));
3345 break;
3346 }
3347
3348 case MODIFYVM_AUTOSTOP_TYPE:
3349 {
3350 AutostopType_T enmAutostopType = AutostopType_Disabled;
3351
3352 if (!RTStrICmp(ValueUnion.psz, "disabled"))
3353 enmAutostopType = AutostopType_Disabled;
3354 else if (!RTStrICmp(ValueUnion.psz, "savestate"))
3355 enmAutostopType = AutostopType_SaveState;
3356 else if (!RTStrICmp(ValueUnion.psz, "poweroff"))
3357 enmAutostopType = AutostopType_PowerOff;
3358 else if (!RTStrICmp(ValueUnion.psz, "acpishutdown"))
3359 enmAutostopType = AutostopType_AcpiShutdown;
3360 else
3361 {
3362 errorArgument(ModifyVM::tr("Invalid --autostop-type argument '%s' (valid: disabled, savestate, poweroff, acpishutdown)"),
3363 ValueUnion.psz);
3364 rc = E_FAIL;
3365 }
3366
3367 if (SUCCEEDED(rc))
3368 CHECK_ERROR(sessionMachine, COMSETTER(AutostopType)(enmAutostopType));
3369 break;
3370 }
3371#ifdef VBOX_WITH_PCI_PASSTHROUGH
3372 case MODIFYVM_ATTACH_PCI:
3373 {
3374 const char* pAt = strchr(ValueUnion.psz, '@');
3375 int32_t iHostAddr, iGuestAddr;
3376
3377 iHostAddr = parsePci(ValueUnion.psz);
3378 iGuestAddr = pAt != NULL ? parsePci(pAt + 1) : iHostAddr;
3379
3380 if (iHostAddr == -1 || iGuestAddr == -1)
3381 {
3382 errorArgument(ModifyVM::tr("Invalid --pciattach argument '%s' (valid: 'HB:HD.HF@GB:GD.GF' or just 'HB:HD.HF')"),
3383 ValueUnion.psz);
3384 rc = E_FAIL;
3385 }
3386 else
3387 {
3388 CHECK_ERROR(sessionMachine, AttachHostPCIDevice(iHostAddr, iGuestAddr, TRUE));
3389 }
3390
3391 break;
3392 }
3393 case MODIFYVM_DETACH_PCI:
3394 {
3395 int32_t iHostAddr;
3396
3397 iHostAddr = parsePci(ValueUnion.psz);
3398 if (iHostAddr == -1)
3399 {
3400 errorArgument(ModifyVM::tr("Invalid --pcidetach argument '%s' (valid: 'HB:HD.HF')"), ValueUnion.psz);
3401 rc = E_FAIL;
3402 }
3403 else
3404 {
3405 CHECK_ERROR(sessionMachine, DetachHostPCIDevice(iHostAddr));
3406 }
3407
3408 break;
3409 }
3410#endif
3411
3412#ifdef VBOX_WITH_USB_CARDREADER
3413 case MODIFYVM_USBCARDREADER:
3414 {
3415 CHECK_ERROR(sessionMachine, COMSETTER(EmulatedUSBCardReaderEnabled)(ValueUnion.f));
3416 break;
3417 }
3418#endif /* VBOX_WITH_USB_CARDREADER */
3419
3420 case MODIFYVM_DEFAULTFRONTEND:
3421 {
3422 Bstr bstr(ValueUnion.psz);
3423 if (bstr == "default")
3424 bstr = Bstr::Empty;
3425 CHECK_ERROR(sessionMachine, COMSETTER(DefaultFrontend)(bstr.raw()));
3426 break;
3427 }
3428
3429 case MODIFYVM_VMPROC_PRIORITY:
3430 {
3431 VMProcPriority_T enmPriority = nameToVMProcPriority(ValueUnion.psz);
3432 if (enmPriority == VMProcPriority_Invalid)
3433 {
3434 errorArgument(ModifyVM::tr("Invalid --vm-process-priority '%s'"), ValueUnion.psz);
3435 rc = E_FAIL;
3436 }
3437 else
3438 {
3439 CHECK_ERROR(sessionMachine, COMSETTER(VMProcessPriority)(enmPriority));
3440 }
3441 break;
3442 }
3443
3444 case MODIFYVM_TESTING_ENABLED:
3445 rc = setExtraData(sessionMachine, "VBoxInternal/Devices/VMMDev/0/Config/TestingEnabled", ValueUnion.f ? "1" : "");
3446 break;
3447
3448 case MODIFYVM_TESTING_MMIO:
3449 rc = setExtraData(sessionMachine, "VBoxInternal/Devices/VMMDev/0/Config/TestingMMIO", ValueUnion.f ? "1" : "");
3450 break;
3451
3452 case MODIFYVM_TESTING_CFG_DWORD:
3453 if (GetOptState.uIndex <= 9)
3454 {
3455 char szVar[128];
3456 RTStrPrintf(szVar, sizeof(szVar), "VBoxInternal/Devices/VMMDev/0/Config/TestingCfgDword%u",
3457 GetOptState.uIndex);
3458 char szValue[32];
3459 RTStrPrintf(szValue, sizeof(szValue), "%u", ValueUnion.u32);
3460 rc = setExtraData(sessionMachine, szVar, szValue);
3461 }
3462 else
3463 rc = errorArgumentHr(ModifyVM::tr("--testing-cfg-dword index %u is out of range: 0 thru 9"),
3464 GetOptState.uIndex);
3465 break;
3466
3467 default:
3468 errorGetOpt(USAGE_MODIFYVM, c, &ValueUnion);
3469 rc = E_FAIL;
3470 break;
3471 }
3472 }
3473
3474 /* commit changes */
3475 if (SUCCEEDED(rc))
3476 CHECK_ERROR(sessionMachine, SaveSettings());
3477
3478 /* it's important to always close sessions */
3479 a->session->UnlockMachine();
3480
3481 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
3482}
3483
3484#endif /* !VBOX_ONLY_DOCS */
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