Correcting the usage of a variable when calling register_disk()
[vdi_driver.git] / src / main.cpp
bloba96acb511bdb06e81c02604feb46f046edd85358
1 /** @file
3 * Simple VBox HDD container test utility.
4 */
6 /*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
18 #include "VBoxHDD.h"
19 #include "file.h"
20 #include "alloc.h"
21 #include <cstdio>
22 #include <cstring>
25 int dotest(const char *pszBaseFilename, const char *pszDiffFilename)
27 PVDIDISK pVdi = VDIDiskCreate();
29 #define CHECK(str) \
30 do \
31 { \
32 printf("%s rc=%i\n", str, rc); \
33 if (VBOX_FAILURE(rc)) \
34 { \
35 VDIDiskCloseAllImages(pVdi); \
36 return rc; \
37 } \
38 } while (0)
41 int rc = VDIDiskOpenImage(pVdi, pszBaseFilename, VDI_OPEN_FLAGS_NORMAL);
42 printf("openImage() rc=%i\n", rc);
43 if (VBOX_FAILURE(rc))
45 rc = VDICreateBaseImage(pszBaseFilename, VDI_IMAGE_TYPE_NORMAL,
46 #ifdef _MSC_VER
47 (1000 * 1024 * 1024UI64),
48 #else
49 (1000 * 1024 * 1024ULL),
50 #endif
51 "Test image", NULL, NULL);
52 CHECK("createImage()");
54 rc = VDIDiskOpenImage(pVdi, pszBaseFilename, VDI_OPEN_FLAGS_NORMAL);
55 CHECK("openImage()");
58 void *pvBuf = RTMemAlloc(1*1124*1024);
60 memset(pvBuf, 'V', 1*1124*1024);
61 rc = VDIDiskWrite(pVdi, 20*1024*1024 + 594040, pvBuf, 1024*1024);
62 CHECK("write()");
64 memset(pvBuf, 'D', 1*1124*1024);
65 rc = VDIDiskWrite(pVdi, 30*1024*1024 + 594040, pvBuf, 1024*1024);
66 CHECK("write()");
68 memset(pvBuf, 'I', 1*1124*1024);
69 rc = VDIDiskWrite(pVdi, 30*1024*1024 + 594040, pvBuf, 1024*1024);
70 CHECK("write()");
72 char buf[30] = "hello world";
73 rc = VDIDiskWrite(pVdi, 0x0, buf, 30); // Reparem que aqui ele salva no endereço 0x00401200
74 CHECK("write()");
77 for (int i = 0; i < 20; i++) buf[i] = '\0';
78 VDIDiskRead(pVdi, 0x0, buf, 11);
80 printf(buf);
82 VDIDiskCloseAllImages(pVdi);
83 #undef CHECK
84 return rc;
88 int main()
90 RTFileDelete("tstVdiBase.vdi");
91 RTFileDelete("tstVdiDiff.vdi");
93 int rc = dotest("tstVdiBase.vdi", "tstVdiDiff.vdi");
94 if (!rc)
95 printf("tstVDI: SUCCESS\n");
96 else
97 printf("tstVDI: FAILURE\n");
99 // RTFileDelete("tstVdiBase.vdi");
100 // RTFileDelete("tstVdiDiff.vdi");
101 return !!rc;