VirtualBox

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

Last change on this file since 31467 was 31298, checked in by vboxsync, 15 years ago

gcc warning

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