VirtualBox

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

Last change on this file since 19176 was 19023, checked in by vboxsync, 16 years ago

fixed typo in VBoxMange modifyvm VM_NAME -idecontroller

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