VirtualBox

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

Last change on this file since 45926 was 45926, checked in by vboxsync, 12 years ago

IMachine::VideoCaptureFps

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 104.0 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 45926 2013-05-06 20:26:43Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of modifyvm command.
4 */
5
6/*
7 * Copyright (C) 2006-2013 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* Header Files *
20*******************************************************************************/
21#ifndef VBOX_ONLY_DOCS
22#include <VBox/com/com.h>
23#include <VBox/com/array.h>
24#include <VBox/com/ErrorInfo.h>
25#include <VBox/com/errorprint.h>
26#include <VBox/com/EventQueue.h>
27
28#include <VBox/com/VirtualBox.h>
29#endif /* !VBOX_ONLY_DOCS */
30
31#include <iprt/cidr.h>
32#include <iprt/ctype.h>
33#include <iprt/file.h>
34#include <iprt/param.h>
35#include <iprt/path.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38#include <iprt/getopt.h>
39#include <VBox/log.h>
40#include "VBoxManage.h"
41
42#ifndef VBOX_ONLY_DOCS
43using namespace com;
44/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
45#if defined(_MSC_VER)
46# pragma optimize("g", off)
47#endif
48
49enum
50{
51 MODIFYVM_NAME = 1000,
52 MODIFYVM_GROUPS,
53 MODIFYVM_OSTYPE,
54 MODIFYVM_MEMORY,
55 MODIFYVM_PAGEFUSION,
56 MODIFYVM_VRAM,
57 MODIFYVM_FIRMWARE,
58 MODIFYVM_ACPI,
59 MODIFYVM_IOAPIC,
60 MODIFYVM_PAE,
61 MODIFYVM_SYNTHCPU,
62 MODIFYVM_HWVIRTEX,
63 MODIFYVM_HWVIRTEXEXCLUSIVE,
64 MODIFYVM_NESTEDPAGING,
65 MODIFYVM_LARGEPAGES,
66 MODIFYVM_VTXVPID,
67 MODIFYVM_CPUS,
68 MODIFYVM_CPUHOTPLUG,
69 MODIFYVM_PLUGCPU,
70 MODIFYVM_UNPLUGCPU,
71 MODIFYVM_SETCPUID,
72 MODIFYVM_DELCPUID,
73 MODIFYVM_DELALLCPUID,
74 MODIFYVM_GRAPHICSCONTROLLER,
75 MODIFYVM_MONITORCOUNT,
76 MODIFYVM_ACCELERATE3D,
77#ifdef VBOX_WITH_VIDEOHWACCEL
78 MODIFYVM_ACCELERATE2DVIDEO,
79#endif
80 MODIFYVM_BIOSLOGOFADEIN,
81 MODIFYVM_BIOSLOGOFADEOUT,
82 MODIFYVM_BIOSLOGODISPLAYTIME,
83 MODIFYVM_BIOSLOGOIMAGEPATH,
84 MODIFYVM_BIOSBOOTMENU,
85 MODIFYVM_BIOSSYSTEMTIMEOFFSET,
86 MODIFYVM_BIOSPXEDEBUG,
87 MODIFYVM_BOOT,
88 MODIFYVM_HDA, // deprecated
89 MODIFYVM_HDB, // deprecated
90 MODIFYVM_HDD, // deprecated
91 MODIFYVM_IDECONTROLLER, // deprecated
92 MODIFYVM_SATAPORTCOUNT, // deprecated
93 MODIFYVM_SATAPORT, // deprecated
94 MODIFYVM_SATA, // deprecated
95 MODIFYVM_SCSIPORT, // deprecated
96 MODIFYVM_SCSITYPE, // deprecated
97 MODIFYVM_SCSI, // deprecated
98 MODIFYVM_DVDPASSTHROUGH, // deprecated
99 MODIFYVM_DVD, // deprecated
100 MODIFYVM_FLOPPY, // deprecated
101 MODIFYVM_NICTRACEFILE,
102 MODIFYVM_NICTRACE,
103 MODIFYVM_NICPROPERTY,
104 MODIFYVM_NICTYPE,
105 MODIFYVM_NICSPEED,
106 MODIFYVM_NICBOOTPRIO,
107 MODIFYVM_NICPROMISC,
108 MODIFYVM_NICBWGROUP,
109 MODIFYVM_NIC,
110 MODIFYVM_CABLECONNECTED,
111 MODIFYVM_BRIDGEADAPTER,
112 MODIFYVM_HOSTONLYADAPTER,
113 MODIFYVM_INTNET,
114 MODIFYVM_NATNET,
115 MODIFYVM_GENERICDRV,
116 MODIFYVM_NATBINDIP,
117 MODIFYVM_NATSETTINGS,
118 MODIFYVM_NATPF,
119 MODIFYVM_NATALIASMODE,
120 MODIFYVM_NATTFTPPREFIX,
121 MODIFYVM_NATTFTPFILE,
122 MODIFYVM_NATTFTPSERVER,
123 MODIFYVM_NATDNSPASSDOMAIN,
124 MODIFYVM_NATDNSPROXY,
125 MODIFYVM_NATDNSHOSTRESOLVER,
126 MODIFYVM_MACADDRESS,
127 MODIFYVM_HIDPTR,
128 MODIFYVM_HIDKBD,
129 MODIFYVM_UARTMODE,
130 MODIFYVM_UART,
131#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
132 MODIFYVM_LPTMODE,
133 MODIFYVM_LPT,
134#endif
135 MODIFYVM_GUESTMEMORYBALLOON,
136 MODIFYVM_AUDIOCONTROLLER,
137 MODIFYVM_AUDIO,
138 MODIFYVM_CLIPBOARD,
139 MODIFYVM_DRAGANDDROP,
140 MODIFYVM_VRDPPORT, /* VRDE: deprecated */
141 MODIFYVM_VRDPADDRESS, /* VRDE: deprecated */
142 MODIFYVM_VRDPAUTHTYPE, /* VRDE: deprecated */
143 MODIFYVM_VRDPMULTICON, /* VRDE: deprecated */
144 MODIFYVM_VRDPREUSECON, /* VRDE: deprecated */
145 MODIFYVM_VRDPVIDEOCHANNEL, /* VRDE: deprecated */
146 MODIFYVM_VRDPVIDEOCHANNELQUALITY, /* VRDE: deprecated */
147 MODIFYVM_VRDP, /* VRDE: deprecated */
148 MODIFYVM_VRDEPROPERTY,
149 MODIFYVM_VRDEPORT,
150 MODIFYVM_VRDEADDRESS,
151 MODIFYVM_VRDEAUTHTYPE,
152 MODIFYVM_VRDEAUTHLIBRARY,
153 MODIFYVM_VRDEMULTICON,
154 MODIFYVM_VRDEREUSECON,
155 MODIFYVM_VRDEVIDEOCHANNEL,
156 MODIFYVM_VRDEVIDEOCHANNELQUALITY,
157 MODIFYVM_VRDE_EXTPACK,
158 MODIFYVM_VRDE,
159 MODIFYVM_RTCUSEUTC,
160 MODIFYVM_USBEHCI,
161 MODIFYVM_USB,
162 MODIFYVM_SNAPSHOTFOLDER,
163 MODIFYVM_TELEPORTER_ENABLED,
164 MODIFYVM_TELEPORTER_PORT,
165 MODIFYVM_TELEPORTER_ADDRESS,
166 MODIFYVM_TELEPORTER_PASSWORD,
167 MODIFYVM_TELEPORTER_PASSWORD_FILE,
168 MODIFYVM_TRACING_ENABLED,
169 MODIFYVM_TRACING_CONFIG,
170 MODIFYVM_TRACING_ALLOW_VM_ACCESS,
171 MODIFYVM_HARDWARE_UUID,
172 MODIFYVM_HPET,
173 MODIFYVM_IOCACHE,
174 MODIFYVM_IOCACHESIZE,
175 MODIFYVM_FAULT_TOLERANCE,
176 MODIFYVM_FAULT_TOLERANCE_ADDRESS,
177 MODIFYVM_FAULT_TOLERANCE_PORT,
178 MODIFYVM_FAULT_TOLERANCE_PASSWORD,
179 MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL,
180 MODIFYVM_CPU_EXECTUION_CAP,
181 MODIFYVM_AUTOSTART_ENABLED,
182 MODIFYVM_AUTOSTART_DELAY,
183 MODIFYVM_AUTOSTOP_TYPE,
184#ifdef VBOX_WITH_PCI_PASSTHROUGH
185 MODIFYVM_ATTACH_PCI,
186 MODIFYVM_DETACH_PCI,
187#endif
188#ifdef VBOX_WITH_USB_VIDEO
189 MODIFYVM_USBWEBCAM,
190#endif
191#ifdef VBOX_WITH_USB_CARDREADER
192 MODIFYVM_USBCARDREADER,
193#endif
194#ifdef VBOX_WITH_VPX
195 MODIFYVM_VCP,
196 MODIFYVM_VCP_FILENAME,
197 MODIFYVM_VCP_WIDTH,
198 MODIFYVM_VCP_HEIGHT,
199 MODIFYVM_VCP_RATE,
200 MODIFYVM_VCP_FPS,
201#endif
202 MODIFYVM_CHIPSET,
203 MODIFYVM_DEFAULTFRONTEND
204};
205
206static const RTGETOPTDEF g_aModifyVMOptions[] =
207{
208 { "--name", MODIFYVM_NAME, RTGETOPT_REQ_STRING },
209 { "--groups", MODIFYVM_GROUPS, RTGETOPT_REQ_STRING },
210 { "--ostype", MODIFYVM_OSTYPE, RTGETOPT_REQ_STRING },
211 { "--memory", MODIFYVM_MEMORY, RTGETOPT_REQ_UINT32 },
212 { "--pagefusion", MODIFYVM_PAGEFUSION, RTGETOPT_REQ_BOOL_ONOFF },
213 { "--vram", MODIFYVM_VRAM, RTGETOPT_REQ_UINT32 },
214 { "--firmware", MODIFYVM_FIRMWARE, RTGETOPT_REQ_STRING },
215 { "--acpi", MODIFYVM_ACPI, RTGETOPT_REQ_BOOL_ONOFF },
216 { "--ioapic", MODIFYVM_IOAPIC, RTGETOPT_REQ_BOOL_ONOFF },
217 { "--pae", MODIFYVM_PAE, RTGETOPT_REQ_BOOL_ONOFF },
218 { "--synthcpu", MODIFYVM_SYNTHCPU, RTGETOPT_REQ_BOOL_ONOFF },
219 { "--hwvirtex", MODIFYVM_HWVIRTEX, RTGETOPT_REQ_BOOL_ONOFF },
220 { "--hwvirtexexcl", MODIFYVM_HWVIRTEXEXCLUSIVE, RTGETOPT_REQ_BOOL_ONOFF },
221 { "--nestedpaging", MODIFYVM_NESTEDPAGING, RTGETOPT_REQ_BOOL_ONOFF },
222 { "--largepages", MODIFYVM_LARGEPAGES, RTGETOPT_REQ_BOOL_ONOFF },
223 { "--vtxvpid", MODIFYVM_VTXVPID, RTGETOPT_REQ_BOOL_ONOFF },
224 { "--cpuidset", MODIFYVM_SETCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
225 { "--cpuidremove", MODIFYVM_DELCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
226 { "--cpuidremoveall", MODIFYVM_DELALLCPUID, RTGETOPT_REQ_NOTHING},
227 { "--cpus", MODIFYVM_CPUS, RTGETOPT_REQ_UINT32 },
228 { "--cpuhotplug", MODIFYVM_CPUHOTPLUG, RTGETOPT_REQ_BOOL_ONOFF },
229 { "--plugcpu", MODIFYVM_PLUGCPU, RTGETOPT_REQ_UINT32 },
230 { "--unplugcpu", MODIFYVM_UNPLUGCPU, RTGETOPT_REQ_UINT32 },
231 { "--cpuexecutioncap", MODIFYVM_CPU_EXECTUION_CAP, RTGETOPT_REQ_UINT32 },
232 { "--rtcuseutc", MODIFYVM_RTCUSEUTC, RTGETOPT_REQ_BOOL_ONOFF },
233 { "--graphicscontroller", MODIFYVM_GRAPHICSCONTROLLER, RTGETOPT_REQ_STRING },
234 { "--monitorcount", MODIFYVM_MONITORCOUNT, RTGETOPT_REQ_UINT32 },
235 { "--accelerate3d", MODIFYVM_ACCELERATE3D, RTGETOPT_REQ_BOOL_ONOFF },
236#ifdef VBOX_WITH_VIDEOHWACCEL
237 { "--accelerate2dvideo", MODIFYVM_ACCELERATE2DVIDEO, RTGETOPT_REQ_BOOL_ONOFF },
238#endif
239 { "--bioslogofadein", MODIFYVM_BIOSLOGOFADEIN, RTGETOPT_REQ_BOOL_ONOFF },
240 { "--bioslogofadeout", MODIFYVM_BIOSLOGOFADEOUT, RTGETOPT_REQ_BOOL_ONOFF },
241 { "--bioslogodisplaytime", MODIFYVM_BIOSLOGODISPLAYTIME, RTGETOPT_REQ_UINT32 },
242 { "--bioslogoimagepath", MODIFYVM_BIOSLOGOIMAGEPATH, RTGETOPT_REQ_STRING },
243 { "--biosbootmenu", MODIFYVM_BIOSBOOTMENU, RTGETOPT_REQ_STRING },
244 { "--biossystemtimeoffset", MODIFYVM_BIOSSYSTEMTIMEOFFSET, RTGETOPT_REQ_INT64 },
245 { "--biospxedebug", MODIFYVM_BIOSPXEDEBUG, RTGETOPT_REQ_BOOL_ONOFF },
246 { "--boot", MODIFYVM_BOOT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
247 { "--hda", MODIFYVM_HDA, RTGETOPT_REQ_STRING },
248 { "--hdb", MODIFYVM_HDB, RTGETOPT_REQ_STRING },
249 { "--hdd", MODIFYVM_HDD, RTGETOPT_REQ_STRING },
250 { "--idecontroller", MODIFYVM_IDECONTROLLER, RTGETOPT_REQ_STRING },
251 { "--sataportcount", MODIFYVM_SATAPORTCOUNT, RTGETOPT_REQ_UINT32 },
252 { "--sataport", MODIFYVM_SATAPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
253 { "--sata", MODIFYVM_SATA, RTGETOPT_REQ_STRING },
254 { "--scsiport", MODIFYVM_SCSIPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
255 { "--scsitype", MODIFYVM_SCSITYPE, RTGETOPT_REQ_STRING },
256 { "--scsi", MODIFYVM_SCSI, RTGETOPT_REQ_STRING },
257 { "--dvdpassthrough", MODIFYVM_DVDPASSTHROUGH, RTGETOPT_REQ_STRING },
258 { "--dvd", MODIFYVM_DVD, RTGETOPT_REQ_STRING },
259 { "--floppy", MODIFYVM_FLOPPY, RTGETOPT_REQ_STRING },
260 { "--nictracefile", MODIFYVM_NICTRACEFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
261 { "--nictrace", MODIFYVM_NICTRACE, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
262 { "--nicproperty", MODIFYVM_NICPROPERTY, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
263 { "--nictype", MODIFYVM_NICTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
264 { "--nicspeed", MODIFYVM_NICSPEED, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
265 { "--nicbootprio", MODIFYVM_NICBOOTPRIO, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
266 { "--nicpromisc", MODIFYVM_NICPROMISC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
267 { "--nicbandwidthgroup", MODIFYVM_NICBWGROUP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
268 { "--nic", MODIFYVM_NIC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
269 { "--cableconnected", MODIFYVM_CABLECONNECTED, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
270 { "--bridgeadapter", MODIFYVM_BRIDGEADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
271 { "--hostonlyadapter", MODIFYVM_HOSTONLYADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
272 { "--intnet", MODIFYVM_INTNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
273 { "--natnet", MODIFYVM_NATNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
274 { "--nicgenericdrv", MODIFYVM_GENERICDRV, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
275 { "--natbindip", MODIFYVM_NATBINDIP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
276 { "--natsettings", MODIFYVM_NATSETTINGS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
277 { "--natpf", MODIFYVM_NATPF, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
278 { "--nataliasmode", MODIFYVM_NATALIASMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
279 { "--nattftpprefix", MODIFYVM_NATTFTPPREFIX, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
280 { "--nattftpfile", MODIFYVM_NATTFTPFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
281 { "--nattftpserver", MODIFYVM_NATTFTPSERVER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
282 { "--natdnspassdomain", MODIFYVM_NATDNSPASSDOMAIN, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
283 { "--natdnsproxy", MODIFYVM_NATDNSPROXY, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
284 { "--natdnshostresolver", MODIFYVM_NATDNSHOSTRESOLVER, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
285 { "--macaddress", MODIFYVM_MACADDRESS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
286 { "--mouse", MODIFYVM_HIDPTR, RTGETOPT_REQ_STRING },
287 { "--keyboard", MODIFYVM_HIDKBD, RTGETOPT_REQ_STRING },
288 { "--uartmode", MODIFYVM_UARTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
289 { "--uart", MODIFYVM_UART, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
290#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
291 { "--lptmode", MODIFYVM_LPTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
292 { "--lpt", MODIFYVM_LPT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
293#endif
294 { "--guestmemoryballoon", MODIFYVM_GUESTMEMORYBALLOON, RTGETOPT_REQ_UINT32 },
295 { "--audiocontroller", MODIFYVM_AUDIOCONTROLLER, RTGETOPT_REQ_STRING },
296 { "--audio", MODIFYVM_AUDIO, RTGETOPT_REQ_STRING },
297 { "--clipboard", MODIFYVM_CLIPBOARD, RTGETOPT_REQ_STRING },
298 { "--draganddrop", MODIFYVM_DRAGANDDROP, RTGETOPT_REQ_STRING },
299 { "--vrdpport", MODIFYVM_VRDPPORT, RTGETOPT_REQ_STRING }, /* deprecated */
300 { "--vrdpaddress", MODIFYVM_VRDPADDRESS, RTGETOPT_REQ_STRING }, /* deprecated */
301 { "--vrdpauthtype", MODIFYVM_VRDPAUTHTYPE, RTGETOPT_REQ_STRING }, /* deprecated */
302 { "--vrdpmulticon", MODIFYVM_VRDPMULTICON, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
303 { "--vrdpreusecon", MODIFYVM_VRDPREUSECON, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
304 { "--vrdpvideochannel", MODIFYVM_VRDPVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
305 { "--vrdpvideochannelquality", MODIFYVM_VRDPVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING }, /* deprecated */
306 { "--vrdp", MODIFYVM_VRDP, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
307 { "--vrdeproperty", MODIFYVM_VRDEPROPERTY, RTGETOPT_REQ_STRING },
308 { "--vrdeport", MODIFYVM_VRDEPORT, RTGETOPT_REQ_STRING },
309 { "--vrdeaddress", MODIFYVM_VRDEADDRESS, RTGETOPT_REQ_STRING },
310 { "--vrdeauthtype", MODIFYVM_VRDEAUTHTYPE, RTGETOPT_REQ_STRING },
311 { "--vrdeauthlibrary", MODIFYVM_VRDEAUTHLIBRARY, RTGETOPT_REQ_STRING },
312 { "--vrdemulticon", MODIFYVM_VRDEMULTICON, RTGETOPT_REQ_BOOL_ONOFF },
313 { "--vrdereusecon", MODIFYVM_VRDEREUSECON, RTGETOPT_REQ_BOOL_ONOFF },
314 { "--vrdevideochannel", MODIFYVM_VRDEVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF },
315 { "--vrdevideochannelquality", MODIFYVM_VRDEVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING },
316 { "--vrdeextpack", MODIFYVM_VRDE_EXTPACK, RTGETOPT_REQ_STRING },
317 { "--vrde", MODIFYVM_VRDE, RTGETOPT_REQ_BOOL_ONOFF },
318 { "--usbehci", MODIFYVM_USBEHCI, RTGETOPT_REQ_BOOL_ONOFF },
319 { "--usb", MODIFYVM_USB, RTGETOPT_REQ_BOOL_ONOFF },
320 { "--snapshotfolder", MODIFYVM_SNAPSHOTFOLDER, RTGETOPT_REQ_STRING },
321 { "--teleporter", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
322 { "--teleporterenabled", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
323 { "--teleporterport", MODIFYVM_TELEPORTER_PORT, RTGETOPT_REQ_UINT32 },
324 { "--teleporteraddress", MODIFYVM_TELEPORTER_ADDRESS, RTGETOPT_REQ_STRING },
325 { "--teleporterpassword", MODIFYVM_TELEPORTER_PASSWORD, RTGETOPT_REQ_STRING },
326 { "--teleporterpasswordfile", MODIFYVM_TELEPORTER_PASSWORD_FILE, RTGETOPT_REQ_STRING },
327 { "--tracing-enabled", MODIFYVM_TRACING_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
328 { "--tracing-config", MODIFYVM_TRACING_CONFIG, RTGETOPT_REQ_STRING },
329 { "--tracing-allow-vm-access", MODIFYVM_TRACING_ALLOW_VM_ACCESS, RTGETOPT_REQ_BOOL_ONOFF },
330 { "--hardwareuuid", MODIFYVM_HARDWARE_UUID, RTGETOPT_REQ_STRING },
331 { "--hpet", MODIFYVM_HPET, RTGETOPT_REQ_BOOL_ONOFF },
332 { "--iocache", MODIFYVM_IOCACHE, RTGETOPT_REQ_BOOL_ONOFF },
333 { "--iocachesize", MODIFYVM_IOCACHESIZE, RTGETOPT_REQ_UINT32 },
334 { "--faulttolerance", MODIFYVM_FAULT_TOLERANCE, RTGETOPT_REQ_STRING },
335 { "--faulttoleranceaddress", MODIFYVM_FAULT_TOLERANCE_ADDRESS, RTGETOPT_REQ_STRING },
336 { "--faulttoleranceport", MODIFYVM_FAULT_TOLERANCE_PORT, RTGETOPT_REQ_UINT32 },
337 { "--faulttolerancepassword", MODIFYVM_FAULT_TOLERANCE_PASSWORD, RTGETOPT_REQ_STRING },
338 { "--faulttolerancesyncinterval", MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL, RTGETOPT_REQ_UINT32 },
339 { "--chipset", MODIFYVM_CHIPSET, RTGETOPT_REQ_STRING },
340#ifdef VBOX_WITH_VPX
341 { "--vcpenabled", MODIFYVM_VCP, RTGETOPT_REQ_BOOL_ONOFF },
342 { "--vcpfile", MODIFYVM_VCP_FILENAME, RTGETOPT_REQ_STRING },
343 { "--vcpwidth", MODIFYVM_VCP_WIDTH, RTGETOPT_REQ_UINT32 },
344 { "--vcpheight", MODIFYVM_VCP_HEIGHT, RTGETOPT_REQ_UINT32 },
345 { "--vcprate", MODIFYVM_VCP_RATE, RTGETOPT_REQ_UINT32 },
346 { "--vcpfps", MODIFYVM_VCP_FPS, RTGETOPT_REQ_UINT32 },
347#endif
348 { "--autostart-enabled", MODIFYVM_AUTOSTART_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
349 { "--autostart-delay", MODIFYVM_AUTOSTART_DELAY, RTGETOPT_REQ_UINT32 },
350 { "--autostop-type", MODIFYVM_AUTOSTOP_TYPE, RTGETOPT_REQ_STRING },
351#ifdef VBOX_WITH_PCI_PASSTHROUGH
352 { "--pciattach", MODIFYVM_ATTACH_PCI, RTGETOPT_REQ_STRING },
353 { "--pcidetach", MODIFYVM_DETACH_PCI, RTGETOPT_REQ_STRING },
354#endif
355#ifdef VBOX_WITH_USB_VIDEO
356 { "--usbwebcam", MODIFYVM_USBWEBCAM, RTGETOPT_REQ_BOOL_ONOFF },
357#endif
358#ifdef VBOX_WITH_USB_CARDREADER
359 { "--usbcardreader", MODIFYVM_USBCARDREADER, RTGETOPT_REQ_BOOL_ONOFF },
360#endif
361 { "--defaultfrontend", MODIFYVM_DEFAULTFRONTEND, RTGETOPT_REQ_STRING },
362};
363
364static void vrdeWarningDeprecatedOption(const char *pszOption)
365{
366 RTStrmPrintf(g_pStdErr, "Warning: '--vrdp%s' is deprecated. Use '--vrde%s'.\n", pszOption, pszOption);
367}
368
369/** Parse PCI address in format 01:02.03 and convert it to the numeric representation. */
370static int32_t parsePci(const char* szPciAddr)
371{
372 char* pszNext = (char*)szPciAddr;
373 int rc;
374 uint8_t aVals[3] = {0, 0, 0};
375
376 rc = RTStrToUInt8Ex(pszNext, &pszNext, 16, &aVals[0]);
377 if (RT_FAILURE(rc) || pszNext == NULL || *pszNext != ':')
378 return -1;
379
380 rc = RTStrToUInt8Ex(pszNext+1, &pszNext, 16, &aVals[1]);
381 if (RT_FAILURE(rc) || pszNext == NULL || *pszNext != '.')
382 return -1;
383
384 rc = RTStrToUInt8Ex(pszNext+1, &pszNext, 16, &aVals[2]);
385 if (RT_FAILURE(rc) || pszNext == NULL)
386 return -1;
387
388 return (aVals[0] << 8) | (aVals[1] << 3) | (aVals[2] << 0);
389}
390
391void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups)
392{
393 while (pcszGroups)
394 {
395 char *pComma = RTStrStr(pcszGroups, ",");
396 if (pComma)
397 {
398 Bstr(pcszGroups, pComma - pcszGroups).detachTo(pGroups->appendedRaw());
399 pcszGroups = pComma + 1;
400 }
401 else
402 {
403 Bstr(pcszGroups).detachTo(pGroups->appendedRaw());
404 pcszGroups = NULL;
405 }
406 }
407}
408
409int handleModifyVM(HandlerArg *a)
410{
411 int c;
412 HRESULT rc;
413 Bstr name;
414 RTGETOPTUNION ValueUnion;
415 RTGETOPTSTATE GetOptState;
416 ComPtr <IMachine> machine;
417 ComPtr <IBIOSSettings> biosSettings;
418
419 /* VM ID + at least one parameter. Parameter arguments are checked
420 * individually. */
421 if (a->argc < 2)
422 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
423
424 /* try to find the given machine */
425 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
426 machine.asOutParam()), 1);
427
428
429 /* Get the number of network adapters */
430 ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, machine);
431
432 /* open a session for the VM */
433 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), 1);
434
435 /* get the mutable session machine */
436 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(machine.asOutParam()), 1);
437 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
438
439 RTGetOptInit(&GetOptState, a->argc, a->argv, g_aModifyVMOptions,
440 RT_ELEMENTS(g_aModifyVMOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
441
442 while ( SUCCEEDED (rc)
443 && (c = RTGetOpt(&GetOptState, &ValueUnion)))
444 {
445 switch (c)
446 {
447 case MODIFYVM_NAME:
448 {
449 CHECK_ERROR(machine, COMSETTER(Name)(Bstr(ValueUnion.psz).raw()));
450 break;
451 }
452 case MODIFYVM_GROUPS:
453 {
454 com::SafeArray<BSTR> groups;
455 parseGroups(ValueUnion.psz, &groups);
456 CHECK_ERROR(machine, COMSETTER(Groups)(ComSafeArrayAsInParam(groups)));
457 break;
458 }
459 case MODIFYVM_OSTYPE:
460 {
461 ComPtr<IGuestOSType> guestOSType;
462 CHECK_ERROR(a->virtualBox, GetGuestOSType(Bstr(ValueUnion.psz).raw(),
463 guestOSType.asOutParam()));
464 if (SUCCEEDED(rc) && guestOSType)
465 {
466 CHECK_ERROR(machine, COMSETTER(OSTypeId)(Bstr(ValueUnion.psz).raw()));
467 }
468 else
469 {
470 errorArgument("Invalid guest OS type '%s'", Utf8Str(ValueUnion.psz).c_str());
471 rc = E_FAIL;
472 }
473 break;
474 }
475
476 case MODIFYVM_MEMORY:
477 {
478 CHECK_ERROR(machine, COMSETTER(MemorySize)(ValueUnion.u32));
479 break;
480 }
481
482 case MODIFYVM_PAGEFUSION:
483 {
484 CHECK_ERROR(machine, COMSETTER(PageFusionEnabled)(ValueUnion.f));
485 break;
486 }
487
488 case MODIFYVM_VRAM:
489 {
490 CHECK_ERROR(machine, COMSETTER(VRAMSize)(ValueUnion.u32));
491 break;
492 }
493
494 case MODIFYVM_FIRMWARE:
495 {
496 if (!RTStrICmp(ValueUnion.psz, "efi"))
497 {
498 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI));
499 }
500 else if (!RTStrICmp(ValueUnion.psz, "efi32"))
501 {
502 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI32));
503 }
504 else if (!RTStrICmp(ValueUnion.psz, "efi64"))
505 {
506 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI64));
507 }
508 else if (!RTStrICmp(ValueUnion.psz, "efidual"))
509 {
510 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFIDUAL));
511 }
512 else if (!RTStrICmp(ValueUnion.psz, "bios"))
513 {
514 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_BIOS));
515 }
516 else
517 {
518 errorArgument("Invalid --firmware argument '%s'", ValueUnion.psz);
519 rc = E_FAIL;
520 }
521 break;
522 }
523
524 case MODIFYVM_ACPI:
525 {
526 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(ValueUnion.f));
527 break;
528 }
529
530 case MODIFYVM_IOAPIC:
531 {
532 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(ValueUnion.f));
533 break;
534 }
535
536 case MODIFYVM_PAE:
537 {
538 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_PAE, ValueUnion.f));
539 break;
540 }
541
542 case MODIFYVM_SYNTHCPU:
543 {
544 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_Synthetic, ValueUnion.f));
545 break;
546 }
547
548 case MODIFYVM_HWVIRTEX:
549 {
550 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Enabled, ValueUnion.f));
551 break;
552 }
553
554 case MODIFYVM_HWVIRTEXEXCLUSIVE:
555 {
556 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Exclusive, ValueUnion.f));
557 break;
558 }
559
560 case MODIFYVM_SETCPUID:
561 {
562 uint32_t id = ValueUnion.u32;
563 uint32_t aValue[4];
564
565 for (unsigned i = 0 ; i < 4 ; i++)
566 {
567 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX);
568 if (RT_FAILURE(vrc))
569 return errorSyntax(USAGE_MODIFYVM,
570 "Missing or Invalid argument to '%s'",
571 GetOptState.pDef->pszLong);
572 aValue[i] = ValueUnion.u32;
573 }
574 CHECK_ERROR(machine, SetCPUIDLeaf(id, aValue[0], aValue[1], aValue[2], aValue[3]));
575 break;
576 }
577
578 case MODIFYVM_DELCPUID:
579 {
580 CHECK_ERROR(machine, RemoveCPUIDLeaf(ValueUnion.u32));
581 break;
582 }
583
584 case MODIFYVM_DELALLCPUID:
585 {
586 CHECK_ERROR(machine, RemoveAllCPUIDLeaves());
587 break;
588 }
589
590 case MODIFYVM_NESTEDPAGING:
591 {
592 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, ValueUnion.f));
593 break;
594 }
595
596 case MODIFYVM_LARGEPAGES:
597 {
598 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_LargePages, ValueUnion.f));
599 break;
600 }
601
602 case MODIFYVM_VTXVPID:
603 {
604 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_VPID, ValueUnion.f));
605 break;
606 }
607
608 case MODIFYVM_CPUS:
609 {
610 CHECK_ERROR(machine, COMSETTER(CPUCount)(ValueUnion.u32));
611 break;
612 }
613
614 case MODIFYVM_RTCUSEUTC:
615 {
616 CHECK_ERROR(machine, COMSETTER(RTCUseUTC)(ValueUnion.f));
617 break;
618 }
619
620 case MODIFYVM_CPUHOTPLUG:
621 {
622 CHECK_ERROR(machine, COMSETTER(CPUHotPlugEnabled)(ValueUnion.f));
623 break;
624 }
625
626 case MODIFYVM_PLUGCPU:
627 {
628 CHECK_ERROR(machine, HotPlugCPU(ValueUnion.u32));
629 break;
630 }
631
632 case MODIFYVM_UNPLUGCPU:
633 {
634 CHECK_ERROR(machine, HotUnplugCPU(ValueUnion.u32));
635 break;
636 }
637
638 case MODIFYVM_CPU_EXECTUION_CAP:
639 {
640 CHECK_ERROR(machine, COMSETTER(CPUExecutionCap)(ValueUnion.u32));
641 break;
642 }
643
644 case MODIFYVM_GRAPHICSCONTROLLER:
645 {
646 if ( !RTStrICmp(ValueUnion.psz, "none")
647 || !RTStrICmp(ValueUnion.psz, "disabled"))
648 CHECK_ERROR(machine, COMSETTER(GraphicsControllerType)(GraphicsControllerType_Null));
649 else if ( !RTStrICmp(ValueUnion.psz, "vboxvga")
650 || !RTStrICmp(ValueUnion.psz, "vbox")
651 || !RTStrICmp(ValueUnion.psz, "vga")
652 || !RTStrICmp(ValueUnion.psz, "vesa"))
653 CHECK_ERROR(machine, COMSETTER(GraphicsControllerType)(GraphicsControllerType_VBoxVGA));
654 else
655 {
656 errorArgument("Invalid --graphicscontroller argument '%s'", ValueUnion.psz);
657 rc = E_FAIL;
658 }
659 break;
660 }
661
662 case MODIFYVM_MONITORCOUNT:
663 {
664 CHECK_ERROR(machine, COMSETTER(MonitorCount)(ValueUnion.u32));
665 break;
666 }
667
668 case MODIFYVM_ACCELERATE3D:
669 {
670 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(ValueUnion.f));
671 break;
672 }
673
674#ifdef VBOX_WITH_VIDEOHWACCEL
675 case MODIFYVM_ACCELERATE2DVIDEO:
676 {
677 CHECK_ERROR(machine, COMSETTER(Accelerate2DVideoEnabled)(ValueUnion.f));
678 break;
679 }
680#endif
681
682 case MODIFYVM_BIOSLOGOFADEIN:
683 {
684 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(ValueUnion.f));
685 break;
686 }
687
688 case MODIFYVM_BIOSLOGOFADEOUT:
689 {
690 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(ValueUnion.f));
691 break;
692 }
693
694 case MODIFYVM_BIOSLOGODISPLAYTIME:
695 {
696 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(ValueUnion.u32));
697 break;
698 }
699
700 case MODIFYVM_BIOSLOGOIMAGEPATH:
701 {
702 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(ValueUnion.psz).raw()));
703 break;
704 }
705
706 case MODIFYVM_BIOSBOOTMENU:
707 {
708 if (!RTStrICmp(ValueUnion.psz, "disabled"))
709 {
710 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
711 }
712 else if (!RTStrICmp(ValueUnion.psz, "menuonly"))
713 {
714 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
715 }
716 else if (!RTStrICmp(ValueUnion.psz, "messageandmenu"))
717 {
718 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
719 }
720 else
721 {
722 errorArgument("Invalid --biosbootmenu argument '%s'", ValueUnion.psz);
723 rc = E_FAIL;
724 }
725 break;
726 }
727
728 case MODIFYVM_BIOSSYSTEMTIMEOFFSET:
729 {
730 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(ValueUnion.i64));
731 break;
732 }
733
734 case MODIFYVM_BIOSPXEDEBUG:
735 {
736 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(ValueUnion.f));
737 break;
738 }
739
740 case MODIFYVM_BOOT:
741 {
742 if (!RTStrICmp(ValueUnion.psz, "none"))
743 {
744 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Null));
745 }
746 else if (!RTStrICmp(ValueUnion.psz, "floppy"))
747 {
748 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Floppy));
749 }
750 else if (!RTStrICmp(ValueUnion.psz, "dvd"))
751 {
752 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_DVD));
753 }
754 else if (!RTStrICmp(ValueUnion.psz, "disk"))
755 {
756 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_HardDisk));
757 }
758 else if (!RTStrICmp(ValueUnion.psz, "net"))
759 {
760 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Network));
761 }
762 else
763 return errorArgument("Invalid boot device '%s'", ValueUnion.psz);
764 break;
765 }
766
767 case MODIFYVM_HDA: // deprecated
768 case MODIFYVM_HDB: // deprecated
769 case MODIFYVM_HDD: // deprecated
770 case MODIFYVM_SATAPORT: // deprecated
771 {
772 uint32_t u1 = 0, u2 = 0;
773 Bstr bstrController = L"IDE Controller";
774
775 switch (c)
776 {
777 case MODIFYVM_HDA: // deprecated
778 u1 = 0;
779 break;
780
781 case MODIFYVM_HDB: // deprecated
782 u1 = 0;
783 u2 = 1;
784 break;
785
786 case MODIFYVM_HDD: // deprecated
787 u1 = 1;
788 u2 = 1;
789 break;
790
791 case MODIFYVM_SATAPORT: // deprecated
792 u1 = GetOptState.uIndex;
793 bstrController = L"SATA";
794 break;
795 }
796
797 if (!RTStrICmp(ValueUnion.psz, "none"))
798 {
799 machine->DetachDevice(bstrController.raw(), u1, u2);
800 }
801 else
802 {
803 ComPtr<IMedium> hardDisk;
804 rc = openMedium(a, ValueUnion.psz, DeviceType_HardDisk,
805 AccessMode_ReadWrite, hardDisk,
806 false /* fForceNewUuidOnOpen */,
807 false /* fSilent */);
808 if (FAILED(rc))
809 break;
810 if (hardDisk)
811 {
812 CHECK_ERROR(machine, AttachDevice(bstrController.raw(),
813 u1, u2,
814 DeviceType_HardDisk,
815 hardDisk));
816 }
817 else
818 rc = E_FAIL;
819 }
820 break;
821 }
822
823 case MODIFYVM_IDECONTROLLER: // deprecated
824 {
825 ComPtr<IStorageController> storageController;
826 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("IDE Controller").raw(),
827 storageController.asOutParam()));
828
829 if (!RTStrICmp(ValueUnion.psz, "PIIX3"))
830 {
831 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
832 }
833 else if (!RTStrICmp(ValueUnion.psz, "PIIX4"))
834 {
835 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
836 }
837 else if (!RTStrICmp(ValueUnion.psz, "ICH6"))
838 {
839 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_ICH6));
840 }
841 else
842 {
843 errorArgument("Invalid --idecontroller argument '%s'", ValueUnion.psz);
844 rc = E_FAIL;
845 }
846 break;
847 }
848
849 case MODIFYVM_SATAPORTCOUNT: // deprecated
850 {
851 ComPtr<IStorageController> SataCtl;
852 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA").raw(),
853 SataCtl.asOutParam()));
854
855 if (SUCCEEDED(rc) && ValueUnion.u32 > 0)
856 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(ValueUnion.u32));
857 break;
858 }
859
860 case MODIFYVM_SATA: // deprecated
861 {
862 if (!RTStrICmp(ValueUnion.psz, "on") || !RTStrICmp(ValueUnion.psz, "enable"))
863 {
864 ComPtr<IStorageController> ctl;
865 CHECK_ERROR(machine, AddStorageController(Bstr("SATA").raw(),
866 StorageBus_SATA,
867 ctl.asOutParam()));
868 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
869 }
870 else if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
871 CHECK_ERROR(machine, RemoveStorageController(Bstr("SATA").raw()));
872 else
873 return errorArgument("Invalid --usb argument '%s'", ValueUnion.psz);
874 break;
875 }
876
877 case MODIFYVM_SCSIPORT: // deprecated
878 {
879 if (!RTStrICmp(ValueUnion.psz, "none"))
880 {
881 rc = machine->DetachDevice(Bstr("LsiLogic").raw(),
882 GetOptState.uIndex, 0);
883 if (FAILED(rc))
884 CHECK_ERROR(machine, DetachDevice(Bstr("BusLogic").raw(),
885 GetOptState.uIndex, 0));
886 }
887 else
888 {
889 ComPtr<IMedium> hardDisk;
890 rc = openMedium(a, ValueUnion.psz, DeviceType_HardDisk,
891 AccessMode_ReadWrite, hardDisk,
892 false /* fForceNewUuidOnOpen */,
893 false /* fSilent */);
894 if (FAILED(rc))
895 break;
896 if (hardDisk)
897 {
898 rc = machine->AttachDevice(Bstr("LsiLogic").raw(),
899 GetOptState.uIndex, 0,
900 DeviceType_HardDisk,
901 hardDisk);
902 if (FAILED(rc))
903 CHECK_ERROR(machine,
904 AttachDevice(Bstr("BusLogic").raw(),
905 GetOptState.uIndex, 0,
906 DeviceType_HardDisk,
907 hardDisk));
908 }
909 else
910 rc = E_FAIL;
911 }
912 break;
913 }
914
915 case MODIFYVM_SCSITYPE: // deprecated
916 {
917 ComPtr<IStorageController> ctl;
918
919 if (!RTStrICmp(ValueUnion.psz, "LsiLogic"))
920 {
921 rc = machine->RemoveStorageController(Bstr("BusLogic").raw());
922 if (FAILED(rc))
923 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic").raw()));
924
925 CHECK_ERROR(machine,
926 AddStorageController(Bstr("LsiLogic").raw(),
927 StorageBus_SCSI,
928 ctl.asOutParam()));
929
930 if (SUCCEEDED(rc))
931 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
932 }
933 else if (!RTStrICmp(ValueUnion.psz, "BusLogic"))
934 {
935 rc = machine->RemoveStorageController(Bstr("LsiLogic").raw());
936 if (FAILED(rc))
937 CHECK_ERROR(machine, RemoveStorageController(Bstr("BusLogic").raw()));
938
939 CHECK_ERROR(machine,
940 AddStorageController(Bstr("BusLogic").raw(),
941 StorageBus_SCSI,
942 ctl.asOutParam()));
943
944 if (SUCCEEDED(rc))
945 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
946 }
947 else
948 return errorArgument("Invalid --scsitype argument '%s'", ValueUnion.psz);
949 break;
950 }
951
952 case MODIFYVM_SCSI: // deprecated
953 {
954 if (!RTStrICmp(ValueUnion.psz, "on") || !RTStrICmp(ValueUnion.psz, "enable"))
955 {
956 ComPtr<IStorageController> ctl;
957
958 CHECK_ERROR(machine, AddStorageController(Bstr("BusLogic").raw(),
959 StorageBus_SCSI,
960 ctl.asOutParam()));
961 if (SUCCEEDED(rc))
962 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
963 }
964 else if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
965 {
966 rc = machine->RemoveStorageController(Bstr("BusLogic").raw());
967 if (FAILED(rc))
968 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic").raw()));
969 }
970 break;
971 }
972
973 case MODIFYVM_DVDPASSTHROUGH: // deprecated
974 {
975 CHECK_ERROR(machine, PassthroughDevice(Bstr("IDE Controller").raw(),
976 1, 0,
977 !RTStrICmp(ValueUnion.psz, "on")));
978 break;
979 }
980
981 case MODIFYVM_DVD: // deprecated
982 {
983 ComPtr<IMedium> dvdMedium;
984
985 /* unmount? */
986 if (!RTStrICmp(ValueUnion.psz, "none"))
987 {
988 /* nothing to do, NULL object will cause unmount */
989 }
990 /* host drive? */
991 else if (!RTStrNICmp(ValueUnion.psz, "host:", 5))
992 {
993 ComPtr<IHost> host;
994 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
995 rc = host->FindHostDVDDrive(Bstr(ValueUnion.psz + 5).raw(),
996 dvdMedium.asOutParam());
997 if (!dvdMedium)
998 {
999 /* 2nd try: try with the real name, important on Linux+libhal */
1000 char szPathReal[RTPATH_MAX];
1001 if (RT_FAILURE(RTPathReal(ValueUnion.psz + 5, szPathReal, sizeof(szPathReal))))
1002 {
1003 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
1004 rc = E_FAIL;
1005 break;
1006 }
1007 rc = host->FindHostDVDDrive(Bstr(szPathReal).raw(),
1008 dvdMedium.asOutParam());
1009 if (!dvdMedium)
1010 {
1011 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
1012 rc = E_FAIL;
1013 break;
1014 }
1015 }
1016 }
1017 else
1018 {
1019 rc = openMedium(a, ValueUnion.psz, DeviceType_DVD,
1020 AccessMode_ReadOnly, dvdMedium,
1021 false /* fForceNewUuidOnOpen */,
1022 false /* fSilent */);
1023 if (FAILED(rc))
1024 break;
1025 if (!dvdMedium)
1026 {
1027 rc = E_FAIL;
1028 break;
1029 }
1030 }
1031
1032 CHECK_ERROR(machine, MountMedium(Bstr("IDE Controller").raw(),
1033 1, 0,
1034 dvdMedium,
1035 FALSE /* aForce */));
1036 break;
1037 }
1038
1039 case MODIFYVM_FLOPPY: // deprecated
1040 {
1041 ComPtr<IMedium> floppyMedium;
1042 ComPtr<IMediumAttachment> floppyAttachment;
1043 machine->GetMediumAttachment(Bstr("Floppy Controller").raw(),
1044 0, 0, floppyAttachment.asOutParam());
1045
1046 /* disable? */
1047 if (!RTStrICmp(ValueUnion.psz, "disabled"))
1048 {
1049 /* disable the controller */
1050 if (floppyAttachment)
1051 CHECK_ERROR(machine, DetachDevice(Bstr("Floppy Controller").raw(),
1052 0, 0));
1053 }
1054 else
1055 {
1056 /* enable the controller */
1057 if (!floppyAttachment)
1058 CHECK_ERROR(machine, AttachDeviceWithoutMedium(Bstr("Floppy Controller").raw(),
1059 0, 0,
1060 DeviceType_Floppy));
1061
1062 /* unmount? */
1063 if ( !RTStrICmp(ValueUnion.psz, "none")
1064 || !RTStrICmp(ValueUnion.psz, "empty")) // deprecated
1065 {
1066 /* nothing to do, NULL object will cause unmount */
1067 }
1068 /* host drive? */
1069 else if (!RTStrNICmp(ValueUnion.psz, "host:", 5))
1070 {
1071 ComPtr<IHost> host;
1072 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1073 rc = host->FindHostFloppyDrive(Bstr(ValueUnion.psz + 5).raw(),
1074 floppyMedium.asOutParam());
1075 if (!floppyMedium)
1076 {
1077 errorArgument("Invalid host floppy drive name \"%s\"", ValueUnion.psz + 5);
1078 rc = E_FAIL;
1079 break;
1080 }
1081 }
1082 else
1083 {
1084 rc = openMedium(a, ValueUnion.psz, DeviceType_Floppy,
1085 AccessMode_ReadWrite, floppyMedium,
1086 false /* fForceNewUuidOnOpen */,
1087 false /* fSilent */);
1088 if (FAILED(rc))
1089 break;
1090 if (!floppyMedium)
1091 {
1092 rc = E_FAIL;
1093 break;
1094 }
1095 }
1096 CHECK_ERROR(machine, MountMedium(Bstr("Floppy Controller").raw(),
1097 0, 0,
1098 floppyMedium,
1099 FALSE /* aForce */));
1100 }
1101 break;
1102 }
1103
1104 case MODIFYVM_NICTRACEFILE:
1105 {
1106 ComPtr<INetworkAdapter> nic;
1107
1108 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1109 ASSERT(nic);
1110
1111 CHECK_ERROR(nic, COMSETTER(TraceFile)(Bstr(ValueUnion.psz).raw()));
1112 break;
1113 }
1114
1115 case MODIFYVM_NICTRACE:
1116 {
1117 ComPtr<INetworkAdapter> nic;
1118
1119 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1120 ASSERT(nic);
1121
1122 CHECK_ERROR(nic, COMSETTER(TraceEnabled)(ValueUnion.f));
1123 break;
1124 }
1125
1126 case MODIFYVM_NICPROPERTY:
1127 {
1128 ComPtr<INetworkAdapter> nic;
1129
1130 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1131 ASSERT(nic);
1132
1133 if (nic)
1134 {
1135 /* Parse 'name=value' */
1136 char *pszProperty = RTStrDup(ValueUnion.psz);
1137 if (pszProperty)
1138 {
1139 char *pDelimiter = strchr(pszProperty, '=');
1140 if (pDelimiter)
1141 {
1142 *pDelimiter = '\0';
1143
1144 Bstr bstrName = pszProperty;
1145 Bstr bstrValue = &pDelimiter[1];
1146 CHECK_ERROR(nic, SetProperty(bstrName.raw(), bstrValue.raw()));
1147 }
1148 else
1149 {
1150 errorArgument("Invalid --nicproperty%d argument '%s'", GetOptState.uIndex, ValueUnion.psz);
1151 rc = E_FAIL;
1152 }
1153 RTStrFree(pszProperty);
1154 }
1155 else
1156 {
1157 RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for --nicproperty%d '%s'\n", GetOptState.uIndex, ValueUnion.psz);
1158 rc = E_FAIL;
1159 }
1160 }
1161 break;
1162 }
1163 case MODIFYVM_NICTYPE:
1164 {
1165 ComPtr<INetworkAdapter> nic;
1166
1167 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1168 ASSERT(nic);
1169
1170 if (!RTStrICmp(ValueUnion.psz, "Am79C970A"))
1171 {
1172 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A));
1173 }
1174 else if (!RTStrICmp(ValueUnion.psz, "Am79C973"))
1175 {
1176 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973));
1177 }
1178#ifdef VBOX_WITH_E1000
1179 else if (!RTStrICmp(ValueUnion.psz, "82540EM"))
1180 {
1181 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM));
1182 }
1183 else if (!RTStrICmp(ValueUnion.psz, "82543GC"))
1184 {
1185 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC));
1186 }
1187 else if (!RTStrICmp(ValueUnion.psz, "82545EM"))
1188 {
1189 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82545EM));
1190 }
1191#endif
1192#ifdef VBOX_WITH_VIRTIO
1193 else if (!RTStrICmp(ValueUnion.psz, "virtio"))
1194 {
1195 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Virtio));
1196 }
1197#endif /* VBOX_WITH_VIRTIO */
1198 else
1199 {
1200 errorArgument("Invalid NIC type '%s' specified for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1201 rc = E_FAIL;
1202 }
1203 break;
1204 }
1205
1206 case MODIFYVM_NICSPEED:
1207 {
1208 ComPtr<INetworkAdapter> nic;
1209
1210 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1211 ASSERT(nic);
1212
1213 CHECK_ERROR(nic, COMSETTER(LineSpeed)(ValueUnion.u32));
1214 break;
1215 }
1216
1217 case MODIFYVM_NICBOOTPRIO:
1218 {
1219 ComPtr<INetworkAdapter> nic;
1220
1221 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1222 ASSERT(nic);
1223
1224 /* Somewhat arbitrary limitation - we can pass a list of up to 4 PCI devices
1225 * to the PXE ROM, hence only boot priorities 1-4 are allowed (in addition to
1226 * 0 for the default lowest priority).
1227 */
1228 if (ValueUnion.u32 > 4)
1229 {
1230 errorArgument("Invalid boot priority '%u' specfied for NIC %u", ValueUnion.u32, GetOptState.uIndex);
1231 rc = E_FAIL;
1232 }
1233 else
1234 {
1235 CHECK_ERROR(nic, COMSETTER(BootPriority)(ValueUnion.u32));
1236 }
1237 break;
1238 }
1239
1240 case MODIFYVM_NICPROMISC:
1241 {
1242 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
1243 if (!RTStrICmp(ValueUnion.psz, "deny"))
1244 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
1245 else if ( !RTStrICmp(ValueUnion.psz, "allow-vms")
1246 || !RTStrICmp(ValueUnion.psz, "allow-network"))
1247 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
1248 else if (!RTStrICmp(ValueUnion.psz, "allow-all"))
1249 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
1250 else
1251 {
1252 errorArgument("Unknown promiscuous mode policy '%s'", ValueUnion.psz);
1253 rc = E_INVALIDARG;
1254 break;
1255 }
1256
1257 ComPtr<INetworkAdapter> nic;
1258 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1259 ASSERT(nic);
1260
1261 CHECK_ERROR(nic, COMSETTER(PromiscModePolicy)(enmPromiscModePolicy));
1262 break;
1263 }
1264
1265 case MODIFYVM_NICBWGROUP:
1266 {
1267 ComPtr<INetworkAdapter> nic;
1268 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1269 ASSERT(nic);
1270
1271 if (!RTStrICmp(ValueUnion.psz, "none"))
1272 {
1273 /* Just remove the bandwidth group. */
1274 CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(NULL));
1275 }
1276 else
1277 {
1278 ComPtr<IBandwidthControl> bwCtrl;
1279 ComPtr<IBandwidthGroup> bwGroup;
1280
1281 CHECK_ERROR(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
1282
1283 if (SUCCEEDED(rc))
1284 {
1285 CHECK_ERROR(bwCtrl, GetBandwidthGroup(Bstr(ValueUnion.psz).raw(), bwGroup.asOutParam()));
1286 if (SUCCEEDED(rc))
1287 {
1288 CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(bwGroup));
1289 }
1290 }
1291 }
1292 break;
1293 }
1294
1295 case MODIFYVM_NIC:
1296 {
1297 ComPtr<INetworkAdapter> nic;
1298
1299 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1300 ASSERT(nic);
1301
1302 if (!RTStrICmp(ValueUnion.psz, "none"))
1303 {
1304 CHECK_ERROR(nic, COMSETTER(Enabled)(FALSE));
1305 }
1306 else if (!RTStrICmp(ValueUnion.psz, "null"))
1307 {
1308 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1309 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Null));
1310 }
1311 else if (!RTStrICmp(ValueUnion.psz, "nat"))
1312 {
1313 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1314 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_NAT));
1315 }
1316 else if ( !RTStrICmp(ValueUnion.psz, "bridged")
1317 || !RTStrICmp(ValueUnion.psz, "hostif")) /* backward compatibility */
1318 {
1319 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1320 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Bridged));
1321 }
1322 else if (!RTStrICmp(ValueUnion.psz, "intnet"))
1323 {
1324 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1325 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Internal));
1326 }
1327 else if (!RTStrICmp(ValueUnion.psz, "hostonly"))
1328 {
1329
1330 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1331 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_HostOnly));
1332 }
1333 else if (!RTStrICmp(ValueUnion.psz, "generic"))
1334 {
1335
1336 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1337 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic));
1338 }
1339 else
1340 {
1341 errorArgument("Invalid type '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1342 rc = E_FAIL;
1343 }
1344 break;
1345 }
1346
1347 case MODIFYVM_CABLECONNECTED:
1348 {
1349 ComPtr<INetworkAdapter> nic;
1350
1351 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1352 ASSERT(nic);
1353
1354 CHECK_ERROR(nic, COMSETTER(CableConnected)(ValueUnion.f));
1355 break;
1356 }
1357
1358 case MODIFYVM_BRIDGEADAPTER:
1359 {
1360 ComPtr<INetworkAdapter> nic;
1361
1362 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1363 ASSERT(nic);
1364
1365 /* remove it? */
1366 if (!RTStrICmp(ValueUnion.psz, "none"))
1367 {
1368 CHECK_ERROR(nic, COMSETTER(BridgedInterface)(Bstr().raw()));
1369 }
1370 else
1371 {
1372 CHECK_ERROR(nic, COMSETTER(BridgedInterface)(Bstr(ValueUnion.psz).raw()));
1373 }
1374 break;
1375 }
1376
1377 case MODIFYVM_HOSTONLYADAPTER:
1378 {
1379 ComPtr<INetworkAdapter> nic;
1380
1381 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1382 ASSERT(nic);
1383
1384 /* remove it? */
1385 if (!RTStrICmp(ValueUnion.psz, "none"))
1386 {
1387 CHECK_ERROR(nic, COMSETTER(HostOnlyInterface)(Bstr().raw()));
1388 }
1389 else
1390 {
1391 CHECK_ERROR(nic, COMSETTER(HostOnlyInterface)(Bstr(ValueUnion.psz).raw()));
1392 }
1393 break;
1394 }
1395
1396 case MODIFYVM_INTNET:
1397 {
1398 ComPtr<INetworkAdapter> nic;
1399
1400 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1401 ASSERT(nic);
1402
1403 /* remove it? */
1404 if (!RTStrICmp(ValueUnion.psz, "none"))
1405 {
1406 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr().raw()));
1407 }
1408 else
1409 {
1410 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr(ValueUnion.psz).raw()));
1411 }
1412 break;
1413 }
1414
1415 case MODIFYVM_GENERICDRV:
1416 {
1417 ComPtr<INetworkAdapter> nic;
1418
1419 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1420 ASSERT(nic);
1421
1422 CHECK_ERROR(nic, COMSETTER(GenericDriver)(Bstr(ValueUnion.psz).raw()));
1423 break;
1424 }
1425
1426 case MODIFYVM_NATNET:
1427 {
1428 ComPtr<INetworkAdapter> nic;
1429 ComPtr<INATEngine> engine;
1430
1431 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1432 ASSERT(nic);
1433
1434 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1435
1436 const char *psz = ValueUnion.psz;
1437 if (!RTStrICmp("default", psz))
1438 psz = "";
1439
1440 CHECK_ERROR(engine, COMSETTER(Network)(Bstr(psz).raw()));
1441 break;
1442 }
1443
1444 case MODIFYVM_NATBINDIP:
1445 {
1446 ComPtr<INetworkAdapter> nic;
1447 ComPtr<INATEngine> engine;
1448
1449 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1450 ASSERT(nic);
1451
1452 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1453 CHECK_ERROR(engine, COMSETTER(HostIP)(Bstr(ValueUnion.psz).raw()));
1454 break;
1455 }
1456
1457#define ITERATE_TO_NEXT_TERM(ch) \
1458 do { \
1459 while (*ch != ',') \
1460 { \
1461 if (*ch == 0) \
1462 { \
1463 return errorSyntax(USAGE_MODIFYVM, \
1464 "Missing or Invalid argument to '%s'", \
1465 GetOptState.pDef->pszLong); \
1466 } \
1467 ch++; \
1468 } \
1469 *ch = '\0'; \
1470 ch++; \
1471 } while(0)
1472
1473 case MODIFYVM_NATSETTINGS:
1474 {
1475 ComPtr<INetworkAdapter> nic;
1476 ComPtr<INATEngine> engine;
1477 char *strMtu;
1478 char *strSockSnd;
1479 char *strSockRcv;
1480 char *strTcpSnd;
1481 char *strTcpRcv;
1482 char *strRaw = RTStrDup(ValueUnion.psz);
1483 char *ch = strRaw;
1484 strMtu = RTStrStrip(ch);
1485 ITERATE_TO_NEXT_TERM(ch);
1486 strSockSnd = RTStrStrip(ch);
1487 ITERATE_TO_NEXT_TERM(ch);
1488 strSockRcv = RTStrStrip(ch);
1489 ITERATE_TO_NEXT_TERM(ch);
1490 strTcpSnd = RTStrStrip(ch);
1491 ITERATE_TO_NEXT_TERM(ch);
1492 strTcpRcv = RTStrStrip(ch);
1493
1494 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1495 ASSERT(nic);
1496
1497 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1498 CHECK_ERROR(engine, SetNetworkSettings(RTStrToUInt32(strMtu), RTStrToUInt32(strSockSnd), RTStrToUInt32(strSockRcv),
1499 RTStrToUInt32(strTcpSnd), RTStrToUInt32(strTcpRcv)));
1500 break;
1501 }
1502
1503
1504 case MODIFYVM_NATPF:
1505 {
1506 ComPtr<INetworkAdapter> nic;
1507 ComPtr<INATEngine> engine;
1508
1509 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1510 ASSERT(nic);
1511
1512 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1513 /* format name:proto:hostip:hostport:guestip:guestport*/
1514 if (RTStrCmp(ValueUnion.psz, "delete") != 0)
1515 {
1516 char *strName;
1517 char *strProto;
1518 char *strHostIp;
1519 char *strHostPort;
1520 char *strGuestIp;
1521 char *strGuestPort;
1522 char *strRaw = RTStrDup(ValueUnion.psz);
1523 char *ch = strRaw;
1524 strName = RTStrStrip(ch);
1525 ITERATE_TO_NEXT_TERM(ch);
1526 strProto = RTStrStrip(ch);
1527 ITERATE_TO_NEXT_TERM(ch);
1528 strHostIp = RTStrStrip(ch);
1529 ITERATE_TO_NEXT_TERM(ch);
1530 strHostPort = RTStrStrip(ch);
1531 ITERATE_TO_NEXT_TERM(ch);
1532 strGuestIp = RTStrStrip(ch);
1533 ITERATE_TO_NEXT_TERM(ch);
1534 strGuestPort = RTStrStrip(ch);
1535 NATProtocol_T proto;
1536 if (RTStrICmp(strProto, "udp") == 0)
1537 proto = NATProtocol_UDP;
1538 else if (RTStrICmp(strProto, "tcp") == 0)
1539 proto = NATProtocol_TCP;
1540 else
1541 {
1542 errorArgument("Invalid proto '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1543 rc = E_FAIL;
1544 break;
1545 }
1546 CHECK_ERROR(engine, AddRedirect(Bstr(strName).raw(), proto,
1547 Bstr(strHostIp).raw(),
1548 RTStrToUInt16(strHostPort),
1549 Bstr(strGuestIp).raw(),
1550 RTStrToUInt16(strGuestPort)));
1551 }
1552 else
1553 {
1554 /* delete NAT Rule operation */
1555 int vrc;
1556 vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1557 if (RT_FAILURE(vrc))
1558 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
1559 CHECK_ERROR(engine, RemoveRedirect(Bstr(ValueUnion.psz).raw()));
1560 }
1561 break;
1562 }
1563 #undef ITERATE_TO_NEXT_TERM
1564 case MODIFYVM_NATALIASMODE:
1565 {
1566 ComPtr<INetworkAdapter> nic;
1567 ComPtr<INATEngine> engine;
1568 uint32_t aliasMode = 0;
1569
1570 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1571 ASSERT(nic);
1572
1573 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1574 if (RTStrCmp(ValueUnion.psz, "default") == 0)
1575 {
1576 aliasMode = 0;
1577 }
1578 else
1579 {
1580 char *token = (char *)ValueUnion.psz;
1581 while(token)
1582 {
1583 if (RTStrNCmp(token, "log", 3) == 0)
1584 aliasMode |= 0x1;
1585 else if (RTStrNCmp(token, "proxyonly", 9) == 0)
1586 aliasMode |= 0x2;
1587 else if (RTStrNCmp(token, "sameports", 9) == 0)
1588 aliasMode |= 0x4;
1589 token = RTStrStr(token, ",");
1590 if (token == NULL)
1591 break;
1592 token++;
1593 }
1594 }
1595 CHECK_ERROR(engine, COMSETTER(AliasMode)(aliasMode));
1596 break;
1597 }
1598
1599 case MODIFYVM_NATTFTPPREFIX:
1600 {
1601 ComPtr<INetworkAdapter> nic;
1602 ComPtr<INATEngine> engine;
1603
1604 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1605 ASSERT(nic);
1606
1607 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1608 CHECK_ERROR(engine, COMSETTER(TFTPPrefix)(Bstr(ValueUnion.psz).raw()));
1609 break;
1610 }
1611
1612 case MODIFYVM_NATTFTPFILE:
1613 {
1614 ComPtr<INetworkAdapter> nic;
1615 ComPtr<INATEngine> engine;
1616
1617 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1618 ASSERT(nic);
1619
1620 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1621 CHECK_ERROR(engine, COMSETTER(TFTPBootFile)(Bstr(ValueUnion.psz).raw()));
1622 break;
1623 }
1624
1625 case MODIFYVM_NATTFTPSERVER:
1626 {
1627 ComPtr<INetworkAdapter> nic;
1628 ComPtr<INATEngine> engine;
1629
1630 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1631 ASSERT(nic);
1632
1633 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1634 CHECK_ERROR(engine, COMSETTER(TFTPNextServer)(Bstr(ValueUnion.psz).raw()));
1635 break;
1636 }
1637 case MODIFYVM_NATDNSPASSDOMAIN:
1638 {
1639 ComPtr<INetworkAdapter> nic;
1640 ComPtr<INATEngine> engine;
1641
1642 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1643 ASSERT(nic);
1644
1645 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1646 CHECK_ERROR(engine, COMSETTER(DNSPassDomain)(ValueUnion.f));
1647 break;
1648 }
1649
1650 case MODIFYVM_NATDNSPROXY:
1651 {
1652 ComPtr<INetworkAdapter> nic;
1653 ComPtr<INATEngine> engine;
1654
1655 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1656 ASSERT(nic);
1657
1658 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1659 CHECK_ERROR(engine, COMSETTER(DNSProxy)(ValueUnion.f));
1660 break;
1661 }
1662
1663 case MODIFYVM_NATDNSHOSTRESOLVER:
1664 {
1665 ComPtr<INetworkAdapter> nic;
1666 ComPtr<INATEngine> engine;
1667
1668 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1669 ASSERT(nic);
1670
1671 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1672 CHECK_ERROR(engine, COMSETTER(DNSUseHostResolver)(ValueUnion.f));
1673 break;
1674 }
1675 case MODIFYVM_MACADDRESS:
1676 {
1677 ComPtr<INetworkAdapter> nic;
1678
1679 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1680 ASSERT(nic);
1681
1682 /* generate one? */
1683 if (!RTStrICmp(ValueUnion.psz, "auto"))
1684 {
1685 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr().raw()));
1686 }
1687 else
1688 {
1689 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr(ValueUnion.psz).raw()));
1690 }
1691 break;
1692 }
1693
1694 case MODIFYVM_HIDPTR:
1695 {
1696 bool fEnableUsb = false;
1697 if (!RTStrICmp(ValueUnion.psz, "ps2"))
1698 {
1699 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_PS2Mouse));
1700 }
1701 else if (!RTStrICmp(ValueUnion.psz, "usb"))
1702 {
1703 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_USBMouse));
1704 if (SUCCEEDED(rc))
1705 fEnableUsb = true;
1706 }
1707 else if (!RTStrICmp(ValueUnion.psz, "usbtablet"))
1708 {
1709 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_USBTablet));
1710 if (SUCCEEDED(rc))
1711 fEnableUsb = true;
1712 }
1713 else
1714 {
1715 errorArgument("Invalid type '%s' specfied for pointing device", ValueUnion.psz);
1716 rc = E_FAIL;
1717 }
1718 if (fEnableUsb)
1719 {
1720 /* Make sure the OHCI controller is enabled. */
1721 ComPtr<IUSBController> UsbCtl;
1722 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1723 if (SUCCEEDED(rc))
1724 {
1725 BOOL fEnabled;
1726 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1727 if (FAILED(rc))
1728 fEnabled = false;
1729 if (!fEnabled)
1730 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1731 }
1732 }
1733 break;
1734 }
1735
1736 case MODIFYVM_HIDKBD:
1737 {
1738 bool fEnableUsb = false;
1739 if (!RTStrICmp(ValueUnion.psz, "ps2"))
1740 {
1741 CHECK_ERROR(machine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_PS2Keyboard));
1742 }
1743 else if (!RTStrICmp(ValueUnion.psz, "usb"))
1744 {
1745 CHECK_ERROR(machine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_USBKeyboard));
1746 if (SUCCEEDED(rc))
1747 fEnableUsb = true;
1748 }
1749 else
1750 {
1751 errorArgument("Invalid type '%s' specfied for keyboard", ValueUnion.psz);
1752 rc = E_FAIL;
1753 }
1754 if (fEnableUsb)
1755 {
1756 /* Make sure the OHCI controller is enabled. */
1757 ComPtr<IUSBController> UsbCtl;
1758 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1759 if (SUCCEEDED(rc))
1760 {
1761 BOOL fEnabled;
1762 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1763 if (FAILED(rc))
1764 fEnabled = false;
1765 if (!fEnabled)
1766 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1767 }
1768 }
1769 break;
1770 }
1771
1772 case MODIFYVM_UARTMODE:
1773 {
1774 ComPtr<ISerialPort> uart;
1775 char *pszIRQ = NULL;
1776
1777 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1778 ASSERT(uart);
1779
1780 if (!RTStrICmp(ValueUnion.psz, "disconnected"))
1781 {
1782 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
1783 }
1784 else if ( !RTStrICmp(ValueUnion.psz, "server")
1785 || !RTStrICmp(ValueUnion.psz, "client")
1786 || !RTStrICmp(ValueUnion.psz, "file"))
1787 {
1788 const char *pszMode = ValueUnion.psz;
1789
1790 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1791 if (RT_FAILURE(vrc))
1792 return errorSyntax(USAGE_MODIFYVM,
1793 "Missing or Invalid argument to '%s'",
1794 GetOptState.pDef->pszLong);
1795
1796 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1797
1798 if (!RTStrICmp(pszMode, "server"))
1799 {
1800 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1801 CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
1802 }
1803 else if (!RTStrICmp(pszMode, "client"))
1804 {
1805 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1806 CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
1807 }
1808 else if (!RTStrICmp(pszMode, "file"))
1809 {
1810 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_RawFile));
1811 }
1812 }
1813 else
1814 {
1815 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1816 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostDevice));
1817 }
1818 break;
1819 }
1820
1821 case MODIFYVM_UART:
1822 {
1823 ComPtr<ISerialPort> uart;
1824
1825 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1826 ASSERT(uart);
1827
1828 if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
1829 CHECK_ERROR(uart, COMSETTER(Enabled)(FALSE));
1830 else
1831 {
1832 const char *pszIOBase = ValueUnion.psz;
1833 uint32_t uVal = 0;
1834
1835 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_UART;
1836 if (RT_FAILURE(vrc))
1837 return errorSyntax(USAGE_MODIFYVM,
1838 "Missing or Invalid argument to '%s'",
1839 GetOptState.pDef->pszLong);
1840
1841 CHECK_ERROR(uart, COMSETTER(IRQ)(ValueUnion.u32));
1842
1843 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1844 if (vrc != VINF_SUCCESS || uVal == 0)
1845 return errorArgument("Error parsing UART I/O base '%s'", pszIOBase);
1846 CHECK_ERROR(uart, COMSETTER(IOBase)(uVal));
1847
1848 CHECK_ERROR(uart, COMSETTER(Enabled)(TRUE));
1849 }
1850 break;
1851 }
1852
1853#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
1854 case MODIFYVM_LPTMODE:
1855 {
1856 ComPtr<IParallelPort> lpt;
1857 char *pszIRQ = NULL;
1858
1859 CHECK_ERROR_BREAK(machine, GetParallelPort(GetOptState.uIndex - 1, lpt.asOutParam()));
1860 ASSERT(lpt);
1861
1862 CHECK_ERROR(lpt, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1863 break;
1864 }
1865
1866 case MODIFYVM_LPT:
1867 {
1868 ComPtr<IParallelPort> lpt;
1869
1870 CHECK_ERROR_BREAK(machine, GetParallelPort(GetOptState.uIndex - 1, lpt.asOutParam()));
1871 ASSERT(lpt);
1872
1873 if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
1874 CHECK_ERROR(lpt, COMSETTER(Enabled)(FALSE));
1875 else
1876 {
1877 const char *pszIOBase = ValueUnion.psz;
1878 uint32_t uVal = 0;
1879
1880 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_LPT;
1881 if (RT_FAILURE(vrc))
1882 return errorSyntax(USAGE_MODIFYVM,
1883 "Missing or Invalid argument to '%s'",
1884 GetOptState.pDef->pszLong);
1885
1886 CHECK_ERROR(lpt, COMSETTER(IRQ)(ValueUnion.u32));
1887
1888 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1889 if (vrc != VINF_SUCCESS || uVal == 0)
1890 return errorArgument("Error parsing LPT I/O base '%s'", pszIOBase);
1891 CHECK_ERROR(lpt, COMSETTER(IOBase)(uVal));
1892
1893 CHECK_ERROR(lpt, COMSETTER(Enabled)(TRUE));
1894 }
1895 break;
1896 }
1897#endif
1898
1899 case MODIFYVM_GUESTMEMORYBALLOON:
1900 {
1901 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(ValueUnion.u32));
1902 break;
1903 }
1904
1905 case MODIFYVM_AUDIOCONTROLLER:
1906 {
1907 ComPtr<IAudioAdapter> audioAdapter;
1908 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1909 ASSERT(audioAdapter);
1910
1911 if (!RTStrICmp(ValueUnion.psz, "sb16"))
1912 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
1913 else if (!RTStrICmp(ValueUnion.psz, "ac97"))
1914 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
1915 else if (!RTStrICmp(ValueUnion.psz, "hda"))
1916 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_HDA));
1917 else
1918 {
1919 errorArgument("Invalid --audiocontroller argument '%s'", ValueUnion.psz);
1920 rc = E_FAIL;
1921 }
1922 break;
1923 }
1924
1925 case MODIFYVM_AUDIO:
1926 {
1927 ComPtr<IAudioAdapter> audioAdapter;
1928 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1929 ASSERT(audioAdapter);
1930
1931 /* disable? */
1932 if (!RTStrICmp(ValueUnion.psz, "none"))
1933 {
1934 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
1935 }
1936 else if (!RTStrICmp(ValueUnion.psz, "null"))
1937 {
1938 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
1939 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1940 }
1941#ifdef RT_OS_WINDOWS
1942#ifdef VBOX_WITH_WINMM
1943 else if (!RTStrICmp(ValueUnion.psz, "winmm"))
1944 {
1945 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
1946 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1947 }
1948#endif
1949 else if (!RTStrICmp(ValueUnion.psz, "dsound"))
1950 {
1951 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
1952 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1953 }
1954#endif /* RT_OS_WINDOWS */
1955#ifdef RT_OS_LINUX
1956# ifdef VBOX_WITH_ALSA
1957 else if (!RTStrICmp(ValueUnion.psz, "alsa"))
1958 {
1959 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
1960 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1961 }
1962# endif
1963# ifdef VBOX_WITH_PULSE
1964 else if (!RTStrICmp(ValueUnion.psz, "pulse"))
1965 {
1966 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1967 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1968 }
1969# endif
1970#endif /* !RT_OS_LINUX */
1971#ifdef RT_OS_SOLARIS
1972 else if (!RTStrICmp(ValueUnion.psz, "solaudio"))
1973 {
1974 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
1975 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1976 }
1977#endif /* !RT_OS_SOLARIS */
1978#ifdef RT_OS_FREEBSD
1979 else if (!RTStrICmp(ValueUnion.psz, "oss"))
1980 {
1981 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1982 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1983 }
1984# ifdef VBOX_WITH_PULSE
1985 else if (!RTStrICmp(ValueUnion.psz, "pulse"))
1986 {
1987 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1988 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1989 }
1990# endif
1991#endif /* !RT_OS_FREEBSD */
1992#ifdef RT_OS_DARWIN
1993 else if (!RTStrICmp(ValueUnion.psz, "coreaudio"))
1994 {
1995 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
1996 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1997 }
1998
1999#endif /* !RT_OS_DARWIN */
2000# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(VBOX_WITH_SOLARIS_OSS)
2001 else if (!RTStrICmp(ValueUnion.psz, "oss"))
2002 {
2003 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
2004 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2005 }
2006# endif
2007 else
2008 {
2009 errorArgument("Invalid --audio argument '%s'", ValueUnion.psz);
2010 rc = E_FAIL;
2011 }
2012 break;
2013 }
2014
2015 case MODIFYVM_CLIPBOARD:
2016 {
2017 ClipboardMode_T mode;
2018 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2019 mode = ClipboardMode_Disabled;
2020 else if (!RTStrICmp(ValueUnion.psz, "hosttoguest"))
2021 mode = ClipboardMode_HostToGuest;
2022 else if (!RTStrICmp(ValueUnion.psz, "guesttohost"))
2023 mode = ClipboardMode_GuestToHost;
2024 else if (!RTStrICmp(ValueUnion.psz, "bidirectional"))
2025 mode = ClipboardMode_Bidirectional;
2026 else
2027 {
2028 errorArgument("Invalid --clipboard argument '%s'", ValueUnion.psz);
2029 rc = E_FAIL;
2030 }
2031 if (SUCCEEDED(rc))
2032 {
2033 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(mode));
2034 }
2035 break;
2036 }
2037
2038 case MODIFYVM_DRAGANDDROP:
2039 {
2040 DragAndDropMode_T mode;
2041 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2042 mode = DragAndDropMode_Disabled;
2043 else if (!RTStrICmp(ValueUnion.psz, "hosttoguest"))
2044 mode = DragAndDropMode_HostToGuest;
2045 else if (!RTStrICmp(ValueUnion.psz, "guesttohost"))
2046 mode = DragAndDropMode_GuestToHost;
2047 else if (!RTStrICmp(ValueUnion.psz, "bidirectional"))
2048 mode = DragAndDropMode_Bidirectional;
2049 else
2050 {
2051 errorArgument("Invalid --draganddrop argument '%s'", ValueUnion.psz);
2052 rc = E_FAIL;
2053 }
2054 if (SUCCEEDED(rc))
2055 {
2056 CHECK_ERROR(machine, COMSETTER(DragAndDropMode)(mode));
2057 }
2058 break;
2059 }
2060
2061 case MODIFYVM_VRDE_EXTPACK:
2062 {
2063 ComPtr<IVRDEServer> vrdeServer;
2064 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2065 ASSERT(vrdeServer);
2066
2067 if (vrdeServer)
2068 {
2069 if (RTStrICmp(ValueUnion.psz, "default") != 0)
2070 {
2071 Bstr bstr(ValueUnion.psz);
2072 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(bstr.raw()));
2073 }
2074 else
2075 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(Bstr().raw()));
2076 }
2077 break;
2078 }
2079
2080 case MODIFYVM_VRDEPROPERTY:
2081 {
2082 ComPtr<IVRDEServer> vrdeServer;
2083 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2084 ASSERT(vrdeServer);
2085
2086 if (vrdeServer)
2087 {
2088 /* Parse 'name=value' */
2089 char *pszProperty = RTStrDup(ValueUnion.psz);
2090 if (pszProperty)
2091 {
2092 char *pDelimiter = strchr(pszProperty, '=');
2093 if (pDelimiter)
2094 {
2095 *pDelimiter = '\0';
2096
2097 Bstr bstrName = pszProperty;
2098 Bstr bstrValue = &pDelimiter[1];
2099 CHECK_ERROR(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
2100 }
2101 else
2102 {
2103 RTStrFree(pszProperty);
2104
2105 errorArgument("Invalid --vrdeproperty argument '%s'", ValueUnion.psz);
2106 rc = E_FAIL;
2107 break;
2108 }
2109 RTStrFree(pszProperty);
2110 }
2111 else
2112 {
2113 RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for VRDE property '%s'\n", ValueUnion.psz);
2114 rc = E_FAIL;
2115 }
2116 }
2117 break;
2118 }
2119
2120 case MODIFYVM_VRDPPORT:
2121 vrdeWarningDeprecatedOption("port");
2122
2123 case MODIFYVM_VRDEPORT:
2124 {
2125 ComPtr<IVRDEServer> vrdeServer;
2126 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2127 ASSERT(vrdeServer);
2128
2129 if (!RTStrICmp(ValueUnion.psz, "default"))
2130 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr("0").raw()));
2131 else
2132 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr(ValueUnion.psz).raw()));
2133 break;
2134 }
2135
2136 case MODIFYVM_VRDPADDRESS:
2137 vrdeWarningDeprecatedOption("address");
2138
2139 case MODIFYVM_VRDEADDRESS:
2140 {
2141 ComPtr<IVRDEServer> vrdeServer;
2142 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2143 ASSERT(vrdeServer);
2144
2145 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Address").raw(), Bstr(ValueUnion.psz).raw()));
2146 break;
2147 }
2148
2149 case MODIFYVM_VRDPAUTHTYPE:
2150 vrdeWarningDeprecatedOption("authtype");
2151 case MODIFYVM_VRDEAUTHTYPE:
2152 {
2153 ComPtr<IVRDEServer> vrdeServer;
2154 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2155 ASSERT(vrdeServer);
2156
2157 if (!RTStrICmp(ValueUnion.psz, "null"))
2158 {
2159 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Null));
2160 }
2161 else if (!RTStrICmp(ValueUnion.psz, "external"))
2162 {
2163 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_External));
2164 }
2165 else if (!RTStrICmp(ValueUnion.psz, "guest"))
2166 {
2167 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Guest));
2168 }
2169 else
2170 {
2171 errorArgument("Invalid --vrdeauthtype argument '%s'", ValueUnion.psz);
2172 rc = E_FAIL;
2173 }
2174 break;
2175 }
2176
2177 case MODIFYVM_VRDEAUTHLIBRARY:
2178 {
2179 ComPtr<IVRDEServer> vrdeServer;
2180 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2181 ASSERT(vrdeServer);
2182
2183 if (vrdeServer)
2184 {
2185 if (RTStrICmp(ValueUnion.psz, "default") != 0)
2186 {
2187 Bstr bstr(ValueUnion.psz);
2188 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(bstr.raw()));
2189 }
2190 else
2191 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(Bstr().raw()));
2192 }
2193 break;
2194 }
2195
2196 case MODIFYVM_VRDPMULTICON:
2197 vrdeWarningDeprecatedOption("multicon");
2198 case MODIFYVM_VRDEMULTICON:
2199 {
2200 ComPtr<IVRDEServer> vrdeServer;
2201 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2202 ASSERT(vrdeServer);
2203
2204 CHECK_ERROR(vrdeServer, COMSETTER(AllowMultiConnection)(ValueUnion.f));
2205 break;
2206 }
2207
2208 case MODIFYVM_VRDPREUSECON:
2209 vrdeWarningDeprecatedOption("reusecon");
2210 case MODIFYVM_VRDEREUSECON:
2211 {
2212 ComPtr<IVRDEServer> vrdeServer;
2213 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2214 ASSERT(vrdeServer);
2215
2216 CHECK_ERROR(vrdeServer, COMSETTER(ReuseSingleConnection)(ValueUnion.f));
2217 break;
2218 }
2219
2220 case MODIFYVM_VRDPVIDEOCHANNEL:
2221 vrdeWarningDeprecatedOption("videochannel");
2222 case MODIFYVM_VRDEVIDEOCHANNEL:
2223 {
2224 ComPtr<IVRDEServer> vrdeServer;
2225 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2226 ASSERT(vrdeServer);
2227
2228 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Enabled").raw(),
2229 ValueUnion.f? Bstr("true").raw(): Bstr("false").raw()));
2230 break;
2231 }
2232
2233 case MODIFYVM_VRDPVIDEOCHANNELQUALITY:
2234 vrdeWarningDeprecatedOption("videochannelquality");
2235 case MODIFYVM_VRDEVIDEOCHANNELQUALITY:
2236 {
2237 ComPtr<IVRDEServer> vrdeServer;
2238 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2239 ASSERT(vrdeServer);
2240
2241 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Quality").raw(),
2242 Bstr(ValueUnion.psz).raw()));
2243 break;
2244 }
2245
2246 case MODIFYVM_VRDP:
2247 vrdeWarningDeprecatedOption("");
2248 case MODIFYVM_VRDE:
2249 {
2250 ComPtr<IVRDEServer> vrdeServer;
2251 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2252 ASSERT(vrdeServer);
2253
2254 CHECK_ERROR(vrdeServer, COMSETTER(Enabled)(ValueUnion.f));
2255 break;
2256 }
2257
2258 case MODIFYVM_USBEHCI:
2259 {
2260 ComPtr<IUSBController> UsbCtl;
2261 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
2262 if (SUCCEEDED(rc))
2263 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEHCI)(ValueUnion.f));
2264 break;
2265 }
2266
2267 case MODIFYVM_USB:
2268 {
2269 ComPtr<IUSBController> UsbCtl;
2270 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
2271 if (SUCCEEDED(rc))
2272 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(ValueUnion.f));
2273 break;
2274 }
2275
2276 case MODIFYVM_SNAPSHOTFOLDER:
2277 {
2278 if (!RTStrICmp(ValueUnion.psz, "default"))
2279 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr().raw()));
2280 else
2281 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(ValueUnion.psz).raw()));
2282 break;
2283 }
2284
2285 case MODIFYVM_TELEPORTER_ENABLED:
2286 {
2287 CHECK_ERROR(machine, COMSETTER(TeleporterEnabled)(ValueUnion.f));
2288 break;
2289 }
2290
2291 case MODIFYVM_TELEPORTER_PORT:
2292 {
2293 CHECK_ERROR(machine, COMSETTER(TeleporterPort)(ValueUnion.u32));
2294 break;
2295 }
2296
2297 case MODIFYVM_TELEPORTER_ADDRESS:
2298 {
2299 CHECK_ERROR(machine, COMSETTER(TeleporterAddress)(Bstr(ValueUnion.psz).raw()));
2300 break;
2301 }
2302
2303 case MODIFYVM_TELEPORTER_PASSWORD:
2304 {
2305 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(ValueUnion.psz).raw()));
2306 break;
2307 }
2308
2309 case MODIFYVM_TELEPORTER_PASSWORD_FILE:
2310 {
2311 Utf8Str password;
2312 RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &password);
2313 if (rcExit != RTEXITCODE_SUCCESS)
2314 rc = E_FAIL;
2315 else
2316 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(password).raw()));
2317 break;
2318 }
2319
2320 case MODIFYVM_TRACING_ENABLED:
2321 {
2322 CHECK_ERROR(machine, COMSETTER(TracingEnabled)(ValueUnion.f));
2323 break;
2324 }
2325
2326 case MODIFYVM_TRACING_CONFIG:
2327 {
2328 CHECK_ERROR(machine, COMSETTER(TracingConfig)(Bstr(ValueUnion.psz).raw()));
2329 break;
2330 }
2331
2332 case MODIFYVM_TRACING_ALLOW_VM_ACCESS:
2333 {
2334 CHECK_ERROR(machine, COMSETTER(AllowTracingToAccessVM)(ValueUnion.f));
2335 break;
2336 }
2337
2338 case MODIFYVM_FAULT_TOLERANCE:
2339 {
2340 if (!RTStrICmp(ValueUnion.psz, "master"))
2341 {
2342 CHECK_ERROR(machine, COMSETTER(FaultToleranceState(FaultToleranceState_Master)));
2343 }
2344 else
2345 if (!RTStrICmp(ValueUnion.psz, "standby"))
2346 {
2347 CHECK_ERROR(machine, COMSETTER(FaultToleranceState(FaultToleranceState_Standby)));
2348 }
2349 else
2350 {
2351 errorArgument("Invalid --faulttolerance argument '%s'", ValueUnion.psz);
2352 rc = E_FAIL;
2353 }
2354 break;
2355 }
2356
2357 case MODIFYVM_FAULT_TOLERANCE_ADDRESS:
2358 {
2359 CHECK_ERROR(machine, COMSETTER(FaultToleranceAddress)(Bstr(ValueUnion.psz).raw()));
2360 break;
2361 }
2362
2363 case MODIFYVM_FAULT_TOLERANCE_PORT:
2364 {
2365 CHECK_ERROR(machine, COMSETTER(FaultTolerancePort)(ValueUnion.u32));
2366 break;
2367 }
2368
2369 case MODIFYVM_FAULT_TOLERANCE_PASSWORD:
2370 {
2371 CHECK_ERROR(machine, COMSETTER(FaultTolerancePassword)(Bstr(ValueUnion.psz).raw()));
2372 break;
2373 }
2374
2375 case MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL:
2376 {
2377 CHECK_ERROR(machine, COMSETTER(FaultToleranceSyncInterval)(ValueUnion.u32));
2378 break;
2379 }
2380
2381 case MODIFYVM_HARDWARE_UUID:
2382 {
2383 CHECK_ERROR(machine, COMSETTER(HardwareUUID)(Bstr(ValueUnion.psz).raw()));
2384 break;
2385 }
2386
2387 case MODIFYVM_HPET:
2388 {
2389 CHECK_ERROR(machine, COMSETTER(HPETEnabled)(ValueUnion.f));
2390 break;
2391 }
2392
2393 case MODIFYVM_IOCACHE:
2394 {
2395 CHECK_ERROR(machine, COMSETTER(IOCacheEnabled)(ValueUnion.f));
2396 break;
2397 }
2398
2399 case MODIFYVM_IOCACHESIZE:
2400 {
2401 CHECK_ERROR(machine, COMSETTER(IOCacheSize)(ValueUnion.u32));
2402 break;
2403 }
2404
2405 case MODIFYVM_CHIPSET:
2406 {
2407 if (!RTStrICmp(ValueUnion.psz, "piix3"))
2408 {
2409 CHECK_ERROR(machine, COMSETTER(ChipsetType)(ChipsetType_PIIX3));
2410 }
2411 else if (!RTStrICmp(ValueUnion.psz, "ich9"))
2412 {
2413 CHECK_ERROR(machine, COMSETTER(ChipsetType)(ChipsetType_ICH9));
2414 BOOL fIoApic = FALSE;
2415 CHECK_ERROR(biosSettings, COMGETTER(IOAPICEnabled)(&fIoApic));
2416 if (!fIoApic)
2417 {
2418 RTStrmPrintf(g_pStdErr, "*** I/O APIC must be enabled for ICH9, enabling. ***\n");
2419 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(TRUE));
2420 }
2421 }
2422 else
2423 {
2424 errorArgument("Invalid --chipset argument '%s' (valid: piix3,ich9)", ValueUnion.psz);
2425 rc = E_FAIL;
2426 }
2427 break;
2428 }
2429#ifdef VBOX_WITH_VPX
2430 case MODIFYVM_VCP:
2431 {
2432 CHECK_ERROR(machine, COMSETTER(VideoCaptureEnabled)(ValueUnion.f));
2433 break;
2434 }
2435 case MODIFYVM_VCP_FILENAME:
2436 {
2437 Bstr bstr(ValueUnion.psz);
2438 CHECK_ERROR(machine, COMSETTER(VideoCaptureFile)(bstr.raw()));
2439 break;
2440 }
2441 case MODIFYVM_VCP_WIDTH:
2442 {
2443 CHECK_ERROR(machine, COMSETTER(VideoCaptureWidth)(ValueUnion.u32));
2444 break;
2445 }
2446 case MODIFYVM_VCP_HEIGHT:
2447 {
2448 CHECK_ERROR(machine, COMSETTER(VideoCaptureHeight)(ValueUnion.u32));
2449 break;
2450 }
2451 case MODIFYVM_VCP_RATE:
2452 {
2453 CHECK_ERROR(machine, COMSETTER(VideoCaptureRate)(ValueUnion.u32));
2454 break;
2455 }
2456 case MODIFYVM_VCP_FPS:
2457 {
2458 CHECK_ERROR(machine, COMSETTER(VideoCaptureFps)(ValueUnion.u32));
2459 break;
2460 }
2461#endif
2462 case MODIFYVM_AUTOSTART_ENABLED:
2463 {
2464 CHECK_ERROR(machine, COMSETTER(AutostartEnabled)(ValueUnion.f));
2465 break;
2466 }
2467
2468 case MODIFYVM_AUTOSTART_DELAY:
2469 {
2470 CHECK_ERROR(machine, COMSETTER(AutostartDelay)(ValueUnion.u32));
2471 break;
2472 }
2473
2474 case MODIFYVM_AUTOSTOP_TYPE:
2475 {
2476 AutostopType_T enmAutostopType = AutostopType_Disabled;
2477
2478 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2479 enmAutostopType = AutostopType_Disabled;
2480 else if (!RTStrICmp(ValueUnion.psz, "savestate"))
2481 enmAutostopType = AutostopType_SaveState;
2482 else if (!RTStrICmp(ValueUnion.psz, "poweroff"))
2483 enmAutostopType = AutostopType_PowerOff;
2484 else if (!RTStrICmp(ValueUnion.psz, "acpishutdown"))
2485 enmAutostopType = AutostopType_AcpiShutdown;
2486 else
2487 {
2488 errorArgument("Invalid --autostop-type argument '%s' (valid: disabled, savestate, poweroff, acpishutdown)", ValueUnion.psz);
2489 rc = E_FAIL;
2490 }
2491
2492 if (SUCCEEDED(rc))
2493 CHECK_ERROR(machine, COMSETTER(AutostopType)(enmAutostopType));
2494 break;
2495 }
2496#ifdef VBOX_WITH_PCI_PASSTHROUGH
2497 case MODIFYVM_ATTACH_PCI:
2498 {
2499 const char* pAt = strchr(ValueUnion.psz, '@');
2500 int32_t iHostAddr, iGuestAddr;
2501
2502 iHostAddr = parsePci(ValueUnion.psz);
2503 iGuestAddr = pAt != NULL ? parsePci(pAt + 1) : iHostAddr;
2504
2505 if (iHostAddr == -1 || iGuestAddr == -1)
2506 {
2507 errorArgument("Invalid --pciattach argument '%s' (valid: 'HB:HD.HF@GB:GD.GF' or just 'HB:HD.HF')", ValueUnion.psz);
2508 rc = E_FAIL;
2509 }
2510 else
2511 {
2512 CHECK_ERROR(machine, AttachHostPCIDevice(iHostAddr, iGuestAddr, TRUE));
2513 }
2514
2515 break;
2516 }
2517 case MODIFYVM_DETACH_PCI:
2518 {
2519 int32_t iHostAddr;
2520
2521 iHostAddr = parsePci(ValueUnion.psz);
2522 if (iHostAddr == -1)
2523 {
2524 errorArgument("Invalid --pcidetach argument '%s' (valid: 'HB:HD.HF')", ValueUnion.psz);
2525 rc = E_FAIL;
2526 }
2527 else
2528 {
2529 CHECK_ERROR(machine, DetachHostPCIDevice(iHostAddr));
2530 }
2531
2532 break;
2533 }
2534#endif
2535
2536#ifdef VBOX_WITH_USB_VIDEO
2537 case MODIFYVM_USBWEBCAM:
2538 {
2539 CHECK_ERROR(machine, COMSETTER(EmulatedUSBWebcameraEnabled)(ValueUnion.f));
2540 break;
2541 }
2542#endif /* VBOX_WITH_USB_VIDEO */
2543
2544#ifdef VBOX_WITH_USB_CARDREADER
2545 case MODIFYVM_USBCARDREADER:
2546 {
2547 CHECK_ERROR(machine, COMSETTER(EmulatedUSBCardReaderEnabled)(ValueUnion.f));
2548 break;
2549 }
2550#endif /* VBOX_WITH_USB_CARDREADER */
2551
2552 case MODIFYVM_DEFAULTFRONTEND:
2553 {
2554 Bstr bstr(ValueUnion.psz);
2555 if (bstr == "default")
2556 bstr = Bstr::Empty;
2557 CHECK_ERROR(machine, COMSETTER(DefaultFrontend)(bstr.raw()));
2558 break;
2559 }
2560
2561 default:
2562 {
2563 errorGetOpt(USAGE_MODIFYVM, c, &ValueUnion);
2564 rc = E_FAIL;
2565 break;
2566 }
2567 }
2568 }
2569
2570 /* commit changes */
2571 if (SUCCEEDED(rc))
2572 CHECK_ERROR(machine, SaveSettings());
2573
2574 /* it's important to always close sessions */
2575 a->session->UnlockMachine();
2576
2577 return SUCCEEDED(rc) ? 0 : 1;
2578}
2579
2580#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