VirtualBox

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

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

introduced VBoxManage modifyvm --rtcuseutc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 62.4 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 25672 2010-01-06 21:23:07Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of modifyvm command.
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#ifndef VBOX_ONLY_DOCS
26#include <VBox/com/com.h>
27#include <VBox/com/array.h>
28#include <VBox/com/ErrorInfo.h>
29#include <VBox/com/errorprint.h>
30#include <VBox/com/EventQueue.h>
31
32#include <VBox/com/VirtualBox.h>
33
34#include <vector>
35#include <list>
36#endif /* !VBOX_ONLY_DOCS */
37
38#include <iprt/cidr.h>
39#include <iprt/param.h>
40#include <iprt/path.h>
41#include <iprt/stream.h>
42#include <iprt/string.h>
43#include <iprt/getopt.h>
44#include <VBox/log.h>
45
46#include "VBoxManage.h"
47
48#ifndef VBOX_ONLY_DOCS
49using namespace com;
50
51
52/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
53#if defined(_MSC_VER)
54# pragma optimize("g", off)
55#endif
56
57enum
58{
59 MODIFYVM_NAME = 1000,
60 MODIFYVM_OSTYPE,
61 MODIFYVM_MEMORY,
62 MODIFYVM_VRAM,
63 MODIFYVM_FIRMWARE,
64 MODIFYVM_ACPI,
65 MODIFYVM_IOAPIC,
66 MODIFYVM_PAE,
67 MODIFYVM_SYNTHCPU,
68 MODIFYVM_HWVIRTEX,
69 MODIFYVM_HWVIRTEXEXCLUSIVE,
70 MODIFYVM_NESTEDPAGING,
71 MODIFYVM_VTXVPID,
72 MODIFYVM_CPUS,
73 MODIFYVM_SETCPUID,
74 MODIFYVM_DELCPUID,
75 MODIFYVM_DELALLCPUID,
76 MODIFYVM_MONITORCOUNT,
77 MODIFYVM_ACCELERATE3D,
78 MODIFYVM_ACCELERATE2DVIDEO,
79 MODIFYVM_BIOSLOGOFADEIN,
80 MODIFYVM_BIOSLOGOFADEOUT,
81 MODIFYVM_BIOSLOGODISPLAYTIME,
82 MODIFYVM_BIOSLOGOIMAGEPATH,
83 MODIFYVM_BIOSBOOTMENU,
84 MODIFYVM_BIOSSYSTEMTIMEOFFSET,
85 MODIFYVM_BIOSPXEDEBUG,
86 MODIFYVM_BOOT,
87 MODIFYVM_HDA, // deprecated
88 MODIFYVM_HDB, // deprecated
89 MODIFYVM_HDD, // deprecated
90 MODIFYVM_IDECONTROLLER, // deprecated
91 MODIFYVM_SATAIDEEMULATION, // deprecated
92 MODIFYVM_SATAPORTCOUNT, // deprecated
93 MODIFYVM_SATAPORT, // deprecated
94 MODIFYVM_SATA, // deprecated
95 MODIFYVM_SCSIPORT, // deprecated
96 MODIFYVM_SCSITYPE, // deprecated
97 MODIFYVM_SCSI, // deprecated
98 MODIFYVM_DVDPASSTHROUGH, // deprecated
99 MODIFYVM_DVD, // deprecated
100 MODIFYVM_FLOPPY, // deprecated
101 MODIFYVM_NICTRACEFILE,
102 MODIFYVM_NICTRACE,
103 MODIFYVM_NICTYPE,
104 MODIFYVM_NICSPEED,
105 MODIFYVM_NIC,
106 MODIFYVM_CABLECONNECTED,
107 MODIFYVM_BRIDGEADAPTER,
108 MODIFYVM_HOSTONLYADAPTER,
109 MODIFYVM_INTNET,
110 MODIFYVM_NATNET,
111 MODIFYVM_MACADDRESS,
112 MODIFYVM_UARTMODE,
113 MODIFYVM_UART,
114 MODIFYVM_GUESTSTATISTICSINTERVAL,
115 MODIFYVM_GUESTMEMORYBALLOON,
116 MODIFYVM_AUDIOCONTROLLER,
117 MODIFYVM_AUDIO,
118 MODIFYVM_CLIPBOARD,
119 MODIFYVM_VRDPPORT,
120 MODIFYVM_VRDPADDRESS,
121 MODIFYVM_VRDPAUTHTYPE,
122 MODIFYVM_VRDPMULTICON,
123 MODIFYVM_VRDPREUSECON,
124 MODIFYVM_VRDP,
125 MODIFYVM_RTCUSEUTC,
126 MODIFYVM_USBEHCI,
127 MODIFYVM_USB,
128 MODIFYVM_SNAPSHOTFOLDER,
129 MODIFYVM_TELEPORTER_ENABLED,
130 MODIFYVM_TELEPORTER_PORT,
131 MODIFYVM_TELEPORTER_ADDRESS,
132 MODIFYVM_TELEPORTER_PASSWORD,
133 MODIFYVM_HARDWARE_UUID
134};
135
136static const RTGETOPTDEF g_aModifyVMOptions[] =
137{
138 { "--name", MODIFYVM_NAME, RTGETOPT_REQ_STRING },
139 { "--ostype", MODIFYVM_OSTYPE, RTGETOPT_REQ_STRING },
140 { "--memory", MODIFYVM_MEMORY, RTGETOPT_REQ_UINT32 },
141 { "--vram", MODIFYVM_VRAM, RTGETOPT_REQ_UINT32 },
142 { "--firmware", MODIFYVM_FIRMWARE, RTGETOPT_REQ_STRING },
143 { "--acpi", MODIFYVM_ACPI, RTGETOPT_REQ_BOOL_ONOFF },
144 { "--ioapic", MODIFYVM_IOAPIC, RTGETOPT_REQ_BOOL_ONOFF },
145 { "--pae", MODIFYVM_PAE, RTGETOPT_REQ_BOOL_ONOFF },
146 { "--synthcpu", MODIFYVM_SYNTHCPU, RTGETOPT_REQ_BOOL_ONOFF },
147 { "--hwvirtex", MODIFYVM_HWVIRTEX, RTGETOPT_REQ_BOOL_ONOFF },
148 { "--hwvirtexexcl", MODIFYVM_HWVIRTEXEXCLUSIVE, RTGETOPT_REQ_BOOL_ONOFF },
149 { "--nestedpaging", MODIFYVM_NESTEDPAGING, RTGETOPT_REQ_BOOL_ONOFF },
150 { "--vtxvpid", MODIFYVM_VTXVPID, RTGETOPT_REQ_BOOL_ONOFF },
151 { "--cpuidset", MODIFYVM_SETCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
152 { "--cpuidremove", MODIFYVM_DELCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
153 { "--cpuidremoveall", MODIFYVM_DELALLCPUID, RTGETOPT_REQ_NOTHING},
154 { "--cpus", MODIFYVM_CPUS, RTGETOPT_REQ_UINT32 },
155 { "--rtcuseutc", MODIFYVM_RTCUSEUTC, RTGETOPT_REQ_BOOL_ONOFF },
156 { "--monitorcount", MODIFYVM_MONITORCOUNT, RTGETOPT_REQ_UINT32 },
157 { "--accelerate3d", MODIFYVM_ACCELERATE3D, RTGETOPT_REQ_BOOL_ONOFF },
158 { "--accelerate2dvideo", MODIFYVM_ACCELERATE2DVIDEO, RTGETOPT_REQ_BOOL_ONOFF },
159 { "--bioslogofadein", MODIFYVM_BIOSLOGOFADEIN, RTGETOPT_REQ_BOOL_ONOFF },
160 { "--bioslogofadeout", MODIFYVM_BIOSLOGOFADEOUT, RTGETOPT_REQ_BOOL_ONOFF },
161 { "--bioslogodisplaytime", MODIFYVM_BIOSLOGODISPLAYTIME, RTGETOPT_REQ_UINT32 },
162 { "--bioslogoimagepath", MODIFYVM_BIOSLOGOIMAGEPATH, RTGETOPT_REQ_STRING },
163 { "--biosbootmenu", MODIFYVM_BIOSBOOTMENU, RTGETOPT_REQ_STRING },
164 { "--biossystemtimeoffset", MODIFYVM_BIOSSYSTEMTIMEOFFSET, RTGETOPT_REQ_INT64 },
165 { "--biospxedebug", MODIFYVM_BIOSPXEDEBUG, RTGETOPT_REQ_BOOL_ONOFF },
166 { "--boot", MODIFYVM_BOOT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
167 { "--hda", MODIFYVM_HDA, RTGETOPT_REQ_STRING },
168 { "--hdb", MODIFYVM_HDB, RTGETOPT_REQ_STRING },
169 { "--hdd", MODIFYVM_HDD, RTGETOPT_REQ_STRING },
170 { "--idecontroller", MODIFYVM_IDECONTROLLER, RTGETOPT_REQ_STRING },
171 { "--sataideemulation", MODIFYVM_SATAIDEEMULATION, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
172 { "--sataportcount", MODIFYVM_SATAPORTCOUNT, RTGETOPT_REQ_UINT32 },
173 { "--sataport", MODIFYVM_SATAPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
174 { "--sata", MODIFYVM_SATA, RTGETOPT_REQ_STRING },
175 { "--scsiport", MODIFYVM_SCSIPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
176 { "--scsitype", MODIFYVM_SCSITYPE, RTGETOPT_REQ_STRING },
177 { "--scsi", MODIFYVM_SCSI, RTGETOPT_REQ_STRING },
178 { "--dvdpassthrough", MODIFYVM_DVDPASSTHROUGH, RTGETOPT_REQ_STRING },
179 { "--dvd", MODIFYVM_DVD, RTGETOPT_REQ_STRING },
180 { "--floppy", MODIFYVM_FLOPPY, RTGETOPT_REQ_STRING },
181 { "--nictracefile", MODIFYVM_NICTRACEFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
182 { "--nictrace", MODIFYVM_NICTRACE, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
183 { "--nictype", MODIFYVM_NICTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
184 { "--nicspeed", MODIFYVM_NICSPEED, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
185 { "--nic", MODIFYVM_NIC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
186 { "--cableconnected", MODIFYVM_CABLECONNECTED, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
187 { "--bridgeadapter", MODIFYVM_BRIDGEADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
188 { "--hostonlyadapter", MODIFYVM_HOSTONLYADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
189 { "--intnet", MODIFYVM_INTNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
190 { "--natnet", MODIFYVM_NATNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
191 { "--macaddress", MODIFYVM_MACADDRESS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
192 { "--uartmode", MODIFYVM_UARTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
193 { "--uart", MODIFYVM_UART, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
194 { "--gueststatisticsinterval", MODIFYVM_GUESTSTATISTICSINTERVAL, RTGETOPT_REQ_UINT32 },
195 { "--guestmemoryballoon", MODIFYVM_GUESTMEMORYBALLOON, RTGETOPT_REQ_UINT32 },
196 { "--audiocontroller", MODIFYVM_AUDIOCONTROLLER, RTGETOPT_REQ_STRING },
197 { "--audio", MODIFYVM_AUDIO, RTGETOPT_REQ_STRING },
198 { "--clipboard", MODIFYVM_CLIPBOARD, RTGETOPT_REQ_STRING },
199 { "--vrdpport", MODIFYVM_VRDPPORT, RTGETOPT_REQ_STRING },
200 { "--vrdpaddress", MODIFYVM_VRDPADDRESS, RTGETOPT_REQ_STRING },
201 { "--vrdpauthtype", MODIFYVM_VRDPAUTHTYPE, RTGETOPT_REQ_STRING },
202 { "--vrdpmulticon", MODIFYVM_VRDPMULTICON, RTGETOPT_REQ_BOOL_ONOFF },
203 { "--vrdpreusecon", MODIFYVM_VRDPREUSECON, RTGETOPT_REQ_BOOL_ONOFF },
204 { "--vrdp", MODIFYVM_VRDP, RTGETOPT_REQ_BOOL_ONOFF },
205 { "--usbehci", MODIFYVM_USBEHCI, RTGETOPT_REQ_BOOL_ONOFF },
206 { "--usb", MODIFYVM_USB, RTGETOPT_REQ_BOOL_ONOFF },
207 { "--snapshotfolder", MODIFYVM_SNAPSHOTFOLDER, RTGETOPT_REQ_STRING },
208 { "--teleporter", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
209 { "--teleporterenabled", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
210 { "--teleporterport", MODIFYVM_TELEPORTER_PORT, RTGETOPT_REQ_UINT32 },
211 { "--teleporteraddress", MODIFYVM_TELEPORTER_ADDRESS, RTGETOPT_REQ_STRING },
212 { "--teleporterpassword", MODIFYVM_TELEPORTER_PASSWORD, RTGETOPT_REQ_STRING },
213 { "--hardwareuuid", MODIFYVM_HARDWARE_UUID, RTGETOPT_REQ_STRING },
214};
215
216int handleModifyVM(HandlerArg *a)
217{
218 int c;
219 HRESULT rc;
220 Bstr name;
221 Bstr machineuuid (a->argv[0]);
222 RTGETOPTUNION ValueUnion;
223 RTGETOPTSTATE GetOptState;
224 ComPtr <IMachine> machine;
225 ComPtr <IBIOSSettings> biosSettings;
226
227 /* VM ID + at least one parameter. Parameter arguments are checked
228 * individually. */
229 if (a->argc < 2)
230 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
231
232 /* Get the number of network adapters */
233 ULONG NetworkAdapterCount = 0;
234 {
235 ComPtr <ISystemProperties> info;
236 CHECK_ERROR_RET(a->virtualBox, COMGETTER(SystemProperties)(info.asOutParam()), 1);
237 CHECK_ERROR_RET(info, COMGETTER(NetworkAdapterCount)(&NetworkAdapterCount), 1);
238 }
239 ULONG SerialPortCount = 0;
240 {
241 ComPtr <ISystemProperties> info;
242 CHECK_ERROR_RET(a->virtualBox, COMGETTER(SystemProperties)(info.asOutParam()), 1);
243 CHECK_ERROR_RET(info, COMGETTER(SerialPortCount)(&SerialPortCount), 1);
244 }
245
246 /* try to find the given machine */
247 if (!Guid(machineuuid).isEmpty())
248 {
249 CHECK_ERROR_RET(a->virtualBox, GetMachine(machineuuid, machine.asOutParam()), 1);
250 }
251 else
252 {
253 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()), 1);
254 machine->COMGETTER(Id)(machineuuid.asOutParam());
255 }
256
257 /* open a session for the VM */
258 CHECK_ERROR_RET(a->virtualBox, OpenSession(a->session, machineuuid), 1);
259
260 /* get the mutable session machine */
261 a->session->COMGETTER(Machine)(machine.asOutParam());
262 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
263
264 RTGetOptInit(&GetOptState, a->argc, a->argv, g_aModifyVMOptions,
265 RT_ELEMENTS(g_aModifyVMOptions), 1, 0 /* fFlags */);
266
267 while ( SUCCEEDED (rc)
268 && (c = RTGetOpt(&GetOptState, &ValueUnion)))
269 {
270 switch (c)
271 {
272 case MODIFYVM_NAME:
273 {
274 CHECK_ERROR(machine, COMSETTER(Name)(Bstr(ValueUnion.psz)));
275 break;
276 }
277 case MODIFYVM_OSTYPE:
278 {
279 ComPtr<IGuestOSType> guestOSType;
280 CHECK_ERROR(a->virtualBox, GetGuestOSType(Bstr(ValueUnion.psz), guestOSType.asOutParam()));
281 if (SUCCEEDED(rc) && guestOSType)
282 {
283 CHECK_ERROR(machine, COMSETTER(OSTypeId)(Bstr(ValueUnion.psz)));
284 }
285 else
286 {
287 errorArgument("Invalid guest OS type '%s'", Utf8Str(ValueUnion.psz).raw());
288 rc = E_FAIL;
289 }
290 break;
291 }
292
293 case MODIFYVM_MEMORY:
294 {
295 CHECK_ERROR(machine, COMSETTER(MemorySize)(ValueUnion.u32));
296 break;
297 }
298
299 case MODIFYVM_VRAM:
300 {
301 CHECK_ERROR(machine, COMSETTER(VRAMSize)(ValueUnion.u32));
302 break;
303 }
304
305 case MODIFYVM_FIRMWARE:
306 {
307 if (!strcmp(ValueUnion.psz, "efi"))
308 {
309 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI));
310 }
311 else if (!strcmp(ValueUnion.psz, "efi32"))
312 {
313 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI32));
314 }
315 else if (!strcmp(ValueUnion.psz, "efi64"))
316 {
317 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI64));
318 }
319 else if (!strcmp(ValueUnion.psz, "efidual"))
320 {
321 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFIDUAL));
322 }
323 else if (!strcmp(ValueUnion.psz, "bios"))
324 {
325 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_BIOS));
326 }
327 else
328 {
329 errorArgument("Invalid --firmware argument '%s'", ValueUnion.psz);
330 rc = E_FAIL;
331 }
332 break;
333 }
334
335 case MODIFYVM_ACPI:
336 {
337 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(ValueUnion.f));
338 break;
339 }
340
341 case MODIFYVM_IOAPIC:
342 {
343 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(ValueUnion.f));
344 break;
345 }
346
347 case MODIFYVM_PAE:
348 {
349 CHECK_ERROR(machine, SetCpuProperty(CpuPropertyType_PAE, ValueUnion.f));
350 break;
351 }
352
353 case MODIFYVM_SYNTHCPU:
354 {
355 CHECK_ERROR(machine, SetCpuProperty(CpuPropertyType_Synthetic, ValueUnion.f));
356 break;
357 }
358
359 case MODIFYVM_HWVIRTEX:
360 {
361 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Enabled, ValueUnion.f));
362 break;
363 }
364
365 case MODIFYVM_HWVIRTEXEXCLUSIVE:
366 {
367 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Exclusive, ValueUnion.f));
368 break;
369 }
370
371 case MODIFYVM_SETCPUID:
372 {
373 uint32_t id = ValueUnion.u32;
374 uint32_t aValue[4];
375
376 for (unsigned i = 0 ; i < 4 ; i++)
377 {
378 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX);
379 if (RT_FAILURE(vrc))
380 return errorSyntax(USAGE_MODIFYVM,
381 "Missing or Invalid argument to '%s'",
382 GetOptState.pDef->pszLong);
383 aValue[i] = ValueUnion.u32;
384 }
385 CHECK_ERROR(machine, SetCpuIdLeaf(id, aValue[0], aValue[1], aValue[2], aValue[3]));
386 break;
387 }
388
389 case MODIFYVM_DELCPUID:
390 {
391 CHECK_ERROR(machine, RemoveCpuIdLeaf(ValueUnion.u32));
392 break;
393 }
394
395 case MODIFYVM_DELALLCPUID:
396 {
397 CHECK_ERROR(machine, RemoveAllCpuIdLeafs());
398 break;
399 }
400
401 case MODIFYVM_NESTEDPAGING:
402 {
403 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, ValueUnion.f));
404 break;
405 }
406
407 case MODIFYVM_VTXVPID:
408 {
409 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_VPID, ValueUnion.f));
410 break;
411 }
412
413 case MODIFYVM_CPUS:
414 {
415 CHECK_ERROR(machine, COMSETTER(CPUCount)(ValueUnion.u32));
416 break;
417 }
418
419 case MODIFYVM_RTCUSEUTC:
420 {
421 CHECK_ERROR(machine, COMSETTER(RTCUseUTC)(ValueUnion.f));
422 break;
423 }
424
425 case MODIFYVM_MONITORCOUNT:
426 {
427 CHECK_ERROR(machine, COMSETTER(MonitorCount)(ValueUnion.u32));
428 break;
429 }
430
431 case MODIFYVM_ACCELERATE3D:
432 {
433 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(ValueUnion.f));
434 break;
435 }
436
437#ifdef VBOX_WITH_VIDEOHWACCEL
438 case MODIFYVM_ACCELERATE2DVIDEO:
439 {
440 CHECK_ERROR(machine, COMSETTER(Accelerate2DVideoEnabled)(ValueUnion.f));
441 break;
442 }
443#endif
444
445 case MODIFYVM_BIOSLOGOFADEIN:
446 {
447 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(ValueUnion.f));
448 break;
449 }
450
451 case MODIFYVM_BIOSLOGOFADEOUT:
452 {
453 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(ValueUnion.f));
454 break;
455 }
456
457 case MODIFYVM_BIOSLOGODISPLAYTIME:
458 {
459 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(ValueUnion.u32));
460 break;
461 }
462
463 case MODIFYVM_BIOSLOGOIMAGEPATH:
464 {
465 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(ValueUnion.psz)));
466 break;
467 }
468
469 case MODIFYVM_BIOSBOOTMENU:
470 {
471 if (!strcmp(ValueUnion.psz, "disabled"))
472 {
473 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
474 }
475 else if (!strcmp(ValueUnion.psz, "menuonly"))
476 {
477 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
478 }
479 else if (!strcmp(ValueUnion.psz, "messageandmenu"))
480 {
481 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
482 }
483 else
484 {
485 errorArgument("Invalid --biosbootmenu argument '%s'", ValueUnion.psz);
486 rc = E_FAIL;
487 }
488 break;
489 }
490
491 case MODIFYVM_BIOSSYSTEMTIMEOFFSET:
492 {
493 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(ValueUnion.i64));
494 break;
495 }
496
497 case MODIFYVM_BIOSPXEDEBUG:
498 {
499 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(ValueUnion.f));
500 break;
501 }
502
503 case MODIFYVM_BOOT:
504 {
505 if (!strcmp(ValueUnion.psz, "none"))
506 {
507 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Null));
508 }
509 else if (!strcmp(ValueUnion.psz, "floppy"))
510 {
511 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Floppy));
512 }
513 else if (!strcmp(ValueUnion.psz, "dvd"))
514 {
515 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_DVD));
516 }
517 else if (!strcmp(ValueUnion.psz, "disk"))
518 {
519 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_HardDisk));
520 }
521 else if (!strcmp(ValueUnion.psz, "net"))
522 {
523 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Network));
524 }
525 else
526 return errorArgument("Invalid boot device '%s'", ValueUnion.psz);
527 break;
528 }
529
530 case MODIFYVM_HDA: // deprecated
531 {
532 if (!strcmp(ValueUnion.psz, "none"))
533 {
534 machine->DetachDevice(Bstr("IDE Controller"), 0, 0);
535 }
536 else
537 {
538 /* first guess is that it's a UUID */
539 Bstr uuid(ValueUnion.psz);
540 ComPtr<IMedium> hardDisk;
541 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
542 /* not successful? Then it must be a filename */
543 if (!hardDisk)
544 {
545 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
546 if (FAILED(rc))
547 {
548 /* open the new hard disk object */
549 CHECK_ERROR(a->virtualBox,
550 OpenHardDisk(Bstr(ValueUnion.psz),
551 AccessMode_ReadWrite, false, Bstr(""),
552 false, Bstr(""), hardDisk.asOutParam()));
553 }
554 }
555 if (hardDisk)
556 {
557 hardDisk->COMGETTER(Id)(uuid.asOutParam());
558 CHECK_ERROR(machine, AttachDevice(Bstr("IDE Controller"), 0, 0, DeviceType_HardDisk, uuid));
559 }
560 else
561 rc = E_FAIL;
562 }
563 break;
564 }
565
566 case MODIFYVM_HDB: // deprecated
567 {
568 if (!strcmp(ValueUnion.psz, "none"))
569 {
570 machine->DetachDevice(Bstr("IDE Controller"), 0, 1);
571 }
572 else
573 {
574 /* first guess is that it's a UUID */
575 Bstr uuid(ValueUnion.psz);
576 ComPtr<IMedium> hardDisk;
577 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
578 /* not successful? Then it must be a filename */
579 if (!hardDisk)
580 {
581 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
582 if (FAILED(rc))
583 {
584 /* open the new hard disk object */
585 CHECK_ERROR(a->virtualBox,
586 OpenHardDisk(Bstr(ValueUnion.psz),
587 AccessMode_ReadWrite, false, Bstr(""),
588 false, Bstr(""), hardDisk.asOutParam()));
589 }
590 }
591 if (hardDisk)
592 {
593 hardDisk->COMGETTER(Id)(uuid.asOutParam());
594 CHECK_ERROR(machine, AttachDevice(Bstr("IDE Controller"), 0, 1, DeviceType_HardDisk, uuid));
595 }
596 else
597 rc = E_FAIL;
598 }
599 break;
600 }
601
602 case MODIFYVM_HDD: // deprecated
603 {
604 if (!strcmp(ValueUnion.psz, "none"))
605 {
606 machine->DetachDevice(Bstr("IDE Controller"), 1, 1);
607 }
608 else
609 {
610 /* first guess is that it's a UUID */
611 Bstr uuid(ValueUnion.psz);
612 ComPtr<IMedium> hardDisk;
613 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
614 /* not successful? Then it must be a filename */
615 if (!hardDisk)
616 {
617 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
618 if (FAILED(rc))
619 {
620 /* open the new hard disk object */
621 CHECK_ERROR(a->virtualBox,
622 OpenHardDisk(Bstr(ValueUnion.psz),
623 AccessMode_ReadWrite, false, Bstr(""),
624 false, Bstr(""), hardDisk.asOutParam()));
625 }
626 }
627 if (hardDisk)
628 {
629 hardDisk->COMGETTER(Id)(uuid.asOutParam());
630 CHECK_ERROR(machine, AttachDevice(Bstr("IDE Controller"), 1, 1, DeviceType_HardDisk, uuid));
631 }
632 else
633 rc = E_FAIL;
634 }
635 break;
636 }
637
638 case MODIFYVM_IDECONTROLLER: // deprecated
639 {
640 ComPtr<IStorageController> storageController;
641 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("IDE Controller"),
642 storageController.asOutParam()));
643
644 if (!RTStrICmp(ValueUnion.psz, "PIIX3"))
645 {
646 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
647 }
648 else if (!RTStrICmp(ValueUnion.psz, "PIIX4"))
649 {
650 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
651 }
652 else if (!RTStrICmp(ValueUnion.psz, "ICH6"))
653 {
654 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_ICH6));
655 }
656 else
657 {
658 errorArgument("Invalid --idecontroller argument '%s'", ValueUnion.psz);
659 rc = E_FAIL;
660 }
661 break;
662 }
663
664 case MODIFYVM_SATAIDEEMULATION: // deprecated
665 {
666 ComPtr<IStorageController> SataCtl;
667 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA"), SataCtl.asOutParam()));
668
669 if (SUCCEEDED(rc))
670 CHECK_ERROR(SataCtl, SetIDEEmulationPort(GetOptState.uIndex, ValueUnion.u32));
671 break;
672 }
673
674 case MODIFYVM_SATAPORTCOUNT: // deprecated
675 {
676 ComPtr<IStorageController> SataCtl;
677 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA"), SataCtl.asOutParam()));
678
679 if (SUCCEEDED(rc) && ValueUnion.u32 > 0)
680 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(ValueUnion.u32));
681 break;
682 }
683
684 case MODIFYVM_SATAPORT: // deprecated
685 {
686 if (!strcmp(ValueUnion.psz, "none"))
687 {
688 machine->DetachDevice(Bstr("SATA"), GetOptState.uIndex, 0);
689 }
690 else
691 {
692 /* first guess is that it's a UUID */
693 Bstr uuid(ValueUnion.psz);
694 ComPtr<IMedium> hardDisk;
695 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
696 /* not successful? Then it must be a filename */
697 if (!hardDisk)
698 {
699 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
700 if (FAILED(rc))
701 {
702 /* open the new hard disk object */
703 CHECK_ERROR(a->virtualBox,
704 OpenHardDisk(Bstr(ValueUnion.psz), AccessMode_ReadWrite,
705 false, Bstr(""), false,
706 Bstr(""), hardDisk.asOutParam()));
707 }
708 }
709 if (hardDisk)
710 {
711 hardDisk->COMGETTER(Id)(uuid.asOutParam());
712 CHECK_ERROR(machine,
713 AttachDevice(Bstr("SATA"), GetOptState.uIndex,
714 0, DeviceType_HardDisk, uuid));
715 }
716 else
717 rc = E_FAIL;
718 }
719 break;
720 }
721
722 case MODIFYVM_SATA: // deprecated
723 {
724 if (!strcmp(ValueUnion.psz, "on") || !strcmp(ValueUnion.psz, "enable"))
725 {
726 ComPtr<IStorageController> ctl;
727 CHECK_ERROR(machine, AddStorageController(Bstr("SATA"), StorageBus_SATA, ctl.asOutParam()));
728 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
729 }
730 else if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
731 CHECK_ERROR(machine, RemoveStorageController(Bstr("SATA")));
732 else
733 return errorArgument("Invalid --usb argument '%s'", ValueUnion.psz);
734 break;
735 }
736
737 case MODIFYVM_SCSIPORT: // deprecated
738 {
739 if (!strcmp(ValueUnion.psz, "none"))
740 {
741 rc = machine->DetachDevice(Bstr("LsiLogic"), GetOptState.uIndex, 0);
742 if (FAILED(rc))
743 CHECK_ERROR(machine, DetachDevice(Bstr("BusLogic"), GetOptState.uIndex, 0));
744 }
745 else
746 {
747 /* first guess is that it's a UUID */
748 Bstr uuid(ValueUnion.psz);
749 ComPtr<IMedium> hardDisk;
750 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
751 /* not successful? Then it must be a filename */
752 if (!hardDisk)
753 {
754 rc = a->virtualBox->FindHardDisk(Bstr(ValueUnion.psz), hardDisk.asOutParam());
755 if (FAILED(rc))
756 {
757 /* open the new hard disk object */
758 CHECK_ERROR(a->virtualBox,
759 OpenHardDisk(Bstr(ValueUnion.psz),
760 AccessMode_ReadWrite, false, Bstr(""),
761 false, Bstr(""), hardDisk.asOutParam()));
762 }
763 }
764 if (hardDisk)
765 {
766 hardDisk->COMGETTER(Id)(uuid.asOutParam());
767 rc = machine->AttachDevice(Bstr("LsiLogic"), GetOptState.uIndex, 0, DeviceType_HardDisk, uuid);
768 if (FAILED(rc))
769 CHECK_ERROR(machine,
770 AttachDevice(Bstr("BusLogic"),
771 GetOptState.uIndex, 0,
772 DeviceType_HardDisk, uuid));
773 }
774 else
775 rc = E_FAIL;
776 }
777 break;
778 }
779
780 case MODIFYVM_SCSITYPE: // deprecated
781 {
782 ComPtr<IStorageController> ctl;
783
784 if (!RTStrICmp(ValueUnion.psz, "LsiLogic"))
785 {
786 rc = machine->RemoveStorageController(Bstr("BusLogic"));
787 if (FAILED(rc))
788 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic")));
789
790 CHECK_ERROR(machine,
791 AddStorageController(Bstr("LsiLogic"),
792 StorageBus_SCSI,
793 ctl.asOutParam()));
794
795 if (SUCCEEDED(rc))
796 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
797 }
798 else if (!RTStrICmp(ValueUnion.psz, "BusLogic"))
799 {
800 rc = machine->RemoveStorageController(Bstr("LsiLogic"));
801 if (FAILED(rc))
802 CHECK_ERROR(machine, RemoveStorageController(Bstr("BusLogic")));
803
804 CHECK_ERROR(machine,
805 AddStorageController(Bstr("BusLogic"),
806 StorageBus_SCSI,
807 ctl.asOutParam()));
808
809 if (SUCCEEDED(rc))
810 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
811 }
812 else
813 return errorArgument("Invalid --scsitype argument '%s'", ValueUnion.psz);
814 break;
815 }
816
817 case MODIFYVM_SCSI: // deprecated
818 {
819 if (!strcmp(ValueUnion.psz, "on") || !strcmp(ValueUnion.psz, "enable"))
820 {
821 ComPtr<IStorageController> ctl;
822
823 CHECK_ERROR(machine, AddStorageController(Bstr("BusLogic"), StorageBus_SCSI, ctl.asOutParam()));
824 if (SUCCEEDED(rc))
825 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
826 }
827 else if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
828 {
829 rc = machine->RemoveStorageController(Bstr("BusLogic"));
830 if (FAILED(rc))
831 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic")));
832 }
833 break;
834 }
835
836 case MODIFYVM_DVDPASSTHROUGH: // deprecated
837 {
838 CHECK_ERROR(machine, PassthroughDevice(Bstr("IDE Controller"), 1, 0, !strcmp(ValueUnion.psz, "on")));
839 break;
840 }
841
842 case MODIFYVM_DVD: // deprecated
843 {
844 ComPtr<IMedium> dvdMedium;
845 Bstr uuid(ValueUnion.psz);
846
847 /* unmount? */
848 if (!strcmp(ValueUnion.psz, "none"))
849 {
850 /* nothing to do, NULL object will cause unmount */
851 }
852 /* host drive? */
853 else if (!strncmp(ValueUnion.psz, "host:", 5))
854 {
855 ComPtr<IHost> host;
856 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
857 rc = host->FindHostDVDDrive(Bstr(ValueUnion.psz + 5), dvdMedium.asOutParam());
858 if (!dvdMedium)
859 {
860 /* 2nd try: try with the real name, important on Linux+libhal */
861 char szPathReal[RTPATH_MAX];
862 if (RT_FAILURE(RTPathReal(ValueUnion.psz + 5, szPathReal, sizeof(szPathReal))))
863 {
864 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
865 rc = E_FAIL;
866 break;
867 }
868 rc = host->FindHostDVDDrive(Bstr(szPathReal), dvdMedium.asOutParam());
869 if (!dvdMedium)
870 {
871 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
872 rc = E_FAIL;
873 break;
874 }
875 }
876 }
877 else
878 {
879 /* first assume it's a UUID */
880 rc = a->virtualBox->GetDVDImage(uuid, dvdMedium.asOutParam());
881 if (FAILED(rc) || !dvdMedium)
882 {
883 /* must be a filename, check if it's in the collection */
884 rc = a->virtualBox->FindDVDImage(Bstr(ValueUnion.psz), dvdMedium.asOutParam());
885 /* not registered, do that on the fly */
886 if (!dvdMedium)
887 {
888 Bstr emptyUUID;
889 CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(ValueUnion.psz),
890 emptyUUID, dvdMedium.asOutParam()));
891 }
892 }
893 if (!dvdMedium)
894 {
895 rc = E_FAIL;
896 break;
897 }
898 }
899
900 /** @todo generalize this, allow arbitrary number of DVD drives
901 * and as a consequence multiple attachments and different
902 * storage controllers. */
903 if (dvdMedium)
904 dvdMedium->COMGETTER(Id)(uuid.asOutParam());
905 CHECK_ERROR(machine, MountMedium(Bstr("IDE Controller"), 1, 0, uuid, FALSE /* aForce */));
906 break;
907 }
908
909 case MODIFYVM_FLOPPY: // deprecated
910 {
911 Bstr uuid(ValueUnion.psz);
912 ComPtr<IMedium> floppyMedium;
913 ComPtr<IMediumAttachment> floppyAttachment;
914 machine->GetMediumAttachment(Bstr("Floppy Controller"), 0, 0, floppyAttachment.asOutParam());
915
916 /* disable? */
917 if (!strcmp(ValueUnion.psz, "disabled"))
918 {
919 /* disable the controller */
920 if (floppyAttachment)
921 CHECK_ERROR(machine, DetachDevice(Bstr("Floppy Controller"), 0, 0));
922 }
923 else
924 {
925 /* enable the controller */
926 if (!floppyAttachment)
927 CHECK_ERROR(machine, AttachDevice(Bstr("Floppy Controller"), 0, 0, DeviceType_Floppy, NULL));
928
929 /* unmount? */
930 if ( !strcmp(ValueUnion.psz, "none")
931 || !strcmp(ValueUnion.psz, "empty")) // deprecated
932 {
933 /* nothing to do, NULL object will cause unmount */
934 }
935 /* host drive? */
936 else if (!strncmp(ValueUnion.psz, "host:", 5))
937 {
938 ComPtr<IHost> host;
939 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
940 rc = host->FindHostFloppyDrive(Bstr(ValueUnion.psz + 5), floppyMedium.asOutParam());
941 if (!floppyMedium)
942 {
943 errorArgument("Invalid host floppy drive name \"%s\"", ValueUnion.psz + 5);
944 rc = E_FAIL;
945 break;
946 }
947 }
948 else
949 {
950 /* first assume it's a UUID */
951 rc = a->virtualBox->GetFloppyImage(uuid, floppyMedium.asOutParam());
952 if (FAILED(rc) || !floppyMedium)
953 {
954 /* must be a filename, check if it's in the collection */
955 rc = a->virtualBox->FindFloppyImage(Bstr(ValueUnion.psz), floppyMedium.asOutParam());
956 /* not registered, do that on the fly */
957 if (!floppyMedium)
958 {
959 Bstr emptyUUID;
960 CHECK_ERROR(a->virtualBox,
961 OpenFloppyImage(Bstr(ValueUnion.psz),
962 emptyUUID,
963 floppyMedium.asOutParam()));
964 }
965 }
966 if (!floppyMedium)
967 {
968 rc = E_FAIL;
969 break;
970 }
971 }
972 floppyMedium->COMGETTER(Id)(uuid.asOutParam());
973 CHECK_ERROR(machine, MountMedium(Bstr("Floppy Controller"), 0, 0, uuid, FALSE /* aForce */));
974 }
975 break;
976 }
977
978 case MODIFYVM_NICTRACEFILE:
979 {
980 ComPtr<INetworkAdapter> nic;
981
982 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
983 ASSERT(nic);
984
985 CHECK_ERROR(nic, COMSETTER(TraceFile)(Bstr(ValueUnion.psz)));
986 break;
987 }
988
989 case MODIFYVM_NICTRACE:
990 {
991 ComPtr<INetworkAdapter> nic;
992
993 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
994 ASSERT(nic);
995
996 CHECK_ERROR(nic, COMSETTER(TraceEnabled)(ValueUnion.f));
997 break;
998 }
999
1000 case MODIFYVM_NICTYPE:
1001 {
1002 ComPtr<INetworkAdapter> nic;
1003
1004 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1005 ASSERT(nic);
1006
1007 if (!strcmp(ValueUnion.psz, "Am79C970A"))
1008 {
1009 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A));
1010 }
1011 else if (!strcmp(ValueUnion.psz, "Am79C973"))
1012 {
1013 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973));
1014 }
1015#ifdef VBOX_WITH_E1000
1016 else if (!strcmp(ValueUnion.psz, "82540EM"))
1017 {
1018 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM));
1019 }
1020 else if (!strcmp(ValueUnion.psz, "82543GC"))
1021 {
1022 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC));
1023 }
1024 else if (!strcmp(ValueUnion.psz, "82545EM"))
1025 {
1026 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82545EM));
1027 }
1028#endif
1029#ifdef VBOX_WITH_VIRTIO
1030 else if (!strcmp(ValueUnion.psz, "virtio"))
1031 {
1032 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Virtio));
1033 }
1034#endif /* VBOX_WITH_VIRTIO */
1035 else
1036 {
1037 errorArgument("Invalid NIC type '%s' specified for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1038 rc = E_FAIL;
1039 }
1040 break;
1041 }
1042
1043 case MODIFYVM_NICSPEED:
1044 {
1045 ComPtr<INetworkAdapter> nic;
1046
1047 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1048 ASSERT(nic);
1049
1050 CHECK_ERROR(nic, COMSETTER(LineSpeed)(ValueUnion.u32));
1051 break;
1052 }
1053
1054 case MODIFYVM_NIC:
1055 {
1056 ComPtr<INetworkAdapter> nic;
1057
1058 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1059 ASSERT(nic);
1060
1061 if (!strcmp(ValueUnion.psz, "none"))
1062 {
1063 CHECK_ERROR(nic, COMSETTER(Enabled)(FALSE));
1064 }
1065 else if (!strcmp(ValueUnion.psz, "null"))
1066 {
1067 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1068 CHECK_ERROR(nic, Detach());
1069 }
1070 else if (!strcmp(ValueUnion.psz, "nat"))
1071 {
1072 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1073 CHECK_ERROR(nic, AttachToNAT());
1074 }
1075 else if ( !strcmp(ValueUnion.psz, "bridged")
1076 || !strcmp(ValueUnion.psz, "hostif")) /* backward compatibility */
1077 {
1078 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1079 CHECK_ERROR(nic, AttachToBridgedInterface());
1080 }
1081 else if (!strcmp(ValueUnion.psz, "intnet"))
1082 {
1083 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1084 CHECK_ERROR(nic, AttachToInternalNetwork());
1085 }
1086#if defined(VBOX_WITH_NETFLT)
1087 else if (!strcmp(ValueUnion.psz, "hostonly"))
1088 {
1089
1090 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1091 CHECK_ERROR(nic, AttachToHostOnlyInterface());
1092 }
1093#endif
1094 else
1095 {
1096 errorArgument("Invalid type '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1097 rc = E_FAIL;
1098 }
1099 break;
1100 }
1101
1102 case MODIFYVM_CABLECONNECTED:
1103 {
1104 ComPtr<INetworkAdapter> nic;
1105
1106 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1107 ASSERT(nic);
1108
1109 CHECK_ERROR(nic, COMSETTER(CableConnected)(ValueUnion.f));
1110 break;
1111 }
1112
1113 case MODIFYVM_BRIDGEADAPTER:
1114 case MODIFYVM_HOSTONLYADAPTER:
1115 {
1116 ComPtr<INetworkAdapter> nic;
1117
1118 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1119 ASSERT(nic);
1120
1121 /* remove it? */
1122 if (!strcmp(ValueUnion.psz, "none"))
1123 {
1124 CHECK_ERROR(nic, COMSETTER(HostInterface)(NULL));
1125 }
1126 else
1127 {
1128 CHECK_ERROR(nic, COMSETTER(HostInterface)(Bstr(ValueUnion.psz)));
1129 }
1130 break;
1131 }
1132
1133 case MODIFYVM_INTNET:
1134 {
1135 ComPtr<INetworkAdapter> nic;
1136
1137 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1138 ASSERT(nic);
1139
1140 /* remove it? */
1141 if (!strcmp(ValueUnion.psz, "none"))
1142 {
1143 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(NULL));
1144 }
1145 else
1146 {
1147 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr(ValueUnion.psz)));
1148 }
1149 break;
1150 }
1151
1152 case MODIFYVM_NATNET:
1153 {
1154 ComPtr<INetworkAdapter> nic;
1155
1156 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1157 ASSERT(nic);
1158
1159 CHECK_ERROR(nic, COMSETTER(NATNetwork)(Bstr(ValueUnion.psz)));
1160 break;
1161 }
1162
1163 case MODIFYVM_MACADDRESS:
1164 {
1165 ComPtr<INetworkAdapter> nic;
1166
1167 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1168 ASSERT(nic);
1169
1170 /* generate one? */
1171 if (!strcmp(ValueUnion.psz, "auto"))
1172 {
1173 CHECK_ERROR(nic, COMSETTER(MACAddress)(NULL));
1174 }
1175 else
1176 {
1177 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr(ValueUnion.psz)));
1178 }
1179 break;
1180 }
1181
1182 case MODIFYVM_UARTMODE:
1183 {
1184 ComPtr<ISerialPort> uart;
1185 char *pszIRQ = NULL;
1186
1187 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1188 ASSERT(uart);
1189
1190 if (!strcmp(ValueUnion.psz, "disconnected"))
1191 {
1192 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
1193 }
1194 else if ( !strcmp(ValueUnion.psz, "server")
1195 || !strcmp(ValueUnion.psz, "client")
1196 || !strcmp(ValueUnion.psz, "file"))
1197 {
1198 const char *pszMode = ValueUnion.psz;
1199
1200 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1201 if (RT_FAILURE(vrc))
1202 return errorSyntax(USAGE_MODIFYVM,
1203 "Missing or Invalid argument to '%s'",
1204 GetOptState.pDef->pszLong);
1205
1206 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz)));
1207
1208 if (!strcmp(pszMode, "server"))
1209 {
1210 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1211 CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
1212 }
1213 else if (!strcmp(pszMode, "client"))
1214 {
1215 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1216 CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
1217 }
1218 else if (!strcmp(pszMode, "file"))
1219 {
1220 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_RawFile));
1221 }
1222 }
1223 else
1224 {
1225 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz)));
1226 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostDevice));
1227 }
1228 break;
1229 }
1230
1231 case MODIFYVM_UART:
1232 {
1233 ComPtr<ISerialPort> uart;
1234
1235 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1236 ASSERT(uart);
1237
1238 if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
1239 CHECK_ERROR(uart, COMSETTER(Enabled)(FALSE));
1240 else
1241 {
1242 const char *pszIOBase = ValueUnion.psz;
1243 uint32_t uVal = 0;
1244
1245 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_UART;
1246 if (RT_FAILURE(vrc))
1247 return errorSyntax(USAGE_MODIFYVM,
1248 "Missing or Invalid argument to '%s'",
1249 GetOptState.pDef->pszLong);
1250
1251 CHECK_ERROR(uart, COMSETTER(IRQ)(ValueUnion.u32));
1252
1253 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1254 if (vrc != VINF_SUCCESS || uVal == 0)
1255 return errorArgument("Error parsing UART I/O base '%s'", pszIOBase);
1256 CHECK_ERROR(uart, COMSETTER(IOBase)(uVal));
1257
1258 CHECK_ERROR(uart, COMSETTER(Enabled)(TRUE));
1259 }
1260 break;
1261 }
1262
1263 case MODIFYVM_GUESTSTATISTICSINTERVAL:
1264 {
1265 CHECK_ERROR(machine, COMSETTER(StatisticsUpdateInterval)(ValueUnion.u32));
1266 break;
1267 }
1268
1269#ifdef VBOX_WITH_MEM_BALLOONING
1270 case MODIFYVM_GUESTMEMORYBALLOON:
1271 {
1272 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(ValueUnion.u32));
1273 break;
1274 }
1275#endif
1276
1277 case MODIFYVM_AUDIOCONTROLLER:
1278 {
1279 ComPtr<IAudioAdapter> audioAdapter;
1280 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1281 ASSERT(audioAdapter);
1282
1283 if (!strcmp(ValueUnion.psz, "sb16"))
1284 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
1285 else if (!strcmp(ValueUnion.psz, "ac97"))
1286 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
1287 else
1288 {
1289 errorArgument("Invalid --audiocontroller argument '%s'", ValueUnion.psz);
1290 rc = E_FAIL;
1291 }
1292 break;
1293 }
1294
1295 case MODIFYVM_AUDIO:
1296 {
1297 ComPtr<IAudioAdapter> audioAdapter;
1298 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1299 ASSERT(audioAdapter);
1300
1301 /* disable? */
1302 if (!strcmp(ValueUnion.psz, "none"))
1303 {
1304 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
1305 }
1306 else if (!strcmp(ValueUnion.psz, "null"))
1307 {
1308 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
1309 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1310 }
1311#ifdef RT_OS_WINDOWS
1312#ifdef VBOX_WITH_WINMM
1313 else if (!strcmp(ValueUnion.psz, "winmm"))
1314 {
1315 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
1316 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1317 }
1318#endif
1319 else if (!strcmp(ValueUnion.psz, "dsound"))
1320 {
1321 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
1322 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1323 }
1324#endif /* RT_OS_WINDOWS */
1325#ifdef RT_OS_LINUX
1326# ifdef VBOX_WITH_ALSA
1327 else if (!strcmp(ValueUnion.psz, "alsa"))
1328 {
1329 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
1330 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1331 }
1332# endif
1333# ifdef VBOX_WITH_PULSE
1334 else if (!strcmp(ValueUnion.psz, "pulse"))
1335 {
1336 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1337 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1338 }
1339# endif
1340#endif /* !RT_OS_LINUX */
1341#ifdef RT_OS_SOLARIS
1342 else if (!strcmp(ValueUnion.psz, "solaudio"))
1343 {
1344 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
1345 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1346 }
1347#endif /* !RT_OS_SOLARIS */
1348#ifdef RT_OS_DARWIN
1349 else if (!strcmp(ValueUnion.psz, "coreaudio"))
1350 {
1351 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
1352 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1353 }
1354
1355#endif /* !RT_OS_DARWIN */
1356# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(VBOX_WITH_SOLARIS_OSS)
1357 else if (!strcmp(ValueUnion.psz, "oss"))
1358 {
1359 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1360 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1361 }
1362# endif
1363 else
1364 {
1365 errorArgument("Invalid --audio argument '%s'", ValueUnion.psz);
1366 rc = E_FAIL;
1367 }
1368 break;
1369 }
1370
1371 case MODIFYVM_CLIPBOARD:
1372 {
1373 if (!strcmp(ValueUnion.psz, "disabled"))
1374 {
1375 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Disabled));
1376 }
1377 else if (!strcmp(ValueUnion.psz, "hosttoguest"))
1378 {
1379 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_HostToGuest));
1380 }
1381 else if (!strcmp(ValueUnion.psz, "guesttohost"))
1382 {
1383 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_GuestToHost));
1384 }
1385 else if (!strcmp(ValueUnion.psz, "bidirectional"))
1386 {
1387 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Bidirectional));
1388 }
1389 else
1390 {
1391 errorArgument("Invalid --clipboard argument '%s'", ValueUnion.psz);
1392 rc = E_FAIL;
1393 }
1394 break;
1395 }
1396
1397#ifdef VBOX_WITH_VRDP
1398 case MODIFYVM_VRDPPORT:
1399 {
1400 ComPtr<IVRDPServer> vrdpServer;
1401 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1402 ASSERT(vrdpServer);
1403
1404 if (!strcmp(ValueUnion.psz, "default"))
1405 CHECK_ERROR(vrdpServer, COMSETTER(Ports)(Bstr("0")));
1406 else
1407 CHECK_ERROR(vrdpServer, COMSETTER(Ports)(Bstr(ValueUnion.psz)));
1408 break;
1409 }
1410
1411 case MODIFYVM_VRDPADDRESS:
1412 {
1413 ComPtr<IVRDPServer> vrdpServer;
1414 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1415 ASSERT(vrdpServer);
1416
1417 CHECK_ERROR(vrdpServer, COMSETTER(NetAddress)(Bstr(ValueUnion.psz)));
1418 break;
1419 }
1420
1421 case MODIFYVM_VRDPAUTHTYPE:
1422 {
1423 ComPtr<IVRDPServer> vrdpServer;
1424 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1425 ASSERT(vrdpServer);
1426
1427 if (!strcmp(ValueUnion.psz, "null"))
1428 {
1429 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Null));
1430 }
1431 else if (!strcmp(ValueUnion.psz, "external"))
1432 {
1433 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_External));
1434 }
1435 else if (!strcmp(ValueUnion.psz, "guest"))
1436 {
1437 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Guest));
1438 }
1439 else
1440 {
1441 errorArgument("Invalid --vrdpauthtype argument '%s'", ValueUnion.psz);
1442 rc = E_FAIL;
1443 }
1444 break;
1445 }
1446
1447 case MODIFYVM_VRDPMULTICON:
1448 {
1449 ComPtr<IVRDPServer> vrdpServer;
1450 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1451 ASSERT(vrdpServer);
1452
1453 CHECK_ERROR(vrdpServer, COMSETTER(AllowMultiConnection)(ValueUnion.f));
1454 break;
1455 }
1456
1457 case MODIFYVM_VRDPREUSECON:
1458 {
1459 ComPtr<IVRDPServer> vrdpServer;
1460 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1461 ASSERT(vrdpServer);
1462
1463 CHECK_ERROR(vrdpServer, COMSETTER(ReuseSingleConnection)(ValueUnion.f));
1464 break;
1465 }
1466
1467 case MODIFYVM_VRDP:
1468 {
1469 ComPtr<IVRDPServer> vrdpServer;
1470 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1471 ASSERT(vrdpServer);
1472
1473 CHECK_ERROR(vrdpServer, COMSETTER(Enabled)(ValueUnion.f));
1474 break;
1475 }
1476#endif /* VBOX_WITH_VRDP */
1477
1478 case MODIFYVM_USBEHCI:
1479 {
1480 ComPtr<IUSBController> UsbCtl;
1481 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1482 if (SUCCEEDED(rc))
1483 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEhci)(ValueUnion.f));
1484 break;
1485 }
1486
1487 case MODIFYVM_USB:
1488 {
1489 ComPtr<IUSBController> UsbCtl;
1490 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1491 if (SUCCEEDED(rc))
1492 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(ValueUnion.f));
1493 break;
1494 }
1495
1496 case MODIFYVM_SNAPSHOTFOLDER:
1497 {
1498 if (!strcmp(ValueUnion.psz, "default"))
1499 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(NULL));
1500 else
1501 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(ValueUnion.psz)));
1502 break;
1503 }
1504
1505 case MODIFYVM_TELEPORTER_ENABLED:
1506 {
1507 CHECK_ERROR(machine, COMSETTER(TeleporterEnabled)(ValueUnion.f));
1508 break;
1509 }
1510
1511 case MODIFYVM_TELEPORTER_PORT:
1512 {
1513 CHECK_ERROR(machine, COMSETTER(TeleporterPort)(ValueUnion.u32));
1514 break;
1515 }
1516
1517 case MODIFYVM_TELEPORTER_ADDRESS:
1518 {
1519 CHECK_ERROR(machine, COMSETTER(TeleporterAddress)(Bstr(ValueUnion.psz)));
1520 break;
1521 }
1522
1523 case MODIFYVM_TELEPORTER_PASSWORD:
1524 {
1525 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(ValueUnion.psz)));
1526 break;
1527 }
1528
1529 case MODIFYVM_HARDWARE_UUID:
1530 {
1531 CHECK_ERROR(machine, COMSETTER(HardwareUUID)(Bstr(ValueUnion.psz)));
1532 break;
1533 }
1534
1535 default:
1536 {
1537 errorGetOpt(USAGE_MODIFYVM, c, &ValueUnion);
1538 rc = E_FAIL;
1539 break;
1540 }
1541 }
1542 }
1543
1544 /* commit changes */
1545 if (SUCCEEDED(rc))
1546 CHECK_ERROR(machine, SaveSettings());
1547
1548 /* it's important to always close sessions */
1549 a->session->Close();
1550
1551 return SUCCEEDED(rc) ? 0 : 1;
1552}
1553
1554#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