VirtualBox

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

Last change on this file since 86671 was 85769, checked in by vboxsync, 4 years ago

Main: bugref:9618 Added Main/API support for AMD-V Virtualized VMSAVE/VMLOAD hardware virtualization feature.

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