1 | /** @file
|
---|
2 | *
|
---|
3 | * Simple VBox HDD container test utility.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 | #include <VBox/err.h>
|
---|
19 | #include <VBox/VBoxHDD.h>
|
---|
20 | #include <iprt/runtime.h>
|
---|
21 | #include <iprt/string.h>
|
---|
22 | #include <iprt/stream.h>
|
---|
23 | #include <iprt/mem.h>
|
---|
24 |
|
---|
25 |
|
---|
26 | int dotest(const char *pszBaseFilename, const char *pszDiffFilename)
|
---|
27 | {
|
---|
28 | PVDIDISK pVdi = VDIDiskCreate();
|
---|
29 |
|
---|
30 | #define CHECK(str) \
|
---|
31 | do \
|
---|
32 | { \
|
---|
33 | RTPrintf("%s rc=%Vrc\n", str, rc); \
|
---|
34 | if (VBOX_FAILURE(rc)) \
|
---|
35 | { \
|
---|
36 | VDIDiskCloseAllImages(pVdi); \
|
---|
37 | return rc; \
|
---|
38 | } \
|
---|
39 | } while (0)
|
---|
40 |
|
---|
41 |
|
---|
42 | int rc = VDIDiskOpenImage(pVdi, pszBaseFilename, VDI_OPEN_FLAGS_NORMAL);
|
---|
43 | RTPrintf("openImage() rc=%Vrc\n", rc);
|
---|
44 | if (VBOX_FAILURE(rc))
|
---|
45 | {
|
---|
46 | rc = VDICreateBaseImage(pszBaseFilename, VDI_IMAGE_TYPE_NORMAL,
|
---|
47 | #ifdef _MSC_VER
|
---|
48 | (1000 * 1024 * 1024UI64),
|
---|
49 | #else
|
---|
50 | (1000 * 1024 * 1024ULL),
|
---|
51 | #endif
|
---|
52 | "Test image", NULL, NULL);
|
---|
53 | CHECK("createImage()");
|
---|
54 |
|
---|
55 | rc = VDIDiskOpenImage(pVdi, pszBaseFilename, VDI_OPEN_FLAGS_NORMAL);
|
---|
56 | CHECK("openImage()");
|
---|
57 | }
|
---|
58 |
|
---|
59 | void *pvBuf = RTMemAlloc(1*1124*1024);
|
---|
60 |
|
---|
61 | memset(pvBuf, 0x33, 1*1124*1024);
|
---|
62 | rc = VDIDiskWrite(pVdi, 20*1024*1024 + 594040, pvBuf, 1024*1024);
|
---|
63 | CHECK("write()");
|
---|
64 |
|
---|
65 | memset(pvBuf, 0x46, 1*1124*1024);
|
---|
66 | rc = VDIDiskWrite(pVdi, 20*1024*1024 + 594040, pvBuf, 1024);
|
---|
67 | CHECK("write()");
|
---|
68 |
|
---|
69 | memset(pvBuf, 0x51, 1*1124*1024);
|
---|
70 | rc = VDIDiskWrite(pVdi, 40*1024*1024 + 594040, pvBuf, 1024);
|
---|
71 | CHECK("write()");
|
---|
72 |
|
---|
73 | rc = VDIDiskCreateOpenDifferenceImage(pVdi, pszDiffFilename, "Test diff image", NULL, NULL);
|
---|
74 | CHECK("create undo");
|
---|
75 | // rc = VHDDOpenSecondImage(pVdi, "undoimg.vdi");
|
---|
76 | // RTPrintf("open undo rc=%Vrc\n", rc);
|
---|
77 |
|
---|
78 | memset(pvBuf, '_', 1*1124*1024);
|
---|
79 | rc = VDIDiskWrite(pVdi, 20*1024*1024 + 594040, pvBuf, 512);
|
---|
80 | CHECK("write()");
|
---|
81 |
|
---|
82 | rc = VDIDiskWrite(pVdi, 22*1024*1024 + 594040, pvBuf, 78263);
|
---|
83 | CHECK("write()");
|
---|
84 | rc = VDIDiskWrite(pVdi, 13*1024*1024 + 594040, pvBuf, 782630);
|
---|
85 | CHECK("write()");
|
---|
86 | rc = VDIDiskWrite(pVdi, 44*1024*1024 + 594040, pvBuf, 67899);
|
---|
87 | CHECK("write()");
|
---|
88 |
|
---|
89 | RTPrintf("committing..\n");
|
---|
90 | VDIDiskDumpImages(pVdi);
|
---|
91 | rc = VDIDiskCommitLastDiff(pVdi, NULL, NULL);
|
---|
92 | CHECK("commit last diff");
|
---|
93 | VDIDiskCloseAllImages(pVdi);
|
---|
94 | #undef CHECK
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | int main()
|
---|
100 | {
|
---|
101 | RTR3Init();
|
---|
102 |
|
---|
103 | RTFileDelete("tmpVdiBase.vdi");
|
---|
104 | RTFileDelete("tmpVdiDiff.vdi");
|
---|
105 |
|
---|
106 | int rc = dotest("tmpVdiBase.vdi", "tmpVdiDiff.vdi");
|
---|
107 | if (!rc)
|
---|
108 | RTPrintf("tstVDI: SUCCESS\n");
|
---|
109 | else
|
---|
110 | RTPrintf("tstVDI: FAILURE\n");
|
---|
111 |
|
---|
112 | RTFileDelete("tmpVdiBase.vdi");
|
---|
113 | RTFileDelete("tmpVdiDiff.vdi");
|
---|
114 | return !!rc;
|
---|
115 | }
|
---|
116 |
|
---|