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