VirtualBox

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

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

Main/EncodeAndVideoRecording Module and API implementation: Integrating an independent encoding and video recording module that will serve all the frontends.
Introducing settings settings and API implementation for accessing and modifying video recording parameters:
->target video capture file
->video capture width
->video capture height
->enable video capturing

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