VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/testcase/tstVDCopy.cpp@ 32598

Last change on this file since 32598 was 32536, checked in by vboxsync, 14 years ago

Storage/VBoxHDD: replace custom open flags with regular IPRT file open flags, introduce user-providable filesystem access interface, eliminate dependency on PGM geometry structure, change pvBuffer/cbBuffer parameter ordering to the usual conventions, eliminate the remains of the old I/O code, make more plugin methods optional to reduce redundancy, lots of cleanups

Storage/DrvVD+testcases,Main/Medium+Frontends: adapt to VBoxHDD changes, logging fixes

Storage/VDI+VMDK+DMG+Raw+VHD+Parallels+VCI: made as similar to each other as possible, added inline VFS wrappers to improve readability, full VFS support, VDI files are now 4K aligned, eliminate the remains of the old I/O code, various more or less severe bugfixes, code sort

Storage/iSCSI: support disks bigger than 2T, streamline the code to be more similar to the file-based backends, memory leak fix, error code usage like file-based backends, code sort

log+err: added new error codes/log groups and eliminated unused old ones

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/** @file
2 *
3 * Simple VBox HDD container test utility. Compares two images and prints
4 * differences. Mainly used to check cloning of disk images.
5 */
6
7/*
8 * Copyright (C) 2006-2010 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include <VBox/err.h>
20#include <VBox/VBoxHDD.h>
21#include <iprt/string.h>
22#include <iprt/stream.h>
23#include <iprt/file.h>
24#include <iprt/mem.h>
25#include <iprt/initterm.h>
26#include <iprt/rand.h>
27#include "stdio.h"
28#include "stdlib.h"
29
30/* from VBoxHDD.cpp */
31#define VD_MERGE_BUFFER_SIZE (16 * _1M)
32
33/*******************************************************************************
34* Global Variables *
35*******************************************************************************/
36/** The error count. */
37unsigned g_cErrors = 0;
38
39
40static void tstVDError(void *pvUser, int rc, RT_SRC_POS_DECL,
41 const char *pszFormat, va_list va)
42{
43 g_cErrors++;
44 RTPrintf("tstVD: Error %Rrc at %s:%u (%s): ", rc, RT_SRC_POS_ARGS);
45 RTPrintfV(pszFormat, va);
46 RTPrintf("\n");
47}
48
49int main(int argc, char *argv[])
50{
51 int rc;
52
53 RTR3Init();
54
55 if (argc != 3)
56 {
57 RTPrintf("Usage: ./tstVDCopy <hdd1> <hdd2>\n");
58 return 1;
59 }
60
61 RTPrintf("tstVDCopy: TESTING...\n");
62
63 PVBOXHDD pVD1 = NULL;
64 PVBOXHDD pVD2 = NULL;
65 PVDINTERFACE pVDIfs = NULL;
66 VDINTERFACE VDIError;
67 VDINTERFACEERROR VDIErrorCallbacks;
68 char *pszVD1 = NULL;
69 char *pszVD2 = NULL;
70 char *pbBuf1 = NULL;
71 char *pbBuf2 = NULL;
72
73#define CHECK(str) \
74 do \
75 { \
76 if (RT_FAILURE(rc)) \
77 { \
78 RTPrintf("%s rc=%Rrc\n", str, rc); \
79 if (pVD1) \
80 VDCloseAll(pVD1); \
81 if (pVD2) \
82 VDCloseAll(pVD2); \
83 return rc; \
84 } \
85 } while (0)
86
87 pbBuf1 = (char *)RTMemAllocZ(VD_MERGE_BUFFER_SIZE);
88 pbBuf2 = (char *)RTMemAllocZ(VD_MERGE_BUFFER_SIZE);
89
90 /* Create error interface. */
91 VDIErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
92 VDIErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
93 VDIErrorCallbacks.pfnError = tstVDError;
94
95 rc = VDInterfaceAdd(&VDIError, "tstVD_Error", VDINTERFACETYPE_ERROR, &VDIErrorCallbacks,
96 NULL, &pVDIfs);
97 AssertRC(rc);
98
99 rc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
100 argv[1], &pszVD1);
101 CHECK("VDGetFormat() hdd1");
102
103 rc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
104 argv[2], &pszVD2);
105 CHECK("VDGetFormat() hdd2");
106
107 rc = VDCreate(&VDIError, &pVD1);
108 CHECK("VDCreate() hdd1");
109
110 rc = VDCreate(&VDIError, &pVD2);
111 CHECK("VDCreate() hdd1");
112
113 rc = VDOpen(pVD1, pszVD1, argv[1], VD_OPEN_FLAGS_NORMAL, NULL);
114 CHECK("VDOpen() hdd1");
115
116 rc = VDOpen(pVD2, pszVD2, argv[2], VD_OPEN_FLAGS_NORMAL, NULL);
117 CHECK("VDOpen() hdd2");
118
119 uint64_t cbSize1 = 0;
120 uint64_t cbSize2 = 0;
121
122 cbSize1 = VDGetSize(pVD1, 0);
123 Assert(cbSize1 != 0);
124 cbSize2 = VDGetSize(pVD1, 0);
125 Assert(cbSize1 != 0);
126
127 if (cbSize1 == cbSize2)
128 {
129 uint64_t uOffCurr = 0;
130
131 /* Compare block by block. */
132 while (uOffCurr < cbSize1)
133 {
134 size_t cbRead = RT_MIN((cbSize1 - uOffCurr), VD_MERGE_BUFFER_SIZE);
135
136 rc = VDRead(pVD1, uOffCurr, pbBuf1, cbRead);
137 CHECK("VDRead() hdd1");
138
139 rc = VDRead(pVD2, uOffCurr, pbBuf2, cbRead);
140 CHECK("VDRead() hdd2");
141
142 if (memcmp(pbBuf1, pbBuf2, cbRead))
143 {
144 RTPrintf("tstVDCopy: Images differ uOffCurr=%llu\n", uOffCurr);
145 /* Do byte by byte comaprison. */
146 for (size_t i = 0; i < cbRead; i++)
147 {
148 if (pbBuf1[i] != pbBuf2[i])
149 {
150 RTPrintf("tstVDCopy: First different byte is at offset %llu\n", uOffCurr + i);
151 break;
152 }
153 }
154 break;
155 }
156
157 uOffCurr += cbRead;
158 }
159 }
160 else
161 RTPrintf("tstVDCopy: Images have different size hdd1=%llu hdd2=%llu\n", cbSize1, cbSize2);
162
163 VDClose(pVD1, false);
164 CHECK("VDClose() hdd1");
165
166 VDClose(pVD2, false);
167 CHECK("VDClose() hdd2");
168
169 VDDestroy(pVD1);
170 VDDestroy(pVD2);
171 RTMemFree(pbBuf1);
172 RTMemFree(pbBuf2);
173#undef CHECK
174
175 rc = VDShutdown();
176 if (RT_FAILURE(rc))
177 {
178 RTPrintf("tstVDCopy: unloading backends failed! rc=%Rrc\n", rc);
179 g_cErrors++;
180 }
181 /*
182 * Summary
183 */
184 if (!g_cErrors)
185 RTPrintf("tstVDCopy: SUCCESS\n");
186 else
187 RTPrintf("tstVDCopy: FAILURE - %d errors\n", g_cErrors);
188
189 return !!g_cErrors;
190}
191
Note: See TracBrowser for help on using the repository browser.

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