VHDDtest.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
2362N/A/** @file
639N/A *
639N/A * Simple VBox HDD container test utility.
639N/A */
639N/A
2362N/A/*
639N/A * Copyright (C) 2006 InnoTek Systemberatung GmbH
2362N/A *
639N/A * This file is part of VirtualBox Open Source Edition (OSE), as
639N/A * available from http://www.virtualbox.org. This file is free software;
639N/A * you can redistribute it and/or modify it under the terms of the GNU
639N/A * General Public License as published by the Free Software Foundation,
639N/A * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
639N/A * distribution. VirtualBox OSE is distributed in the hope that it will
639N/A * be useful, but WITHOUT ANY WARRANTY of any kind.
639N/A *
639N/A * If you received this file as part of a commercial VirtualBox
639N/A * distribution, then only the terms of your commercial VirtualBox
639N/A * license agreement apply instead of the previous paragraph.
2362N/A */
2362N/A
2362N/A#include <VBox/err.h>
639N/A#include <VBox/VBoxHDD.h>
639N/A#include <iprt/runtime.h>
639N/A#include <iprt/string.h>
639N/A
639N/A#include <stdio.h>
639N/A#include <stdlib.h>
639N/A
639N/Aint main ()
639N/A{
639N/A int rc;
639N/A RTR3Init();
639N/A
639N/A PVDIDISK vhdd = VDIDiskCreate();
639N/A
639N/A rc = VDIDiskOpenImage(vhdd, "testimg.vdi", VDI_OPEN_FLAGS_NORMAL);
639N/A printf("openImage() rc=%d\r\n", rc);
639N/A
639N/A if (VBOX_FAILURE(rc))
639N/A {
639N/A rc = VDICreateBaseImage("testimg.vdi", VDI_IMAGE_TYPE_NORMAL,
639N/A#ifdef _MSC_VER
639N/A (1000 * 1024 * 1024UI64),
639N/A#else
639N/A (1000 * 1024 * 1024ULL),
639N/A#endif
639N/A "Test image", NULL, NULL);
639N/A printf ("createImage() rc=%d\r\n", rc);
639N/A
639N/A rc = VDIDiskOpenImage(vhdd, "testimg.vdi", VDI_OPEN_FLAGS_NORMAL);
639N/A printf ("openImage() rc=%d\r\n", rc);
639N/A }
639N/A
639N/A void *buf = malloc(1*1124*1024);
639N/A
639N/A memset(buf, 0x33, 1*1124*1024);
639N/A rc = VDIDiskWrite(vhdd, 20*1024*1024 + 594040, buf, 1024*1024);
639N/A printf ("write() rc=%d\r\n", rc);
memset(buf, 0x46, 1*1124*1024);
rc = VDIDiskWrite(vhdd, 20*1024*1024 + 594040, buf, 1024);
printf ("write() rc=%d\r\n", rc);
memset(buf, 0x51, 1*1124*1024);
rc = VDIDiskWrite(vhdd, 40*1024*1024 + 594040, buf, 1024);
printf ("write() rc=%d\r\n", rc);
rc = VDIDiskCreateOpenDifferenceImage(vhdd, "diffimg.vdi", "Test diff image", NULL, NULL);
printf("create undo rc=%d\r\n", rc);
// rc = VHDDOpenSecondImage(vhdd, "undoimg.vdi");
// printf ("open undo rc=%d\r\n", rc);
memset(buf, '_', 1*1124*1024);
rc = VDIDiskWrite(vhdd, 20*1024*1024 + 594040, buf, 512);
printf("write() rc=%d\r\n", rc);
rc = VDIDiskWrite(vhdd, 22*1024*1024 + 594040, buf, 78263);
printf("write() rc=%d\r\n", rc);
rc = VDIDiskWrite(vhdd, 13*1024*1024 + 594040, buf, 782630);
printf("write() rc=%d\r\n", rc);
rc = VDIDiskWrite(vhdd, 44*1024*1024 + 594040, buf, 67899);
printf("write() rc=%d\r\n", rc);
printf("committing..\r\n");
VDIDiskDumpImages(vhdd);
rc = VDIDiskCommitLastDiff(vhdd, NULL, NULL);
printf("commit last diff rc=%d\r\n", rc);
VDIDiskCloseAllImages(vhdd);
return (0);
}