VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp@ 29607

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 61.2 KB
Line 
1/* $Id: VBoxInternalManage.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'internalcommands' command.
4 *
5 * VBoxInternalManage used to be a second CLI for doing special tricks,
6 * not intended for general usage, only for assisting VBox developers.
7 * It is now integrated into VBoxManage.
8 */
9
10/*
11 * Copyright (C) 2006-2010 Oracle Corporation
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.virtualbox.org. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License (GPL) as published by the Free Software
17 * Foundation, in version 2 as it comes in the "COPYING" file of the
18 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20 */
21
22
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/com/com.h>
28#include <VBox/com/string.h>
29#include <VBox/com/Guid.h>
30#include <VBox/com/ErrorInfo.h>
31#include <VBox/com/errorprint.h>
32
33#include <VBox/com/VirtualBox.h>
34
35#include <VBox/VBoxHDD.h>
36#include <VBox/sup.h>
37#include <VBox/err.h>
38#include <VBox/log.h>
39
40#include <iprt/file.h>
41#include <iprt/initterm.h>
42#include <iprt/stream.h>
43#include <iprt/string.h>
44#include <iprt/uuid.h>
45
46
47#include "VBoxManage.h"
48
49/* Includes for the raw disk stuff. */
50#ifdef RT_OS_WINDOWS
51# include <windows.h>
52# include <winioctl.h>
53#elif defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) \
54 || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
55# include <errno.h>
56# include <sys/ioctl.h>
57# include <sys/types.h>
58# include <sys/stat.h>
59# include <fcntl.h>
60# include <unistd.h>
61#endif
62#ifdef RT_OS_LINUX
63# include <sys/utsname.h>
64# include <linux/hdreg.h>
65# include <linux/fs.h>
66# include <stdlib.h> /* atoi() */
67#endif /* RT_OS_LINUX */
68#ifdef RT_OS_DARWIN
69# include <sys/disk.h>
70#endif /* RT_OS_DARWIN */
71#ifdef RT_OS_SOLARIS
72# include <stropts.h>
73# include <sys/dkio.h>
74# include <sys/vtoc.h>
75#endif /* RT_OS_SOLARIS */
76#ifdef RT_OS_FREEBSD
77# include <sys/disk.h>
78#endif /* RT_OS_FREEBSD */
79
80using namespace com;
81
82
83/** Macro for checking whether a partition is of extended type or not. */
84#define PARTTYPE_IS_EXTENDED(x) ((x) == 0x05 || (x) == 0x0f || (x) == 0x85)
85
86/* Maximum number of partitions we can deal with. Ridiculously large number,
87 * but the memory consumption is rather low so who cares about never using
88 * most entries. */
89#define HOSTPARTITION_MAX 100
90
91
92typedef struct HOSTPARTITION
93{
94 unsigned uIndex;
95 /** partition type */
96 unsigned uType;
97 /** CHS/cylinder of the first sector */
98 unsigned uStartCylinder;
99 /** CHS/head of the first sector */
100 unsigned uStartHead;
101 /** CHS/head of the first sector */
102 unsigned uStartSector;
103 /** CHS/cylinder of the last sector */
104 unsigned uEndCylinder;
105 /** CHS/head of the last sector */
106 unsigned uEndHead;
107 /** CHS/sector of the last sector */
108 unsigned uEndSector;
109 /** start sector of this partition relative to the beginning of the hard
110 * disk or relative to the beginning of the extended partition table */
111 uint64_t uStart;
112 /** numer of sectors of the partition */
113 uint64_t uSize;
114 /** start sector of this partition _table_ */
115 uint64_t uPartDataStart;
116 /** numer of sectors of this partition _table_ */
117 uint64_t cPartDataSectors;
118} HOSTPARTITION, *PHOSTPARTITION;
119
120typedef struct HOSTPARTITIONS
121{
122 unsigned cPartitions;
123 HOSTPARTITION aPartitions[HOSTPARTITION_MAX];
124} HOSTPARTITIONS, *PHOSTPARTITIONS;
125
126/** flag whether we're in internal mode */
127bool g_fInternalMode;
128
129/**
130 * Print the usage info.
131 */
132void printUsageInternal(USAGECATEGORY u64Cmd)
133{
134 RTPrintf("Usage: VBoxManage internalcommands <command> [command arguments]\n"
135 "\n"
136 "Commands:\n"
137 "\n"
138 "%s%s%s%s%s%s%s%s%s"
139 "WARNING: This is a development tool and shall only be used to analyse\n"
140 " problems. It is completely unsupported and will change in\n"
141 " incompatible ways without warning.\n",
142 (u64Cmd & USAGE_LOADSYMS) ?
143 " loadsyms <vmname>|<uuid> <symfile> [delta] [module] [module address]\n"
144 " This will instruct DBGF to load the given symbolfile\n"
145 " during initialization.\n"
146 "\n"
147 : "",
148 (u64Cmd & USAGE_UNLOADSYMS) ?
149 " unloadsyms <vmname>|<uuid> <symfile>\n"
150 " Removes <symfile> from the list of symbol files that\n"
151 " should be loaded during DBF initialization.\n"
152 "\n"
153 : "",
154 (u64Cmd & USAGE_SETHDUUID) ?
155 " sethduuid <filepath>\n"
156 " Assigns a new UUID to the given image file. This way, multiple copies\n"
157 " of a container can be registered.\n"
158 "\n"
159 : "",
160 (u64Cmd & USAGE_DUMPHDINFO) ?
161 " dumphdinfo <filepath>\n"
162 " Prints information about the image at the given location.\n"
163 "\n"
164 : "",
165 (u64Cmd & USAGE_LISTPARTITIONS) ?
166 " listpartitions -rawdisk <diskname>\n"
167 " Lists all partitions on <diskname>.\n"
168 "\n"
169 : "",
170 (u64Cmd & USAGE_CREATERAWVMDK) ?
171 " createrawvmdk -filename <filename> -rawdisk <diskname>\n"
172 " [-partitions <list of partition numbers> [-mbr <filename>] ]\n"
173 " [-register] [-relative]\n"
174 " Creates a new VMDK image which gives access to an entite host disk (if\n"
175 " the parameter -partitions is not specified) or some partitions of a\n"
176 " host disk. If access to individual partitions is granted, then the\n"
177 " parameter -mbr can be used to specify an alternative MBR to be used\n"
178 " (the partitioning information in the MBR file is ignored).\n"
179 " The diskname is on Linux e.g. /dev/sda, and on Windows e.g.\n"
180 " \\\\.\\PhysicalDrive0).\n"
181 " On Linux host the parameter -relative causes a VMDK file to be created\n"
182 " which refers to individual partitions instead to the entire disk.\n"
183 " Optionally the created image can be immediately registered.\n"
184 " The necessary partition numbers can be queried with\n"
185 " VBoxManage internalcommands listpartitions\n"
186 "\n"
187 : "",
188 (u64Cmd & USAGE_RENAMEVMDK) ?
189 " renamevmdk -from <filename> -to <filename>\n"
190 " Renames an existing VMDK image, including the base file and all its extents.\n"
191 "\n"
192 : "",
193 (u64Cmd & USAGE_CONVERTTORAW) ?
194 " converttoraw [-format <fileformat>] <filename> <outputfile>"
195#ifdef ENABLE_CONVERT_RAW_TO_STDOUT
196 "|stdout"
197#endif /* ENABLE_CONVERT_RAW_TO_STDOUT */
198 "\n"
199 " Convert image to raw, writing to file"
200#ifdef ENABLE_CONVERT_RAW_TO_STDOUT
201 " or stdout"
202#endif /* ENABLE_CONVERT_RAW_TO_STDOUT */
203 ".\n"
204 "\n"
205 : "",
206 (u64Cmd & USAGE_CONVERTHD) ?
207 " converthd [-srcformat VDI|VMDK|VHD|RAW]\n"
208 " [-dstformat VDI|VMDK|VHD|RAW]\n"
209 " <inputfile> <outputfile>\n"
210 " converts hard disk images between formats\n"
211 "\n"
212 : "",
213#ifdef RT_OS_WINDOWS
214 (u64Cmd & USAGE_MODINSTALL) ?
215 " modinstall\n"
216 " Installs the neccessary driver for the host OS\n"
217 "\n"
218 : "",
219 (u64Cmd & USAGE_MODUNINSTALL) ?
220 " moduninstall\n"
221 " Deinstalls the driver\n"
222 "\n"
223 : ""
224#else
225 "",
226 ""
227#endif
228 );
229}
230
231/** @todo this is no longer necessary, we can enumerate extra data */
232/**
233 * Finds a new unique key name.
234 *
235 * I don't think this is 100% race condition proof, but we assumes
236 * the user is not trying to push this point.
237 *
238 * @returns Result from the insert.
239 * @param pMachine The Machine object.
240 * @param pszKeyBase The base key.
241 * @param rKey Reference to the string object in which we will return the key.
242 */
243static HRESULT NewUniqueKey(ComPtr<IMachine> pMachine, const char *pszKeyBase, Utf8Str &rKey)
244{
245 Bstr Keys;
246 HRESULT hrc = pMachine->GetExtraData(Bstr(pszKeyBase), Keys.asOutParam());
247 if (FAILED(hrc))
248 return hrc;
249
250 /* if there are no keys, it's simple. */
251 if (Keys.isEmpty())
252 {
253 rKey = "1";
254 return pMachine->SetExtraData(Bstr(pszKeyBase), Bstr("1"));
255 }
256
257 /* find a unique number - brute force rulez. */
258 Utf8Str KeysUtf8(Keys);
259 const char *pszKeys = RTStrStripL(KeysUtf8.raw());
260 for (unsigned i = 1; i < 1000000; i++)
261 {
262 char szKey[32];
263 size_t cchKey = RTStrPrintf(szKey, sizeof(szKey), "%#x", i);
264 const char *psz = strstr(pszKeys, szKey);
265 while (psz)
266 {
267 if ( ( psz == pszKeys
268 || psz[-1] == ' ')
269 && ( psz[cchKey] == ' '
270 || !psz[cchKey])
271 )
272 break;
273 psz = strstr(psz + cchKey, szKey);
274 }
275 if (!psz)
276 {
277 rKey = szKey;
278 Utf8StrFmt NewKeysUtf8("%s %s", pszKeys, szKey);
279 return pMachine->SetExtraData(Bstr(pszKeyBase), Bstr(NewKeysUtf8));
280 }
281 }
282 RTPrintf("Error: Cannot find unique key for '%s'!\n", pszKeyBase);
283 return E_FAIL;
284}
285
286
287#if 0
288/**
289 * Remove a key.
290 *
291 * I don't think this isn't 100% race condition proof, but we assumes
292 * the user is not trying to push this point.
293 *
294 * @returns Result from the insert.
295 * @param pMachine The machine object.
296 * @param pszKeyBase The base key.
297 * @param pszKey The key to remove.
298 */
299static HRESULT RemoveKey(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey)
300{
301 Bstr Keys;
302 HRESULT hrc = pMachine->GetExtraData(Bstr(pszKeyBase), Keys.asOutParam());
303 if (FAILED(hrc))
304 return hrc;
305
306 /* if there are no keys, it's simple. */
307 if (Keys.isEmpty())
308 return S_OK;
309
310 char *pszKeys;
311 int rc = RTUtf16ToUtf8(Keys.raw(), &pszKeys);
312 if (RT_SUCCESS(rc))
313 {
314 /* locate it */
315 size_t cchKey = strlen(pszKey);
316 char *psz = strstr(pszKeys, pszKey);
317 while (psz)
318 {
319 if ( ( psz == pszKeys
320 || psz[-1] == ' ')
321 && ( psz[cchKey] == ' '
322 || !psz[cchKey])
323 )
324 break;
325 psz = strstr(psz + cchKey, pszKey);
326 }
327 if (psz)
328 {
329 /* remove it */
330 char *pszNext = RTStrStripL(psz + cchKey);
331 if (*pszNext)
332 memmove(psz, pszNext, strlen(pszNext) + 1);
333 else
334 *psz = '\0';
335 psz = RTStrStrip(pszKeys);
336
337 /* update */
338 hrc = pMachine->SetExtraData(Bstr(pszKeyBase), Bstr(psz));
339 }
340
341 RTStrFree(pszKeys);
342 return hrc;
343 }
344 else
345 RTPrintf("error: failed to delete key '%s' from '%s', string conversion error %Rrc!\n",
346 pszKey, pszKeyBase, rc);
347
348 return E_FAIL;
349}
350#endif
351
352
353/**
354 * Sets a key value, does necessary error bitching.
355 *
356 * @returns COM status code.
357 * @param pMachine The Machine object.
358 * @param pszKeyBase The key base.
359 * @param pszKey The key.
360 * @param pszAttribute The attribute name.
361 * @param pszValue The string value.
362 */
363static HRESULT SetString(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, const char *pszValue)
364{
365 HRESULT hrc = pMachine->SetExtraData(Bstr(Utf8StrFmt("%s/%s/%s", pszKeyBase, pszKey, pszAttribute)), Bstr(pszValue));
366 if (FAILED(hrc))
367 RTPrintf("error: Failed to set '%s/%s/%s' to '%s'! hrc=%#x\n",
368 pszKeyBase, pszKey, pszAttribute, pszValue, hrc);
369 return hrc;
370}
371
372
373/**
374 * Sets a key value, does necessary error bitching.
375 *
376 * @returns COM status code.
377 * @param pMachine The Machine object.
378 * @param pszKeyBase The key base.
379 * @param pszKey The key.
380 * @param pszAttribute The attribute name.
381 * @param u64Value The value.
382 */
383static HRESULT SetUInt64(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, uint64_t u64Value)
384{
385 char szValue[64];
386 RTStrPrintf(szValue, sizeof(szValue), "%#RX64", u64Value);
387 return SetString(pMachine, pszKeyBase, pszKey, pszAttribute, szValue);
388}
389
390
391/**
392 * Sets a key value, does necessary error bitching.
393 *
394 * @returns COM status code.
395 * @param pMachine The Machine object.
396 * @param pszKeyBase The key base.
397 * @param pszKey The key.
398 * @param pszAttribute The attribute name.
399 * @param i64Value The value.
400 */
401static HRESULT SetInt64(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, int64_t i64Value)
402{
403 char szValue[64];
404 RTStrPrintf(szValue, sizeof(szValue), "%RI64", i64Value);
405 return SetString(pMachine, pszKeyBase, pszKey, pszAttribute, szValue);
406}
407
408
409/**
410 * Identical to the 'loadsyms' command.
411 */
412static int CmdLoadSyms(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
413{
414 HRESULT rc;
415
416 /*
417 * Get the VM
418 */
419 ComPtr<IMachine> machine;
420 /* assume it's a UUID */
421 rc = aVirtualBox->GetMachine(Bstr(argv[0]), machine.asOutParam());
422 if (FAILED(rc) || !machine)
423 {
424 /* must be a name */
425 CHECK_ERROR_RET(aVirtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()), 1);
426 }
427
428 /*
429 * Parse the command.
430 */
431 const char *pszFilename;
432 int64_t offDelta = 0;
433 const char *pszModule = NULL;
434 uint64_t ModuleAddress = ~0;
435 uint64_t ModuleSize = 0;
436
437 /* filename */
438 if (argc < 2)
439 return errorArgument("Missing the filename argument!\n");
440 pszFilename = argv[1];
441
442 /* offDelta */
443 if (argc >= 3)
444 {
445 int irc = RTStrToInt64Ex(argv[2], NULL, 0, &offDelta);
446 if (RT_FAILURE(irc))
447 return errorArgument(argv[0], "Failed to read delta '%s', rc=%Rrc\n", argv[2], rc);
448 }
449
450 /* pszModule */
451 if (argc >= 4)
452 pszModule = argv[3];
453
454 /* ModuleAddress */
455 if (argc >= 5)
456 {
457 int irc = RTStrToUInt64Ex(argv[4], NULL, 0, &ModuleAddress);
458 if (RT_FAILURE(irc))
459 return errorArgument(argv[0], "Failed to read module address '%s', rc=%Rrc\n", argv[4], rc);
460 }
461
462 /* ModuleSize */
463 if (argc >= 6)
464 {
465 int irc = RTStrToUInt64Ex(argv[5], NULL, 0, &ModuleSize);
466 if (RT_FAILURE(irc))
467 return errorArgument(argv[0], "Failed to read module size '%s', rc=%Rrc\n", argv[5], rc);
468 }
469
470 /*
471 * Add extra data.
472 */
473 Utf8Str KeyStr;
474 HRESULT hrc = NewUniqueKey(machine, "VBoxInternal/DBGF/loadsyms", KeyStr);
475 if (SUCCEEDED(hrc))
476 hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Filename", pszFilename);
477 if (SUCCEEDED(hrc) && argc >= 3)
478 hrc = SetInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Delta", offDelta);
479 if (SUCCEEDED(hrc) && argc >= 4)
480 hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Module", pszModule);
481 if (SUCCEEDED(hrc) && argc >= 5)
482 hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "ModuleAddress", ModuleAddress);
483 if (SUCCEEDED(hrc) && argc >= 6)
484 hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "ModuleSize", ModuleSize);
485
486 return FAILED(hrc);
487}
488
489
490static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
491{
492 RTPrintf("ERROR: ");
493 RTPrintfV(pszFormat, va);
494 RTPrintf("\n");
495 RTPrintf("Error code %Rrc at %s(%u) in function %s\n", rc, RT_SRC_POS_ARGS);
496}
497
498static int CmdSetHDUUID(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
499{
500 /* we need exactly one parameter: the image file */
501 if (argc != 1)
502 {
503 return errorSyntax(USAGE_SETHDUUID, "Not enough parameters");
504 }
505
506 /* generate a new UUID */
507 Guid uuid;
508 uuid.create();
509
510 /* just try it */
511 char *pszFormat = NULL;
512 int rc = VDGetFormat(NULL, argv[0], &pszFormat);
513 if (RT_FAILURE(rc))
514 {
515 RTPrintf("Format autodetect failed: %Rrc\n", rc);
516 return 1;
517 }
518
519 PVBOXHDD pDisk = NULL;
520
521 PVDINTERFACE pVDIfs = NULL;
522 VDINTERFACE vdInterfaceError;
523 VDINTERFACEERROR vdInterfaceErrorCallbacks;
524 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
525 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
526 vdInterfaceErrorCallbacks.pfnError = handleVDError;
527 vdInterfaceErrorCallbacks.pfnMessage = NULL;
528
529 rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
530 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
531 AssertRC(rc);
532
533 rc = VDCreate(pVDIfs, &pDisk);
534 if (RT_FAILURE(rc))
535 {
536 RTPrintf("Error while creating the virtual disk container: %Rrc\n", rc);
537 return 1;
538 }
539
540 /* Open the image */
541 rc = VDOpen(pDisk, pszFormat, argv[0], VD_OPEN_FLAGS_NORMAL, NULL);
542 if (RT_FAILURE(rc))
543 {
544 RTPrintf("Error while opening the image: %Rrc\n", rc);
545 return 1;
546 }
547
548 rc = VDSetUuid(pDisk, VD_LAST_IMAGE, uuid.raw());
549 if (RT_FAILURE(rc))
550 RTPrintf("Error while setting a new UUID: %Rrc\n", rc);
551 else
552 RTPrintf("UUID changed to: %s\n", uuid.toString().raw());
553
554 VDCloseAll(pDisk);
555
556 return RT_FAILURE(rc);
557}
558
559
560static int handleVDMessage(void *pvUser, const char *pszFormat, ...)
561{
562 NOREF(pvUser);
563 va_list args;
564 va_start(args, pszFormat);
565 int rc = RTPrintfV(pszFormat, args);
566 va_end(args);
567 return rc;
568}
569
570static int CmdDumpHDInfo(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
571{
572 /* we need exactly one parameter: the image file */
573 if (argc != 1)
574 {
575 return errorSyntax(USAGE_SETHDUUID, "Not enough parameters");
576 }
577
578 /* just try it */
579 char *pszFormat = NULL;
580 int rc = VDGetFormat(NULL, argv[0], &pszFormat);
581 if (RT_FAILURE(rc))
582 {
583 RTPrintf("Format autodetect failed: %Rrc\n", rc);
584 return 1;
585 }
586
587 PVBOXHDD pDisk = NULL;
588
589 PVDINTERFACE pVDIfs = NULL;
590 VDINTERFACE vdInterfaceError;
591 VDINTERFACEERROR vdInterfaceErrorCallbacks;
592 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
593 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
594 vdInterfaceErrorCallbacks.pfnError = handleVDError;
595 vdInterfaceErrorCallbacks.pfnMessage = handleVDMessage;
596
597 rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
598 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
599 AssertRC(rc);
600
601 rc = VDCreate(pVDIfs, &pDisk);
602 if (RT_FAILURE(rc))
603 {
604 RTPrintf("Error while creating the virtual disk container: %Rrc\n", rc);
605 return 1;
606 }
607
608 /* Open the image */
609 rc = VDOpen(pDisk, pszFormat, argv[0], VD_OPEN_FLAGS_INFO, NULL);
610 if (RT_FAILURE(rc))
611 {
612 RTPrintf("Error while opening the image: %Rrc\n", rc);
613 return 1;
614 }
615
616 VDDumpImages(pDisk);
617
618 VDCloseAll(pDisk);
619
620 return RT_FAILURE(rc);
621}
622
623static int partRead(RTFILE File, PHOSTPARTITIONS pPart)
624{
625 uint8_t aBuffer[512];
626 int rc;
627
628 pPart->cPartitions = 0;
629 memset(pPart->aPartitions, '\0', sizeof(pPart->aPartitions));
630 rc = RTFileReadAt(File, 0, &aBuffer, sizeof(aBuffer), NULL);
631 if (RT_FAILURE(rc))
632 return rc;
633 if (aBuffer[510] != 0x55 || aBuffer[511] != 0xaa)
634 return VERR_INVALID_PARAMETER;
635
636 unsigned uExtended = (unsigned)-1;
637
638 for (unsigned i = 0; i < 4; i++)
639 {
640 uint8_t *p = &aBuffer[0x1be + i * 16];
641 if (p[4] == 0)
642 continue;
643 PHOSTPARTITION pCP = &pPart->aPartitions[pPart->cPartitions++];
644 pCP->uIndex = i + 1;
645 pCP->uType = p[4];
646 pCP->uStartCylinder = (uint32_t)p[3] + ((uint32_t)(p[2] & 0xc0) << 2);
647 pCP->uStartHead = p[1];
648 pCP->uStartSector = p[2] & 0x3f;
649 pCP->uEndCylinder = (uint32_t)p[7] + ((uint32_t)(p[6] & 0xc0) << 2);
650 pCP->uEndHead = p[5];
651 pCP->uEndSector = p[6] & 0x3f;
652 pCP->uStart = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
653 pCP->uSize = RT_MAKE_U32_FROM_U8(p[12], p[13], p[14], p[15]);
654 pCP->uPartDataStart = 0; /* will be filled out later properly. */
655 pCP->cPartDataSectors = 0;
656
657 if (PARTTYPE_IS_EXTENDED(p[4]))
658 {
659 if (uExtended == (unsigned)-1)
660 uExtended = (unsigned)(pCP - pPart->aPartitions);
661 else
662 {
663 RTPrintf("More than one extended partition. Aborting\n");
664 return VERR_INVALID_PARAMETER;
665 }
666 }
667 }
668
669 if (uExtended != (unsigned)-1)
670 {
671 unsigned uIndex = 5;
672 uint64_t uStart = pPart->aPartitions[uExtended].uStart;
673 uint64_t uOffset = 0;
674 if (!uStart)
675 {
676 RTPrintf("Inconsistency for logical partition start. Aborting\n");
677 return VERR_INVALID_PARAMETER;
678 }
679
680 do
681 {
682 rc = RTFileReadAt(File, (uStart + uOffset) * 512, &aBuffer, sizeof(aBuffer), NULL);
683 if (RT_FAILURE(rc))
684 return rc;
685
686 if (aBuffer[510] != 0x55 || aBuffer[511] != 0xaa)
687 {
688 RTPrintf("Logical partition without magic. Aborting\n");
689 return VERR_INVALID_PARAMETER;
690 }
691 uint8_t *p = &aBuffer[0x1be];
692
693 if (p[4] == 0)
694 {
695 RTPrintf("Logical partition with type 0 encountered. Aborting\n");
696 return VERR_INVALID_PARAMETER;
697 }
698
699 PHOSTPARTITION pCP = &pPart->aPartitions[pPart->cPartitions++];
700 pCP->uIndex = uIndex;
701 pCP->uType = p[4];
702 pCP->uStartCylinder = (uint32_t)p[3] + ((uint32_t)(p[2] & 0xc0) << 2);
703 pCP->uStartHead = p[1];
704 pCP->uStartSector = p[2] & 0x3f;
705 pCP->uEndCylinder = (uint32_t)p[7] + ((uint32_t)(p[6] & 0xc0) << 2);
706 pCP->uEndHead = p[5];
707 pCP->uEndSector = p[6] & 0x3f;
708 uint32_t uStartOffset = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
709 if (!uStartOffset)
710 {
711 RTPrintf("Invalid partition start offset. Aborting\n");
712 return VERR_INVALID_PARAMETER;
713 }
714 pCP->uStart = uStart + uOffset + uStartOffset;
715 pCP->uSize = RT_MAKE_U32_FROM_U8(p[12], p[13], p[14], p[15]);
716 /* Fill out partitioning location info for EBR. */
717 pCP->uPartDataStart = uStart + uOffset;
718 pCP->cPartDataSectors = uStartOffset;
719 p += 16;
720 if (p[4] == 0)
721 uExtended = (unsigned)-1;
722 else if (PARTTYPE_IS_EXTENDED(p[4]))
723 {
724 uExtended = uIndex++;
725 uOffset = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
726 }
727 else
728 {
729 RTPrintf("Logical partition chain broken. Aborting\n");
730 return VERR_INVALID_PARAMETER;
731 }
732 } while (uExtended != (unsigned)-1);
733 }
734
735 /* Sort partitions in ascending order of start sector, plus a trivial
736 * bit of consistency checking. */
737 for (unsigned i = 0; i < pPart->cPartitions-1; i++)
738 {
739 unsigned uMinIdx = i;
740 uint64_t uMinVal = pPart->aPartitions[i].uStart;
741 for (unsigned j = i + 1; j < pPart->cPartitions; j++)
742 {
743 if (pPart->aPartitions[j].uStart < uMinVal)
744 {
745 uMinIdx = j;
746 uMinVal = pPart->aPartitions[j].uStart;
747 }
748 else if (pPart->aPartitions[j].uStart == uMinVal)
749 {
750 RTPrintf("Two partitions start at the same place. Aborting\n");
751 return VERR_INVALID_PARAMETER;
752 }
753 else if (pPart->aPartitions[j].uStart == 0)
754 {
755 RTPrintf("Partition starts at sector 0. Aborting\n");
756 return VERR_INVALID_PARAMETER;
757 }
758 }
759 if (uMinIdx != i)
760 {
761 /* Swap entries at index i and uMinIdx. */
762 memcpy(&pPart->aPartitions[pPart->cPartitions],
763 &pPart->aPartitions[i], sizeof(HOSTPARTITION));
764 memcpy(&pPart->aPartitions[i],
765 &pPart->aPartitions[uMinIdx], sizeof(HOSTPARTITION));
766 memcpy(&pPart->aPartitions[uMinIdx],
767 &pPart->aPartitions[pPart->cPartitions], sizeof(HOSTPARTITION));
768 }
769 }
770
771 /* Now do a lot of consistency checking. */
772 uint64_t uPrevEnd = 0;
773 for (unsigned i = 0; i < pPart->cPartitions-1; i++)
774 {
775 if (pPart->aPartitions[i].cPartDataSectors)
776 {
777 if (pPart->aPartitions[i].uPartDataStart < uPrevEnd)
778 {
779 RTPrintf("Overlapping partition description areas. Aborting\n");
780 return VERR_INVALID_PARAMETER;
781 }
782 uPrevEnd = pPart->aPartitions[i].uPartDataStart + pPart->aPartitions[i].cPartDataSectors;
783 }
784 if (pPart->aPartitions[i].uStart < uPrevEnd)
785 {
786 RTPrintf("Overlapping partitions. Aborting\n");
787 return VERR_INVALID_PARAMETER;
788 }
789 if (!PARTTYPE_IS_EXTENDED(pPart->aPartitions[i].uType))
790 uPrevEnd = pPart->aPartitions[i].uStart + pPart->aPartitions[i].uSize;
791 }
792
793 /* Fill out partitioning location info for MBR. */
794 pPart->aPartitions[0].uPartDataStart = 0;
795 pPart->aPartitions[0].cPartDataSectors = pPart->aPartitions[0].uStart;
796
797 return VINF_SUCCESS;
798}
799
800static int CmdListPartitions(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
801{
802 Utf8Str rawdisk;
803
804 /* let's have a closer look at the arguments */
805 for (int i = 0; i < argc; i++)
806 {
807 if (strcmp(argv[i], "-rawdisk") == 0)
808 {
809 if (argc <= i + 1)
810 {
811 return errorArgument("Missing argument to '%s'", argv[i]);
812 }
813 i++;
814 rawdisk = argv[i];
815 }
816 else
817 {
818 return errorSyntax(USAGE_LISTPARTITIONS, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
819 }
820 }
821
822 if (rawdisk.isEmpty())
823 return errorSyntax(USAGE_LISTPARTITIONS, "Mandatory parameter -rawdisk missing");
824
825 RTFILE RawFile;
826 int vrc = RTFileOpen(&RawFile, rawdisk.raw(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
827 if (RT_FAILURE(vrc))
828 {
829 RTPrintf("Error opening the raw disk: %Rrc\n", vrc);
830 return vrc;
831 }
832
833 HOSTPARTITIONS partitions;
834 vrc = partRead(RawFile, &partitions);
835 if (RT_FAILURE(vrc))
836 return vrc;
837
838 RTPrintf("Number Type StartCHS EndCHS Size (MiB) Start (Sect)\n");
839 for (unsigned i = 0; i < partitions.cPartitions; i++)
840 {
841 /* Suppress printing the extended partition. Otherwise people
842 * might add it to the list of partitions for raw partition
843 * access (which is not good). */
844 if (PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
845 continue;
846
847 RTPrintf("%-7u %#04x %-4u/%-3u/%-2u %-4u/%-3u/%-2u %10llu %10llu\n",
848 partitions.aPartitions[i].uIndex,
849 partitions.aPartitions[i].uType,
850 partitions.aPartitions[i].uStartCylinder,
851 partitions.aPartitions[i].uStartHead,
852 partitions.aPartitions[i].uStartSector,
853 partitions.aPartitions[i].uEndCylinder,
854 partitions.aPartitions[i].uEndHead,
855 partitions.aPartitions[i].uEndSector,
856 partitions.aPartitions[i].uSize / 2048,
857 partitions.aPartitions[i].uStart);
858 }
859
860 return 0;
861}
862
863static int CmdCreateRawVMDK(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
864{
865 HRESULT rc = S_OK;
866 Bstr filename;
867 const char *pszMBRFilename = NULL;
868 Utf8Str rawdisk;
869 const char *pszPartitions = NULL;
870 bool fRegister = false;
871 bool fRelative = false;
872
873 uint64_t cbSize = 0;
874 PVBOXHDD pDisk = NULL;
875 VBOXHDDRAW RawDescriptor;
876 HOSTPARTITIONS partitions;
877 uint32_t uPartitions = 0;
878 PVDINTERFACE pVDIfs = NULL;
879
880 /* let's have a closer look at the arguments */
881 for (int i = 0; i < argc; i++)
882 {
883 if (strcmp(argv[i], "-filename") == 0)
884 {
885 if (argc <= i + 1)
886 {
887 return errorArgument("Missing argument to '%s'", argv[i]);
888 }
889 i++;
890 filename = argv[i];
891 }
892 else if (strcmp(argv[i], "-mbr") == 0)
893 {
894 if (argc <= i + 1)
895 {
896 return errorArgument("Missing argument to '%s'", argv[i]);
897 }
898 i++;
899 pszMBRFilename = argv[i];
900 }
901 else if (strcmp(argv[i], "-rawdisk") == 0)
902 {
903 if (argc <= i + 1)
904 {
905 return errorArgument("Missing argument to '%s'", argv[i]);
906 }
907 i++;
908 rawdisk = argv[i];
909 }
910 else if (strcmp(argv[i], "-partitions") == 0)
911 {
912 if (argc <= i + 1)
913 {
914 return errorArgument("Missing argument to '%s'", argv[i]);
915 }
916 i++;
917 pszPartitions = argv[i];
918 }
919 else if (strcmp(argv[i], "-register") == 0)
920 {
921 fRegister = true;
922 }
923#ifdef RT_OS_LINUX
924 else if (strcmp(argv[i], "-relative") == 0)
925 {
926 fRelative = true;
927 }
928#endif /* RT_OS_LINUX */
929 else
930 {
931 return errorSyntax(USAGE_CREATERAWVMDK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
932 }
933 }
934
935 if (filename.isEmpty())
936 return errorSyntax(USAGE_CREATERAWVMDK, "Mandatory parameter -filename missing");
937 if (rawdisk.isEmpty())
938 return errorSyntax(USAGE_CREATERAWVMDK, "Mandatory parameter -rawdisk missing");
939 if (!pszPartitions && pszMBRFilename)
940 return errorSyntax(USAGE_CREATERAWVMDK, "The parameter -mbr is only valid when the parameter -partitions is also present");
941
942#ifdef RT_OS_DARWIN
943 fRelative = true;
944#endif /* RT_OS_DARWIN */
945 RTFILE RawFile;
946 int vrc = RTFileOpen(&RawFile, rawdisk.raw(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
947 if (RT_FAILURE(vrc))
948 {
949 RTPrintf("Error opening the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
950 goto out;
951 }
952
953#ifdef RT_OS_WINDOWS
954 /* Windows NT has no IOCTL_DISK_GET_LENGTH_INFORMATION ioctl. This was
955 * added to Windows XP, so we have to use the available info from DriveGeo.
956 * Note that we cannot simply use IOCTL_DISK_GET_DRIVE_GEOMETRY as it
957 * yields a slightly different result than IOCTL_DISK_GET_LENGTH_INFO.
958 * We call IOCTL_DISK_GET_DRIVE_GEOMETRY first as we need to check the media
959 * type anyway, and if IOCTL_DISK_GET_LENGTH_INFORMATION is supported
960 * we will later override cbSize.
961 */
962 DISK_GEOMETRY DriveGeo;
963 DWORD cbDriveGeo;
964 if (DeviceIoControl((HANDLE)RawFile,
965 IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
966 &DriveGeo, sizeof(DriveGeo), &cbDriveGeo, NULL))
967 {
968 if ( DriveGeo.MediaType == FixedMedia
969 || DriveGeo.MediaType == RemovableMedia)
970 {
971 cbSize = DriveGeo.Cylinders.QuadPart
972 * DriveGeo.TracksPerCylinder
973 * DriveGeo.SectorsPerTrack
974 * DriveGeo.BytesPerSector;
975 }
976 else
977 {
978 RTPrintf("File '%s' is no fixed/removable medium device\n", rawdisk.raw());
979 vrc = VERR_INVALID_PARAMETER;
980 goto out;
981 }
982
983 GET_LENGTH_INFORMATION DiskLenInfo;
984 DWORD junk;
985 if (DeviceIoControl((HANDLE)RawFile,
986 IOCTL_DISK_GET_LENGTH_INFO, NULL, 0,
987 &DiskLenInfo, sizeof(DiskLenInfo), &junk, (LPOVERLAPPED)NULL))
988 {
989 /* IOCTL_DISK_GET_LENGTH_INFO is supported -- override cbSize. */
990 cbSize = DiskLenInfo.Length.QuadPart;
991 }
992 }
993 else
994 {
995 vrc = RTErrConvertFromWin32(GetLastError());
996 RTPrintf("Error getting the geometry of the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
997 goto out;
998 }
999#elif defined(RT_OS_LINUX)
1000 struct stat DevStat;
1001 if (!fstat(RawFile, &DevStat) && S_ISBLK(DevStat.st_mode))
1002 {
1003#ifdef BLKGETSIZE64
1004 /* BLKGETSIZE64 is broken up to 2.4.17 and in many 2.5.x. In 2.6.0
1005 * it works without problems. */
1006 struct utsname utsname;
1007 if ( uname(&utsname) == 0
1008 && ( (strncmp(utsname.release, "2.5.", 4) == 0 && atoi(&utsname.release[4]) >= 18)
1009 || (strncmp(utsname.release, "2.", 2) == 0 && atoi(&utsname.release[2]) >= 6)))
1010 {
1011 uint64_t cbBlk;
1012 if (!ioctl(RawFile, BLKGETSIZE64, &cbBlk))
1013 cbSize = cbBlk;
1014 }
1015#endif /* BLKGETSIZE64 */
1016 if (!cbSize)
1017 {
1018 long cBlocks;
1019 if (!ioctl(RawFile, BLKGETSIZE, &cBlocks))
1020 cbSize = (uint64_t)cBlocks << 9;
1021 else
1022 {
1023 vrc = RTErrConvertFromErrno(errno);
1024 RTPrintf("Error getting the size of the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
1025 goto out;
1026 }
1027 }
1028 }
1029 else
1030 {
1031 RTPrintf("File '%s' is no block device\n", rawdisk.raw());
1032 vrc = VERR_INVALID_PARAMETER;
1033 goto out;
1034 }
1035#elif defined(RT_OS_DARWIN)
1036 struct stat DevStat;
1037 if (!fstat(RawFile, &DevStat) && S_ISBLK(DevStat.st_mode))
1038 {
1039 uint64_t cBlocks;
1040 uint32_t cbBlock;
1041 if (!ioctl(RawFile, DKIOCGETBLOCKCOUNT, &cBlocks))
1042 {
1043 if (!ioctl(RawFile, DKIOCGETBLOCKSIZE, &cbBlock))
1044 cbSize = cBlocks * cbBlock;
1045 else
1046 {
1047 RTPrintf("Cannot get the block size for file '%s': %Rrc", rawdisk.raw(), vrc);
1048 vrc = RTErrConvertFromErrno(errno);
1049 goto out;
1050 }
1051 }
1052 else
1053 {
1054 vrc = RTErrConvertFromErrno(errno);
1055 RTPrintf("Cannot get the block count for file '%s': %Rrc", rawdisk.raw(), vrc);
1056 goto out;
1057 }
1058 }
1059 else
1060 {
1061 RTPrintf("File '%s' is no block device\n", rawdisk.raw());
1062 vrc = VERR_INVALID_PARAMETER;
1063 goto out;
1064 }
1065#elif defined(RT_OS_SOLARIS)
1066 struct stat DevStat;
1067 if (!fstat(RawFile, &DevStat) && ( S_ISBLK(DevStat.st_mode)
1068 || S_ISCHR(DevStat.st_mode)))
1069 {
1070 struct dk_minfo mediainfo;
1071 if (!ioctl(RawFile, DKIOCGMEDIAINFO, &mediainfo))
1072 cbSize = mediainfo.dki_capacity * mediainfo.dki_lbsize;
1073 else
1074 {
1075 vrc = RTErrConvertFromErrno(errno);
1076 RTPrintf("Error getting the size of the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
1077 goto out;
1078 }
1079 }
1080 else
1081 {
1082 RTPrintf("File '%s' is no block or char device\n", rawdisk.raw());
1083 vrc = VERR_INVALID_PARAMETER;
1084 goto out;
1085 }
1086#elif defined(RT_OS_FREEBSD)
1087 struct stat DevStat;
1088 if (!fstat(RawFile, &DevStat) && S_ISCHR(DevStat.st_mode))
1089 {
1090 off_t cbMedia = 0;
1091 if (!ioctl(RawFile, DIOCGMEDIASIZE, &cbMedia))
1092 {
1093 cbSize = cbMedia;
1094 }
1095 else
1096 {
1097 vrc = RTErrConvertFromErrno(errno);
1098 RTPrintf("Cannot get the block count for file '%s': %Rrc", rawdisk.raw(), vrc);
1099 goto out;
1100 }
1101 }
1102 else
1103 {
1104 RTPrintf("File '%s' is no character device\n", rawdisk.raw());
1105 vrc = VERR_INVALID_PARAMETER;
1106 goto out;
1107 }
1108#else /* all unrecognized OSes */
1109 /* Hopefully this works on all other hosts. If it doesn't, it'll just fail
1110 * creating the VMDK, so no real harm done. */
1111 vrc = RTFileGetSize(RawFile, &cbSize);
1112 if (RT_FAILURE(vrc))
1113 {
1114 RTPrintf("Error getting the size of the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
1115 goto out;
1116 }
1117#endif
1118
1119 /* Check whether cbSize is actually sensible. */
1120 if (!cbSize || cbSize % 512)
1121 {
1122 RTPrintf("Detected size of raw disk '%s' is %s, an invalid value\n", rawdisk.raw(), cbSize);
1123 vrc = VERR_INVALID_PARAMETER;
1124 goto out;
1125 }
1126
1127 RawDescriptor.szSignature[0] = 'R';
1128 RawDescriptor.szSignature[1] = 'A';
1129 RawDescriptor.szSignature[2] = 'W';
1130 RawDescriptor.szSignature[3] = '\0';
1131 if (!pszPartitions)
1132 {
1133 RawDescriptor.fRawDisk = true;
1134 RawDescriptor.pszRawDisk = rawdisk.raw();
1135 }
1136 else
1137 {
1138 RawDescriptor.fRawDisk = false;
1139 RawDescriptor.pszRawDisk = NULL;
1140 RawDescriptor.cPartitions = 0;
1141
1142 const char *p = pszPartitions;
1143 char *pszNext;
1144 uint32_t u32;
1145 while (*p != '\0')
1146 {
1147 vrc = RTStrToUInt32Ex(p, &pszNext, 0, &u32);
1148 if (RT_FAILURE(vrc))
1149 {
1150 RTPrintf("Incorrect value in partitions parameter\n");
1151 goto out;
1152 }
1153 uPartitions |= RT_BIT(u32);
1154 p = pszNext;
1155 if (*p == ',')
1156 p++;
1157 else if (*p != '\0')
1158 {
1159 RTPrintf("Incorrect separator in partitions parameter\n");
1160 vrc = VERR_INVALID_PARAMETER;
1161 goto out;
1162 }
1163 }
1164
1165 vrc = partRead(RawFile, &partitions);
1166 if (RT_FAILURE(vrc))
1167 {
1168 RTPrintf("Error reading the partition information from '%s'\n", rawdisk.raw());
1169 goto out;
1170 }
1171
1172 for (unsigned i = 0; i < partitions.cPartitions; i++)
1173 {
1174 if ( uPartitions & RT_BIT(partitions.aPartitions[i].uIndex)
1175 && PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
1176 {
1177 /* Some ignorant user specified an extended partition.
1178 * Bad idea, as this would trigger an overlapping
1179 * partitions error later during VMDK creation. So warn
1180 * here and ignore what the user requested. */
1181 RTPrintf("Warning: it is not possible (and necessary) to explicitly give access to the\n"
1182 " extended partition %u. If required, enable access to all logical\n"
1183 " partitions inside this extended partition.\n", partitions.aPartitions[i].uIndex);
1184 uPartitions &= ~RT_BIT(partitions.aPartitions[i].uIndex);
1185 }
1186 }
1187
1188 RawDescriptor.cPartitions = partitions.cPartitions;
1189 RawDescriptor.pPartitions = (PVBOXHDDRAWPART)RTMemAllocZ(partitions.cPartitions * sizeof(VBOXHDDRAWPART));
1190 if (!RawDescriptor.pPartitions)
1191 {
1192 RTPrintf("Out of memory allocating the partition list for '%s'\n", rawdisk.raw());
1193 vrc = VERR_NO_MEMORY;
1194 goto out;
1195 }
1196 for (unsigned i = 0; i < partitions.cPartitions; i++)
1197 {
1198 if (uPartitions & RT_BIT(partitions.aPartitions[i].uIndex))
1199 {
1200 if (fRelative)
1201 {
1202#ifdef RT_OS_LINUX
1203 /* Refer to the correct partition and use offset 0. */
1204 char *pszRawName;
1205 vrc = RTStrAPrintf(&pszRawName, "%s%u", rawdisk.raw(),
1206 partitions.aPartitions[i].uIndex);
1207 if (RT_FAILURE(vrc))
1208 {
1209 RTPrintf("Error creating reference to individual partition %u, rc=%Rrc\n",
1210 partitions.aPartitions[i].uIndex, vrc);
1211 goto out;
1212 }
1213 RawDescriptor.pPartitions[i].pszRawDevice = pszRawName;
1214 RawDescriptor.pPartitions[i].uPartitionStartOffset = 0;
1215 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1216#elif defined(RT_OS_DARWIN)
1217 /* Refer to the correct partition and use offset 0. */
1218 char *pszRawName;
1219 vrc = RTStrAPrintf(&pszRawName, "%ss%u", rawdisk.raw(),
1220 partitions.aPartitions[i].uIndex);
1221 if (RT_FAILURE(vrc))
1222 {
1223 RTPrintf("Error creating reference to individual partition %u, rc=%Rrc\n",
1224 partitions.aPartitions[i].uIndex, vrc);
1225 goto out;
1226 }
1227 RawDescriptor.pPartitions[i].pszRawDevice = pszRawName;
1228 RawDescriptor.pPartitions[i].uPartitionStartOffset = 0;
1229 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1230#else
1231 /** @todo not implemented yet for Windows host. Treat just
1232 * like not specified (this code is actually never reached). */
1233 RawDescriptor.pPartitions[i].pszRawDevice = rawdisk.raw();
1234 RawDescriptor.pPartitions[i].uPartitionStartOffset = partitions.aPartitions[i].uStart * 512;
1235 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1236#endif
1237 }
1238 else
1239 {
1240 /* This is the "everything refers to the base raw device"
1241 * variant. This requires opening the base device in RW
1242 * mode even for creation. */
1243 RawDescriptor.pPartitions[i].pszRawDevice = rawdisk.raw();
1244 RawDescriptor.pPartitions[i].uPartitionStartOffset = partitions.aPartitions[i].uStart * 512;
1245 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1246 }
1247 }
1248 else
1249 {
1250 /* Suppress access to this partition. */
1251 RawDescriptor.pPartitions[i].pszRawDevice = NULL;
1252 RawDescriptor.pPartitions[i].uPartitionStartOffset = 0;
1253 /* This is used in the plausibility check in the creation
1254 * code. In theory it's a dummy, but I don't want to make
1255 * the VMDK creatiion any more complicated than what it needs
1256 * to be. */
1257 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1258 }
1259 if (PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
1260 {
1261 /* Suppress exporting the actual extended partition. Only
1262 * logical partitions should be processed. However completely
1263 * ignoring it leads to leaving out the MBR data. */
1264 RawDescriptor.pPartitions[i].cbPartition = 0;
1265 }
1266 else
1267 RawDescriptor.pPartitions[i].cbPartition = partitions.aPartitions[i].uSize * 512;
1268 RawDescriptor.pPartitions[i].uPartitionDataStart = partitions.aPartitions[i].uPartDataStart * 512;
1269 /** @todo the clipping below isn't 100% accurate, as it should
1270 * actually clip to the track size. However that's easier said
1271 * than done as figuring out the track size is heuristics. */
1272 RawDescriptor.pPartitions[i].cbPartitionData = RT_MIN(partitions.aPartitions[i].cPartDataSectors, 63) * 512;
1273 if (RawDescriptor.pPartitions[i].cbPartitionData)
1274 {
1275 Assert (RawDescriptor.pPartitions[i].cbPartitionData -
1276 (size_t)RawDescriptor.pPartitions[i].cbPartitionData == 0);
1277 void *pPartData = RTMemAlloc((size_t)RawDescriptor.pPartitions[i].cbPartitionData);
1278 if (!pPartData)
1279 {
1280 RTPrintf("Out of memory allocating the partition descriptor for '%s'\n", rawdisk.raw());
1281 vrc = VERR_NO_MEMORY;
1282 goto out;
1283 }
1284 vrc = RTFileReadAt(RawFile, partitions.aPartitions[i].uPartDataStart * 512, pPartData, (size_t)RawDescriptor.pPartitions[i].cbPartitionData, NULL);
1285 if (RT_FAILURE(vrc))
1286 {
1287 RTPrintf("Cannot read partition data from raw device '%s': %Rrc\n", rawdisk.raw(), vrc);
1288 goto out;
1289 }
1290 /* Splice in the replacement MBR code if specified. */
1291 if ( partitions.aPartitions[i].uPartDataStart == 0
1292 && pszMBRFilename)
1293 {
1294 RTFILE MBRFile;
1295 vrc = RTFileOpen(&MBRFile, pszMBRFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
1296 if (RT_FAILURE(vrc))
1297 {
1298 RTPrintf("Cannot open replacement MBR file '%s' specified with -mbr: %Rrc\n", pszMBRFilename, vrc);
1299 goto out;
1300 }
1301 vrc = RTFileReadAt(MBRFile, 0, pPartData, 0x1be, NULL);
1302 RTFileClose(MBRFile);
1303 if (RT_FAILURE(vrc))
1304 {
1305 RTPrintf("Cannot read replacement MBR file '%s': %Rrc\n", pszMBRFilename, vrc);
1306 goto out;
1307 }
1308 }
1309 RawDescriptor.pPartitions[i].pvPartitionData = pPartData;
1310 }
1311 }
1312 }
1313
1314 RTFileClose(RawFile);
1315
1316 VDINTERFACE vdInterfaceError;
1317 VDINTERFACEERROR vdInterfaceErrorCallbacks;
1318 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1319 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1320 vdInterfaceErrorCallbacks.pfnError = handleVDError;
1321 vdInterfaceErrorCallbacks.pfnMessage = NULL;
1322
1323 vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1324 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1325 AssertRC(vrc);
1326
1327 vrc = VDCreate(pVDIfs, &pDisk);
1328 if (RT_FAILURE(vrc))
1329 {
1330 RTPrintf("Error while creating the virtual disk container: %Rrc\n", vrc);
1331 goto out;
1332 }
1333
1334 Assert(RT_MIN(cbSize / 512 / 16 / 63, 16383) -
1335 (unsigned int)RT_MIN(cbSize / 512 / 16 / 63, 16383) == 0);
1336 PDMMEDIAGEOMETRY PCHS, LCHS;
1337 PCHS.cCylinders = (unsigned int)RT_MIN(cbSize / 512 / 16 / 63, 16383);
1338 PCHS.cHeads = 16;
1339 PCHS.cSectors = 63;
1340 LCHS.cCylinders = 0;
1341 LCHS.cHeads = 0;
1342 LCHS.cSectors = 0;
1343 vrc = VDCreateBase(pDisk, "VMDK", Utf8Str(filename).raw(), cbSize,
1344 VD_IMAGE_FLAGS_FIXED | VD_VMDK_IMAGE_FLAGS_RAWDISK,
1345 (char *)&RawDescriptor, &PCHS, &LCHS, NULL,
1346 VD_OPEN_FLAGS_NORMAL, NULL, NULL);
1347 if (RT_FAILURE(vrc))
1348 {
1349 RTPrintf("Error while creating the raw disk VMDK: %Rrc\n", vrc);
1350 goto out;
1351 }
1352 RTPrintf("RAW host disk access VMDK file %s created successfully.\n", Utf8Str(filename).raw());
1353
1354 VDCloseAll(pDisk);
1355
1356 /* Clean up allocated memory etc. */
1357 if (pszPartitions)
1358 {
1359 for (unsigned i = 0; i < partitions.cPartitions; i++)
1360 {
1361 if (uPartitions & RT_BIT(partitions.aPartitions[i].uIndex))
1362 {
1363 if (fRelative)
1364 {
1365#ifdef RT_OS_LINUX
1366 /* Free memory allocated above. */
1367 RTStrFree((char *)(void *)RawDescriptor.pPartitions[i].pszRawDevice);
1368#endif /* RT_OS_LINUX */
1369 }
1370 }
1371 }
1372 }
1373
1374 if (fRegister)
1375 {
1376 ComPtr<IMedium> hardDisk;
1377 CHECK_ERROR(aVirtualBox, OpenHardDisk(filename, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
1378 }
1379
1380 return SUCCEEDED(rc) ? 0 : 1;
1381
1382out:
1383 RTPrintf("The raw disk vmdk file was not created\n");
1384 return RT_SUCCESS(vrc) ? 0 : 1;
1385}
1386
1387static int CmdRenameVMDK(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
1388{
1389 Bstr src;
1390 Bstr dst;
1391 /* Parse the arguments. */
1392 for (int i = 0; i < argc; i++)
1393 {
1394 if (strcmp(argv[i], "-from") == 0)
1395 {
1396 if (argc <= i + 1)
1397 {
1398 return errorArgument("Missing argument to '%s'", argv[i]);
1399 }
1400 i++;
1401 src = argv[i];
1402 }
1403 else if (strcmp(argv[i], "-to") == 0)
1404 {
1405 if (argc <= i + 1)
1406 {
1407 return errorArgument("Missing argument to '%s'", argv[i]);
1408 }
1409 i++;
1410 dst = argv[i];
1411 }
1412 else
1413 {
1414 return errorSyntax(USAGE_RENAMEVMDK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
1415 }
1416 }
1417
1418 if (src.isEmpty())
1419 return errorSyntax(USAGE_RENAMEVMDK, "Mandatory parameter -from missing");
1420 if (dst.isEmpty())
1421 return errorSyntax(USAGE_RENAMEVMDK, "Mandatory parameter -to missing");
1422
1423 PVBOXHDD pDisk = NULL;
1424
1425 PVDINTERFACE pVDIfs = NULL;
1426 VDINTERFACE vdInterfaceError;
1427 VDINTERFACEERROR vdInterfaceErrorCallbacks;
1428 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1429 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1430 vdInterfaceErrorCallbacks.pfnError = handleVDError;
1431 vdInterfaceErrorCallbacks.pfnMessage = NULL;
1432
1433 int vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1434 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1435 AssertRC(vrc);
1436
1437 vrc = VDCreate(pVDIfs, &pDisk);
1438 if (RT_FAILURE(vrc))
1439 {
1440 RTPrintf("Error while creating the virtual disk container: %Rrc\n", vrc);
1441 return vrc;
1442 }
1443 else
1444 {
1445 vrc = VDOpen(pDisk, "VMDK", Utf8Str(src).raw(), VD_OPEN_FLAGS_NORMAL, NULL);
1446 if (RT_FAILURE(vrc))
1447 {
1448 RTPrintf("Error while opening the source image: %Rrc\n", vrc);
1449 }
1450 else
1451 {
1452 vrc = VDCopy(pDisk, 0, pDisk, "VMDK", Utf8Str(dst).raw(), true, 0, VD_IMAGE_FLAGS_NONE, NULL, NULL, NULL, NULL);
1453 if (RT_FAILURE(vrc))
1454 {
1455 RTPrintf("Error while renaming the image: %Rrc\n", vrc);
1456 }
1457 }
1458 }
1459 VDCloseAll(pDisk);
1460 return vrc;
1461}
1462
1463static int CmdConvertToRaw(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
1464{
1465 Bstr srcformat;
1466 Bstr src;
1467 Bstr dst;
1468 bool fWriteToStdOut = false;
1469
1470 /* Parse the arguments. */
1471 for (int i = 0; i < argc; i++)
1472 {
1473 if (strcmp(argv[i], "-format") == 0)
1474 {
1475 if (argc <= i + 1)
1476 {
1477 return errorArgument("Missing argument to '%s'", argv[i]);
1478 }
1479 i++;
1480 srcformat = argv[i];
1481 }
1482 else if (src.isEmpty())
1483 {
1484 src = argv[i];
1485 }
1486 else if (dst.isEmpty())
1487 {
1488 dst = argv[i];
1489#ifdef ENABLE_CONVERT_RAW_TO_STDOUT
1490 if (!strcmp(argv[i], "stdout"))
1491 fWriteToStdOut = true;
1492#endif /* ENABLE_CONVERT_RAW_TO_STDOUT */
1493 }
1494 else
1495 {
1496 return errorSyntax(USAGE_CONVERTTORAW, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
1497 }
1498 }
1499
1500 if (src.isEmpty())
1501 return errorSyntax(USAGE_CONVERTTORAW, "Mandatory filename parameter missing");
1502 if (dst.isEmpty())
1503 return errorSyntax(USAGE_CONVERTTORAW, "Mandatory outputfile parameter missing");
1504
1505 PVBOXHDD pDisk = NULL;
1506
1507 PVDINTERFACE pVDIfs = NULL;
1508 VDINTERFACE vdInterfaceError;
1509 VDINTERFACEERROR vdInterfaceErrorCallbacks;
1510 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1511 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1512 vdInterfaceErrorCallbacks.pfnError = handleVDError;
1513 vdInterfaceErrorCallbacks.pfnMessage = NULL;
1514
1515 int vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1516 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1517 AssertRC(vrc);
1518
1519 vrc = VDCreate(pVDIfs, &pDisk);
1520 if (RT_FAILURE(vrc))
1521 {
1522 RTPrintf("Error while creating the virtual disk container: %Rrc\n", vrc);
1523 return 1;
1524 }
1525
1526 /* Open raw output file. */
1527 RTFILE outFile;
1528 vrc = VINF_SUCCESS;
1529 if (fWriteToStdOut)
1530 outFile = 1;
1531 else
1532 vrc = RTFileOpen(&outFile, Utf8Str(dst).raw(), RTFILE_O_WRITE | RTFILE_O_CREATE | RTFILE_O_DENY_ALL);
1533 if (RT_FAILURE(vrc))
1534 {
1535 VDCloseAll(pDisk);
1536 RTPrintf("Error while creating destination file \"%s\": %Rrc\n", Utf8Str(dst).raw(), vrc);
1537 return 1;
1538 }
1539
1540 if (srcformat.isEmpty())
1541 {
1542 char *pszFormat = NULL;
1543 vrc = VDGetFormat(NULL, Utf8Str(src).raw(), &pszFormat);
1544 if (RT_FAILURE(vrc))
1545 {
1546 VDCloseAll(pDisk);
1547 if (!fWriteToStdOut)
1548 {
1549 RTFileClose(outFile);
1550 RTFileDelete(Utf8Str(dst).raw());
1551 }
1552 RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc);
1553 return 1;
1554 }
1555 srcformat = pszFormat;
1556 RTStrFree(pszFormat);
1557 }
1558 vrc = VDOpen(pDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL);
1559 if (RT_FAILURE(vrc))
1560 {
1561 VDCloseAll(pDisk);
1562 if (!fWriteToStdOut)
1563 {
1564 RTFileClose(outFile);
1565 RTFileDelete(Utf8Str(dst).raw());
1566 }
1567 RTPrintf("Error while opening the source image: %Rrc\n", vrc);
1568 return 1;
1569 }
1570
1571 uint64_t cbSize = VDGetSize(pDisk, VD_LAST_IMAGE);
1572 uint64_t offFile = 0;
1573#define RAW_BUFFER_SIZE _128K
1574 size_t cbBuf = RAW_BUFFER_SIZE;
1575 void *pvBuf = RTMemAlloc(cbBuf);
1576 if (pvBuf)
1577 {
1578 RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB) to raw...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M);
1579 while (offFile < cbSize)
1580 {
1581 size_t cb = (size_t)RT_MIN(cbSize - offFile, cbBuf);
1582 vrc = VDRead(pDisk, offFile, pvBuf, cb);
1583 if (RT_FAILURE(vrc))
1584 break;
1585 vrc = RTFileWrite(outFile, pvBuf, cb, NULL);
1586 if (RT_FAILURE(vrc))
1587 break;
1588 offFile += cb;
1589 }
1590 if (RT_FAILURE(vrc))
1591 {
1592 VDCloseAll(pDisk);
1593 if (!fWriteToStdOut)
1594 {
1595 RTFileClose(outFile);
1596 RTFileDelete(Utf8Str(dst).raw());
1597 }
1598 RTPrintf("Error copying image data: %Rrc\n", vrc);
1599 return 1;
1600 }
1601 }
1602 else
1603 {
1604 vrc = VERR_NO_MEMORY;
1605 VDCloseAll(pDisk);
1606 if (!fWriteToStdOut)
1607 {
1608 RTFileClose(outFile);
1609 RTFileDelete(Utf8Str(dst).raw());
1610 }
1611 RTPrintf("Error allocating read buffer: %Rrc\n", vrc);
1612 return 1;
1613 }
1614
1615 if (!fWriteToStdOut)
1616 RTFileClose(outFile);
1617 VDCloseAll(pDisk);
1618 return 0;
1619}
1620
1621static int CmdConvertHardDisk(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
1622{
1623 Bstr srcformat;
1624 Bstr dstformat;
1625 Bstr src;
1626 Bstr dst;
1627 int vrc;
1628 PVBOXHDD pSrcDisk = NULL;
1629 PVBOXHDD pDstDisk = NULL;
1630
1631 /* Parse the arguments. */
1632 for (int i = 0; i < argc; i++)
1633 {
1634 if (strcmp(argv[i], "-srcformat") == 0)
1635 {
1636 if (argc <= i + 1)
1637 {
1638 return errorArgument("Missing argument to '%s'", argv[i]);
1639 }
1640 i++;
1641 srcformat = argv[i];
1642 }
1643 else if (strcmp(argv[i], "-dstformat") == 0)
1644 {
1645 if (argc <= i + 1)
1646 {
1647 return errorArgument("Missing argument to '%s'", argv[i]);
1648 }
1649 i++;
1650 dstformat = argv[i];
1651 }
1652 else if (src.isEmpty())
1653 {
1654 src = argv[i];
1655 }
1656 else if (dst.isEmpty())
1657 {
1658 dst = argv[i];
1659 }
1660 else
1661 {
1662 return errorSyntax(USAGE_CONVERTHD, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
1663 }
1664 }
1665
1666 if (src.isEmpty())
1667 return errorSyntax(USAGE_CONVERTHD, "Mandatory input image parameter missing");
1668 if (dst.isEmpty())
1669 return errorSyntax(USAGE_CONVERTHD, "Mandatory output image parameter missing");
1670
1671
1672 PVDINTERFACE pVDIfs = NULL;
1673 VDINTERFACE vdInterfaceError;
1674 VDINTERFACEERROR vdInterfaceErrorCallbacks;
1675 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1676 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1677 vdInterfaceErrorCallbacks.pfnError = handleVDError;
1678 vdInterfaceErrorCallbacks.pfnMessage = NULL;
1679
1680 vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1681 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1682 AssertRC(vrc);
1683
1684 do
1685 {
1686 /* Try to determine input image format */
1687 if (srcformat.isEmpty())
1688 {
1689 char *pszFormat = NULL;
1690 vrc = VDGetFormat(NULL, Utf8Str(src).raw(), &pszFormat);
1691 if (RT_FAILURE(vrc))
1692 {
1693 RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc);
1694 break;
1695 }
1696 srcformat = pszFormat;
1697 RTStrFree(pszFormat);
1698 }
1699
1700 vrc = VDCreate(pVDIfs, &pSrcDisk);
1701 if (RT_FAILURE(vrc))
1702 {
1703 RTPrintf("Error while creating the source virtual disk container: %Rrc\n", vrc);
1704 break;
1705 }
1706
1707 /* Open the input image */
1708 vrc = VDOpen(pSrcDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL);
1709 if (RT_FAILURE(vrc))
1710 {
1711 RTPrintf("Error while opening the source image: %Rrc\n", vrc);
1712 break;
1713 }
1714
1715 /* Output format defaults to VDI */
1716 if (dstformat.isEmpty())
1717 dstformat = "VDI";
1718
1719 vrc = VDCreate(pVDIfs, &pDstDisk);
1720 if (RT_FAILURE(vrc))
1721 {
1722 RTPrintf("Error while creating the destination virtual disk container: %Rrc\n", vrc);
1723 break;
1724 }
1725
1726 uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE);
1727 RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M);
1728
1729 /* Create the output image */
1730 vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, Utf8Str(dstformat).raw(),
1731 Utf8Str(dst).raw(), false, 0, VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED, NULL, NULL, NULL, NULL);
1732 if (RT_FAILURE(vrc))
1733 {
1734 RTPrintf("Error while copying the image: %Rrc\n", vrc);
1735 break;
1736 }
1737 }
1738 while (0);
1739 if (pDstDisk)
1740 VDCloseAll(pDstDisk);
1741 if (pSrcDisk)
1742 VDCloseAll(pSrcDisk);
1743
1744 return RT_SUCCESS(vrc) ? 0 : 1;
1745}
1746
1747/**
1748 * Unloads the neccessary driver.
1749 *
1750 * @returns VBox status code
1751 */
1752int CmdModUninstall(void)
1753{
1754 int rc;
1755
1756 rc = SUPR3Uninstall();
1757 if (RT_SUCCESS(rc))
1758 return 0;
1759 if (rc == VERR_NOT_IMPLEMENTED)
1760 return 0;
1761 return E_FAIL;
1762}
1763
1764/**
1765 * Loads the neccessary driver.
1766 *
1767 * @returns VBox status code
1768 */
1769int CmdModInstall(void)
1770{
1771 int rc;
1772
1773 rc = SUPR3Install();
1774 if (RT_SUCCESS(rc))
1775 return 0;
1776 if (rc == VERR_NOT_IMPLEMENTED)
1777 return 0;
1778 return E_FAIL;
1779}
1780
1781/**
1782 * Wrapper for handling internal commands
1783 */
1784int handleInternalCommands(HandlerArg *a)
1785{
1786 g_fInternalMode = true;
1787
1788 /* at least a command is required */
1789 if (a->argc < 1)
1790 return errorSyntax(USAGE_ALL, "Command missing");
1791
1792 /*
1793 * The 'string switch' on command name.
1794 */
1795 const char *pszCmd = a->argv[0];
1796 if (!strcmp(pszCmd, "loadsyms"))
1797 return CmdLoadSyms(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1798 //if (!strcmp(pszCmd, "unloadsyms"))
1799 // return CmdUnloadSyms(argc - 1 , &a->argv[1]);
1800 if (!strcmp(pszCmd, "sethduuid") || !strcmp(pszCmd, "setvdiuuid"))
1801 return CmdSetHDUUID(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1802 if (!strcmp(pszCmd, "dumphdinfo"))
1803 return CmdDumpHDInfo(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1804 if (!strcmp(pszCmd, "listpartitions"))
1805 return CmdListPartitions(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1806 if (!strcmp(pszCmd, "createrawvmdk"))
1807 return CmdCreateRawVMDK(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1808 if (!strcmp(pszCmd, "renamevmdk"))
1809 return CmdRenameVMDK(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1810 if (!strcmp(pszCmd, "converttoraw"))
1811 return CmdConvertToRaw(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1812 if (!strcmp(pszCmd, "converthd"))
1813 return CmdConvertHardDisk(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1814
1815 if (!strcmp(pszCmd, "modinstall"))
1816 return CmdModInstall();
1817 if (!strcmp(pszCmd, "moduninstall"))
1818 return CmdModUninstall();
1819
1820 /* default: */
1821 return errorSyntax(USAGE_ALL, "Invalid command '%s'", Utf8Str(a->argv[0]).raw());
1822}
1823
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