VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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