VirtualBox

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

Last change on this file since 31020 was 31019, checked in by vboxsync, 14 years ago

Main: rename LockForSession() API to LockMachine() and fix parameters; move code from internal open*Session() methods into LockMachine()

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