VirtualBox

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

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

AMD IOMMU: bugref:9654 Main/API: AMD IOMMU support.

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