VirtualBox

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

Last change on this file since 18011 was 17939, checked in by vboxsync, 16 years ago

VBoxManage: Make it possible to specify the SCSI controller type

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 69.7 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 17939 2009-03-16 14:28:53Z 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/errorprint2.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 <VBox/log.h>
44
45#include "VBoxManage.h"
46
47#ifndef VBOX_ONLY_DOCS
48using namespace com;
49
50
51/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
52#if defined(_MSC_VER)
53# pragma optimize("g", off)
54#endif
55
56int handleModifyVM(HandlerArg *a)
57{
58 HRESULT rc;
59 Bstr name;
60 Bstr ostype;
61 uint32_t memorySize = 0;
62 uint32_t vramSize = 0;
63 char *acpi = NULL;
64 char *hwvirtex = NULL;
65 char *nestedpaging = NULL;
66 char *vtxvpid = NULL;
67 char *pae = NULL;
68 char *ioapic = NULL;
69 uint32_t monitorcount = ~0;
70 char *accelerate3d = NULL;
71 char *bioslogofadein = NULL;
72 char *bioslogofadeout = NULL;
73 uint32_t bioslogodisplaytime = ~0;
74 char *bioslogoimagepath = NULL;
75 char *biosbootmenumode = NULL;
76 char *biossystemtimeoffset = NULL;
77 char *biospxedebug = NULL;
78 DeviceType_T bootDevice[4];
79 int bootDeviceChanged[4] = { false };
80 char *hdds[50] = {0};
81 char *dvd = NULL;
82 char *dvdpassthrough = NULL;
83 char *idecontroller = NULL;
84 char *floppy = NULL;
85 char *audio = NULL;
86 char *audiocontroller = NULL;
87 char *clipboard = NULL;
88#ifdef VBOX_WITH_VRDP
89 char *vrdp = NULL;
90 uint16_t vrdpport = UINT16_MAX;
91 char *vrdpaddress = NULL;
92 char *vrdpauthtype = NULL;
93 char *vrdpmulticon = NULL;
94 char *vrdpreusecon = NULL;
95#endif
96 int fUsbEnabled = -1;
97 int fUsbEhciEnabled = -1;
98 char *snapshotFolder = NULL;
99 ULONG guestMemBalloonSize = (ULONG)-1;
100 ULONG guestStatInterval = (ULONG)-1;
101 int fSataEnabled = -1;
102 int fScsiEnabled = -1;
103 int fScsiLsiLogic = -1;
104 int sataPortCount = -1;
105 int sataBootDevices[4] = {-1,-1,-1,-1};
106
107 /* VM ID + at least one parameter. Parameter arguments are checked
108 * individually. */
109 if (a->argc < 2)
110 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
111
112 /* Get the number of network adapters */
113 ULONG NetworkAdapterCount = 0;
114 {
115 ComPtr <ISystemProperties> info;
116 CHECK_ERROR_RET (a->virtualBox, COMGETTER(SystemProperties) (info.asOutParam()), 1);
117 CHECK_ERROR_RET (info, COMGETTER(NetworkAdapterCount) (&NetworkAdapterCount), 1);
118 }
119 ULONG SerialPortCount = 0;
120 {
121 ComPtr <ISystemProperties> info;
122 CHECK_ERROR_RET (a->virtualBox, COMGETTER(SystemProperties) (info.asOutParam()), 1);
123 CHECK_ERROR_RET (info, COMGETTER(SerialPortCount) (&SerialPortCount), 1);
124 }
125
126 std::vector <char *> nics (NetworkAdapterCount, 0);
127 std::vector <char *> nictype (NetworkAdapterCount, 0);
128 std::vector <char *> cableconnected (NetworkAdapterCount, 0);
129 std::vector <char *> nictrace (NetworkAdapterCount, 0);
130 std::vector <char *> nictracefile (NetworkAdapterCount, 0);
131 std::vector <char *> nicspeed (NetworkAdapterCount, 0);
132 std::vector <char *> hostifdev (NetworkAdapterCount, 0);
133 std::vector <const char *> intnet (NetworkAdapterCount, 0);
134 std::vector <const char *> natnet (NetworkAdapterCount, 0);
135 std::vector <char *> macs (NetworkAdapterCount, 0);
136 std::vector <char *> uarts_mode (SerialPortCount, 0);
137 std::vector <ULONG> uarts_base (SerialPortCount, 0);
138 std::vector <ULONG> uarts_irq (SerialPortCount, 0);
139 std::vector <char *> uarts_path (SerialPortCount, 0);
140
141 for (int i = 1; i < a->argc; i++)
142 {
143 if (strcmp(a->argv[i], "-name") == 0)
144 {
145 if (a->argc <= i + 1)
146 return errorArgument("Missing argument to '%s'", a->argv[i]);
147 i++;
148 name = a->argv[i];
149 }
150 else if (strcmp(a->argv[i], "-ostype") == 0)
151 {
152 if (a->argc <= i + 1)
153 return errorArgument("Missing argument to '%s'", a->argv[i]);
154 i++;
155 ostype = a->argv[i];
156 }
157 else if (strcmp(a->argv[i], "-memory") == 0)
158 {
159 if (a->argc <= i + 1)
160 return errorArgument("Missing argument to '%s'", a->argv[i]);
161 i++;
162 memorySize = RTStrToUInt32(a->argv[i]);
163 }
164 else if (strcmp(a->argv[i], "-vram") == 0)
165 {
166 if (a->argc <= i + 1)
167 return errorArgument("Missing argument to '%s'", a->argv[i]);
168 i++;
169 vramSize = RTStrToUInt32(a->argv[i]);
170 }
171 else if (strcmp(a->argv[i], "-acpi") == 0)
172 {
173 if (a->argc <= i + 1)
174 return errorArgument("Missing argument to '%s'", a->argv[i]);
175 i++;
176 acpi = a->argv[i];
177 }
178 else if (strcmp(a->argv[i], "-ioapic") == 0)
179 {
180 if (a->argc <= i + 1)
181 return errorArgument("Missing argument to '%s'", a->argv[i]);
182 i++;
183 ioapic = a->argv[i];
184 }
185 else if (strcmp(a->argv[i], "-hwvirtex") == 0)
186 {
187 if (a->argc <= i + 1)
188 return errorArgument("Missing argument to '%s'", a->argv[i]);
189 i++;
190 hwvirtex = a->argv[i];
191 }
192 else if (strcmp(a->argv[i], "-nestedpaging") == 0)
193 {
194 if (a->argc <= i + 1)
195 return errorArgument("Missing argument to '%s'", a->argv[i]);
196 i++;
197 nestedpaging = a->argv[i];
198 }
199 else if (strcmp(a->argv[i], "-vtxvpid") == 0)
200 {
201 if (a->argc <= i + 1)
202 return errorArgument("Missing argument to '%s'", a->argv[i]);
203 i++;
204 vtxvpid = a->argv[i];
205 }
206 else if (strcmp(a->argv[i], "-pae") == 0)
207 {
208 if (a->argc <= i + 1)
209 return errorArgument("Missing argument to '%s'", a->argv[i]);
210 i++;
211 pae = a->argv[i];
212 }
213 else if (strcmp(a->argv[i], "-monitorcount") == 0)
214 {
215 if (a->argc <= i + 1)
216 return errorArgument("Missing argument to '%s'", a->argv[i]);
217 i++;
218 monitorcount = RTStrToUInt32(a->argv[i]);
219 }
220 else if (strcmp(a->argv[i], "-accelerate3d") == 0)
221 {
222 if (a->argc <= i + 1)
223 return errorArgument("Missing argument to '%s'", a->argv[i]);
224 i++;
225 accelerate3d = a->argv[i];
226 }
227 else if (strcmp(a->argv[i], "-bioslogofadein") == 0)
228 {
229 if (a->argc <= i + 1)
230 return errorArgument("Missing argument to '%s'", a->argv[i]);
231 i++;
232 bioslogofadein = a->argv[i];
233 }
234 else if (strcmp(a->argv[i], "-bioslogofadeout") == 0)
235 {
236 if (a->argc <= i + 1)
237 return errorArgument("Missing argument to '%s'", a->argv[i]);
238 i++;
239 bioslogofadeout = a->argv[i];
240 }
241 else if (strcmp(a->argv[i], "-bioslogodisplaytime") == 0)
242 {
243 if (a->argc <= i + 1)
244 return errorArgument("Missing argument to '%s'", a->argv[i]);
245 i++;
246 bioslogodisplaytime = RTStrToUInt32(a->argv[i]);
247 }
248 else if (strcmp(a->argv[i], "-bioslogoimagepath") == 0)
249 {
250 if (a->argc <= i + 1)
251 return errorArgument("Missing argument to '%s'", a->argv[i]);
252 i++;
253 bioslogoimagepath = a->argv[i];
254 }
255 else if (strcmp(a->argv[i], "-biosbootmenu") == 0)
256 {
257 if (a->argc <= i + 1)
258 return errorArgument("Missing argument to '%s'", a->argv[i]);
259 i++;
260 biosbootmenumode = a->argv[i];
261 }
262 else if (strcmp(a->argv[i], "-biossystemtimeoffset") == 0)
263 {
264 if (a->argc <= i + 1)
265 return errorArgument("Missing argument to '%s'", a->argv[i]);
266 i++;
267 biossystemtimeoffset = a->argv[i];
268 }
269 else if (strcmp(a->argv[i], "-biospxedebug") == 0)
270 {
271 if (a->argc <= i + 1)
272 return errorArgument("Missing argument to '%s'", a->argv[i]);
273 i++;
274 biospxedebug = a->argv[i];
275 }
276 else if (strncmp(a->argv[i], "-boot", 5) == 0)
277 {
278 uint32_t n = 0;
279 if (!a->argv[i][5])
280 return errorSyntax(USAGE_MODIFYVM, "Missing boot slot number in '%s'", a->argv[i]);
281 if (VINF_SUCCESS != RTStrToUInt32Full(&a->argv[i][5], 10, &n))
282 return errorSyntax(USAGE_MODIFYVM, "Invalid boot slot number in '%s'", a->argv[i]);
283 if (a->argc <= i + 1)
284 return errorArgument("Missing argument to '%s'", a->argv[i]);
285 i++;
286 if (strcmp(a->argv[i], "none") == 0)
287 {
288 bootDevice[n - 1] = DeviceType_Null;
289 }
290 else if (strcmp(a->argv[i], "floppy") == 0)
291 {
292 bootDevice[n - 1] = DeviceType_Floppy;
293 }
294 else if (strcmp(a->argv[i], "dvd") == 0)
295 {
296 bootDevice[n - 1] = DeviceType_DVD;
297 }
298 else if (strcmp(a->argv[i], "disk") == 0)
299 {
300 bootDevice[n - 1] = DeviceType_HardDisk;
301 }
302 else if (strcmp(a->argv[i], "net") == 0)
303 {
304 bootDevice[n - 1] = DeviceType_Network;
305 }
306 else
307 return errorArgument("Invalid boot device '%s'", a->argv[i]);
308
309 bootDeviceChanged[n - 1] = true;
310 }
311 else if (strcmp(a->argv[i], "-hda") == 0)
312 {
313 if (a->argc <= i + 1)
314 return errorArgument("Missing argument to '%s'", a->argv[i]);
315 i++;
316 hdds[0] = a->argv[i];
317 }
318 else if (strcmp(a->argv[i], "-hdb") == 0)
319 {
320 if (a->argc <= i + 1)
321 return errorArgument("Missing argument to '%s'", a->argv[i]);
322 i++;
323 hdds[1] = a->argv[i];
324 }
325 else if (strcmp(a->argv[i], "-hdd") == 0)
326 {
327 if (a->argc <= i + 1)
328 return errorArgument("Missing argument to '%s'", a->argv[i]);
329 i++;
330 hdds[2] = a->argv[i];
331 }
332 else if (strcmp(a->argv[i], "-dvd") == 0)
333 {
334 if (a->argc <= i + 1)
335 return errorArgument("Missing argument to '%s'", a->argv[i]);
336 i++;
337 dvd = a->argv[i];
338 }
339 else if (strcmp(a->argv[i], "-dvdpassthrough") == 0)
340 {
341 if (a->argc <= i + 1)
342 return errorArgument("Missing argument to '%s'", a->argv[i]);
343 i++;
344 dvdpassthrough = a->argv[i];
345 }
346 else if (strcmp(a->argv[i], "-idecontroller") == 0)
347 {
348 if (a->argc <= i + 1)
349 return errorArgument("Missing argument to '%s'", a->argv[i]);
350 i++;
351 idecontroller = a->argv[i];
352 }
353 else if (strcmp(a->argv[i], "-floppy") == 0)
354 {
355 if (a->argc <= i + 1)
356 return errorArgument("Missing argument to '%s'", a->argv[i]);
357 i++;
358 floppy = a->argv[i];
359 }
360 else if (strcmp(a->argv[i], "-audio") == 0)
361 {
362 if (a->argc <= i + 1)
363 return errorArgument("Missing argument to '%s'", a->argv[i]);
364 i++;
365 audio = a->argv[i];
366 }
367 else if (strcmp(a->argv[i], "-audiocontroller") == 0)
368 {
369 if (a->argc <= i + 1)
370 return errorArgument("Missing argument to '%s'", a->argv[i]);
371 i++;
372 audiocontroller = a->argv[i];
373 }
374 else if (strcmp(a->argv[i], "-clipboard") == 0)
375 {
376 if (a->argc <= i + 1)
377 return errorArgument("Missing argument to '%s'", a->argv[i]);
378 i++;
379 clipboard = a->argv[i];
380 }
381 else if (strncmp(a->argv[i], "-cableconnected", 15) == 0)
382 {
383 unsigned n = parseNum(&a->argv[i][15], NetworkAdapterCount, "NIC");
384 if (!n)
385 return 1;
386
387 if (a->argc <= i + 1)
388 return errorArgument("Missing argument to '%s'", a->argv[i]);
389
390 cableconnected[n - 1] = a->argv[i + 1];
391 i++;
392 }
393 /* watch for the right order of these -nic* comparisons! */
394 else if (strncmp(a->argv[i], "-nictracefile", 13) == 0)
395 {
396 unsigned n = parseNum(&a->argv[i][13], NetworkAdapterCount, "NIC");
397 if (!n)
398 return 1;
399 if (a->argc <= i + 1)
400 {
401 return errorArgument("Missing argument to '%s'", a->argv[i]);
402 }
403 nictracefile[n - 1] = a->argv[i + 1];
404 i++;
405 }
406 else if (strncmp(a->argv[i], "-nictrace", 9) == 0)
407 {
408 unsigned n = parseNum(&a->argv[i][9], NetworkAdapterCount, "NIC");
409 if (!n)
410 return 1;
411 if (a->argc <= i + 1)
412 return errorArgument("Missing argument to '%s'", a->argv[i]);
413 nictrace[n - 1] = a->argv[i + 1];
414 i++;
415 }
416 else if (strncmp(a->argv[i], "-nictype", 8) == 0)
417 {
418 unsigned n = parseNum(&a->argv[i][8], NetworkAdapterCount, "NIC");
419 if (!n)
420 return 1;
421 if (a->argc <= i + 1)
422 return errorArgument("Missing argument to '%s'", a->argv[i]);
423 nictype[n - 1] = a->argv[i + 1];
424 i++;
425 }
426 else if (strncmp(a->argv[i], "-nicspeed", 9) == 0)
427 {
428 unsigned n = parseNum(&a->argv[i][9], NetworkAdapterCount, "NIC");
429 if (!n)
430 return 1;
431 if (a->argc <= i + 1)
432 return errorArgument("Missing argument to '%s'", a->argv[i]);
433 nicspeed[n - 1] = a->argv[i + 1];
434 i++;
435 }
436 else if (strncmp(a->argv[i], "-nic", 4) == 0)
437 {
438 unsigned n = parseNum(&a->argv[i][4], NetworkAdapterCount, "NIC");
439 if (!n)
440 return 1;
441 if (a->argc <= i + 1)
442 return errorArgument("Missing argument to '%s'", a->argv[i]);
443 nics[n - 1] = a->argv[i + 1];
444 i++;
445 }
446 else if (strncmp(a->argv[i], "-hostifdev", 10) == 0) /* backward compatibility */
447 {
448 unsigned n = parseNum(&a->argv[i][10], NetworkAdapterCount, "NIC");
449 if (!n)
450 return 1;
451 if (a->argc <= i + 1)
452 return errorArgument("Missing argument to '%s'", a->argv[i]);
453 hostifdev[n - 1] = a->argv[i + 1];
454 i++;
455 }
456 else if ( strncmp(a->argv[i], "-bridgeadapter", 14) == 0)
457 {
458 unsigned n = parseNum(&a->argv[i][14], NetworkAdapterCount, "NIC");
459 if (!n)
460 return 1;
461 if (a->argc <= i + 1)
462 return errorArgument("Missing argument to '%s'", a->argv[i]);
463 hostifdev[n - 1] = a->argv[i + 1];
464 i++;
465 }
466 else if (strncmp(a->argv[i], "-hostonlyadapter", 16) == 0)
467 {
468 unsigned n = parseNum(&a->argv[i][16], NetworkAdapterCount, "NIC");
469 if (!n)
470 return 1;
471 if (a->argc <= i + 1)
472 return errorArgument("Missing argument to '%s'", a->argv[i]);
473 hostifdev[n - 1] = a->argv[i + 1];
474 i++;
475 }
476 else if (strncmp(a->argv[i], "-intnet", 7) == 0)
477 {
478 unsigned n = parseNum(&a->argv[i][7], NetworkAdapterCount, "NIC");
479 if (!n)
480 return 1;
481 if (a->argc <= i + 1)
482 return errorArgument("Missing argument to '%s'", a->argv[i]);
483 intnet[n - 1] = a->argv[i + 1];
484 i++;
485 }
486 else if (strncmp(a->argv[i], "-natnet", 7) == 0)
487 {
488 unsigned n = parseNum(&a->argv[i][7], NetworkAdapterCount, "NIC");
489 if (!n)
490 return 1;
491 if (a->argc <= i + 1)
492 return errorArgument("Missing argument to '%s'", a->argv[i]);
493
494 if (!strcmp(a->argv[i + 1], "default"))
495 natnet[n - 1] = "";
496 else
497 {
498 RTIPV4ADDR Network;
499 RTIPV4ADDR Netmask;
500 int rc = RTCidrStrToIPv4(a->argv[i + 1], &Network, &Netmask);
501 if (RT_FAILURE(rc))
502 return errorArgument("Invalid IPv4 network '%s' specified -- CIDR notation expected.\n", a->argv[i + 1]);
503 if (Netmask & 0x1f)
504 return errorArgument("Prefix length of the NAT network must be less than 28.\n");
505 natnet[n - 1] = a->argv[i + 1];
506 }
507 i++;
508 }
509 else if (strncmp(a->argv[i], "-macaddress", 11) == 0)
510 {
511 unsigned n = parseNum(&a->argv[i][11], NetworkAdapterCount, "NIC");
512 if (!n)
513 return 1;
514 if (a->argc <= i + 1)
515 return errorArgument("Missing argument to '%s'", a->argv[i]);
516 macs[n - 1] = a->argv[i + 1];
517 i++;
518 }
519#ifdef VBOX_WITH_VRDP
520 else if (strcmp(a->argv[i], "-vrdp") == 0)
521 {
522 if (a->argc <= i + 1)
523 return errorArgument("Missing argument to '%s'", a->argv[i]);
524 i++;
525 vrdp = a->argv[i];
526 }
527 else if (strcmp(a->argv[i], "-vrdpport") == 0)
528 {
529 if (a->argc <= i + 1)
530 return errorArgument("Missing argument to '%s'", a->argv[i]);
531 i++;
532 if (strcmp(a->argv[i], "default") == 0)
533 vrdpport = 0;
534 else
535 vrdpport = RTStrToUInt16(a->argv[i]);
536 }
537 else if (strcmp(a->argv[i], "-vrdpaddress") == 0)
538 {
539 if (a->argc <= i + 1)
540 return errorArgument("Missing argument to '%s'", a->argv[i]);
541 i++;
542 vrdpaddress = a->argv[i];
543 }
544 else if (strcmp(a->argv[i], "-vrdpauthtype") == 0)
545 {
546 if (a->argc <= i + 1)
547 return errorArgument("Missing argument to '%s'", a->argv[i]);
548 i++;
549 vrdpauthtype = a->argv[i];
550 }
551 else if (strcmp(a->argv[i], "-vrdpmulticon") == 0)
552 {
553 if (a->argc <= i + 1)
554 return errorArgument("Missing argument to '%s'", a->argv[i]);
555 i++;
556 vrdpmulticon = a->argv[i];
557 }
558 else if (strcmp(a->argv[i], "-vrdpreusecon") == 0)
559 {
560 if (a->argc <= i + 1)
561 return errorArgument("Missing argument to '%s'", a->argv[i]);
562 i++;
563 vrdpreusecon = a->argv[i];
564 }
565#endif /* VBOX_WITH_VRDP */
566 else if (strcmp(a->argv[i], "-usb") == 0)
567 {
568 if (a->argc <= i + 1)
569 return errorArgument("Missing argument to '%s'", a->argv[i]);
570 i++;
571 if (strcmp(a->argv[i], "on") == 0 || strcmp(a->argv[i], "enable") == 0)
572 fUsbEnabled = 1;
573 else if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
574 fUsbEnabled = 0;
575 else
576 return errorArgument("Invalid -usb argument '%s'", a->argv[i]);
577 }
578 else if (strcmp(a->argv[i], "-usbehci") == 0)
579 {
580 if (a->argc <= i + 1)
581 return errorArgument("Missing argument to '%s'", a->argv[i]);
582 i++;
583 if (strcmp(a->argv[i], "on") == 0 || strcmp(a->argv[i], "enable") == 0)
584 fUsbEhciEnabled = 1;
585 else if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
586 fUsbEhciEnabled = 0;
587 else
588 return errorArgument("Invalid -usbehci argument '%s'", a->argv[i]);
589 }
590 else if (strcmp(a->argv[i], "-snapshotfolder") == 0)
591 {
592 if (a->argc <= i + 1)
593 return errorArgument("Missing argument to '%s'", a->argv[i]);
594 i++;
595 snapshotFolder = a->argv[i];
596 }
597 else if (strncmp(a->argv[i], "-uartmode", 9) == 0)
598 {
599 unsigned n = parseNum(&a->argv[i][9], SerialPortCount, "UART");
600 if (!n)
601 return 1;
602 i++;
603 if (strcmp(a->argv[i], "disconnected") == 0)
604 {
605 uarts_mode[n - 1] = a->argv[i];
606 }
607 else
608 {
609 if (strcmp(a->argv[i], "server") == 0 || strcmp(a->argv[i], "client") == 0)
610 {
611 uarts_mode[n - 1] = a->argv[i];
612 i++;
613#ifdef RT_OS_WINDOWS
614 if (strncmp(a->argv[i], "\\\\.\\pipe\\", 9))
615 return errorArgument("Uart pipe must start with \\\\.\\pipe\\");
616#endif
617 }
618 else
619 {
620 uarts_mode[n - 1] = (char*)"device";
621 }
622 if (a->argc <= i)
623 return errorArgument("Missing argument to -uartmode");
624 uarts_path[n - 1] = a->argv[i];
625 }
626 }
627 else if (strncmp(a->argv[i], "-uart", 5) == 0)
628 {
629 unsigned n = parseNum(&a->argv[i][5], SerialPortCount, "UART");
630 if (!n)
631 return 1;
632 if (a->argc <= i + 1)
633 return errorArgument("Missing argument to '%s'", a->argv[i]);
634 i++;
635 if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
636 {
637 uarts_base[n - 1] = (ULONG)-1;
638 }
639 else
640 {
641 if (a->argc <= i + 1)
642 return errorArgument("Missing argument to '%s'", a->argv[i-1]);
643 uint32_t uVal;
644 int vrc;
645 vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &uVal);
646 if (vrc != VINF_SUCCESS || uVal == 0)
647 return errorArgument("Error parsing UART I/O base '%s'", a->argv[i]);
648 uarts_base[n - 1] = uVal;
649 i++;
650 vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &uVal);
651 if (vrc != VINF_SUCCESS)
652 return errorArgument("Error parsing UART IRQ '%s'", a->argv[i]);
653 uarts_irq[n - 1] = uVal;
654 }
655 }
656#ifdef VBOX_WITH_MEM_BALLOONING
657 else if (strncmp(a->argv[i], "-guestmemoryballoon", 19) == 0)
658 {
659 if (a->argc <= i + 1)
660 return errorArgument("Missing argument to '%s'", a->argv[i]);
661 i++;
662 uint32_t uVal;
663 int vrc;
664 vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &uVal);
665 if (vrc != VINF_SUCCESS)
666 return errorArgument("Error parsing guest memory balloon size '%s'", a->argv[i]);
667 guestMemBalloonSize = uVal;
668 }
669#endif
670 else if (strncmp(a->argv[i], "-gueststatisticsinterval", 24) == 0)
671 {
672 if (a->argc <= i + 1)
673 return errorArgument("Missing argument to '%s'", a->argv[i]);
674 i++;
675 uint32_t uVal;
676 int vrc;
677 vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &uVal);
678 if (vrc != VINF_SUCCESS)
679 return errorArgument("Error parsing guest statistics interval '%s'", a->argv[i]);
680 guestStatInterval = uVal;
681 }
682 else if (strcmp(a->argv[i], "-sata") == 0)
683 {
684 if (a->argc <= i + 1)
685 return errorArgument("Missing argument to '%s'", a->argv[i]);
686 i++;
687 if (strcmp(a->argv[i], "on") == 0 || strcmp(a->argv[i], "enable") == 0)
688 fSataEnabled = 1;
689 else if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
690 fSataEnabled = 0;
691 else
692 return errorArgument("Invalid -usb argument '%s'", a->argv[i]);
693 }
694 else if (strcmp(a->argv[i], "-sataportcount") == 0)
695 {
696 unsigned n;
697
698 if (a->argc <= i + 1)
699 return errorArgument("Missing arguments to '%s'", a->argv[i]);
700 i++;
701
702 n = parseNum(a->argv[i], 30, "SATA");
703 if (!n)
704 return 1;
705 sataPortCount = n;
706 }
707 else if (strncmp(a->argv[i], "-sataport", 9) == 0)
708 {
709 unsigned n = parseNum(&a->argv[i][9], 30, "SATA");
710 if (!n)
711 return 1;
712 if (a->argc <= i + 1)
713 return errorArgument("Missing argument to '%s'", a->argv[i]);
714 i++;
715 hdds[n-1+4] = a->argv[i];
716 }
717 else if (strncmp(a->argv[i], "-sataideemulation", 17) == 0)
718 {
719 unsigned bootDevicePos = 0;
720 unsigned n;
721
722 bootDevicePos = parseNum(&a->argv[i][17], 4, "SATA");
723 if (!bootDevicePos)
724 return 1;
725 bootDevicePos--;
726
727 if (a->argc <= i + 1)
728 return errorArgument("Missing arguments to '%s'", a->argv[i]);
729 i++;
730
731 n = parseNum(a->argv[i], 30, "SATA");
732 if (!n)
733 return 1;
734
735 sataBootDevices[bootDevicePos] = n-1;
736 }
737 else if (strcmp(a->argv[i], "-scsi") == 0)
738 {
739 if (a->argc <= i + 1)
740 return errorArgument("Missing argument to '%s'", a->argv[i]);
741 i++;
742 if (strcmp(a->argv[i], "on") == 0 || strcmp(a->argv[i], "enable") == 0)
743 fScsiEnabled = 1;
744 else if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
745 fScsiEnabled = 0;
746 else
747 return errorArgument("Invalid -scsi argument '%s'", a->argv[i]);
748 }
749 else if (strncmp(a->argv[i], "-scsiport", 9) == 0)
750 {
751 unsigned n = parseNum(&a->argv[i][9], 16, "SCSI");
752 if (!n)
753 return 1;
754 if (a->argc <= i + 1)
755 return errorArgument("Missing argument to '%s'", a->argv[i]);
756 i++;
757 hdds[n-1+34] = a->argv[i];
758 }
759 else if (strcmp(a->argv[i], "-scsitype") == 0)
760 {
761 if (a->argc <= i + 1)
762 return errorArgument("Missing argument to '%s'", a->argv[i]);
763 i++;
764 if (strcmp(a->argv[i], "LsiLogic") == 0 )
765 fScsiLsiLogic = 1;
766 else if (strcmp(a->argv[i], "BusLogic") == 0)
767 fScsiLsiLogic = 0;
768 else
769 return errorArgument("Invalid -scsitype argument '%s'", a->argv[i]);
770 }
771 else
772 return errorSyntax(USAGE_MODIFYVM, "Invalid parameter '%s'", Utf8Str(a->argv[i]).raw());
773 }
774
775 /* try to find the given machine */
776 ComPtr <IMachine> machine;
777 Guid uuid (a->argv[0]);
778 if (!uuid.isEmpty())
779 {
780 CHECK_ERROR (a->virtualBox, GetMachine (uuid, machine.asOutParam()));
781 }
782 else
783 {
784 CHECK_ERROR (a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
785 if (SUCCEEDED (rc))
786 machine->COMGETTER(Id)(uuid.asOutParam());
787 }
788 if (FAILED (rc))
789 return 1;
790
791 /* open a session for the VM */
792 CHECK_ERROR_RET (a->virtualBox, OpenSession(a->session, uuid), 1);
793
794 do
795 {
796 /* get the mutable session machine */
797 a->session->COMGETTER(Machine)(machine.asOutParam());
798
799 ComPtr <IBIOSSettings> biosSettings;
800 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
801
802 if (name)
803 CHECK_ERROR(machine, COMSETTER(Name)(name));
804 if (ostype)
805 {
806 ComPtr<IGuestOSType> guestOSType;
807 CHECK_ERROR(a->virtualBox, GetGuestOSType(ostype, guestOSType.asOutParam()));
808 if (SUCCEEDED(rc) && guestOSType)
809 {
810 CHECK_ERROR(machine, COMSETTER(OSTypeId)(ostype));
811 }
812 else
813 {
814 errorArgument("Invalid guest OS type '%s'", Utf8Str(ostype).raw());
815 rc = E_FAIL;
816 break;
817 }
818 }
819 if (memorySize > 0)
820 CHECK_ERROR(machine, COMSETTER(MemorySize)(memorySize));
821 if (vramSize > 0)
822 CHECK_ERROR(machine, COMSETTER(VRAMSize)(vramSize));
823 if (acpi)
824 {
825 if (strcmp(acpi, "on") == 0)
826 {
827 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(true));
828 }
829 else if (strcmp(acpi, "off") == 0)
830 {
831 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(false));
832 }
833 else
834 {
835 errorArgument("Invalid -acpi argument '%s'", acpi);
836 rc = E_FAIL;
837 break;
838 }
839 }
840 if (ioapic)
841 {
842 if (strcmp(ioapic, "on") == 0)
843 {
844 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(true));
845 }
846 else if (strcmp(ioapic, "off") == 0)
847 {
848 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(false));
849 }
850 else
851 {
852 errorArgument("Invalid -ioapic argument '%s'", ioapic);
853 rc = E_FAIL;
854 break;
855 }
856 }
857 if (hwvirtex)
858 {
859 if (strcmp(hwvirtex, "on") == 0)
860 {
861 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_True));
862 }
863 else if (strcmp(hwvirtex, "off") == 0)
864 {
865 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_False));
866 }
867 else if (strcmp(hwvirtex, "default") == 0)
868 {
869 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_Default));
870 }
871 else
872 {
873 errorArgument("Invalid -hwvirtex argument '%s'", hwvirtex);
874 rc = E_FAIL;
875 break;
876 }
877 }
878 if (nestedpaging)
879 {
880 if (strcmp(nestedpaging, "on") == 0)
881 {
882 CHECK_ERROR(machine, COMSETTER(HWVirtExNestedPagingEnabled)(true));
883 }
884 else if (strcmp(nestedpaging, "off") == 0)
885 {
886 CHECK_ERROR(machine, COMSETTER(HWVirtExNestedPagingEnabled)(false));
887 }
888 else
889 {
890 errorArgument("Invalid -nestedpaging argument '%s'", ioapic);
891 rc = E_FAIL;
892 break;
893 }
894 }
895 if (vtxvpid)
896 {
897 if (strcmp(vtxvpid, "on") == 0)
898 {
899 CHECK_ERROR(machine, COMSETTER(HWVirtExVPIDEnabled)(true));
900 }
901 else if (strcmp(vtxvpid, "off") == 0)
902 {
903 CHECK_ERROR(machine, COMSETTER(HWVirtExVPIDEnabled)(false));
904 }
905 else
906 {
907 errorArgument("Invalid -vtxvpid argument '%s'", ioapic);
908 rc = E_FAIL;
909 break;
910 }
911 }
912 if (pae)
913 {
914 if (strcmp(pae, "on") == 0)
915 {
916 CHECK_ERROR(machine, COMSETTER(PAEEnabled)(true));
917 }
918 else if (strcmp(pae, "off") == 0)
919 {
920 CHECK_ERROR(machine, COMSETTER(PAEEnabled)(false));
921 }
922 else
923 {
924 errorArgument("Invalid -pae argument '%s'", ioapic);
925 rc = E_FAIL;
926 break;
927 }
928 }
929 if (monitorcount != ~0U)
930 {
931 CHECK_ERROR(machine, COMSETTER(MonitorCount)(monitorcount));
932 }
933 if (accelerate3d)
934 {
935 if (strcmp(accelerate3d, "on") == 0)
936 {
937 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(true));
938 }
939 else if (strcmp(accelerate3d, "off") == 0)
940 {
941 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(false));
942 }
943 else
944 {
945 errorArgument("Invalid -accelerate3d argument '%s'", ioapic);
946 rc = E_FAIL;
947 break;
948 }
949 }
950 if (bioslogofadein)
951 {
952 if (strcmp(bioslogofadein, "on") == 0)
953 {
954 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(true));
955 }
956 else if (strcmp(bioslogofadein, "off") == 0)
957 {
958 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(false));
959 }
960 else
961 {
962 errorArgument("Invalid -bioslogofadein argument '%s'", bioslogofadein);
963 rc = E_FAIL;
964 break;
965 }
966 }
967 if (bioslogofadeout)
968 {
969 if (strcmp(bioslogofadeout, "on") == 0)
970 {
971 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(true));
972 }
973 else if (strcmp(bioslogofadeout, "off") == 0)
974 {
975 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(false));
976 }
977 else
978 {
979 errorArgument("Invalid -bioslogofadeout argument '%s'", bioslogofadeout);
980 rc = E_FAIL;
981 break;
982 }
983 }
984 if (bioslogodisplaytime != ~0U)
985 {
986 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(bioslogodisplaytime));
987 }
988 if (bioslogoimagepath)
989 {
990 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(bioslogoimagepath)));
991 }
992 if (biosbootmenumode)
993 {
994 if (strcmp(biosbootmenumode, "disabled") == 0)
995 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
996 else if (strcmp(biosbootmenumode, "menuonly") == 0)
997 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
998 else if (strcmp(biosbootmenumode, "messageandmenu") == 0)
999 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
1000 else
1001 {
1002 errorArgument("Invalid -biosbootmenu argument '%s'", biosbootmenumode);
1003 rc = E_FAIL;
1004 break;
1005 }
1006
1007 }
1008 if (biossystemtimeoffset)
1009 {
1010 LONG64 timeOffset = RTStrToInt64(biossystemtimeoffset);
1011 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(timeOffset));
1012 }
1013 if (biospxedebug)
1014 {
1015 if (strcmp(biospxedebug, "on") == 0)
1016 {
1017 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(true));
1018 }
1019 else if (strcmp(biospxedebug, "off") == 0)
1020 {
1021 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(false));
1022 }
1023 else
1024 {
1025 errorArgument("Invalid -biospxedebug argument '%s'", biospxedebug);
1026 rc = E_FAIL;
1027 break;
1028 }
1029 }
1030 for (int curBootDev = 0; curBootDev < 4; curBootDev++)
1031 {
1032 if (bootDeviceChanged[curBootDev])
1033 CHECK_ERROR(machine, SetBootOrder (curBootDev + 1, bootDevice[curBootDev]));
1034 }
1035 if (hdds[0])
1036 {
1037 if (strcmp(hdds[0], "none") == 0)
1038 {
1039 machine->DetachHardDisk(Bstr("IDE"), 0, 0);
1040 }
1041 else
1042 {
1043 /* first guess is that it's a UUID */
1044 Guid uuid(hdds[0]);
1045 ComPtr<IHardDisk> hardDisk;
1046 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
1047 /* not successful? Then it must be a filename */
1048 if (!hardDisk)
1049 {
1050 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[0]), hardDisk.asOutParam()));
1051 if (FAILED(rc))
1052 {
1053 /* open the new hard disk object */
1054 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[0]), hardDisk.asOutParam()));
1055 }
1056 }
1057 if (hardDisk)
1058 {
1059 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1060 CHECK_ERROR(machine, AttachHardDisk(uuid, Bstr("IDE"), 0, 0));
1061 }
1062 else
1063 rc = E_FAIL;
1064 if (FAILED(rc))
1065 break;
1066 }
1067 }
1068 if (hdds[1])
1069 {
1070 if (strcmp(hdds[1], "none") == 0)
1071 {
1072 machine->DetachHardDisk(Bstr("IDE"), 0, 1);
1073 }
1074 else
1075 {
1076 /* first guess is that it's a UUID */
1077 Guid uuid(hdds[1]);
1078 ComPtr<IHardDisk> hardDisk;
1079 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
1080 /* not successful? Then it must be a filename */
1081 if (!hardDisk)
1082 {
1083 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[1]), hardDisk.asOutParam()));
1084 if (FAILED(rc))
1085 {
1086 /* open the new hard disk object */
1087 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[1]), hardDisk.asOutParam()));
1088 }
1089 }
1090 if (hardDisk)
1091 {
1092 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1093 CHECK_ERROR(machine, AttachHardDisk(uuid, Bstr("IDE"), 0, 1));
1094 }
1095 else
1096 rc = E_FAIL;
1097 if (FAILED(rc))
1098 break;
1099 }
1100 }
1101 if (hdds[2])
1102 {
1103 if (strcmp(hdds[2], "none") == 0)
1104 {
1105 machine->DetachHardDisk(Bstr("IDE"), 1, 1);
1106 }
1107 else
1108 {
1109 /* first guess is that it's a UUID */
1110 Guid uuid(hdds[2]);
1111 ComPtr<IHardDisk> hardDisk;
1112 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
1113 /* not successful? Then it must be a filename */
1114 if (!hardDisk)
1115 {
1116 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[2]), hardDisk.asOutParam()));
1117 if (FAILED(rc))
1118 {
1119 /* open the new hard disk object */
1120 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[2]), hardDisk.asOutParam()));
1121 }
1122 }
1123 if (hardDisk)
1124 {
1125 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1126 CHECK_ERROR(machine, AttachHardDisk(uuid, Bstr("IDE"), 1, 1));
1127 }
1128 else
1129 rc = E_FAIL;
1130 if (FAILED(rc))
1131 break;
1132 }
1133 }
1134 if (dvd)
1135 {
1136 ComPtr<IDVDDrive> dvdDrive;
1137 machine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
1138 ASSERT(dvdDrive);
1139
1140 /* unmount? */
1141 if (strcmp(dvd, "none") == 0)
1142 {
1143 CHECK_ERROR(dvdDrive, Unmount());
1144 }
1145 /* host drive? */
1146 else if (strncmp(dvd, "host:", 5) == 0)
1147 {
1148 ComPtr<IHost> host;
1149 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1150 com::SafeIfaceArray <IHostDVDDrive> hostDVDs;
1151 rc = host->COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(hostDVDs));
1152
1153 ComPtr<IHostDVDDrive> hostDVDDrive;
1154 rc = host->FindHostDVDDrive(Bstr(dvd + 5), hostDVDDrive.asOutParam());
1155 if (!hostDVDDrive)
1156 {
1157 /* 2nd try: try with the real name, important on Linux+libhal */
1158 char szPathReal[RTPATH_MAX];
1159 if (RT_FAILURE(RTPathReal(dvd + 5, szPathReal, sizeof(szPathReal))))
1160 {
1161 errorArgument("Invalid host DVD drive name");
1162 rc = E_FAIL;
1163 break;
1164 }
1165 rc = host->FindHostDVDDrive(Bstr(szPathReal), hostDVDDrive.asOutParam());
1166 if (!hostDVDDrive)
1167 {
1168 errorArgument("Invalid host DVD drive name");
1169 rc = E_FAIL;
1170 break;
1171 }
1172 }
1173 CHECK_ERROR(dvdDrive, CaptureHostDrive(hostDVDDrive));
1174 }
1175 else
1176 {
1177 /* first assume it's a UUID */
1178 Guid uuid(dvd);
1179 ComPtr<IDVDImage> dvdImage;
1180 rc = a->virtualBox->GetDVDImage(uuid, dvdImage.asOutParam());
1181 if (FAILED(rc) || !dvdImage)
1182 {
1183 /* must be a filename, check if it's in the collection */
1184 rc = a->virtualBox->FindDVDImage(Bstr(dvd), dvdImage.asOutParam());
1185 /* not registered, do that on the fly */
1186 if (!dvdImage)
1187 {
1188 Guid emptyUUID;
1189 CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(dvd), emptyUUID, dvdImage.asOutParam()));
1190 }
1191 }
1192 if (!dvdImage)
1193 {
1194 rc = E_FAIL;
1195 break;
1196 }
1197
1198 dvdImage->COMGETTER(Id)(uuid.asOutParam());
1199 CHECK_ERROR(dvdDrive, MountImage(uuid));
1200 }
1201 }
1202 if (dvdpassthrough)
1203 {
1204 ComPtr<IDVDDrive> dvdDrive;
1205 machine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
1206 ASSERT(dvdDrive);
1207
1208 CHECK_ERROR(dvdDrive, COMSETTER(Passthrough)(strcmp(dvdpassthrough, "on") == 0));
1209 }
1210 if (idecontroller)
1211 {
1212 ComPtr<IStorageController> storageController;
1213 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("IDE"), storageController.asOutParam()));
1214
1215 if (RTStrICmp(idecontroller, "PIIX3") == 0)
1216 {
1217 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
1218 }
1219 else if (RTStrICmp(idecontroller, "PIIX4") == 0)
1220 {
1221 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
1222 }
1223 else if (RTStrICmp(idecontroller, "ICH6") == 0)
1224 {
1225 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_ICH6));
1226 }
1227 else
1228 {
1229 errorArgument("Invalid -idecontroller argument '%s'", idecontroller);
1230 rc = E_FAIL;
1231 break;
1232 }
1233 }
1234 if (floppy)
1235 {
1236 ComPtr<IFloppyDrive> floppyDrive;
1237 machine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
1238 ASSERT(floppyDrive);
1239
1240 /* disable? */
1241 if (strcmp(floppy, "disabled") == 0)
1242 {
1243 /* disable the controller */
1244 CHECK_ERROR(floppyDrive, COMSETTER(Enabled)(false));
1245 }
1246 else
1247 {
1248 /* enable the controller */
1249 CHECK_ERROR(floppyDrive, COMSETTER(Enabled)(true));
1250
1251 /* unmount? */
1252 if (strcmp(floppy, "empty") == 0)
1253 {
1254 CHECK_ERROR(floppyDrive, Unmount());
1255 }
1256 /* host drive? */
1257 else if (strncmp(floppy, "host:", 5) == 0)
1258 {
1259 ComPtr<IHost> host;
1260 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1261 com::SafeIfaceArray <IHostFloppyDrive> hostFloppies;
1262 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(hostFloppies)));
1263 ComPtr<IHostFloppyDrive> hostFloppyDrive;
1264 rc = host->FindHostFloppyDrive(Bstr(floppy + 5), hostFloppyDrive.asOutParam());
1265 if (!hostFloppyDrive)
1266 {
1267 errorArgument("Invalid host floppy drive name");
1268 rc = E_FAIL;
1269 break;
1270 }
1271 CHECK_ERROR(floppyDrive, CaptureHostDrive(hostFloppyDrive));
1272 }
1273 else
1274 {
1275 /* first assume it's a UUID */
1276 Guid uuid(floppy);
1277 ComPtr<IFloppyImage> floppyImage;
1278 rc = a->virtualBox->GetFloppyImage(uuid, floppyImage.asOutParam());
1279 if (FAILED(rc) || !floppyImage)
1280 {
1281 /* must be a filename, check if it's in the collection */
1282 rc = a->virtualBox->FindFloppyImage(Bstr(floppy), floppyImage.asOutParam());
1283 /* not registered, do that on the fly */
1284 if (!floppyImage)
1285 {
1286 Guid emptyUUID;
1287 CHECK_ERROR(a->virtualBox, OpenFloppyImage(Bstr(floppy), emptyUUID, floppyImage.asOutParam()));
1288 }
1289 }
1290 if (!floppyImage)
1291 {
1292 rc = E_FAIL;
1293 break;
1294 }
1295
1296 floppyImage->COMGETTER(Id)(uuid.asOutParam());
1297 CHECK_ERROR(floppyDrive, MountImage(uuid));
1298 }
1299 }
1300 }
1301 if (audio || audiocontroller)
1302 {
1303 ComPtr<IAudioAdapter> audioAdapter;
1304 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1305 ASSERT(audioAdapter);
1306
1307 if (audio)
1308 {
1309 /* disable? */
1310 if (strcmp(audio, "none") == 0)
1311 {
1312 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
1313 }
1314 else if (strcmp(audio, "null") == 0)
1315 {
1316 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
1317 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1318 }
1319#ifdef RT_OS_WINDOWS
1320#ifdef VBOX_WITH_WINMM
1321 else if (strcmp(audio, "winmm") == 0)
1322 {
1323 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
1324 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1325 }
1326#endif
1327 else if (strcmp(audio, "dsound") == 0)
1328 {
1329 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
1330 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1331 }
1332#endif /* RT_OS_WINDOWS */
1333#ifdef RT_OS_LINUX
1334 else if (strcmp(audio, "oss") == 0)
1335 {
1336 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1337 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1338 }
1339# ifdef VBOX_WITH_ALSA
1340 else if (strcmp(audio, "alsa") == 0)
1341 {
1342 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
1343 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1344 }
1345# endif
1346# ifdef VBOX_WITH_PULSE
1347 else if (strcmp(audio, "pulse") == 0)
1348 {
1349 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1350 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1351 }
1352# endif
1353#endif /* !RT_OS_LINUX */
1354#ifdef RT_OS_SOLARIS
1355 else if (strcmp(audio, "solaudio") == 0)
1356 {
1357 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
1358 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1359 }
1360
1361#endif /* !RT_OS_SOLARIS */
1362#ifdef RT_OS_DARWIN
1363 else if (strcmp(audio, "coreaudio") == 0)
1364 {
1365 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
1366 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1367 }
1368
1369#endif /* !RT_OS_DARWIN */
1370 else
1371 {
1372 errorArgument("Invalid -audio argument '%s'", audio);
1373 rc = E_FAIL;
1374 break;
1375 }
1376 }
1377 if (audiocontroller)
1378 {
1379 if (strcmp(audiocontroller, "sb16") == 0)
1380 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
1381 else if (strcmp(audiocontroller, "ac97") == 0)
1382 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
1383 else
1384 {
1385 errorArgument("Invalid -audiocontroller argument '%s'", audiocontroller);
1386 rc = E_FAIL;
1387 break;
1388 }
1389 }
1390 }
1391 /* Shared clipboard state */
1392 if (clipboard)
1393 {
1394/* ComPtr<IClipboardMode> clipboardMode;
1395 machine->COMGETTER(ClipboardMode)(clipboardMode.asOutParam());
1396 ASSERT(clipboardMode);
1397*/
1398 if (strcmp(clipboard, "disabled") == 0)
1399 {
1400 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Disabled));
1401 }
1402 else if (strcmp(clipboard, "hosttoguest") == 0)
1403 {
1404 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_HostToGuest));
1405 }
1406 else if (strcmp(clipboard, "guesttohost") == 0)
1407 {
1408 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_GuestToHost));
1409 }
1410 else if (strcmp(clipboard, "bidirectional") == 0)
1411 {
1412 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Bidirectional));
1413 }
1414 else
1415 {
1416 errorArgument("Invalid -clipboard argument '%s'", clipboard);
1417 rc = E_FAIL;
1418 break;
1419 }
1420 }
1421 /* iterate through all possible NICs */
1422 for (ULONG n = 0; n < NetworkAdapterCount; n ++)
1423 {
1424 ComPtr<INetworkAdapter> nic;
1425 CHECK_ERROR_RET (machine, GetNetworkAdapter (n, nic.asOutParam()), 1);
1426
1427 ASSERT(nic);
1428
1429 /* something about the NIC? */
1430 if (nics[n])
1431 {
1432 if (strcmp(nics[n], "none") == 0)
1433 {
1434 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (FALSE), 1);
1435 }
1436 else if (strcmp(nics[n], "null") == 0)
1437 {
1438 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1439 CHECK_ERROR_RET(nic, Detach(), 1);
1440 }
1441 else if (strcmp(nics[n], "nat") == 0)
1442 {
1443 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1444 CHECK_ERROR_RET(nic, AttachToNAT(), 1);
1445 }
1446 else if ( strcmp(nics[n], "bridged") == 0
1447 || strcmp(nics[n], "hostif") == 0) /* backward compatibility */
1448 {
1449 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1450 CHECK_ERROR_RET(nic, AttachToBridgedInterface(), 1);
1451 }
1452 else if (strcmp(nics[n], "intnet") == 0)
1453 {
1454 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1455 CHECK_ERROR_RET(nic, AttachToInternalNetwork(), 1);
1456 }
1457#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || (defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT))
1458 else if (strcmp(nics[n], "hostonly") == 0)
1459 {
1460
1461 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1462 CHECK_ERROR_RET(nic, AttachToHostOnlyInterface(), 1);
1463 }
1464#endif /* defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) */
1465 else
1466 {
1467 errorArgument("Invalid type '%s' specfied for NIC %lu", nics[n], n + 1);
1468 rc = E_FAIL;
1469 break;
1470 }
1471 }
1472
1473 /* something about the NIC type? */
1474 if (nictype[n])
1475 {
1476 if (strcmp(nictype[n], "Am79C970A") == 0)
1477 {
1478 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A), 1);
1479 }
1480 else if (strcmp(nictype[n], "Am79C973") == 0)
1481 {
1482 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973), 1);
1483 }
1484#ifdef VBOX_WITH_E1000
1485 else if (strcmp(nictype[n], "82540EM") == 0)
1486 {
1487 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM), 1);
1488 }
1489 else if (strcmp(nictype[n], "82543GC") == 0)
1490 {
1491 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC), 1);
1492 }
1493#endif
1494 else
1495 {
1496 errorArgument("Invalid NIC type '%s' specified for NIC %lu", nictype[n], n + 1);
1497 rc = E_FAIL;
1498 break;
1499 }
1500 }
1501
1502 /* something about the MAC address? */
1503 if (macs[n])
1504 {
1505 /* generate one? */
1506 if (strcmp(macs[n], "auto") == 0)
1507 {
1508 CHECK_ERROR_RET(nic, COMSETTER(MACAddress)(NULL), 1);
1509 }
1510 else
1511 {
1512 CHECK_ERROR_RET(nic, COMSETTER(MACAddress)(Bstr(macs[n])), 1);
1513 }
1514 }
1515
1516 /* something about the reported link speed? */
1517 if (nicspeed[n])
1518 {
1519 uint32_t u32LineSpeed;
1520
1521 u32LineSpeed = RTStrToUInt32(nicspeed[n]);
1522
1523 if (u32LineSpeed < 1000 || u32LineSpeed > 4000000)
1524 {
1525 errorArgument("Invalid -nicspeed%lu argument '%s'", n + 1, nicspeed[n]);
1526 rc = E_FAIL;
1527 break;
1528 }
1529 CHECK_ERROR_RET(nic, COMSETTER(LineSpeed)(u32LineSpeed), 1);
1530 }
1531
1532 /* the link status flag? */
1533 if (cableconnected[n])
1534 {
1535 if (strcmp(cableconnected[n], "on") == 0)
1536 {
1537 CHECK_ERROR_RET(nic, COMSETTER(CableConnected)(TRUE), 1);
1538 }
1539 else if (strcmp(cableconnected[n], "off") == 0)
1540 {
1541 CHECK_ERROR_RET(nic, COMSETTER(CableConnected)(FALSE), 1);
1542 }
1543 else
1544 {
1545 errorArgument("Invalid -cableconnected%lu argument '%s'", n + 1, cableconnected[n]);
1546 rc = E_FAIL;
1547 break;
1548 }
1549 }
1550
1551 /* the trace flag? */
1552 if (nictrace[n])
1553 {
1554 if (strcmp(nictrace[n], "on") == 0)
1555 {
1556 CHECK_ERROR_RET(nic, COMSETTER(TraceEnabled)(TRUE), 1);
1557 }
1558 else if (strcmp(nictrace[n], "off") == 0)
1559 {
1560 CHECK_ERROR_RET(nic, COMSETTER(TraceEnabled)(FALSE), 1);
1561 }
1562 else
1563 {
1564 errorArgument("Invalid -nictrace%lu argument '%s'", n + 1, nictrace[n]);
1565 rc = E_FAIL;
1566 break;
1567 }
1568 }
1569
1570 /* the tracefile flag? */
1571 if (nictracefile[n])
1572 {
1573 CHECK_ERROR_RET(nic, COMSETTER(TraceFile)(Bstr(nictracefile[n])), 1);
1574 }
1575
1576 /* the host interface device? */
1577 if (hostifdev[n])
1578 {
1579 /* remove it? */
1580 if (strcmp(hostifdev[n], "none") == 0)
1581 {
1582 CHECK_ERROR_RET(nic, COMSETTER(HostInterface)(NULL), 1);
1583 }
1584 else
1585 {
1586 CHECK_ERROR_RET(nic, COMSETTER(HostInterface)(Bstr(hostifdev[n])), 1);
1587 }
1588 }
1589
1590 /* the internal network name? */
1591 if (intnet[n])
1592 {
1593 /* remove it? */
1594 if (strcmp(intnet[n], "none") == 0)
1595 {
1596 CHECK_ERROR_RET(nic, COMSETTER(InternalNetwork)(NULL), 1);
1597 }
1598 else
1599 {
1600 CHECK_ERROR_RET(nic, COMSETTER(InternalNetwork)(Bstr(intnet[n])), 1);
1601 }
1602 }
1603 /* the network of the NAT */
1604 if (natnet[n])
1605 {
1606 CHECK_ERROR_RET(nic, COMSETTER(NATNetwork)(Bstr(natnet[n])), 1);
1607 }
1608 }
1609 if (FAILED(rc))
1610 break;
1611
1612 /* iterate through all possible serial ports */
1613 for (ULONG n = 0; n < SerialPortCount; n ++)
1614 {
1615 ComPtr<ISerialPort> uart;
1616 CHECK_ERROR_RET (machine, GetSerialPort (n, uart.asOutParam()), 1);
1617
1618 ASSERT(uart);
1619
1620 if (uarts_base[n])
1621 {
1622 if (uarts_base[n] == (ULONG)-1)
1623 {
1624 CHECK_ERROR_RET(uart, COMSETTER(Enabled) (FALSE), 1);
1625 }
1626 else
1627 {
1628 CHECK_ERROR_RET(uart, COMSETTER(IOBase) (uarts_base[n]), 1);
1629 CHECK_ERROR_RET(uart, COMSETTER(IRQ) (uarts_irq[n]), 1);
1630 CHECK_ERROR_RET(uart, COMSETTER(Enabled) (TRUE), 1);
1631 }
1632 }
1633 if (uarts_mode[n])
1634 {
1635 if (strcmp(uarts_mode[n], "disconnected") == 0)
1636 {
1637 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_Disconnected), 1);
1638 }
1639 else
1640 {
1641 CHECK_ERROR_RET(uart, COMSETTER(Path) (Bstr(uarts_path[n])), 1);
1642 if (strcmp(uarts_mode[n], "server") == 0)
1643 {
1644 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostPipe), 1);
1645 CHECK_ERROR_RET(uart, COMSETTER(Server) (TRUE), 1);
1646 }
1647 else if (strcmp(uarts_mode[n], "client") == 0)
1648 {
1649 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostPipe), 1);
1650 CHECK_ERROR_RET(uart, COMSETTER(Server) (FALSE), 1);
1651 }
1652 else
1653 {
1654 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostDevice), 1);
1655 }
1656 }
1657 }
1658 }
1659 if (FAILED(rc))
1660 break;
1661
1662#ifdef VBOX_WITH_VRDP
1663 if (vrdp || (vrdpport != UINT16_MAX) || vrdpaddress || vrdpauthtype || vrdpmulticon || vrdpreusecon)
1664 {
1665 ComPtr<IVRDPServer> vrdpServer;
1666 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1667 ASSERT(vrdpServer);
1668 if (vrdpServer)
1669 {
1670 if (vrdp)
1671 {
1672 if (strcmp(vrdp, "on") == 0)
1673 {
1674 CHECK_ERROR(vrdpServer, COMSETTER(Enabled)(true));
1675 }
1676 else if (strcmp(vrdp, "off") == 0)
1677 {
1678 CHECK_ERROR(vrdpServer, COMSETTER(Enabled)(false));
1679 }
1680 else
1681 {
1682 errorArgument("Invalid -vrdp argument '%s'", vrdp);
1683 rc = E_FAIL;
1684 break;
1685 }
1686 }
1687 if (vrdpport != UINT16_MAX)
1688 {
1689 CHECK_ERROR(vrdpServer, COMSETTER(Port)(vrdpport));
1690 }
1691 if (vrdpaddress)
1692 {
1693 CHECK_ERROR(vrdpServer, COMSETTER(NetAddress)(Bstr(vrdpaddress)));
1694 }
1695 if (vrdpauthtype)
1696 {
1697 if (strcmp(vrdpauthtype, "null") == 0)
1698 {
1699 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Null));
1700 }
1701 else if (strcmp(vrdpauthtype, "external") == 0)
1702 {
1703 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_External));
1704 }
1705 else if (strcmp(vrdpauthtype, "guest") == 0)
1706 {
1707 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Guest));
1708 }
1709 else
1710 {
1711 errorArgument("Invalid -vrdpauthtype argument '%s'", vrdpauthtype);
1712 rc = E_FAIL;
1713 break;
1714 }
1715 }
1716 if (vrdpmulticon)
1717 {
1718 if (strcmp(vrdpmulticon, "on") == 0)
1719 {
1720 CHECK_ERROR(vrdpServer, COMSETTER(AllowMultiConnection)(true));
1721 }
1722 else if (strcmp(vrdpmulticon, "off") == 0)
1723 {
1724 CHECK_ERROR(vrdpServer, COMSETTER(AllowMultiConnection)(false));
1725 }
1726 else
1727 {
1728 errorArgument("Invalid -vrdpmulticon argument '%s'", vrdpmulticon);
1729 rc = E_FAIL;
1730 break;
1731 }
1732 }
1733 if (vrdpreusecon)
1734 {
1735 if (strcmp(vrdpreusecon, "on") == 0)
1736 {
1737 CHECK_ERROR(vrdpServer, COMSETTER(ReuseSingleConnection)(true));
1738 }
1739 else if (strcmp(vrdpreusecon, "off") == 0)
1740 {
1741 CHECK_ERROR(vrdpServer, COMSETTER(ReuseSingleConnection)(false));
1742 }
1743 else
1744 {
1745 errorArgument("Invalid -vrdpreusecon argument '%s'", vrdpreusecon);
1746 rc = E_FAIL;
1747 break;
1748 }
1749 }
1750 }
1751 }
1752#endif /* VBOX_WITH_VRDP */
1753
1754 /*
1755 * USB enable/disable
1756 */
1757 if (fUsbEnabled != -1)
1758 {
1759 ComPtr<IUSBController> UsbCtl;
1760 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1761 if (SUCCEEDED(rc))
1762 {
1763 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(!!fUsbEnabled));
1764 }
1765 }
1766 /*
1767 * USB EHCI enable/disable
1768 */
1769 if (fUsbEhciEnabled != -1)
1770 {
1771 ComPtr<IUSBController> UsbCtl;
1772 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1773 if (SUCCEEDED(rc))
1774 {
1775 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEhci)(!!fUsbEhciEnabled));
1776 }
1777 }
1778
1779 if (snapshotFolder)
1780 {
1781 if (strcmp(snapshotFolder, "default") == 0)
1782 {
1783 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(NULL));
1784 }
1785 else
1786 {
1787 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(snapshotFolder)));
1788 }
1789 }
1790
1791 if (guestMemBalloonSize != (ULONG)-1)
1792 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(guestMemBalloonSize));
1793
1794 if (guestStatInterval != (ULONG)-1)
1795 CHECK_ERROR(machine, COMSETTER(StatisticsUpdateInterval)(guestStatInterval));
1796
1797 /*
1798 * SATA controller enable/disable
1799 */
1800 if (fSataEnabled != -1)
1801 {
1802 if (fSataEnabled)
1803 {
1804 ComPtr<IStorageController> ctl;
1805 CHECK_ERROR(machine, AddStorageController(Bstr("SATA"), StorageBus_SATA, ctl.asOutParam()));
1806 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
1807 }
1808 else
1809 CHECK_ERROR(machine, RemoveStorageController(Bstr("SATA")));
1810 }
1811
1812 for (uint32_t i = 4; i < 34; i++)
1813 {
1814 if (hdds[i])
1815 {
1816 if (strcmp(hdds[i], "none") == 0)
1817 {
1818 machine->DetachHardDisk(Bstr("SATA"), i-4, 0);
1819 }
1820 else
1821 {
1822 /* first guess is that it's a UUID */
1823 Guid uuid(hdds[i]);
1824 ComPtr<IHardDisk> hardDisk;
1825 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
1826 /* not successful? Then it must be a filename */
1827 if (!hardDisk)
1828 {
1829 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[i]), hardDisk.asOutParam()));
1830 if (FAILED(rc))
1831 {
1832 /* open the new hard disk object */
1833 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), hardDisk.asOutParam()));
1834 }
1835 }
1836 if (hardDisk)
1837 {
1838 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1839 CHECK_ERROR(machine, AttachHardDisk(uuid, Bstr("SATA"), i-4, 0));
1840 }
1841 else
1842 rc = E_FAIL;
1843 if (FAILED(rc))
1844 break;
1845 }
1846 }
1847 }
1848
1849 for (uint32_t i = 0; i < 4; i++)
1850 {
1851 if (sataBootDevices[i] != -1)
1852 {
1853 ComPtr<IStorageController> SataCtl;
1854 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA"), SataCtl.asOutParam()));
1855 if (SUCCEEDED(rc))
1856 {
1857 CHECK_ERROR(SataCtl, SetIDEEmulationPort(i, sataBootDevices[i]));
1858 }
1859 }
1860 }
1861
1862 if (sataPortCount != -1)
1863 {
1864 ComPtr<IStorageController> SataCtl;
1865 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA"), SataCtl.asOutParam()));
1866 if (SUCCEEDED(rc))
1867 {
1868 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(sataPortCount));
1869 }
1870 }
1871
1872 /*
1873 * SCSI controller enable/disable
1874 */
1875 if (fScsiEnabled != -1)
1876 {
1877 if (fScsiEnabled)
1878 {
1879 ComPtr<IStorageController> ctl;
1880 if (fScsiLsiLogic == 0)
1881 {
1882 CHECK_ERROR(machine, AddStorageController(Bstr("BusLogic"), StorageBus_SCSI, ctl.asOutParam()));
1883 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
1884 }
1885 else /* LsiLogic is default */
1886 {
1887 CHECK_ERROR(machine, AddStorageController(Bstr("LsiLogic"), StorageBus_SCSI, ctl.asOutParam()));
1888 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
1889 }
1890 }
1891 else
1892 {
1893 rc = machine->RemoveStorageController(Bstr("LsiLogic"));
1894 if (!SUCCEEDED(rc))
1895 CHECK_ERROR(machine, RemoveStorageController(Bstr("BusLogic")));
1896 }
1897 }
1898
1899 for (uint32_t i = 34; i < 50; i++)
1900 {
1901 if (hdds[i])
1902 {
1903 if (strcmp(hdds[i], "none") == 0)
1904 {
1905 rc = machine->DetachHardDisk(Bstr("LsiLogic"), i-34, 0);
1906 if (!SUCCEEDED(rc))
1907 CHECK_ERROR(machine, DetachHardDisk(Bstr("BusLogic"), i-34, 0));
1908 }
1909 else
1910 {
1911 /* first guess is that it's a UUID */
1912 Guid uuid(hdds[i]);
1913 ComPtr<IHardDisk> hardDisk;
1914 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
1915 /* not successful? Then it must be a filename */
1916 if (!hardDisk)
1917 {
1918 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[i]), hardDisk.asOutParam()));
1919 if (FAILED(rc))
1920 {
1921 /* open the new hard disk object */
1922 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), hardDisk.asOutParam()));
1923 }
1924 }
1925 if (hardDisk)
1926 {
1927 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1928 rc = machine->AttachHardDisk(uuid, Bstr("LsiLogic"), i-34, 0);
1929 if (!SUCCEEDED(rc))
1930 CHECK_ERROR(machine, AttachHardDisk(uuid, Bstr("BusLogic"), i-34, 0));
1931 }
1932 else
1933 rc = E_FAIL;
1934 if (FAILED(rc))
1935 break;
1936 }
1937 }
1938 }
1939
1940 /* commit changes */
1941 CHECK_ERROR(machine, SaveSettings());
1942 }
1943 while (0);
1944
1945 /* it's important to always close sessions */
1946 a->session->Close();
1947
1948 return SUCCEEDED(rc) ? 0 : 1;
1949}
1950
1951#endif /* !VBOX_ONLY_DOCS */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette