VirtualBox

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

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

API/others: Renamed IConsole::discardSavedState to IConsole::forgetSavedState, added parameter. Deleted old IConsole::powerDown, renamed IConsole::powerDownAsync to IConsole::powerDown (as promised for 2.1). Implemented perl sample code for registering a hard disk. Cleaned up constant formatting in the API docs. Updated SDK changelog. Renamed com/errorprint2.h to com/errorprint.h, added a few assertion variants. Eliminated com/errorprint_legacy.h. Adjusted all files using the affected headers and APIs. Renamed tstHeadless2 to tstHeadless.

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