VirtualBox

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

Last change on this file since 79611 was 78632, checked in by vboxsync, 6 years ago

Forward ported 130474,130475,130477,130479. bugref:9453

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