VirtualBox

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

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

VBoxManageModifyVM.cpp: --bioslogodisplaytime takes a 32-bit unsigned int, not 64-bit.

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