VirtualBox

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

Last change on this file since 29455 was 29218, checked in by vboxsync, 15 years ago

Main/Settings: Drop global iomgr and iobackend settings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 82.1 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 29218 2010-05-07 14:52:27Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of modifyvm command.
4 */
5
6/*
7 * Copyright (C) 2006-2009 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
30#include <vector>
31#include <list>
32#endif /* !VBOX_ONLY_DOCS */
33
34#include <iprt/cidr.h>
35#include <iprt/param.h>
36#include <iprt/path.h>
37#include <iprt/stream.h>
38#include <iprt/string.h>
39#include <iprt/getopt.h>
40#include <VBox/log.h>
41
42#include "VBoxManage.h"
43
44#ifndef VBOX_ONLY_DOCS
45using namespace com;
46
47
48/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
49#if defined(_MSC_VER)
50# pragma optimize("g", off)
51#endif
52
53enum
54{
55 MODIFYVM_NAME = 1000,
56 MODIFYVM_OSTYPE,
57 MODIFYVM_MEMORY,
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_NICTYPE,
106 MODIFYVM_NICSPEED,
107 MODIFYVM_NICBOOTPRIO,
108 MODIFYVM_NIC,
109 MODIFYVM_CABLECONNECTED,
110 MODIFYVM_BRIDGEADAPTER,
111 MODIFYVM_HOSTONLYADAPTER,
112 MODIFYVM_INTNET,
113 MODIFYVM_NATNET,
114#ifdef VBOX_WITH_VDE
115 MODIFYVM_VDENET,
116#endif
117 MODIFYVM_NATBINDIP,
118 MODIFYVM_NATSETTINGS,
119 MODIFYVM_NATPF,
120 MODIFYVM_NATALIASMODE,
121 MODIFYVM_NATTFTPPREFIX,
122 MODIFYVM_NATTFTPFILE,
123 MODIFYVM_NATTFTPSERVER,
124 MODIFYVM_NATDNSPASSDOMAIN,
125 MODIFYVM_NATDNSPROXY,
126 MODIFYVM_NATDNSHOSTRESOLVER,
127 MODIFYVM_MACADDRESS,
128 MODIFYVM_HIDPTR,
129 MODIFYVM_HIDKBD,
130 MODIFYVM_UARTMODE,
131 MODIFYVM_UART,
132 MODIFYVM_GUESTMEMORYBALLOON,
133 MODIFYVM_AUDIOCONTROLLER,
134 MODIFYVM_AUDIO,
135 MODIFYVM_CLIPBOARD,
136#ifdef VBOX_WITH_VRDP
137 MODIFYVM_VRDPPORT,
138 MODIFYVM_VRDPADDRESS,
139 MODIFYVM_VRDPAUTHTYPE,
140 MODIFYVM_VRDPMULTICON,
141 MODIFYVM_VRDPREUSECON,
142 MODIFYVM_VRDPVIDEOCHANNEL,
143 MODIFYVM_VRDPVIDEOCHANNELQUALITY,
144 MODIFYVM_VRDP,
145#endif
146 MODIFYVM_RTCUSEUTC,
147 MODIFYVM_USBEHCI,
148 MODIFYVM_USB,
149 MODIFYVM_SNAPSHOTFOLDER,
150 MODIFYVM_TELEPORTER_ENABLED,
151 MODIFYVM_TELEPORTER_PORT,
152 MODIFYVM_TELEPORTER_ADDRESS,
153 MODIFYVM_TELEPORTER_PASSWORD,
154 MODIFYVM_HARDWARE_UUID,
155 MODIFYVM_HPET,
156 MODIFYVM_IOCACHE,
157 MODIFYVM_IOCACHESIZE,
158 MODIFYVM_IOBANDWIDTHMAX
159};
160
161static const RTGETOPTDEF g_aModifyVMOptions[] =
162{
163 { "--name", MODIFYVM_NAME, RTGETOPT_REQ_STRING },
164 { "--ostype", MODIFYVM_OSTYPE, RTGETOPT_REQ_STRING },
165 { "--memory", MODIFYVM_MEMORY, RTGETOPT_REQ_UINT32 },
166 { "--vram", MODIFYVM_VRAM, RTGETOPT_REQ_UINT32 },
167 { "--firmware", MODIFYVM_FIRMWARE, RTGETOPT_REQ_STRING },
168 { "--acpi", MODIFYVM_ACPI, RTGETOPT_REQ_BOOL_ONOFF },
169 { "--ioapic", MODIFYVM_IOAPIC, RTGETOPT_REQ_BOOL_ONOFF },
170 { "--pae", MODIFYVM_PAE, RTGETOPT_REQ_BOOL_ONOFF },
171 { "--synthcpu", MODIFYVM_SYNTHCPU, RTGETOPT_REQ_BOOL_ONOFF },
172 { "--hwvirtex", MODIFYVM_HWVIRTEX, RTGETOPT_REQ_BOOL_ONOFF },
173 { "--hwvirtexexcl", MODIFYVM_HWVIRTEXEXCLUSIVE, RTGETOPT_REQ_BOOL_ONOFF },
174 { "--nestedpaging", MODIFYVM_NESTEDPAGING, RTGETOPT_REQ_BOOL_ONOFF },
175 { "--largepages", MODIFYVM_LARGEPAGES, RTGETOPT_REQ_BOOL_ONOFF },
176 { "--vtxvpid", MODIFYVM_VTXVPID, RTGETOPT_REQ_BOOL_ONOFF },
177 { "--cpuidset", MODIFYVM_SETCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
178 { "--cpuidremove", MODIFYVM_DELCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
179 { "--cpuidremoveall", MODIFYVM_DELALLCPUID, RTGETOPT_REQ_NOTHING},
180 { "--cpus", MODIFYVM_CPUS, RTGETOPT_REQ_UINT32 },
181 { "--cpuhotplug", MODIFYVM_CPUHOTPLUG, RTGETOPT_REQ_BOOL_ONOFF },
182 { "--plugcpu", MODIFYVM_PLUGCPU, RTGETOPT_REQ_UINT32 },
183 { "--unplugcpu", MODIFYVM_UNPLUGCPU, RTGETOPT_REQ_UINT32 },
184 { "--rtcuseutc", MODIFYVM_RTCUSEUTC, RTGETOPT_REQ_BOOL_ONOFF },
185 { "--monitorcount", MODIFYVM_MONITORCOUNT, RTGETOPT_REQ_UINT32 },
186 { "--accelerate3d", MODIFYVM_ACCELERATE3D, RTGETOPT_REQ_BOOL_ONOFF },
187#ifdef VBOX_WITH_VIDEOHWACCEL
188 { "--accelerate2dvideo", MODIFYVM_ACCELERATE2DVIDEO, RTGETOPT_REQ_BOOL_ONOFF },
189#endif
190 { "--bioslogofadein", MODIFYVM_BIOSLOGOFADEIN, RTGETOPT_REQ_BOOL_ONOFF },
191 { "--bioslogofadeout", MODIFYVM_BIOSLOGOFADEOUT, RTGETOPT_REQ_BOOL_ONOFF },
192 { "--bioslogodisplaytime", MODIFYVM_BIOSLOGODISPLAYTIME, RTGETOPT_REQ_UINT32 },
193 { "--bioslogoimagepath", MODIFYVM_BIOSLOGOIMAGEPATH, RTGETOPT_REQ_STRING },
194 { "--biosbootmenu", MODIFYVM_BIOSBOOTMENU, RTGETOPT_REQ_STRING },
195 { "--biossystemtimeoffset", MODIFYVM_BIOSSYSTEMTIMEOFFSET, RTGETOPT_REQ_INT64 },
196 { "--biospxedebug", MODIFYVM_BIOSPXEDEBUG, RTGETOPT_REQ_BOOL_ONOFF },
197 { "--boot", MODIFYVM_BOOT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
198 { "--hda", MODIFYVM_HDA, RTGETOPT_REQ_STRING },
199 { "--hdb", MODIFYVM_HDB, RTGETOPT_REQ_STRING },
200 { "--hdd", MODIFYVM_HDD, RTGETOPT_REQ_STRING },
201 { "--idecontroller", MODIFYVM_IDECONTROLLER, RTGETOPT_REQ_STRING },
202 { "--sataideemulation", MODIFYVM_SATAIDEEMULATION, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
203 { "--sataportcount", MODIFYVM_SATAPORTCOUNT, RTGETOPT_REQ_UINT32 },
204 { "--sataport", MODIFYVM_SATAPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
205 { "--sata", MODIFYVM_SATA, RTGETOPT_REQ_STRING },
206 { "--scsiport", MODIFYVM_SCSIPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
207 { "--scsitype", MODIFYVM_SCSITYPE, RTGETOPT_REQ_STRING },
208 { "--scsi", MODIFYVM_SCSI, RTGETOPT_REQ_STRING },
209 { "--dvdpassthrough", MODIFYVM_DVDPASSTHROUGH, RTGETOPT_REQ_STRING },
210 { "--dvd", MODIFYVM_DVD, RTGETOPT_REQ_STRING },
211 { "--floppy", MODIFYVM_FLOPPY, RTGETOPT_REQ_STRING },
212 { "--nictracefile", MODIFYVM_NICTRACEFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
213 { "--nictrace", MODIFYVM_NICTRACE, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
214 { "--nictype", MODIFYVM_NICTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
215 { "--nicspeed", MODIFYVM_NICSPEED, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
216 { "--nicbootprio", MODIFYVM_NICBOOTPRIO, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
217 { "--nic", MODIFYVM_NIC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
218 { "--cableconnected", MODIFYVM_CABLECONNECTED, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
219 { "--bridgeadapter", MODIFYVM_BRIDGEADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
220 { "--hostonlyadapter", MODIFYVM_HOSTONLYADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
221 { "--intnet", MODIFYVM_INTNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
222 { "--natnet", MODIFYVM_NATNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
223#ifdef VBOX_WITH_VDE
224 { "--vdenet", MODIFYVM_VDENET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
225#endif
226 { "--natbindip", MODIFYVM_NATBINDIP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
227 { "--natsettings", MODIFYVM_NATSETTINGS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
228 { "--natpf", MODIFYVM_NATPF, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
229 { "--nataliasmode", MODIFYVM_NATALIASMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
230 { "--nattftpprefix", MODIFYVM_NATTFTPPREFIX, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
231 { "--nattftpfile", MODIFYVM_NATTFTPFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
232 { "--nattftpserver", MODIFYVM_NATTFTPSERVER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
233 { "--natdnspassdomain", MODIFYVM_NATDNSPASSDOMAIN, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
234 { "--natdnsproxy", MODIFYVM_NATDNSPROXY, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
235 { "--natdnshostresolver", MODIFYVM_NATDNSHOSTRESOLVER, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
236 { "--macaddress", MODIFYVM_MACADDRESS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
237 { "--mouse", MODIFYVM_HIDPTR, RTGETOPT_REQ_STRING },
238 { "--keyboard", MODIFYVM_HIDKBD, RTGETOPT_REQ_STRING },
239 { "--uartmode", MODIFYVM_UARTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
240 { "--uart", MODIFYVM_UART, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
241 { "--guestmemoryballoon", MODIFYVM_GUESTMEMORYBALLOON, RTGETOPT_REQ_UINT32 },
242 { "--audiocontroller", MODIFYVM_AUDIOCONTROLLER, RTGETOPT_REQ_STRING },
243 { "--audio", MODIFYVM_AUDIO, RTGETOPT_REQ_STRING },
244 { "--clipboard", MODIFYVM_CLIPBOARD, RTGETOPT_REQ_STRING },
245#ifdef VBOX_WITH_VRDP
246 { "--vrdpport", MODIFYVM_VRDPPORT, RTGETOPT_REQ_STRING },
247 { "--vrdpaddress", MODIFYVM_VRDPADDRESS, RTGETOPT_REQ_STRING },
248 { "--vrdpauthtype", MODIFYVM_VRDPAUTHTYPE, RTGETOPT_REQ_STRING },
249 { "--vrdpmulticon", MODIFYVM_VRDPMULTICON, RTGETOPT_REQ_BOOL_ONOFF },
250 { "--vrdpreusecon", MODIFYVM_VRDPREUSECON, RTGETOPT_REQ_BOOL_ONOFF },
251 { "--vrdpvideochannel", MODIFYVM_VRDPVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF },
252 { "--vrdpvideochannelquality", MODIFYVM_VRDPVIDEOCHANNELQUALITY, RTGETOPT_REQ_UINT32 },
253 { "--vrdp", MODIFYVM_VRDP, RTGETOPT_REQ_BOOL_ONOFF },
254#endif
255 { "--usbehci", MODIFYVM_USBEHCI, RTGETOPT_REQ_BOOL_ONOFF },
256 { "--usb", MODIFYVM_USB, RTGETOPT_REQ_BOOL_ONOFF },
257 { "--snapshotfolder", MODIFYVM_SNAPSHOTFOLDER, RTGETOPT_REQ_STRING },
258 { "--teleporter", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
259 { "--teleporterenabled", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
260 { "--teleporterport", MODIFYVM_TELEPORTER_PORT, RTGETOPT_REQ_UINT32 },
261 { "--teleporteraddress", MODIFYVM_TELEPORTER_ADDRESS, RTGETOPT_REQ_STRING },
262 { "--teleporterpassword", MODIFYVM_TELEPORTER_PASSWORD, RTGETOPT_REQ_STRING },
263 { "--hardwareuuid", MODIFYVM_HARDWARE_UUID, RTGETOPT_REQ_STRING },
264 { "--hpet", MODIFYVM_HPET, RTGETOPT_REQ_BOOL_ONOFF },
265 { "--iocache", MODIFYVM_IOCACHE, RTGETOPT_REQ_BOOL_ONOFF },
266 { "--iocachesize", MODIFYVM_IOCACHESIZE, RTGETOPT_REQ_UINT32 },
267 { "--iobandwidthmax", MODIFYVM_IOBANDWIDTHMAX, RTGETOPT_REQ_UINT32 },
268};
269
270int handleModifyVM(HandlerArg *a)
271{
272 int c;
273 HRESULT rc;
274 Bstr name;
275 Bstr machineuuid (a->argv[0]);
276 RTGETOPTUNION ValueUnion;
277 RTGETOPTSTATE GetOptState;
278 ComPtr <IMachine> machine;
279 ComPtr <IBIOSSettings> biosSettings;
280
281 /* VM ID + at least one parameter. Parameter arguments are checked
282 * individually. */
283 if (a->argc < 2)
284 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
285
286 /* Get the number of network adapters */
287 ULONG NetworkAdapterCount = 0;
288 {
289 ComPtr <ISystemProperties> info;
290 CHECK_ERROR_RET(a->virtualBox, COMGETTER(SystemProperties)(info.asOutParam()), 1);
291 CHECK_ERROR_RET(info, COMGETTER(NetworkAdapterCount)(&NetworkAdapterCount), 1);
292 }
293 ULONG SerialPortCount = 0;
294 {
295 ComPtr <ISystemProperties> info;
296 CHECK_ERROR_RET(a->virtualBox, COMGETTER(SystemProperties)(info.asOutParam()), 1);
297 CHECK_ERROR_RET(info, COMGETTER(SerialPortCount)(&SerialPortCount), 1);
298 }
299
300 /* try to find the given machine */
301 if (!Guid(machineuuid).isEmpty())
302 {
303 CHECK_ERROR_RET(a->virtualBox, GetMachine(machineuuid, machine.asOutParam()), 1);
304 }
305 else
306 {
307 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()), 1);
308 machine->COMGETTER(Id)(machineuuid.asOutParam());
309 }
310
311 /* open a session for the VM */
312 CHECK_ERROR_RET(a->virtualBox, OpenSession(a->session, machineuuid), 1);
313
314 /* get the mutable session machine */
315 a->session->COMGETTER(Machine)(machine.asOutParam());
316 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
317
318 RTGetOptInit(&GetOptState, a->argc, a->argv, g_aModifyVMOptions,
319 RT_ELEMENTS(g_aModifyVMOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
320
321 while ( SUCCEEDED (rc)
322 && (c = RTGetOpt(&GetOptState, &ValueUnion)))
323 {
324 switch (c)
325 {
326 case MODIFYVM_NAME:
327 {
328 CHECK_ERROR(machine, COMSETTER(Name)(Bstr(ValueUnion.psz)));
329 break;
330 }
331 case MODIFYVM_OSTYPE:
332 {
333 ComPtr<IGuestOSType> guestOSType;
334 CHECK_ERROR(a->virtualBox, GetGuestOSType(Bstr(ValueUnion.psz), guestOSType.asOutParam()));
335 if (SUCCEEDED(rc) && guestOSType)
336 {
337 CHECK_ERROR(machine, COMSETTER(OSTypeId)(Bstr(ValueUnion.psz)));
338 }
339 else
340 {
341 errorArgument("Invalid guest OS type '%s'", Utf8Str(ValueUnion.psz).raw());
342 rc = E_FAIL;
343 }
344 break;
345 }
346
347 case MODIFYVM_MEMORY:
348 {
349 CHECK_ERROR(machine, COMSETTER(MemorySize)(ValueUnion.u32));
350 break;
351 }
352
353 case MODIFYVM_VRAM:
354 {
355 CHECK_ERROR(machine, COMSETTER(VRAMSize)(ValueUnion.u32));
356 break;
357 }
358
359 case MODIFYVM_FIRMWARE:
360 {
361 if (!strcmp(ValueUnion.psz, "efi"))
362 {
363 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI));
364 }
365 else if (!strcmp(ValueUnion.psz, "efi32"))
366 {
367 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI32));
368 }
369 else if (!strcmp(ValueUnion.psz, "efi64"))
370 {
371 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI64));
372 }
373 else if (!strcmp(ValueUnion.psz, "efidual"))
374 {
375 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFIDUAL));
376 }
377 else if (!strcmp(ValueUnion.psz, "bios"))
378 {
379 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_BIOS));
380 }
381 else
382 {
383 errorArgument("Invalid --firmware argument '%s'", ValueUnion.psz);
384 rc = E_FAIL;
385 }
386 break;
387 }
388
389 case MODIFYVM_ACPI:
390 {
391 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(ValueUnion.f));
392 break;
393 }
394
395 case MODIFYVM_IOAPIC:
396 {
397 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(ValueUnion.f));
398 break;
399 }
400
401 case MODIFYVM_PAE:
402 {
403 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_PAE, ValueUnion.f));
404 break;
405 }
406
407 case MODIFYVM_SYNTHCPU:
408 {
409 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_Synthetic, ValueUnion.f));
410 break;
411 }
412
413 case MODIFYVM_HWVIRTEX:
414 {
415 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Enabled, ValueUnion.f));
416 break;
417 }
418
419 case MODIFYVM_HWVIRTEXEXCLUSIVE:
420 {
421 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Exclusive, ValueUnion.f));
422 break;
423 }
424
425 case MODIFYVM_SETCPUID:
426 {
427 uint32_t id = ValueUnion.u32;
428 uint32_t aValue[4];
429
430 for (unsigned i = 0 ; i < 4 ; i++)
431 {
432 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX);
433 if (RT_FAILURE(vrc))
434 return errorSyntax(USAGE_MODIFYVM,
435 "Missing or Invalid argument to '%s'",
436 GetOptState.pDef->pszLong);
437 aValue[i] = ValueUnion.u32;
438 }
439 CHECK_ERROR(machine, SetCPUIDLeaf(id, aValue[0], aValue[1], aValue[2], aValue[3]));
440 break;
441 }
442
443 case MODIFYVM_DELCPUID:
444 {
445 CHECK_ERROR(machine, RemoveCPUIDLeaf(ValueUnion.u32));
446 break;
447 }
448
449 case MODIFYVM_DELALLCPUID:
450 {
451 CHECK_ERROR(machine, RemoveAllCPUIDLeaves());
452 break;
453 }
454
455 case MODIFYVM_NESTEDPAGING:
456 {
457 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, ValueUnion.f));
458 break;
459 }
460
461 case MODIFYVM_LARGEPAGES:
462 {
463 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_LargePages, ValueUnion.f));
464 break;
465 }
466
467 case MODIFYVM_VTXVPID:
468 {
469 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_VPID, ValueUnion.f));
470 break;
471 }
472
473 case MODIFYVM_CPUS:
474 {
475 CHECK_ERROR(machine, COMSETTER(CPUCount)(ValueUnion.u32));
476 break;
477 }
478
479 case MODIFYVM_RTCUSEUTC:
480 {
481 CHECK_ERROR(machine, COMSETTER(RTCUseUTC)(ValueUnion.f));
482 break;
483 }
484
485 case MODIFYVM_CPUHOTPLUG:
486 {
487 CHECK_ERROR(machine, COMSETTER(CPUHotPlugEnabled)(ValueUnion.f));
488 break;
489 }
490
491 case MODIFYVM_PLUGCPU:
492 {
493 CHECK_ERROR(machine, HotPlugCPU(ValueUnion.u32));
494 break;
495 }
496
497 case MODIFYVM_UNPLUGCPU:
498 {
499 CHECK_ERROR(machine, HotUnplugCPU(ValueUnion.u32));
500 break;
501 }
502
503 case MODIFYVM_MONITORCOUNT:
504 {
505 CHECK_ERROR(machine, COMSETTER(MonitorCount)(ValueUnion.u32));
506 break;
507 }
508
509 case MODIFYVM_ACCELERATE3D:
510 {
511 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(ValueUnion.f));
512 break;
513 }
514
515#ifdef VBOX_WITH_VIDEOHWACCEL
516 case MODIFYVM_ACCELERATE2DVIDEO:
517 {
518 CHECK_ERROR(machine, COMSETTER(Accelerate2DVideoEnabled)(ValueUnion.f));
519 break;
520 }
521#endif
522
523 case MODIFYVM_BIOSLOGOFADEIN:
524 {
525 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(ValueUnion.f));
526 break;
527 }
528
529 case MODIFYVM_BIOSLOGOFADEOUT:
530 {
531 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(ValueUnion.f));
532 break;
533 }
534
535 case MODIFYVM_BIOSLOGODISPLAYTIME:
536 {
537 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(ValueUnion.u32));
538 break;
539 }
540
541 case MODIFYVM_BIOSLOGOIMAGEPATH:
542 {
543 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(ValueUnion.psz)));
544 break;
545 }
546
547 case MODIFYVM_BIOSBOOTMENU:
548 {
549 if (!strcmp(ValueUnion.psz, "disabled"))
550 {
551 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
552 }
553 else if (!strcmp(ValueUnion.psz, "menuonly"))
554 {
555 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
556 }
557 else if (!strcmp(ValueUnion.psz, "messageandmenu"))
558 {
559 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
560 }
561 else
562 {
563 errorArgument("Invalid --biosbootmenu argument '%s'", ValueUnion.psz);
564 rc = E_FAIL;
565 }
566 break;
567 }
568
569 case MODIFYVM_BIOSSYSTEMTIMEOFFSET:
570 {
571 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(ValueUnion.i64));
572 break;
573 }
574
575 case MODIFYVM_BIOSPXEDEBUG:
576 {
577 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(ValueUnion.f));
578 break;
579 }
580
581 case MODIFYVM_BOOT:
582 {
583 if (!strcmp(ValueUnion.psz, "none"))
584 {
585 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Null));
586 }
587 else if (!strcmp(ValueUnion.psz, "floppy"))
588 {
589 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Floppy));
590 }
591 else if (!strcmp(ValueUnion.psz, "dvd"))
592 {
593 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_DVD));
594 }
595 else if (!strcmp(ValueUnion.psz, "disk"))
596 {
597 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_HardDisk));
598 }
599 else if (!strcmp(ValueUnion.psz, "net"))
600 {
601 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Network));
602 }
603 else
604 return errorArgument("Invalid boot device '%s'", ValueUnion.psz);
605 break;
606 }
607
608 case MODIFYVM_HDA: // deprecated
609 {
610 if (!strcmp(ValueUnion.psz, "none"))
611 {
612 machine->DetachDevice(Bstr("IDE Controller"), 0, 0);
613 }
614 else
615 {
616 /* first guess is that it's a UUID */
617 Bstr uuid(ValueUnion.psz);
618 ComPtr<IMedium> hardDisk;
619 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
620 /* not successful? Then it must be a filename */
621 if (!hardDisk)
622 {
623 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
624 if (FAILED(rc))
625 {
626 /* open the new hard disk object */
627 CHECK_ERROR(a->virtualBox,
628 OpenHardDisk(Bstr(ValueUnion.psz),
629 AccessMode_ReadWrite, false, Bstr(""),
630 false, Bstr(""), hardDisk.asOutParam()));
631 }
632 }
633 if (hardDisk)
634 {
635 hardDisk->COMGETTER(Id)(uuid.asOutParam());
636 CHECK_ERROR(machine, AttachDevice(Bstr("IDE Controller"), 0, 0, DeviceType_HardDisk, uuid));
637 }
638 else
639 rc = E_FAIL;
640 }
641 break;
642 }
643
644 case MODIFYVM_HDB: // deprecated
645 {
646 if (!strcmp(ValueUnion.psz, "none"))
647 {
648 machine->DetachDevice(Bstr("IDE Controller"), 0, 1);
649 }
650 else
651 {
652 /* first guess is that it's a UUID */
653 Bstr uuid(ValueUnion.psz);
654 ComPtr<IMedium> hardDisk;
655 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
656 /* not successful? Then it must be a filename */
657 if (!hardDisk)
658 {
659 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
660 if (FAILED(rc))
661 {
662 /* open the new hard disk object */
663 CHECK_ERROR(a->virtualBox,
664 OpenHardDisk(Bstr(ValueUnion.psz),
665 AccessMode_ReadWrite, false, Bstr(""),
666 false, Bstr(""), hardDisk.asOutParam()));
667 }
668 }
669 if (hardDisk)
670 {
671 hardDisk->COMGETTER(Id)(uuid.asOutParam());
672 CHECK_ERROR(machine, AttachDevice(Bstr("IDE Controller"), 0, 1, DeviceType_HardDisk, uuid));
673 }
674 else
675 rc = E_FAIL;
676 }
677 break;
678 }
679
680 case MODIFYVM_HDD: // deprecated
681 {
682 if (!strcmp(ValueUnion.psz, "none"))
683 {
684 machine->DetachDevice(Bstr("IDE Controller"), 1, 1);
685 }
686 else
687 {
688 /* first guess is that it's a UUID */
689 Bstr uuid(ValueUnion.psz);
690 ComPtr<IMedium> hardDisk;
691 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
692 /* not successful? Then it must be a filename */
693 if (!hardDisk)
694 {
695 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
696 if (FAILED(rc))
697 {
698 /* open the new hard disk object */
699 CHECK_ERROR(a->virtualBox,
700 OpenHardDisk(Bstr(ValueUnion.psz),
701 AccessMode_ReadWrite, false, Bstr(""),
702 false, Bstr(""), hardDisk.asOutParam()));
703 }
704 }
705 if (hardDisk)
706 {
707 hardDisk->COMGETTER(Id)(uuid.asOutParam());
708 CHECK_ERROR(machine, AttachDevice(Bstr("IDE Controller"), 1, 1, DeviceType_HardDisk, uuid));
709 }
710 else
711 rc = E_FAIL;
712 }
713 break;
714 }
715
716 case MODIFYVM_IDECONTROLLER: // deprecated
717 {
718 ComPtr<IStorageController> storageController;
719 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("IDE Controller"),
720 storageController.asOutParam()));
721
722 if (!RTStrICmp(ValueUnion.psz, "PIIX3"))
723 {
724 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
725 }
726 else if (!RTStrICmp(ValueUnion.psz, "PIIX4"))
727 {
728 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
729 }
730 else if (!RTStrICmp(ValueUnion.psz, "ICH6"))
731 {
732 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_ICH6));
733 }
734 else
735 {
736 errorArgument("Invalid --idecontroller argument '%s'", ValueUnion.psz);
737 rc = E_FAIL;
738 }
739 break;
740 }
741
742 case MODIFYVM_SATAIDEEMULATION: // deprecated
743 {
744 ComPtr<IStorageController> SataCtl;
745 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA"), SataCtl.asOutParam()));
746
747 if (SUCCEEDED(rc))
748 CHECK_ERROR(SataCtl, SetIDEEmulationPort(GetOptState.uIndex, ValueUnion.u32));
749 break;
750 }
751
752 case MODIFYVM_SATAPORTCOUNT: // deprecated
753 {
754 ComPtr<IStorageController> SataCtl;
755 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA"), SataCtl.asOutParam()));
756
757 if (SUCCEEDED(rc) && ValueUnion.u32 > 0)
758 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(ValueUnion.u32));
759 break;
760 }
761
762 case MODIFYVM_SATAPORT: // deprecated
763 {
764 if (!strcmp(ValueUnion.psz, "none"))
765 {
766 machine->DetachDevice(Bstr("SATA"), GetOptState.uIndex, 0);
767 }
768 else
769 {
770 /* first guess is that it's a UUID */
771 Bstr uuid(ValueUnion.psz);
772 ComPtr<IMedium> hardDisk;
773 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
774 /* not successful? Then it must be a filename */
775 if (!hardDisk)
776 {
777 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
778 if (FAILED(rc))
779 {
780 /* open the new hard disk object */
781 CHECK_ERROR(a->virtualBox,
782 OpenHardDisk(Bstr(ValueUnion.psz), AccessMode_ReadWrite,
783 false, Bstr(""), false,
784 Bstr(""), hardDisk.asOutParam()));
785 }
786 }
787 if (hardDisk)
788 {
789 hardDisk->COMGETTER(Id)(uuid.asOutParam());
790 CHECK_ERROR(machine,
791 AttachDevice(Bstr("SATA"), GetOptState.uIndex,
792 0, DeviceType_HardDisk, uuid));
793 }
794 else
795 rc = E_FAIL;
796 }
797 break;
798 }
799
800 case MODIFYVM_SATA: // deprecated
801 {
802 if (!strcmp(ValueUnion.psz, "on") || !strcmp(ValueUnion.psz, "enable"))
803 {
804 ComPtr<IStorageController> ctl;
805 CHECK_ERROR(machine, AddStorageController(Bstr("SATA"), StorageBus_SATA, ctl.asOutParam()));
806 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
807 }
808 else if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
809 CHECK_ERROR(machine, RemoveStorageController(Bstr("SATA")));
810 else
811 return errorArgument("Invalid --usb argument '%s'", ValueUnion.psz);
812 break;
813 }
814
815 case MODIFYVM_SCSIPORT: // deprecated
816 {
817 if (!strcmp(ValueUnion.psz, "none"))
818 {
819 rc = machine->DetachDevice(Bstr("LsiLogic"), GetOptState.uIndex, 0);
820 if (FAILED(rc))
821 CHECK_ERROR(machine, DetachDevice(Bstr("BusLogic"), GetOptState.uIndex, 0));
822 }
823 else
824 {
825 /* first guess is that it's a UUID */
826 Bstr uuid(ValueUnion.psz);
827 ComPtr<IMedium> hardDisk;
828 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
829 /* not successful? Then it must be a filename */
830 if (!hardDisk)
831 {
832 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
833 if (FAILED(rc))
834 {
835 /* open the new hard disk object */
836 CHECK_ERROR(a->virtualBox,
837 OpenHardDisk(Bstr(ValueUnion.psz),
838 AccessMode_ReadWrite, false, Bstr(""),
839 false, Bstr(""), hardDisk.asOutParam()));
840 }
841 }
842 if (hardDisk)
843 {
844 hardDisk->COMGETTER(Id)(uuid.asOutParam());
845 rc = machine->AttachDevice(Bstr("LsiLogic"), GetOptState.uIndex, 0, DeviceType_HardDisk, uuid);
846 if (FAILED(rc))
847 CHECK_ERROR(machine,
848 AttachDevice(Bstr("BusLogic"),
849 GetOptState.uIndex, 0,
850 DeviceType_HardDisk, uuid));
851 }
852 else
853 rc = E_FAIL;
854 }
855 break;
856 }
857
858 case MODIFYVM_SCSITYPE: // deprecated
859 {
860 ComPtr<IStorageController> ctl;
861
862 if (!RTStrICmp(ValueUnion.psz, "LsiLogic"))
863 {
864 rc = machine->RemoveStorageController(Bstr("BusLogic"));
865 if (FAILED(rc))
866 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic")));
867
868 CHECK_ERROR(machine,
869 AddStorageController(Bstr("LsiLogic"),
870 StorageBus_SCSI,
871 ctl.asOutParam()));
872
873 if (SUCCEEDED(rc))
874 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
875 }
876 else if (!RTStrICmp(ValueUnion.psz, "BusLogic"))
877 {
878 rc = machine->RemoveStorageController(Bstr("LsiLogic"));
879 if (FAILED(rc))
880 CHECK_ERROR(machine, RemoveStorageController(Bstr("BusLogic")));
881
882 CHECK_ERROR(machine,
883 AddStorageController(Bstr("BusLogic"),
884 StorageBus_SCSI,
885 ctl.asOutParam()));
886
887 if (SUCCEEDED(rc))
888 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
889 }
890 else
891 return errorArgument("Invalid --scsitype argument '%s'", ValueUnion.psz);
892 break;
893 }
894
895 case MODIFYVM_SCSI: // deprecated
896 {
897 if (!strcmp(ValueUnion.psz, "on") || !strcmp(ValueUnion.psz, "enable"))
898 {
899 ComPtr<IStorageController> ctl;
900
901 CHECK_ERROR(machine, AddStorageController(Bstr("BusLogic"), StorageBus_SCSI, ctl.asOutParam()));
902 if (SUCCEEDED(rc))
903 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
904 }
905 else if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
906 {
907 rc = machine->RemoveStorageController(Bstr("BusLogic"));
908 if (FAILED(rc))
909 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic")));
910 }
911 break;
912 }
913
914 case MODIFYVM_DVDPASSTHROUGH: // deprecated
915 {
916 CHECK_ERROR(machine, PassthroughDevice(Bstr("IDE Controller"), 1, 0, !strcmp(ValueUnion.psz, "on")));
917 break;
918 }
919
920 case MODIFYVM_DVD: // deprecated
921 {
922 ComPtr<IMedium> dvdMedium;
923 Bstr uuid(ValueUnion.psz);
924
925 /* unmount? */
926 if (!strcmp(ValueUnion.psz, "none"))
927 {
928 /* nothing to do, NULL object will cause unmount */
929 }
930 /* host drive? */
931 else if (!strncmp(ValueUnion.psz, "host:", 5))
932 {
933 ComPtr<IHost> host;
934 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
935 rc = host->FindHostDVDDrive(Bstr(ValueUnion.psz + 5), dvdMedium.asOutParam());
936 if (!dvdMedium)
937 {
938 /* 2nd try: try with the real name, important on Linux+libhal */
939 char szPathReal[RTPATH_MAX];
940 if (RT_FAILURE(RTPathReal(ValueUnion.psz + 5, szPathReal, sizeof(szPathReal))))
941 {
942 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
943 rc = E_FAIL;
944 break;
945 }
946 rc = host->FindHostDVDDrive(Bstr(szPathReal), dvdMedium.asOutParam());
947 if (!dvdMedium)
948 {
949 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
950 rc = E_FAIL;
951 break;
952 }
953 }
954 }
955 else
956 {
957 /* first assume it's a UUID */
958 rc = a->virtualBox->GetDVDImage(uuid, dvdMedium.asOutParam());
959 if (FAILED(rc) || !dvdMedium)
960 {
961 /* must be a filename, check if it's in the collection */
962 rc = a->virtualBox->FindDVDImage(Bstr(ValueUnion.psz), dvdMedium.asOutParam());
963 /* not registered, do that on the fly */
964 if (!dvdMedium)
965 {
966 Bstr emptyUUID;
967 CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(ValueUnion.psz),
968 emptyUUID, dvdMedium.asOutParam()));
969 }
970 }
971 if (!dvdMedium)
972 {
973 rc = E_FAIL;
974 break;
975 }
976 }
977
978 /** @todo generalize this, allow arbitrary number of DVD drives
979 * and as a consequence multiple attachments and different
980 * storage controllers. */
981 if (dvdMedium)
982 dvdMedium->COMGETTER(Id)(uuid.asOutParam());
983 CHECK_ERROR(machine, MountMedium(Bstr("IDE Controller"), 1, 0, uuid, FALSE /* aForce */));
984 break;
985 }
986
987 case MODIFYVM_FLOPPY: // deprecated
988 {
989 Bstr uuid(ValueUnion.psz);
990 ComPtr<IMedium> floppyMedium;
991 ComPtr<IMediumAttachment> floppyAttachment;
992 machine->GetMediumAttachment(Bstr("Floppy Controller"), 0, 0, floppyAttachment.asOutParam());
993
994 /* disable? */
995 if (!strcmp(ValueUnion.psz, "disabled"))
996 {
997 /* disable the controller */
998 if (floppyAttachment)
999 CHECK_ERROR(machine, DetachDevice(Bstr("Floppy Controller"), 0, 0));
1000 }
1001 else
1002 {
1003 /* enable the controller */
1004 if (!floppyAttachment)
1005 CHECK_ERROR(machine, AttachDevice(Bstr("Floppy Controller"), 0, 0, DeviceType_Floppy, NULL));
1006
1007 /* unmount? */
1008 if ( !strcmp(ValueUnion.psz, "none")
1009 || !strcmp(ValueUnion.psz, "empty")) // deprecated
1010 {
1011 /* nothing to do, NULL object will cause unmount */
1012 }
1013 /* host drive? */
1014 else if (!strncmp(ValueUnion.psz, "host:", 5))
1015 {
1016 ComPtr<IHost> host;
1017 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1018 rc = host->FindHostFloppyDrive(Bstr(ValueUnion.psz + 5), floppyMedium.asOutParam());
1019 if (!floppyMedium)
1020 {
1021 errorArgument("Invalid host floppy drive name \"%s\"", ValueUnion.psz + 5);
1022 rc = E_FAIL;
1023 break;
1024 }
1025 }
1026 else
1027 {
1028 /* first assume it's a UUID */
1029 rc = a->virtualBox->GetFloppyImage(uuid, floppyMedium.asOutParam());
1030 if (FAILED(rc) || !floppyMedium)
1031 {
1032 /* must be a filename, check if it's in the collection */
1033 rc = a->virtualBox->FindFloppyImage(Bstr(ValueUnion.psz), floppyMedium.asOutParam());
1034 /* not registered, do that on the fly */
1035 if (!floppyMedium)
1036 {
1037 Bstr emptyUUID;
1038 CHECK_ERROR(a->virtualBox,
1039 OpenFloppyImage(Bstr(ValueUnion.psz),
1040 emptyUUID,
1041 floppyMedium.asOutParam()));
1042 }
1043 }
1044 if (!floppyMedium)
1045 {
1046 rc = E_FAIL;
1047 break;
1048 }
1049 }
1050 floppyMedium->COMGETTER(Id)(uuid.asOutParam());
1051 CHECK_ERROR(machine, MountMedium(Bstr("Floppy Controller"), 0, 0, uuid, FALSE /* aForce */));
1052 }
1053 break;
1054 }
1055
1056 case MODIFYVM_NICTRACEFILE:
1057 {
1058 ComPtr<INetworkAdapter> nic;
1059
1060 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1061 ASSERT(nic);
1062
1063 CHECK_ERROR(nic, COMSETTER(TraceFile)(Bstr(ValueUnion.psz)));
1064 break;
1065 }
1066
1067 case MODIFYVM_NICTRACE:
1068 {
1069 ComPtr<INetworkAdapter> nic;
1070
1071 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1072 ASSERT(nic);
1073
1074 CHECK_ERROR(nic, COMSETTER(TraceEnabled)(ValueUnion.f));
1075 break;
1076 }
1077
1078 case MODIFYVM_NICTYPE:
1079 {
1080 ComPtr<INetworkAdapter> nic;
1081
1082 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1083 ASSERT(nic);
1084
1085 if (!strcmp(ValueUnion.psz, "Am79C970A"))
1086 {
1087 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A));
1088 }
1089 else if (!strcmp(ValueUnion.psz, "Am79C973"))
1090 {
1091 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973));
1092 }
1093#ifdef VBOX_WITH_E1000
1094 else if (!strcmp(ValueUnion.psz, "82540EM"))
1095 {
1096 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM));
1097 }
1098 else if (!strcmp(ValueUnion.psz, "82543GC"))
1099 {
1100 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC));
1101 }
1102 else if (!strcmp(ValueUnion.psz, "82545EM"))
1103 {
1104 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82545EM));
1105 }
1106#endif
1107#ifdef VBOX_WITH_VIRTIO
1108 else if (!strcmp(ValueUnion.psz, "virtio"))
1109 {
1110 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Virtio));
1111 }
1112#endif /* VBOX_WITH_VIRTIO */
1113 else
1114 {
1115 errorArgument("Invalid NIC type '%s' specified for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1116 rc = E_FAIL;
1117 }
1118 break;
1119 }
1120
1121 case MODIFYVM_NICSPEED:
1122 {
1123 ComPtr<INetworkAdapter> nic;
1124
1125 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1126 ASSERT(nic);
1127
1128 CHECK_ERROR(nic, COMSETTER(LineSpeed)(ValueUnion.u32));
1129 break;
1130 }
1131
1132 case MODIFYVM_NICBOOTPRIO:
1133 {
1134 ComPtr<INetworkAdapter> nic;
1135
1136 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1137 ASSERT(nic);
1138
1139 /* Somewhat arbitrary limitation - we can pass a list of up to 4 PCI devices
1140 * to the PXE ROM, hence only boot priorities 1-4 are allowed (in addition to
1141 * 0 for the default lowest priority).
1142 */
1143 if (ValueUnion.u32 > 4)
1144 {
1145 errorArgument("Invalid boot priority '%u' specfied for NIC %u", ValueUnion.u32, GetOptState.uIndex);
1146 rc = E_FAIL;
1147 }
1148 else
1149 {
1150 CHECK_ERROR(nic, COMSETTER(BootPriority)(ValueUnion.u32));
1151 }
1152 break;
1153 }
1154
1155 case MODIFYVM_NIC:
1156 {
1157 ComPtr<INetworkAdapter> nic;
1158
1159 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1160 ASSERT(nic);
1161
1162 if (!strcmp(ValueUnion.psz, "none"))
1163 {
1164 CHECK_ERROR(nic, COMSETTER(Enabled)(FALSE));
1165 }
1166 else if (!strcmp(ValueUnion.psz, "null"))
1167 {
1168 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1169 CHECK_ERROR(nic, Detach());
1170 }
1171 else if (!strcmp(ValueUnion.psz, "nat"))
1172 {
1173 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1174 CHECK_ERROR(nic, AttachToNAT());
1175 }
1176 else if ( !strcmp(ValueUnion.psz, "bridged")
1177 || !strcmp(ValueUnion.psz, "hostif")) /* backward compatibility */
1178 {
1179 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1180 CHECK_ERROR(nic, AttachToBridgedInterface());
1181 }
1182 else if (!strcmp(ValueUnion.psz, "intnet"))
1183 {
1184 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1185 CHECK_ERROR(nic, AttachToInternalNetwork());
1186 }
1187#if defined(VBOX_WITH_NETFLT)
1188 else if (!strcmp(ValueUnion.psz, "hostonly"))
1189 {
1190
1191 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1192 CHECK_ERROR(nic, AttachToHostOnlyInterface());
1193 }
1194#endif
1195#ifdef VBOX_WITH_VDE
1196 else if (!strcmp(ValueUnion.psz, "vde"))
1197 {
1198
1199 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1200 CHECK_ERROR(nic, AttachToVDE());
1201 }
1202#endif
1203 else
1204 {
1205 errorArgument("Invalid type '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1206 rc = E_FAIL;
1207 }
1208 break;
1209 }
1210
1211 case MODIFYVM_CABLECONNECTED:
1212 {
1213 ComPtr<INetworkAdapter> nic;
1214
1215 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1216 ASSERT(nic);
1217
1218 CHECK_ERROR(nic, COMSETTER(CableConnected)(ValueUnion.f));
1219 break;
1220 }
1221
1222 case MODIFYVM_BRIDGEADAPTER:
1223 case MODIFYVM_HOSTONLYADAPTER:
1224 {
1225 ComPtr<INetworkAdapter> nic;
1226
1227 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1228 ASSERT(nic);
1229
1230 /* remove it? */
1231 if (!strcmp(ValueUnion.psz, "none"))
1232 {
1233 CHECK_ERROR(nic, COMSETTER(HostInterface)(NULL));
1234 }
1235 else
1236 {
1237 CHECK_ERROR(nic, COMSETTER(HostInterface)(Bstr(ValueUnion.psz)));
1238 }
1239 break;
1240 }
1241
1242 case MODIFYVM_INTNET:
1243 {
1244 ComPtr<INetworkAdapter> nic;
1245
1246 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1247 ASSERT(nic);
1248
1249 /* remove it? */
1250 if (!strcmp(ValueUnion.psz, "none"))
1251 {
1252 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(NULL));
1253 }
1254 else
1255 {
1256 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr(ValueUnion.psz)));
1257 }
1258 break;
1259 }
1260
1261#ifdef VBOX_WITH_VDE
1262 case MODIFYVM_VDENET:
1263 {
1264 ComPtr<INetworkAdapter> nic;
1265
1266 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1267 ASSERT(nic);
1268
1269 if (!strcmp(ValueUnion.psz, "default"))
1270 {
1271 CHECK_ERROR(nic, COMSETTER(VDENetwork)(NULL));
1272 }
1273 else
1274 {
1275 CHECK_ERROR(nic, COMSETTER(VDENetwork)(Bstr(ValueUnion.psz)));
1276 }
1277 break;
1278 }
1279#endif
1280 case MODIFYVM_NATNET:
1281 {
1282 ComPtr<INetworkAdapter> nic;
1283 ComPtr<INATEngine> driver;
1284
1285 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1286 ASSERT(nic);
1287
1288 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1289
1290 const char *psz = ValueUnion.psz;
1291 if (!strcmp("default", psz))
1292 psz = "";
1293
1294 CHECK_ERROR(driver, COMSETTER(Network)(Bstr(psz)));
1295 break;
1296 }
1297
1298 case MODIFYVM_NATBINDIP:
1299 {
1300 ComPtr<INetworkAdapter> nic;
1301 ComPtr<INATEngine> driver;
1302
1303 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1304 ASSERT(nic);
1305
1306 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1307 CHECK_ERROR(driver, COMSETTER(HostIP)(Bstr(ValueUnion.psz)));
1308 break;
1309 }
1310
1311#define ITERATE_TO_NEXT_TERM(ch) \
1312 do { \
1313 while (*ch != ',') \
1314 { \
1315 if (*ch == 0) \
1316 { \
1317 return errorSyntax(USAGE_MODIFYVM, \
1318 "Missing or Invalid argument to '%s'", \
1319 GetOptState.pDef->pszLong); \
1320 } \
1321 ch++; \
1322 } \
1323 *ch = '\0'; \
1324 ch++; \
1325 } while(0)
1326
1327 case MODIFYVM_NATSETTINGS:
1328 {
1329 ComPtr<INetworkAdapter> nic;
1330 ComPtr<INATEngine> driver;
1331 char *strMtu;
1332 char *strSockSnd;
1333 char *strSockRcv;
1334 char *strTcpSnd;
1335 char *strTcpRcv;
1336 char *strRaw = RTStrDup(ValueUnion.psz);
1337 char *ch = strRaw;
1338 strMtu = RTStrStrip(ch);
1339 ITERATE_TO_NEXT_TERM(ch);
1340 strSockSnd = RTStrStrip(ch);
1341 ITERATE_TO_NEXT_TERM(ch);
1342 strSockRcv = RTStrStrip(ch);
1343 ITERATE_TO_NEXT_TERM(ch);
1344 strTcpSnd = RTStrStrip(ch);
1345 ITERATE_TO_NEXT_TERM(ch);
1346 strTcpRcv = RTStrStrip(ch);
1347
1348 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1349 ASSERT(nic);
1350
1351 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1352 CHECK_ERROR(driver, SetNetworkSettings(RTStrToUInt32(strMtu), RTStrToUInt32(strSockSnd), RTStrToUInt32(strSockRcv),
1353 RTStrToUInt32(strTcpSnd), RTStrToUInt32(strTcpRcv)));
1354 break;
1355 }
1356
1357
1358 case MODIFYVM_NATPF:
1359 {
1360 ComPtr<INetworkAdapter> nic;
1361 ComPtr<INATEngine> driver;
1362
1363 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1364 ASSERT(nic);
1365
1366 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1367 /* format name:proto:hostip:hostport:guestip:guestport*/
1368 if (RTStrCmp(ValueUnion.psz, "delete") != 0)
1369 {
1370 char *strName;
1371 char *strProto;
1372 char *strHostIp;
1373 char *strHostPort;
1374 char *strGuestIp;
1375 char *strGuestPort;
1376 char *strRaw = RTStrDup(ValueUnion.psz);
1377 char *ch = strRaw;
1378 strName = RTStrStrip(ch);
1379 ITERATE_TO_NEXT_TERM(ch);
1380 strProto = RTStrStrip(ch);
1381 ITERATE_TO_NEXT_TERM(ch);
1382 strHostIp = RTStrStrip(ch);
1383 ITERATE_TO_NEXT_TERM(ch);
1384 strHostPort = RTStrStrip(ch);
1385 ITERATE_TO_NEXT_TERM(ch);
1386 strGuestIp = RTStrStrip(ch);
1387 ITERATE_TO_NEXT_TERM(ch);
1388 strGuestPort = RTStrStrip(ch);
1389 NATProtocol_T proto;
1390 if (RTStrICmp(strProto, "udp") == 0)
1391 proto = NATProtocol_UDP;
1392 else if (RTStrICmp(strProto, "tcp") == 0)
1393 proto = NATProtocol_TCP;
1394 else
1395 {
1396 errorArgument("Invalid proto '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1397 rc = E_FAIL;
1398 break;
1399 }
1400 CHECK_ERROR(driver, AddRedirect(Bstr(strName), proto, Bstr(strHostIp),
1401 RTStrToUInt16(strHostPort), Bstr(strGuestIp), RTStrToUInt16(strGuestPort)));
1402 }
1403 else
1404 {
1405 /* delete NAT Rule operation */
1406 int vrc;
1407 vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1408 if (RT_FAILURE(vrc))
1409 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
1410 CHECK_ERROR(driver, RemoveRedirect(Bstr(ValueUnion.psz)));
1411 }
1412 break;
1413 }
1414 #undef ITERATE_TO_NEXT_TERM
1415 case MODIFYVM_NATALIASMODE:
1416 {
1417 ComPtr<INetworkAdapter> nic;
1418 ComPtr<INATEngine> driver;
1419 uint32_t aliasMode = 0;
1420
1421 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1422 ASSERT(nic);
1423
1424 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1425 if (RTStrCmp(ValueUnion.psz,"default") == 0)
1426 {
1427 aliasMode = 0;
1428 }
1429 else
1430 {
1431 char *token = (char *)ValueUnion.psz;
1432 while(token)
1433 {
1434 if (RTStrNCmp(token, "log", 3) == 0)
1435 aliasMode |= 0x1;
1436 else if (RTStrNCmp(token, "proxyonly", 9) == 0)
1437 aliasMode |= 0x2;
1438 else if (RTStrNCmp(token, "sameports", 9) == 0)
1439 aliasMode |= 0x4;
1440 token = RTStrStr(token, ",");
1441 if (token == NULL)
1442 break;
1443 token++;
1444 }
1445 }
1446 CHECK_ERROR(driver, COMSETTER(AliasMode)(aliasMode));
1447 break;
1448 }
1449
1450 case MODIFYVM_NATTFTPPREFIX:
1451 {
1452 ComPtr<INetworkAdapter> nic;
1453 ComPtr<INATEngine> driver;
1454
1455 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1456 ASSERT(nic);
1457
1458 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1459 CHECK_ERROR(driver, COMSETTER(TftpPrefix)(Bstr(ValueUnion.psz)));
1460 break;
1461 }
1462
1463 case MODIFYVM_NATTFTPFILE:
1464 {
1465 ComPtr<INetworkAdapter> nic;
1466 ComPtr<INATEngine> driver;
1467
1468 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1469 ASSERT(nic);
1470
1471 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1472 CHECK_ERROR(driver, COMSETTER(TftpBootFile)(Bstr(ValueUnion.psz)));
1473 break;
1474 }
1475
1476 case MODIFYVM_NATTFTPSERVER:
1477 {
1478 ComPtr<INetworkAdapter> nic;
1479 ComPtr<INATEngine> driver;
1480
1481 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1482 ASSERT(nic);
1483
1484 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1485 CHECK_ERROR(driver, COMSETTER(TftpNextServer)(Bstr(ValueUnion.psz)));
1486 break;
1487 }
1488 case MODIFYVM_NATDNSPASSDOMAIN:
1489 {
1490 ComPtr<INetworkAdapter> nic;
1491 ComPtr<INATEngine> driver;
1492
1493 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1494 ASSERT(nic);
1495
1496 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1497 CHECK_ERROR(driver, COMSETTER(DnsPassDomain)(ValueUnion.f));
1498 break;
1499 }
1500
1501 case MODIFYVM_NATDNSPROXY:
1502 {
1503 ComPtr<INetworkAdapter> nic;
1504 ComPtr<INATEngine> driver;
1505
1506 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1507 ASSERT(nic);
1508
1509 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1510 CHECK_ERROR(driver, COMSETTER(DnsProxy)(ValueUnion.f));
1511 break;
1512 }
1513
1514 case MODIFYVM_NATDNSHOSTRESOLVER:
1515 {
1516 ComPtr<INetworkAdapter> nic;
1517 ComPtr<INATEngine> driver;
1518
1519 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1520 ASSERT(nic);
1521
1522 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1523 CHECK_ERROR(driver, COMSETTER(DnsUseHostResolver)(ValueUnion.f));
1524 break;
1525 }
1526 case MODIFYVM_MACADDRESS:
1527 {
1528 ComPtr<INetworkAdapter> nic;
1529
1530 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1531 ASSERT(nic);
1532
1533 /* generate one? */
1534 if (!strcmp(ValueUnion.psz, "auto"))
1535 {
1536 CHECK_ERROR(nic, COMSETTER(MACAddress)(NULL));
1537 }
1538 else
1539 {
1540 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr(ValueUnion.psz)));
1541 }
1542 break;
1543 }
1544
1545 case MODIFYVM_HIDPTR:
1546 {
1547 bool fEnableUsb = false;
1548 if (!strcmp(ValueUnion.psz, "ps2"))
1549 {
1550 CHECK_ERROR(machine, COMSETTER(PointingHidType)(PointingHidType_PS2Mouse));
1551 }
1552 else if (!strcmp(ValueUnion.psz, "usb"))
1553 {
1554 CHECK_ERROR(machine, COMSETTER(PointingHidType)(PointingHidType_USBMouse));
1555 if (SUCCEEDED(rc))
1556 fEnableUsb = true;
1557 }
1558 else if (!strcmp(ValueUnion.psz, "usbtablet"))
1559 {
1560 CHECK_ERROR(machine, COMSETTER(PointingHidType)(PointingHidType_USBTablet));
1561 if (SUCCEEDED(rc))
1562 fEnableUsb = true;
1563 }
1564 else
1565 {
1566 errorArgument("Invalid type '%s' specfied for pointing device", ValueUnion.psz);
1567 rc = E_FAIL;
1568 }
1569 if (fEnableUsb)
1570 {
1571 /* Make sure the OHCI controller is enabled. */
1572 ComPtr<IUSBController> UsbCtl;
1573 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1574 if (SUCCEEDED(rc))
1575 {
1576 BOOL fEnabled;
1577 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1578 if (FAILED(rc))
1579 fEnabled = false;
1580 if (!fEnabled)
1581 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1582 }
1583 }
1584 break;
1585 }
1586
1587 case MODIFYVM_HIDKBD:
1588 {
1589 bool fEnableUsb = false;
1590 if (!strcmp(ValueUnion.psz, "ps2"))
1591 {
1592 CHECK_ERROR(machine, COMSETTER(KeyboardHidType)(KeyboardHidType_PS2Keyboard));
1593 }
1594 else if (!strcmp(ValueUnion.psz, "usb"))
1595 {
1596 CHECK_ERROR(machine, COMSETTER(KeyboardHidType)(KeyboardHidType_USBKeyboard));
1597 if (SUCCEEDED(rc))
1598 fEnableUsb = true;
1599 }
1600 else
1601 {
1602 errorArgument("Invalid type '%s' specfied for keyboard", ValueUnion.psz);
1603 rc = E_FAIL;
1604 }
1605 if (fEnableUsb)
1606 {
1607 /* Make sure the OHCI controller is enabled. */
1608 ComPtr<IUSBController> UsbCtl;
1609 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1610 if (SUCCEEDED(rc))
1611 {
1612 BOOL fEnabled;
1613 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1614 if (FAILED(rc))
1615 fEnabled = false;
1616 if (!fEnabled)
1617 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1618 }
1619 }
1620 break;
1621 }
1622
1623 case MODIFYVM_UARTMODE:
1624 {
1625 ComPtr<ISerialPort> uart;
1626 char *pszIRQ = NULL;
1627
1628 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1629 ASSERT(uart);
1630
1631 if (!strcmp(ValueUnion.psz, "disconnected"))
1632 {
1633 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
1634 }
1635 else if ( !strcmp(ValueUnion.psz, "server")
1636 || !strcmp(ValueUnion.psz, "client")
1637 || !strcmp(ValueUnion.psz, "file"))
1638 {
1639 const char *pszMode = ValueUnion.psz;
1640
1641 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1642 if (RT_FAILURE(vrc))
1643 return errorSyntax(USAGE_MODIFYVM,
1644 "Missing or Invalid argument to '%s'",
1645 GetOptState.pDef->pszLong);
1646
1647 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz)));
1648
1649 if (!strcmp(pszMode, "server"))
1650 {
1651 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1652 CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
1653 }
1654 else if (!strcmp(pszMode, "client"))
1655 {
1656 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1657 CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
1658 }
1659 else if (!strcmp(pszMode, "file"))
1660 {
1661 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_RawFile));
1662 }
1663 }
1664 else
1665 {
1666 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz)));
1667 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostDevice));
1668 }
1669 break;
1670 }
1671
1672 case MODIFYVM_UART:
1673 {
1674 ComPtr<ISerialPort> uart;
1675
1676 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1677 ASSERT(uart);
1678
1679 if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
1680 CHECK_ERROR(uart, COMSETTER(Enabled)(FALSE));
1681 else
1682 {
1683 const char *pszIOBase = ValueUnion.psz;
1684 uint32_t uVal = 0;
1685
1686 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_UART;
1687 if (RT_FAILURE(vrc))
1688 return errorSyntax(USAGE_MODIFYVM,
1689 "Missing or Invalid argument to '%s'",
1690 GetOptState.pDef->pszLong);
1691
1692 CHECK_ERROR(uart, COMSETTER(IRQ)(ValueUnion.u32));
1693
1694 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1695 if (vrc != VINF_SUCCESS || uVal == 0)
1696 return errorArgument("Error parsing UART I/O base '%s'", pszIOBase);
1697 CHECK_ERROR(uart, COMSETTER(IOBase)(uVal));
1698
1699 CHECK_ERROR(uart, COMSETTER(Enabled)(TRUE));
1700 }
1701 break;
1702 }
1703
1704 case MODIFYVM_GUESTMEMORYBALLOON:
1705 {
1706 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(ValueUnion.u32));
1707 break;
1708 }
1709
1710 case MODIFYVM_AUDIOCONTROLLER:
1711 {
1712 ComPtr<IAudioAdapter> audioAdapter;
1713 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1714 ASSERT(audioAdapter);
1715
1716 if (!strcmp(ValueUnion.psz, "sb16"))
1717 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
1718 else if (!strcmp(ValueUnion.psz, "ac97"))
1719 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
1720 else
1721 {
1722 errorArgument("Invalid --audiocontroller argument '%s'", ValueUnion.psz);
1723 rc = E_FAIL;
1724 }
1725 break;
1726 }
1727
1728 case MODIFYVM_AUDIO:
1729 {
1730 ComPtr<IAudioAdapter> audioAdapter;
1731 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1732 ASSERT(audioAdapter);
1733
1734 /* disable? */
1735 if (!strcmp(ValueUnion.psz, "none"))
1736 {
1737 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
1738 }
1739 else if (!strcmp(ValueUnion.psz, "null"))
1740 {
1741 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
1742 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1743 }
1744#ifdef RT_OS_WINDOWS
1745#ifdef VBOX_WITH_WINMM
1746 else if (!strcmp(ValueUnion.psz, "winmm"))
1747 {
1748 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
1749 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1750 }
1751#endif
1752 else if (!strcmp(ValueUnion.psz, "dsound"))
1753 {
1754 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
1755 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1756 }
1757#endif /* RT_OS_WINDOWS */
1758#ifdef RT_OS_LINUX
1759# ifdef VBOX_WITH_ALSA
1760 else if (!strcmp(ValueUnion.psz, "alsa"))
1761 {
1762 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
1763 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1764 }
1765# endif
1766# ifdef VBOX_WITH_PULSE
1767 else if (!strcmp(ValueUnion.psz, "pulse"))
1768 {
1769 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1770 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1771 }
1772# endif
1773#endif /* !RT_OS_LINUX */
1774#ifdef RT_OS_SOLARIS
1775 else if (!strcmp(ValueUnion.psz, "solaudio"))
1776 {
1777 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
1778 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1779 }
1780#endif /* !RT_OS_SOLARIS */
1781#ifdef RT_OS_FREEBSD
1782 else if (!strcmp(ValueUnion.psz, "oss"))
1783 {
1784 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1785 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1786 }
1787# ifdef VBOX_WITH_PULSE
1788 else if (!strcmp(ValueUnion.psz, "pulse"))
1789 {
1790 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1791 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1792 }
1793# endif
1794#endif /* !RT_OS_FREEBSD */
1795#ifdef RT_OS_DARWIN
1796 else if (!strcmp(ValueUnion.psz, "coreaudio"))
1797 {
1798 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
1799 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1800 }
1801
1802#endif /* !RT_OS_DARWIN */
1803# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(VBOX_WITH_SOLARIS_OSS)
1804 else if (!strcmp(ValueUnion.psz, "oss"))
1805 {
1806 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1807 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1808 }
1809# endif
1810 else
1811 {
1812 errorArgument("Invalid --audio argument '%s'", ValueUnion.psz);
1813 rc = E_FAIL;
1814 }
1815 break;
1816 }
1817
1818 case MODIFYVM_CLIPBOARD:
1819 {
1820 if (!strcmp(ValueUnion.psz, "disabled"))
1821 {
1822 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Disabled));
1823 }
1824 else if (!strcmp(ValueUnion.psz, "hosttoguest"))
1825 {
1826 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_HostToGuest));
1827 }
1828 else if (!strcmp(ValueUnion.psz, "guesttohost"))
1829 {
1830 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_GuestToHost));
1831 }
1832 else if (!strcmp(ValueUnion.psz, "bidirectional"))
1833 {
1834 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Bidirectional));
1835 }
1836 else
1837 {
1838 errorArgument("Invalid --clipboard argument '%s'", ValueUnion.psz);
1839 rc = E_FAIL;
1840 }
1841 break;
1842 }
1843
1844#ifdef VBOX_WITH_VRDP
1845 case MODIFYVM_VRDPPORT:
1846 {
1847 ComPtr<IVRDPServer> vrdpServer;
1848 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1849 ASSERT(vrdpServer);
1850
1851 if (!strcmp(ValueUnion.psz, "default"))
1852 CHECK_ERROR(vrdpServer, COMSETTER(Ports)(Bstr("0")));
1853 else
1854 CHECK_ERROR(vrdpServer, COMSETTER(Ports)(Bstr(ValueUnion.psz)));
1855 break;
1856 }
1857
1858 case MODIFYVM_VRDPADDRESS:
1859 {
1860 ComPtr<IVRDPServer> vrdpServer;
1861 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1862 ASSERT(vrdpServer);
1863
1864 CHECK_ERROR(vrdpServer, COMSETTER(NetAddress)(Bstr(ValueUnion.psz)));
1865 break;
1866 }
1867
1868 case MODIFYVM_VRDPAUTHTYPE:
1869 {
1870 ComPtr<IVRDPServer> vrdpServer;
1871 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1872 ASSERT(vrdpServer);
1873
1874 if (!strcmp(ValueUnion.psz, "null"))
1875 {
1876 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Null));
1877 }
1878 else if (!strcmp(ValueUnion.psz, "external"))
1879 {
1880 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_External));
1881 }
1882 else if (!strcmp(ValueUnion.psz, "guest"))
1883 {
1884 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Guest));
1885 }
1886 else
1887 {
1888 errorArgument("Invalid --vrdpauthtype argument '%s'", ValueUnion.psz);
1889 rc = E_FAIL;
1890 }
1891 break;
1892 }
1893
1894 case MODIFYVM_VRDPMULTICON:
1895 {
1896 ComPtr<IVRDPServer> vrdpServer;
1897 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1898 ASSERT(vrdpServer);
1899
1900 CHECK_ERROR(vrdpServer, COMSETTER(AllowMultiConnection)(ValueUnion.f));
1901 break;
1902 }
1903
1904 case MODIFYVM_VRDPREUSECON:
1905 {
1906 ComPtr<IVRDPServer> vrdpServer;
1907 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1908 ASSERT(vrdpServer);
1909
1910 CHECK_ERROR(vrdpServer, COMSETTER(ReuseSingleConnection)(ValueUnion.f));
1911 break;
1912 }
1913
1914 case MODIFYVM_VRDPVIDEOCHANNEL:
1915 {
1916 ComPtr<IVRDPServer> vrdpServer;
1917 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1918 ASSERT(vrdpServer);
1919
1920 CHECK_ERROR(vrdpServer, COMSETTER(VideoChannel)(ValueUnion.f));
1921 break;
1922 }
1923
1924 case MODIFYVM_VRDPVIDEOCHANNELQUALITY:
1925 {
1926 ComPtr<IVRDPServer> vrdpServer;
1927 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1928 ASSERT(vrdpServer);
1929
1930 CHECK_ERROR(vrdpServer, COMSETTER(VideoChannelQuality)(ValueUnion.u32));
1931 break;
1932 }
1933
1934 case MODIFYVM_VRDP:
1935 {
1936 ComPtr<IVRDPServer> vrdpServer;
1937 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1938 ASSERT(vrdpServer);
1939
1940 CHECK_ERROR(vrdpServer, COMSETTER(Enabled)(ValueUnion.f));
1941 break;
1942 }
1943#endif /* VBOX_WITH_VRDP */
1944
1945 case MODIFYVM_USBEHCI:
1946 {
1947 ComPtr<IUSBController> UsbCtl;
1948 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1949 if (SUCCEEDED(rc))
1950 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEhci)(ValueUnion.f));
1951 break;
1952 }
1953
1954 case MODIFYVM_USB:
1955 {
1956 ComPtr<IUSBController> UsbCtl;
1957 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1958 if (SUCCEEDED(rc))
1959 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(ValueUnion.f));
1960 break;
1961 }
1962
1963 case MODIFYVM_SNAPSHOTFOLDER:
1964 {
1965 if (!strcmp(ValueUnion.psz, "default"))
1966 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(NULL));
1967 else
1968 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(ValueUnion.psz)));
1969 break;
1970 }
1971
1972 case MODIFYVM_TELEPORTER_ENABLED:
1973 {
1974 CHECK_ERROR(machine, COMSETTER(TeleporterEnabled)(ValueUnion.f));
1975 break;
1976 }
1977
1978 case MODIFYVM_TELEPORTER_PORT:
1979 {
1980 CHECK_ERROR(machine, COMSETTER(TeleporterPort)(ValueUnion.u32));
1981 break;
1982 }
1983
1984 case MODIFYVM_TELEPORTER_ADDRESS:
1985 {
1986 CHECK_ERROR(machine, COMSETTER(TeleporterAddress)(Bstr(ValueUnion.psz)));
1987 break;
1988 }
1989
1990 case MODIFYVM_TELEPORTER_PASSWORD:
1991 {
1992 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(ValueUnion.psz)));
1993 break;
1994 }
1995
1996 case MODIFYVM_HARDWARE_UUID:
1997 {
1998 CHECK_ERROR(machine, COMSETTER(HardwareUUID)(Bstr(ValueUnion.psz)));
1999 break;
2000 }
2001
2002 case MODIFYVM_HPET:
2003 {
2004 CHECK_ERROR(machine, COMSETTER(HpetEnabled)(ValueUnion.f));
2005 break;
2006 }
2007
2008 case MODIFYVM_IOCACHE:
2009 {
2010 CHECK_ERROR(machine, COMSETTER(IoCacheEnabled)(ValueUnion.f));
2011 break;
2012 }
2013
2014 case MODIFYVM_IOCACHESIZE:
2015 {
2016 CHECK_ERROR(machine, COMSETTER(IoCacheSize)(ValueUnion.u32));
2017 break;
2018 }
2019
2020 case MODIFYVM_IOBANDWIDTHMAX:
2021 {
2022 CHECK_ERROR(machine, COMSETTER(IoBandwidthMax)(ValueUnion.u32));
2023 break;
2024 }
2025
2026 default:
2027 {
2028 errorGetOpt(USAGE_MODIFYVM, c, &ValueUnion);
2029 rc = E_FAIL;
2030 break;
2031 }
2032 }
2033 }
2034
2035 /* commit changes */
2036 if (SUCCEEDED(rc))
2037 CHECK_ERROR(machine, SaveSettings());
2038
2039 /* it's important to always close sessions */
2040 a->session->Close();
2041
2042 return SUCCEEDED(rc) ? 0 : 1;
2043}
2044
2045#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