VirtualBox

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

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

virtio-net works on linux in local testing, and virtio-scsi works on windows. Integrating the switchover to make DevVirtioNet_1_0.cpp the 'virtio-net' option in the Virtual Network Controller list.

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

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