VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp@ 40956

Last change on this file since 40956 was 40905, checked in by vboxsync, 13 years ago

VBoxManage: correct usage message for modifyhd.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.0 KB
Line 
1/* $Id: VBoxManageDisk.cpp 40905 2012-04-13 16:06:50Z vboxsync $ */
2/** @file
3 * VBoxManage - The disk related commands.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
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
18#ifndef VBOX_ONLY_DOCS
19
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <VBox/com/com.h>
24#include <VBox/com/array.h>
25#include <VBox/com/ErrorInfo.h>
26#include <VBox/com/errorprint.h>
27#include <VBox/com/VirtualBox.h>
28
29#include <iprt/asm.h>
30#include <iprt/file.h>
31#include <iprt/path.h>
32#include <iprt/param.h>
33#include <iprt/stream.h>
34#include <iprt/string.h>
35#include <iprt/ctype.h>
36#include <iprt/getopt.h>
37#include <VBox/log.h>
38#include <VBox/vd.h>
39
40#include "VBoxManage.h"
41using namespace com;
42
43
44// funcs
45///////////////////////////////////////////////////////////////////////////////
46
47
48static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
49{
50 RTMsgError(pszFormat, va);
51 RTMsgError("Error code %Rrc at %s(%u) in function %s", rc, RT_SRC_POS_ARGS);
52}
53
54
55static int parseDiskVariant(const char *psz, MediumVariant_T *pDiskVariant)
56{
57 int rc = VINF_SUCCESS;
58 unsigned DiskVariant = (unsigned)(*pDiskVariant);
59 while (psz && *psz && RT_SUCCESS(rc))
60 {
61 size_t len;
62 const char *pszComma = strchr(psz, ',');
63 if (pszComma)
64 len = pszComma - psz;
65 else
66 len = strlen(psz);
67 if (len > 0)
68 {
69 // Parsing is intentionally inconsistent: "standard" resets the
70 // variant, whereas the other flags are cumulative.
71 if (!RTStrNICmp(psz, "standard", len))
72 DiskVariant = MediumVariant_Standard;
73 else if ( !RTStrNICmp(psz, "fixed", len)
74 || !RTStrNICmp(psz, "static", len))
75 DiskVariant |= MediumVariant_Fixed;
76 else if (!RTStrNICmp(psz, "Diff", len))
77 DiskVariant |= MediumVariant_Diff;
78 else if (!RTStrNICmp(psz, "split2g", len))
79 DiskVariant |= MediumVariant_VmdkSplit2G;
80 else if ( !RTStrNICmp(psz, "stream", len)
81 || !RTStrNICmp(psz, "streamoptimized", len))
82 DiskVariant |= MediumVariant_VmdkStreamOptimized;
83 else if (!RTStrNICmp(psz, "esx", len))
84 DiskVariant |= MediumVariant_VmdkESX;
85 else
86 rc = VERR_PARSE_ERROR;
87 }
88 if (pszComma)
89 psz += len + 1;
90 else
91 psz += len;
92 }
93
94 if (RT_SUCCESS(rc))
95 *pDiskVariant = (MediumVariant_T)DiskVariant;
96 return rc;
97}
98
99int parseDiskType(const char *psz, MediumType_T *pDiskType)
100{
101 int rc = VINF_SUCCESS;
102 MediumType_T DiskType = MediumType_Normal;
103 if (!RTStrICmp(psz, "normal"))
104 DiskType = MediumType_Normal;
105 else if (!RTStrICmp(psz, "immutable"))
106 DiskType = MediumType_Immutable;
107 else if (!RTStrICmp(psz, "writethrough"))
108 DiskType = MediumType_Writethrough;
109 else if (!RTStrICmp(psz, "shareable"))
110 DiskType = MediumType_Shareable;
111 else if (!RTStrICmp(psz, "readonly"))
112 DiskType = MediumType_Readonly;
113 else if (!RTStrICmp(psz, "multiattach"))
114 DiskType = MediumType_MultiAttach;
115 else
116 rc = VERR_PARSE_ERROR;
117
118 if (RT_SUCCESS(rc))
119 *pDiskType = DiskType;
120 return rc;
121}
122
123/** @todo move this into getopt, as getting bool values is generic */
124static int parseBool(const char *psz, bool *pb)
125{
126 int rc = VINF_SUCCESS;
127 if ( !RTStrICmp(psz, "on")
128 || !RTStrICmp(psz, "yes")
129 || !RTStrICmp(psz, "true")
130 || !RTStrICmp(psz, "1")
131 || !RTStrICmp(psz, "enable")
132 || !RTStrICmp(psz, "enabled"))
133 {
134 *pb = true;
135 }
136 else if ( !RTStrICmp(psz, "off")
137 || !RTStrICmp(psz, "no")
138 || !RTStrICmp(psz, "false")
139 || !RTStrICmp(psz, "0")
140 || !RTStrICmp(psz, "disable")
141 || !RTStrICmp(psz, "disabled"))
142 {
143 *pb = false;
144 }
145 else
146 rc = VERR_PARSE_ERROR;
147
148 return rc;
149}
150
151HRESULT findMedium(HandlerArg *a, const char *pszFilenameOrUuid,
152 DeviceType_T enmDevType, bool fSilent,
153 ComPtr<IMedium> &pMedium)
154{
155 HRESULT rc;
156 Guid id(pszFilenameOrUuid);
157 char szFilenameAbs[RTPATH_MAX] = "";
158
159 /* If it is no UUID, convert the filename to an absolute one. */
160 if (id.isEmpty())
161 {
162 int irc = RTPathAbs(pszFilenameOrUuid, szFilenameAbs, sizeof(szFilenameAbs));
163 if (RT_FAILURE(irc))
164 {
165 if (!fSilent)
166 RTMsgError("Cannot convert filename \"%s\" to absolute path", pszFilenameOrUuid);
167 return E_FAIL;
168 }
169 pszFilenameOrUuid = szFilenameAbs;
170 }
171
172 if (!fSilent)
173 CHECK_ERROR(a->virtualBox, FindMedium(Bstr(pszFilenameOrUuid).raw(),
174 enmDevType, pMedium.asOutParam()));
175 else
176 rc = a->virtualBox->FindMedium(Bstr(pszFilenameOrUuid).raw(),
177 enmDevType, pMedium.asOutParam());
178 return rc;
179}
180
181HRESULT findOrOpenMedium(HandlerArg *a, const char *pszFilenameOrUuid,
182 DeviceType_T enmDevType, ComPtr<IMedium> &pMedium,
183 bool fForceNewUuidOnOpen, bool *pfWasUnknown)
184{
185 HRESULT rc;
186 bool fWasUnknown = false;
187 Guid id(pszFilenameOrUuid);
188 char szFilenameAbs[RTPATH_MAX] = "";
189
190 /* If it is no UUID, convert the filename to an absolute one. */
191 if (id.isEmpty())
192 {
193 int irc = RTPathAbs(pszFilenameOrUuid, szFilenameAbs, sizeof(szFilenameAbs));
194 if (RT_FAILURE(irc))
195 {
196 RTMsgError("Cannot convert filename \"%s\" to absolute path", pszFilenameOrUuid);
197 return E_FAIL;
198 }
199 pszFilenameOrUuid = szFilenameAbs;
200 }
201
202 rc = a->virtualBox->FindMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType,
203 pMedium.asOutParam());
204 /* If the medium is unknown try to open it. */
205 if (!pMedium)
206 {
207 CHECK_ERROR(a->virtualBox, OpenMedium(Bstr(pszFilenameOrUuid).raw(),
208 enmDevType, AccessMode_ReadWrite,
209 fForceNewUuidOnOpen,
210 pMedium.asOutParam()));
211 if (SUCCEEDED(rc))
212 fWasUnknown = true;
213 }
214 if (RT_VALID_PTR(pfWasUnknown))
215 *pfWasUnknown = fWasUnknown;
216 return rc;
217}
218
219static HRESULT createHardDisk(HandlerArg *a, const char *pszFormat,
220 const char *pszFilename, ComPtr<IMedium> &pMedium)
221{
222 HRESULT rc;
223 char szFilenameAbs[RTPATH_MAX] = "";
224
225 /** @todo laziness shortcut. should really check the MediumFormatCapabilities */
226 if (RTStrICmp(pszFormat, "iSCSI"))
227 {
228 int irc = RTPathAbs(pszFilename, szFilenameAbs, sizeof(szFilenameAbs));
229 if (RT_FAILURE(irc))
230 {
231 RTMsgError("Cannot convert filename \"%s\" to absolute path", pszFilename);
232 return E_FAIL;
233 }
234 pszFilename = szFilenameAbs;
235 }
236
237 CHECK_ERROR(a->virtualBox, CreateHardDisk(Bstr(pszFormat).raw(),
238 Bstr(pszFilename).raw(),
239 pMedium.asOutParam()));
240 return rc;
241}
242
243static const RTGETOPTDEF g_aCreateHardDiskOptions[] =
244{
245 { "--filename", 'f', RTGETOPT_REQ_STRING },
246 { "-filename", 'f', RTGETOPT_REQ_STRING }, // deprecated
247 { "--diffparent", 'd', RTGETOPT_REQ_STRING },
248 { "--size", 's', RTGETOPT_REQ_UINT64 },
249 { "-size", 's', RTGETOPT_REQ_UINT64 }, // deprecated
250 { "--sizebyte", 'S', RTGETOPT_REQ_UINT64 },
251 { "--format", 'o', RTGETOPT_REQ_STRING },
252 { "-format", 'o', RTGETOPT_REQ_STRING }, // deprecated
253 { "--static", 'F', RTGETOPT_REQ_NOTHING },
254 { "-static", 'F', RTGETOPT_REQ_NOTHING }, // deprecated
255 { "--variant", 'm', RTGETOPT_REQ_STRING },
256 { "-variant", 'm', RTGETOPT_REQ_STRING }, // deprecated
257};
258
259int handleCreateHardDisk(HandlerArg *a)
260{
261 HRESULT rc;
262 int vrc;
263 const char *filename = NULL;
264 const char *diffparent = NULL;
265 uint64_t size = 0;
266 const char *format = NULL;
267 bool fBase = true;
268 MediumVariant_T DiskVariant = MediumVariant_Standard;
269
270 int c;
271 RTGETOPTUNION ValueUnion;
272 RTGETOPTSTATE GetState;
273 // start at 0 because main() has hacked both the argc and argv given to us
274 RTGetOptInit(&GetState, a->argc, a->argv, g_aCreateHardDiskOptions, RT_ELEMENTS(g_aCreateHardDiskOptions),
275 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
276 while ((c = RTGetOpt(&GetState, &ValueUnion)))
277 {
278 switch (c)
279 {
280 case 'f': // --filename
281 filename = ValueUnion.psz;
282 break;
283
284 case 'd': // --diffparent
285 diffparent = ValueUnion.psz;
286 fBase = false;
287 break;
288
289 case 's': // --size
290 size = ValueUnion.u64 * _1M;
291 break;
292
293 case 'S': // --sizebyte
294 size = ValueUnion.u64;
295 break;
296
297 case 'o': // --format
298 format = ValueUnion.psz;
299 break;
300
301 case 'F': // --static ("fixed"/"flat")
302 {
303 unsigned uDiskVariant = (unsigned)DiskVariant;
304 uDiskVariant |= MediumVariant_Fixed;
305 DiskVariant = (MediumVariant_T)uDiskVariant;
306 break;
307 }
308
309 case 'm': // --variant
310 vrc = parseDiskVariant(ValueUnion.psz, &DiskVariant);
311 if (RT_FAILURE(vrc))
312 return errorArgument("Invalid hard disk variant '%s'", ValueUnion.psz);
313 break;
314
315 case VINF_GETOPT_NOT_OPTION:
316 return errorSyntax(USAGE_CREATEHD, "Invalid parameter '%s'", ValueUnion.psz);
317
318 default:
319 if (c > 0)
320 {
321 if (RT_C_IS_PRINT(c))
322 return errorSyntax(USAGE_CREATEHD, "Invalid option -%c", c);
323 else
324 return errorSyntax(USAGE_CREATEHD, "Invalid option case %i", c);
325 }
326 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
327 return errorSyntax(USAGE_CREATEHD, "unknown option: %s\n", ValueUnion.psz);
328 else if (ValueUnion.pDef)
329 return errorSyntax(USAGE_CREATEHD, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
330 else
331 return errorSyntax(USAGE_CREATEHD, "error: %Rrs", c);
332 }
333 }
334
335 /* check the outcome */
336 bool fUnknownParent = false;
337 ComPtr<IMedium> parentHardDisk;
338 if (fBase)
339 {
340 if ( !filename
341 || !*filename
342 || size == 0)
343 return errorSyntax(USAGE_CREATEHD, "Parameters --filename and --size are required");
344 if (!format || !*format)
345 format = "VDI";
346 }
347 else
348 {
349 if ( !filename
350 || !*filename)
351 return errorSyntax(USAGE_CREATEHD, "Parameters --filename is required");
352 size = 0;
353 DiskVariant = MediumVariant_Diff;
354 if (!format || !*format)
355 {
356 const char *pszExt = RTPathExt(filename);
357 /* Skip over . if there is an extension. */
358 if (pszExt)
359 pszExt++;
360 if (!pszExt || !*pszExt)
361 format = "VDI";
362 else
363 format = pszExt;
364 }
365 rc = findOrOpenMedium(a, diffparent, DeviceType_HardDisk,
366 parentHardDisk, false /* fForceNewUuidOnOpen */,
367 &fUnknownParent);
368 if (FAILED(rc))
369 return 1;
370 if (parentHardDisk.isNull())
371 {
372 RTMsgError("Invalid parent hard disk reference, avoiding crash");
373 return 1;
374 }
375 MediumState_T state;
376 CHECK_ERROR(parentHardDisk, COMGETTER(State)(&state));
377 if (FAILED(rc))
378 return 1;
379 if (state == MediumState_Inaccessible)
380 {
381 CHECK_ERROR(parentHardDisk, RefreshState(&state));
382 if (FAILED(rc))
383 return 1;
384 }
385 }
386 /* check for filename extension */
387 /** @todo use IMediumFormat to cover all extensions generically */
388 Utf8Str strName(filename);
389 if (!RTPathHaveExt(strName.c_str()))
390 {
391 Utf8Str strFormat(format);
392 if (strFormat.compare("vmdk", RTCString::CaseInsensitive) == 0)
393 strName.append(".vmdk");
394 else if (strFormat.compare("vhd", RTCString::CaseInsensitive) == 0)
395 strName.append(".vhd");
396 else
397 strName.append(".vdi");
398 filename = strName.c_str();
399 }
400
401 ComPtr<IMedium> hardDisk;
402 rc = createHardDisk(a, format, filename, hardDisk);
403 if (SUCCEEDED(rc) && hardDisk)
404 {
405 ComPtr<IProgress> progress;
406 if (fBase)
407 CHECK_ERROR(hardDisk, CreateBaseStorage(size, DiskVariant, progress.asOutParam()));
408 else
409 CHECK_ERROR(parentHardDisk, CreateDiffStorage(hardDisk, DiskVariant, progress.asOutParam()));
410 if (SUCCEEDED(rc) && progress)
411 {
412 rc = showProgress(progress);
413 CHECK_PROGRESS_ERROR(progress, ("Failed to create hard disk"));
414 if (SUCCEEDED(rc))
415 {
416 Bstr uuid;
417 CHECK_ERROR(hardDisk, COMGETTER(Id)(uuid.asOutParam()));
418 RTPrintf("Disk image created. UUID: %s\n", Utf8Str(uuid).c_str());
419 }
420 }
421
422 CHECK_ERROR(hardDisk, Close());
423 if (!fBase && fUnknownParent)
424 CHECK_ERROR(parentHardDisk, Close());
425 }
426 return SUCCEEDED(rc) ? 0 : 1;
427}
428
429static const RTGETOPTDEF g_aModifyHardDiskOptions[] =
430{
431 { "--type", 't', RTGETOPT_REQ_STRING },
432 { "-type", 't', RTGETOPT_REQ_STRING }, // deprecated
433 { "settype", 't', RTGETOPT_REQ_STRING }, // deprecated
434 { "--autoreset", 'z', RTGETOPT_REQ_STRING },
435 { "-autoreset", 'z', RTGETOPT_REQ_STRING }, // deprecated
436 { "autoreset", 'z', RTGETOPT_REQ_STRING }, // deprecated
437 { "--compact", 'c', RTGETOPT_REQ_NOTHING },
438 { "-compact", 'c', RTGETOPT_REQ_NOTHING }, // deprecated
439 { "compact", 'c', RTGETOPT_REQ_NOTHING }, // deprecated
440 { "--resize", 'r', RTGETOPT_REQ_UINT64 },
441 { "--resizebyte", 'R', RTGETOPT_REQ_UINT64 }
442};
443
444int handleModifyHardDisk(HandlerArg *a)
445{
446 HRESULT rc;
447 int vrc;
448 ComPtr<IMedium> hardDisk;
449 MediumType_T DiskType;
450 bool AutoReset = false;
451 bool fModifyDiskType = false, fModifyAutoReset = false, fModifyCompact = false;
452 bool fModifyResize = false;
453 uint64_t cbResize = 0;
454 const char *FilenameOrUuid = NULL;
455 bool unknown = false;
456
457 int c;
458 RTGETOPTUNION ValueUnion;
459 RTGETOPTSTATE GetState;
460 // start at 0 because main() has hacked both the argc and argv given to us
461 RTGetOptInit(&GetState, a->argc, a->argv, g_aModifyHardDiskOptions, RT_ELEMENTS(g_aModifyHardDiskOptions),
462 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
463 while ((c = RTGetOpt(&GetState, &ValueUnion)))
464 {
465 switch (c)
466 {
467 case 't': // --type
468 vrc = parseDiskType(ValueUnion.psz, &DiskType);
469 if (RT_FAILURE(vrc))
470 return errorArgument("Invalid hard disk type '%s'", ValueUnion.psz);
471 fModifyDiskType = true;
472 break;
473
474 case 'z': // --autoreset
475 vrc = parseBool(ValueUnion.psz, &AutoReset);
476 if (RT_FAILURE(vrc))
477 return errorArgument("Invalid autoreset parameter '%s'", ValueUnion.psz);
478 fModifyAutoReset = true;
479 break;
480
481 case 'c': // --compact
482 fModifyCompact = true;
483 break;
484
485 case 'r': // --resize
486 cbResize = ValueUnion.u64 * _1M;
487 fModifyResize = true;
488 break;
489
490 case 'R': // --resizebyte
491 cbResize = ValueUnion.u64;
492 fModifyResize = true;
493 break;
494
495 case VINF_GETOPT_NOT_OPTION:
496 if (!FilenameOrUuid)
497 FilenameOrUuid = ValueUnion.psz;
498 else
499 return errorSyntax(USAGE_MODIFYHD, "Invalid parameter '%s'", ValueUnion.psz);
500 break;
501
502 default:
503 if (c > 0)
504 {
505 if (RT_C_IS_PRINT(c))
506 return errorSyntax(USAGE_MODIFYHD, "Invalid option -%c", c);
507 else
508 return errorSyntax(USAGE_MODIFYHD, "Invalid option case %i", c);
509 }
510 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
511 return errorSyntax(USAGE_MODIFYHD, "unknown option: %s\n", ValueUnion.psz);
512 else if (ValueUnion.pDef)
513 return errorSyntax(USAGE_MODIFYHD, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
514 else
515 return errorSyntax(USAGE_MODIFYHD, "error: %Rrs", c);
516 }
517 }
518
519 if (!FilenameOrUuid)
520 return errorSyntax(USAGE_MODIFYHD, "Disk name or UUID required");
521
522 if (!fModifyDiskType && !fModifyAutoReset && !fModifyCompact && !fModifyResize)
523 return errorSyntax(USAGE_MODIFYHD, "No operation specified");
524
525 /* Depending on the operation the medium must be in the registry or
526 * may be opened on demand. */
527 if (fModifyDiskType || fModifyAutoReset)
528 rc = findMedium(a, FilenameOrUuid, DeviceType_HardDisk, false /* fSilent */, hardDisk);
529 else
530 rc = findOrOpenMedium(a, FilenameOrUuid, DeviceType_HardDisk,
531 hardDisk, false /* fForceNewUuidOnOpen */, &unknown);
532 if (FAILED(rc))
533 return 1;
534 if (hardDisk.isNull())
535 {
536 RTMsgError("Invalid hard disk reference, avoiding crash");
537 return 1;
538 }
539
540 if (fModifyDiskType)
541 {
542 MediumType_T hddType;
543 CHECK_ERROR(hardDisk, COMGETTER(Type)(&hddType));
544
545 if (hddType != DiskType)
546 CHECK_ERROR(hardDisk, COMSETTER(Type)(DiskType));
547 }
548
549 if (fModifyAutoReset)
550 {
551 CHECK_ERROR(hardDisk, COMSETTER(AutoReset)(AutoReset));
552 }
553
554 if (fModifyCompact)
555 {
556 ComPtr<IProgress> progress;
557 CHECK_ERROR(hardDisk, Compact(progress.asOutParam()));
558 if (SUCCEEDED(rc))
559 rc = showProgress(progress);
560 if (FAILED(rc))
561 {
562 if (rc == E_NOTIMPL)
563 RTMsgError("Compact hard disk operation is not implemented!");
564 else if (rc == VBOX_E_NOT_SUPPORTED)
565 RTMsgError("Compact hard disk operation for this format is not implemented yet!");
566 else if (!progress.isNull())
567 CHECK_PROGRESS_ERROR(progress, ("Failed to compact hard disk"));
568 else
569 RTMsgError("Failed to compact hard disk!");
570 }
571 }
572
573 if (fModifyResize)
574 {
575 ComPtr<IProgress> progress;
576 CHECK_ERROR(hardDisk, Resize(cbResize, progress.asOutParam()));
577 if (SUCCEEDED(rc))
578 rc = showProgress(progress);
579 if (FAILED(rc))
580 {
581 if (rc == E_NOTIMPL)
582 RTMsgError("Resize hard disk operation is not implemented!");
583 else if (rc == VBOX_E_NOT_SUPPORTED)
584 RTMsgError("Resize hard disk operation for this format is not implemented yet!");
585 else
586 CHECK_PROGRESS_ERROR(progress, ("Failed to resize hard disk"));
587 }
588 }
589
590 if (unknown)
591 hardDisk->Close();
592
593 return SUCCEEDED(rc) ? 0 : 1;
594}
595
596static const RTGETOPTDEF g_aCloneHardDiskOptions[] =
597{
598 { "--format", 'o', RTGETOPT_REQ_STRING },
599 { "-format", 'o', RTGETOPT_REQ_STRING },
600 { "--static", 'F', RTGETOPT_REQ_NOTHING },
601 { "-static", 'F', RTGETOPT_REQ_NOTHING },
602 { "--existing", 'E', RTGETOPT_REQ_NOTHING },
603 { "--variant", 'm', RTGETOPT_REQ_STRING },
604 { "-variant", 'm', RTGETOPT_REQ_STRING },
605};
606
607int handleCloneHardDisk(HandlerArg *a)
608{
609 HRESULT rc;
610 int vrc;
611 const char *pszSrc = NULL;
612 const char *pszDst = NULL;
613 Bstr format;
614 MediumVariant_T DiskVariant = MediumVariant_Standard;
615 bool fExisting = false;
616
617 int c;
618 RTGETOPTUNION ValueUnion;
619 RTGETOPTSTATE GetState;
620 // start at 0 because main() has hacked both the argc and argv given to us
621 RTGetOptInit(&GetState, a->argc, a->argv, g_aCloneHardDiskOptions, RT_ELEMENTS(g_aCloneHardDiskOptions),
622 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
623 while ((c = RTGetOpt(&GetState, &ValueUnion)))
624 {
625 switch (c)
626 {
627 case 'o': // --format
628 format = ValueUnion.psz;
629 break;
630
631 case 'F': // --static
632 {
633 unsigned uDiskVariant = (unsigned)DiskVariant;
634 uDiskVariant |= MediumVariant_Fixed;
635 DiskVariant = (MediumVariant_T)uDiskVariant;
636 break;
637 }
638
639 case 'E': // --existing
640 fExisting = true;
641 break;
642
643 case 'm': // --variant
644 vrc = parseDiskVariant(ValueUnion.psz, &DiskVariant);
645 if (RT_FAILURE(vrc))
646 return errorArgument("Invalid hard disk variant '%s'", ValueUnion.psz);
647 break;
648
649 case VINF_GETOPT_NOT_OPTION:
650 if (!pszSrc)
651 pszSrc = ValueUnion.psz;
652 else if (!pszDst)
653 pszDst = ValueUnion.psz;
654 else
655 return errorSyntax(USAGE_CLONEHD, "Invalid parameter '%s'", ValueUnion.psz);
656 break;
657
658 default:
659 if (c > 0)
660 {
661 if (RT_C_IS_GRAPH(c))
662 return errorSyntax(USAGE_CLONEHD, "unhandled option: -%c", c);
663 else
664 return errorSyntax(USAGE_CLONEHD, "unhandled option: %i", c);
665 }
666 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
667 return errorSyntax(USAGE_CLONEHD, "unknown option: %s", ValueUnion.psz);
668 else if (ValueUnion.pDef)
669 return errorSyntax(USAGE_CLONEHD, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
670 else
671 return errorSyntax(USAGE_CLONEHD, "error: %Rrs", c);
672 }
673 }
674
675 if (!pszSrc)
676 return errorSyntax(USAGE_CLONEHD, "Mandatory UUID or input file parameter missing");
677 if (!pszDst)
678 return errorSyntax(USAGE_CLONEHD, "Mandatory output file parameter missing");
679 if (fExisting && (!format.isEmpty() || DiskVariant != MediumType_Normal))
680 return errorSyntax(USAGE_CLONEHD, "Specified options which cannot be used with --existing");
681
682 ComPtr<IMedium> srcDisk;
683 ComPtr<IMedium> dstDisk;
684 bool fSrcUnknown = false;
685 bool fDstUnknown = false;
686
687 rc = findOrOpenMedium(a, pszSrc, DeviceType_HardDisk, srcDisk,
688 false /* fForceNewUuidOnOpen */, &fSrcUnknown);
689 if (FAILED(rc))
690 return 1;
691
692 do
693 {
694 /* open/create destination hard disk */
695 if (fExisting)
696 {
697 rc = findOrOpenMedium(a, pszDst, DeviceType_HardDisk, dstDisk,
698 false /* fForceNewUuidOnOpen */, &fDstUnknown);
699 if (FAILED(rc))
700 break;
701
702 /* Perform accessibility check now. */
703 MediumState_T state;
704 CHECK_ERROR_BREAK(dstDisk, RefreshState(&state));
705 CHECK_ERROR_BREAK(dstDisk, COMGETTER(Format)(format.asOutParam()));
706 }
707 else
708 {
709 /* use the format of the source hard disk if unspecified */
710 if (format.isEmpty())
711 CHECK_ERROR_BREAK(srcDisk, COMGETTER(Format)(format.asOutParam()));
712 rc = createHardDisk(a, Utf8Str(format).c_str(), pszDst, dstDisk);
713 if (FAILED(rc))
714 break;
715 fDstUnknown = true;
716 }
717
718 ComPtr<IProgress> progress;
719 CHECK_ERROR_BREAK(srcDisk, CloneTo(dstDisk, DiskVariant, NULL, progress.asOutParam()));
720
721 rc = showProgress(progress);
722 CHECK_PROGRESS_ERROR_BREAK(progress, ("Failed to clone hard disk"));
723
724 Bstr uuid;
725 CHECK_ERROR_BREAK(dstDisk, COMGETTER(Id)(uuid.asOutParam()));
726
727 RTPrintf("Clone hard disk created in format '%ls'. UUID: %s\n",
728 format.raw(), Utf8Str(uuid).c_str());
729 }
730 while (0);
731
732 if (fDstUnknown && !dstDisk.isNull())
733 {
734 /* forget the created clone */
735 dstDisk->Close();
736 }
737 if (fSrcUnknown)
738 {
739 /* close the unknown hard disk to forget it again */
740 srcDisk->Close();
741 }
742
743 return SUCCEEDED(rc) ? 0 : 1;
744}
745
746static const RTGETOPTDEF g_aConvertFromRawHardDiskOptions[] =
747{
748 { "--format", 'o', RTGETOPT_REQ_STRING },
749 { "-format", 'o', RTGETOPT_REQ_STRING },
750 { "--static", 'F', RTGETOPT_REQ_NOTHING },
751 { "-static", 'F', RTGETOPT_REQ_NOTHING },
752 { "--variant", 'm', RTGETOPT_REQ_STRING },
753 { "-variant", 'm', RTGETOPT_REQ_STRING },
754 { "--uuid", 'u', RTGETOPT_REQ_STRING },
755};
756
757RTEXITCODE handleConvertFromRaw(int argc, char *argv[])
758{
759 int rc = VINF_SUCCESS;
760 bool fReadFromStdIn = false;
761 const char *format = "VDI";
762 const char *srcfilename = NULL;
763 const char *dstfilename = NULL;
764 const char *filesize = NULL;
765 unsigned uImageFlags = VD_IMAGE_FLAGS_NONE;
766 void *pvBuf = NULL;
767 RTUUID uuid;
768 PCRTUUID pUuid = NULL;
769
770 int c;
771 RTGETOPTUNION ValueUnion;
772 RTGETOPTSTATE GetState;
773 // start at 0 because main() has hacked both the argc and argv given to us
774 RTGetOptInit(&GetState, argc, argv, g_aConvertFromRawHardDiskOptions, RT_ELEMENTS(g_aConvertFromRawHardDiskOptions),
775 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
776 while ((c = RTGetOpt(&GetState, &ValueUnion)))
777 {
778 switch (c)
779 {
780 case 'u': // --uuid
781 if (RT_FAILURE(RTUuidFromStr(&uuid, ValueUnion.psz)))
782 return errorSyntax(USAGE_CONVERTFROMRAW, "Invalid UUID '%s'", ValueUnion.psz);
783 pUuid = &uuid;
784 break;
785 case 'o': // --format
786 format = ValueUnion.psz;
787 break;
788
789 case 'm': // --variant
790 MediumVariant_T DiskVariant;
791 rc = parseDiskVariant(ValueUnion.psz, &DiskVariant);
792 if (RT_FAILURE(rc))
793 return errorArgument("Invalid hard disk variant '%s'", ValueUnion.psz);
794 /// @todo cleaner solution than assuming 1:1 mapping?
795 uImageFlags = (unsigned)DiskVariant;
796 break;
797
798 case VINF_GETOPT_NOT_OPTION:
799 if (!srcfilename)
800 {
801 srcfilename = ValueUnion.psz;
802 fReadFromStdIn = !strcmp(srcfilename, "stdin");
803 }
804 else if (!dstfilename)
805 dstfilename = ValueUnion.psz;
806 else if (fReadFromStdIn && !filesize)
807 filesize = ValueUnion.psz;
808 else
809 return errorSyntax(USAGE_CONVERTFROMRAW, "Invalid parameter '%s'", ValueUnion.psz);
810 break;
811
812 default:
813 return errorGetOpt(USAGE_CONVERTFROMRAW, c, &ValueUnion);
814 }
815 }
816
817 if (!srcfilename || !dstfilename || (fReadFromStdIn && !filesize))
818 return errorSyntax(USAGE_CONVERTFROMRAW, "Incorrect number of parameters");
819 RTStrmPrintf(g_pStdErr, "Converting from raw image file=\"%s\" to file=\"%s\"...\n",
820 srcfilename, dstfilename);
821
822 PVBOXHDD pDisk = NULL;
823
824 PVDINTERFACE pVDIfs = NULL;
825 VDINTERFACEERROR vdInterfaceError;
826 vdInterfaceError.pfnError = handleVDError;
827 vdInterfaceError.pfnMessage = NULL;
828
829 rc = VDInterfaceAdd(&vdInterfaceError.Core, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
830 NULL, sizeof(VDINTERFACEERROR), &pVDIfs);
831 AssertRC(rc);
832
833 /* open raw image file. */
834 RTFILE File;
835 if (fReadFromStdIn)
836 rc = RTFileFromNative(&File, RTFILE_NATIVE_STDIN);
837 else
838 rc = RTFileOpen(&File, srcfilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
839 if (RT_FAILURE(rc))
840 {
841 RTMsgError("Cannot open file \"%s\": %Rrc", srcfilename, rc);
842 goto out;
843 }
844
845 uint64_t cbFile;
846 /* get image size. */
847 if (fReadFromStdIn)
848 cbFile = RTStrToUInt64(filesize);
849 else
850 rc = RTFileGetSize(File, &cbFile);
851 if (RT_FAILURE(rc))
852 {
853 RTMsgError("Cannot get image size for file \"%s\": %Rrc", srcfilename, rc);
854 goto out;
855 }
856
857 RTStrmPrintf(g_pStdErr, "Creating %s image with size %RU64 bytes (%RU64MB)...\n",
858 (uImageFlags & VD_IMAGE_FLAGS_FIXED) ? "fixed" : "dynamic", cbFile, (cbFile + _1M - 1) / _1M);
859 char pszComment[256];
860 RTStrPrintf(pszComment, sizeof(pszComment), "Converted image from %s", srcfilename);
861 rc = VDCreate(pVDIfs, VDTYPE_HDD, &pDisk);
862 if (RT_FAILURE(rc))
863 {
864 RTMsgError("Cannot create the virtual disk container: %Rrc", rc);
865 goto out;
866 }
867
868 Assert(RT_MIN(cbFile / 512 / 16 / 63, 16383) -
869 (unsigned int)RT_MIN(cbFile / 512 / 16 / 63, 16383) == 0);
870 VDGEOMETRY PCHS, LCHS;
871 PCHS.cCylinders = (unsigned int)RT_MIN(cbFile / 512 / 16 / 63, 16383);
872 PCHS.cHeads = 16;
873 PCHS.cSectors = 63;
874 LCHS.cCylinders = 0;
875 LCHS.cHeads = 0;
876 LCHS.cSectors = 0;
877 rc = VDCreateBase(pDisk, format, dstfilename, cbFile,
878 uImageFlags, pszComment, &PCHS, &LCHS, pUuid,
879 VD_OPEN_FLAGS_NORMAL, NULL, NULL);
880 if (RT_FAILURE(rc))
881 {
882 RTMsgError("Cannot create the disk image \"%s\": %Rrc", dstfilename, rc);
883 goto out;
884 }
885
886 size_t cbBuffer;
887 cbBuffer = _1M;
888 pvBuf = RTMemAlloc(cbBuffer);
889 if (!pvBuf)
890 {
891 rc = VERR_NO_MEMORY;
892 RTMsgError("Out of memory allocating buffers for image \"%s\": %Rrc", dstfilename, rc);
893 goto out;
894 }
895
896 uint64_t offFile;
897 offFile = 0;
898 while (offFile < cbFile)
899 {
900 size_t cbRead;
901 size_t cbToRead;
902 cbRead = 0;
903 cbToRead = cbFile - offFile >= (uint64_t)cbBuffer ?
904 cbBuffer : (size_t)(cbFile - offFile);
905 rc = RTFileRead(File, pvBuf, cbToRead, &cbRead);
906 if (RT_FAILURE(rc) || !cbRead)
907 break;
908 rc = VDWrite(pDisk, offFile, pvBuf, cbRead);
909 if (RT_FAILURE(rc))
910 {
911 RTMsgError("Failed to write to disk image \"%s\": %Rrc", dstfilename, rc);
912 goto out;
913 }
914 offFile += cbRead;
915 }
916
917out:
918 if (pvBuf)
919 RTMemFree(pvBuf);
920 if (pDisk)
921 VDClose(pDisk, RT_FAILURE(rc));
922 if (File != NIL_RTFILE)
923 RTFileClose(File);
924
925 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
926}
927
928static const RTGETOPTDEF g_aShowHardDiskInfoOptions[] =
929{
930 { "--dummy", 256, RTGETOPT_REQ_NOTHING }, // placeholder for C++
931};
932
933int handleShowHardDiskInfo(HandlerArg *a)
934{
935 HRESULT rc;
936 const char *FilenameOrUuid = NULL;
937
938 int c;
939 RTGETOPTUNION ValueUnion;
940 RTGETOPTSTATE GetState;
941 // start at 0 because main() has hacked both the argc and argv given to us
942 RTGetOptInit(&GetState, a->argc, a->argv, g_aShowHardDiskInfoOptions, RT_ELEMENTS(g_aShowHardDiskInfoOptions),
943 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
944 while ((c = RTGetOpt(&GetState, &ValueUnion)))
945 {
946 switch (c)
947 {
948 case VINF_GETOPT_NOT_OPTION:
949 if (!FilenameOrUuid)
950 FilenameOrUuid = ValueUnion.psz;
951 else
952 return errorSyntax(USAGE_SHOWHDINFO, "Invalid parameter '%s'", ValueUnion.psz);
953 break;
954
955 default:
956 if (c > 0)
957 {
958 if (RT_C_IS_PRINT(c))
959 return errorSyntax(USAGE_SHOWHDINFO, "Invalid option -%c", c);
960 else
961 return errorSyntax(USAGE_SHOWHDINFO, "Invalid option case %i", c);
962 }
963 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
964 return errorSyntax(USAGE_SHOWHDINFO, "unknown option: %s\n", ValueUnion.psz);
965 else if (ValueUnion.pDef)
966 return errorSyntax(USAGE_SHOWHDINFO, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
967 else
968 return errorSyntax(USAGE_SHOWHDINFO, "error: %Rrs", c);
969 }
970 }
971
972 /* check for required options */
973 if (!FilenameOrUuid)
974 return errorSyntax(USAGE_SHOWHDINFO, "Disk name or UUID required");
975
976 ComPtr<IMedium> hardDisk;
977 bool unknown = false;
978
979 rc = findOrOpenMedium(a, FilenameOrUuid, DeviceType_HardDisk, hardDisk,
980 false /* fForceNewUuidOnOpen */, &unknown);
981 if (FAILED(rc))
982 return 1;
983
984 do
985 {
986 Bstr uuid;
987 hardDisk->COMGETTER(Id)(uuid.asOutParam());
988 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
989
990 /* check for accessibility */
991 /// @todo NEWMEDIA check accessibility of all parents
992 /// @todo NEWMEDIA print the full state value
993 MediumState_T state;
994 CHECK_ERROR_BREAK(hardDisk, RefreshState(&state));
995 RTPrintf("Accessible: %s\n", state != MediumState_Inaccessible ? "yes" : "no");
996
997 if (state == MediumState_Inaccessible)
998 {
999 Bstr err;
1000 CHECK_ERROR_BREAK(hardDisk, COMGETTER(LastAccessError)(err.asOutParam()));
1001 RTPrintf("Access Error: %ls\n", err.raw());
1002 }
1003
1004 Bstr description;
1005 hardDisk->COMGETTER(Description)(description.asOutParam());
1006 if (!description.isEmpty())
1007 {
1008 RTPrintf("Description: %ls\n", description.raw());
1009 }
1010
1011 LONG64 logicalSize;
1012 hardDisk->COMGETTER(LogicalSize)(&logicalSize);
1013 RTPrintf("Logical size: %lld MBytes\n", logicalSize >> 20);
1014 LONG64 actualSize;
1015 hardDisk->COMGETTER(Size)(&actualSize);
1016 RTPrintf("Current size on disk: %lld MBytes\n", actualSize >> 20);
1017
1018 ComPtr <IMedium> parent;
1019 hardDisk->COMGETTER(Parent)(parent.asOutParam());
1020
1021 MediumType_T type;
1022 hardDisk->COMGETTER(Type)(&type);
1023 const char *typeStr = "unknown";
1024 switch (type)
1025 {
1026 case MediumType_Normal:
1027 if (!parent.isNull())
1028 typeStr = "normal (differencing)";
1029 else
1030 typeStr = "normal (base)";
1031 break;
1032 case MediumType_Immutable:
1033 typeStr = "immutable";
1034 break;
1035 case MediumType_Writethrough:
1036 typeStr = "writethrough";
1037 break;
1038 case MediumType_Shareable:
1039 typeStr = "shareable";
1040 break;
1041 case MediumType_Readonly:
1042 typeStr = "readonly";
1043 break;
1044 case MediumType_MultiAttach:
1045 typeStr = "multiattach";
1046 break;
1047 }
1048 RTPrintf("Type: %s\n", typeStr);
1049
1050 Bstr format;
1051 hardDisk->COMGETTER(Format)(format.asOutParam());
1052 RTPrintf("Storage format: %ls\n", format.raw());
1053 ULONG variant;
1054 hardDisk->COMGETTER(Variant)(&variant);
1055 const char *variantStr = "unknown";
1056 switch (variant & ~(MediumVariant_Fixed | MediumVariant_Diff))
1057 {
1058 case MediumVariant_VmdkSplit2G:
1059 variantStr = "split2G";
1060 break;
1061 case MediumVariant_VmdkStreamOptimized:
1062 variantStr = "streamOptimized";
1063 break;
1064 case MediumVariant_VmdkESX:
1065 variantStr = "ESX";
1066 break;
1067 case MediumVariant_Standard:
1068 variantStr = "default";
1069 break;
1070 }
1071 const char *variantTypeStr = "dynamic";
1072 if (variant & MediumVariant_Fixed)
1073 variantTypeStr = "fixed";
1074 else if (variant & MediumVariant_Diff)
1075 variantTypeStr = "differencing";
1076 RTPrintf("Format variant: %s %s\n", variantTypeStr, variantStr);
1077
1078 /// @todo also dump config parameters (iSCSI)
1079
1080 if (!unknown)
1081 {
1082 com::SafeArray<BSTR> machineIds;
1083 hardDisk->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
1084 for (size_t j = 0; j < machineIds.size(); ++ j)
1085 {
1086 ComPtr<IMachine> machine;
1087 CHECK_ERROR(a->virtualBox, FindMachine(machineIds[j], machine.asOutParam()));
1088 ASSERT(machine);
1089 Bstr name;
1090 machine->COMGETTER(Name)(name.asOutParam());
1091 machine->COMGETTER(Id)(uuid.asOutParam());
1092 RTPrintf("%s%ls (UUID: %ls)\n",
1093 j == 0 ? "In use by VMs: " : " ",
1094 name.raw(), machineIds[j]);
1095 }
1096 /// @todo NEWMEDIA check usage in snapshots too
1097 /// @todo NEWMEDIA also list children
1098 }
1099
1100 Bstr loc;
1101 hardDisk->COMGETTER(Location)(loc.asOutParam());
1102 RTPrintf("Location: %ls\n", loc.raw());
1103
1104 /* print out information specific for differencing hard disks */
1105 if (!parent.isNull())
1106 {
1107 BOOL autoReset = FALSE;
1108 hardDisk->COMGETTER(AutoReset)(&autoReset);
1109 RTPrintf("Auto-Reset: %s\n", autoReset ? "on" : "off");
1110 }
1111 }
1112 while (0);
1113
1114 if (unknown)
1115 {
1116 /* close the unknown hard disk to forget it again */
1117 hardDisk->Close();
1118 }
1119
1120 return SUCCEEDED(rc) ? 0 : 1;
1121}
1122
1123static const RTGETOPTDEF g_aCloseMediumOptions[] =
1124{
1125 { "disk", 'd', RTGETOPT_REQ_NOTHING },
1126 { "dvd", 'D', RTGETOPT_REQ_NOTHING },
1127 { "floppy", 'f', RTGETOPT_REQ_NOTHING },
1128 { "--delete", 'r', RTGETOPT_REQ_NOTHING },
1129};
1130
1131int handleCloseMedium(HandlerArg *a)
1132{
1133 HRESULT rc = S_OK;
1134 enum {
1135 CMD_NONE,
1136 CMD_DISK,
1137 CMD_DVD,
1138 CMD_FLOPPY
1139 } cmd = CMD_NONE;
1140 const char *FilenameOrUuid = NULL;
1141 bool fDelete = false;
1142
1143 int c;
1144 RTGETOPTUNION ValueUnion;
1145 RTGETOPTSTATE GetState;
1146 // start at 0 because main() has hacked both the argc and argv given to us
1147 RTGetOptInit(&GetState, a->argc, a->argv, g_aCloseMediumOptions, RT_ELEMENTS(g_aCloseMediumOptions),
1148 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
1149 while ((c = RTGetOpt(&GetState, &ValueUnion)))
1150 {
1151 switch (c)
1152 {
1153 case 'd': // disk
1154 if (cmd != CMD_NONE)
1155 return errorSyntax(USAGE_CLOSEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz);
1156 cmd = CMD_DISK;
1157 break;
1158
1159 case 'D': // DVD
1160 if (cmd != CMD_NONE)
1161 return errorSyntax(USAGE_CLOSEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz);
1162 cmd = CMD_DVD;
1163 break;
1164
1165 case 'f': // floppy
1166 if (cmd != CMD_NONE)
1167 return errorSyntax(USAGE_CLOSEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz);
1168 cmd = CMD_FLOPPY;
1169 break;
1170
1171 case 'r': // --delete
1172 fDelete = true;
1173 break;
1174
1175 case VINF_GETOPT_NOT_OPTION:
1176 if (!FilenameOrUuid)
1177 FilenameOrUuid = ValueUnion.psz;
1178 else
1179 return errorSyntax(USAGE_CLOSEMEDIUM, "Invalid parameter '%s'", ValueUnion.psz);
1180 break;
1181
1182 default:
1183 if (c > 0)
1184 {
1185 if (RT_C_IS_PRINT(c))
1186 return errorSyntax(USAGE_CLOSEMEDIUM, "Invalid option -%c", c);
1187 else
1188 return errorSyntax(USAGE_CLOSEMEDIUM, "Invalid option case %i", c);
1189 }
1190 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
1191 return errorSyntax(USAGE_CLOSEMEDIUM, "unknown option: %s\n", ValueUnion.psz);
1192 else if (ValueUnion.pDef)
1193 return errorSyntax(USAGE_CLOSEMEDIUM, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
1194 else
1195 return errorSyntax(USAGE_CLOSEMEDIUM, "error: %Rrs", c);
1196 }
1197 }
1198
1199 /* check for required options */
1200 if (cmd == CMD_NONE)
1201 return errorSyntax(USAGE_CLOSEMEDIUM, "Command variant disk/dvd/floppy required");
1202 if (!FilenameOrUuid)
1203 return errorSyntax(USAGE_CLOSEMEDIUM, "Disk name or UUID required");
1204
1205 ComPtr<IMedium> medium;
1206
1207 if (cmd == CMD_DISK)
1208 rc = findMedium(a, FilenameOrUuid, DeviceType_HardDisk, false /* fSilent */, medium);
1209 else if (cmd == CMD_DVD)
1210 rc = findMedium(a, FilenameOrUuid, DeviceType_DVD, false /* fSilent */, medium);
1211 else if (cmd == CMD_FLOPPY)
1212 rc = findMedium(a, FilenameOrUuid, DeviceType_Floppy, false /* fSilent */, medium);
1213
1214 if (SUCCEEDED(rc) && medium)
1215 {
1216 if (fDelete)
1217 {
1218 ComPtr<IProgress> progress;
1219 CHECK_ERROR(medium, DeleteStorage(progress.asOutParam()));
1220 if (SUCCEEDED(rc))
1221 {
1222 rc = showProgress(progress);
1223 CHECK_PROGRESS_ERROR(progress, ("Failed to delete medium"));
1224 }
1225 else
1226 RTMsgError("Failed to delete medium. Error code %Rrc", rc);
1227 }
1228 CHECK_ERROR(medium, Close());
1229 }
1230
1231 return SUCCEEDED(rc) ? 0 : 1;
1232}
1233#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