VirtualBox

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

Last change on this file since 82979 was 82979, checked in by vboxsync, 5 years ago

VBoxManage: keep old --clipboard option which was superseded by --clipboard-mode in 6.1

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