2006-12-17 11:17:28 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2006-12-17 11:17:28 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file provides support for VMWare's virtual disk image
|
|
|
|
* format version 4 and above.
|
|
|
|
*
|
|
|
|
* Author: Sharvil Nanavati
|
|
|
|
* Contact: snrrrub@gmail.com
|
|
|
|
*
|
2015-03-20 21:01:52 +03:00
|
|
|
* Copyright (C) 2006 Sharvil Nanavati.
|
|
|
|
* Copyright (C) 2006-2015 The Bochs Project
|
2006-12-17 11:17:28 +03:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-12-17 11:17:28 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
|
|
|
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
|
|
|
// is used to know when we are exporting symbols and when we are importing.
|
|
|
|
#define BX_PLUGGABLE
|
|
|
|
|
2013-10-13 18:33:55 +04:00
|
|
|
#ifdef BXIMAGE
|
|
|
|
#include "config.h"
|
|
|
|
#include "misc/bxcompat.h"
|
2013-10-14 00:30:51 +04:00
|
|
|
#include "osdep.h"
|
2015-03-20 21:01:52 +03:00
|
|
|
#include "misc/bswap.h"
|
2013-10-13 18:33:55 +04:00
|
|
|
#else
|
2006-12-17 11:17:28 +03:00
|
|
|
#include "iodev.h"
|
2013-10-13 18:33:55 +04:00
|
|
|
#endif
|
2006-12-17 11:17:28 +03:00
|
|
|
#include "hdimage.h"
|
|
|
|
#include "vmware4.h"
|
|
|
|
|
2011-01-14 19:43:55 +03:00
|
|
|
#define LOG_THIS bx_devices.pluginHDImageCtl->
|
|
|
|
|
2006-12-17 11:17:28 +03:00
|
|
|
const off_t vmware4_image_t::INVALID_OFFSET = (off_t)-1;
|
|
|
|
const int vmware4_image_t::SECTOR_SIZE = 512;
|
|
|
|
|
|
|
|
vmware4_image_t::vmware4_image_t()
|
2012-09-20 01:05:18 +04:00
|
|
|
: file_descriptor(-1),
|
|
|
|
tlb(0),
|
|
|
|
tlb_offset(INVALID_OFFSET),
|
|
|
|
current_offset(INVALID_OFFSET),
|
|
|
|
is_dirty(0)
|
2006-12-17 11:17:28 +03:00
|
|
|
{
|
2013-11-03 11:41:29 +04:00
|
|
|
if (sizeof(_VM4_Header) != 77) {
|
2013-11-01 15:34:51 +04:00
|
|
|
BX_PANIC(("system error: invalid header structure size"));
|
|
|
|
}
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
vmware4_image_t::~vmware4_image_t()
|
|
|
|
{
|
2012-09-20 01:05:18 +04:00
|
|
|
close();
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
2012-10-07 22:36:22 +04:00
|
|
|
int vmware4_image_t::open(const char* _pathname, int flags)
|
2006-12-17 11:17:28 +03:00
|
|
|
{
|
2012-10-07 22:36:22 +04:00
|
|
|
Bit64u imgsize = 0;
|
|
|
|
|
2012-09-25 20:24:19 +04:00
|
|
|
pathname = _pathname;
|
2012-09-20 01:05:18 +04:00
|
|
|
close();
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-10-07 22:36:22 +04:00
|
|
|
file_descriptor = hdimage_open_file(pathname, flags, &imgsize, &mtime);
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
if (!is_open())
|
|
|
|
return -1;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-10-06 14:12:36 +04:00
|
|
|
if (!read_header()) {
|
2012-09-20 01:05:18 +04:00
|
|
|
BX_PANIC(("unable to read vmware4 virtual disk header from file '%s'", pathname));
|
2012-10-06 14:12:36 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
tlb = new Bit8u[(unsigned)header.tlb_size_sectors * SECTOR_SIZE];
|
|
|
|
if (tlb == 0)
|
|
|
|
BX_PANIC(("unable to allocate " FMT_LL "d bytes for vmware4 image's tlb", header.tlb_size_sectors * SECTOR_SIZE));
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
tlb_offset = INVALID_OFFSET;
|
|
|
|
current_offset = 0;
|
|
|
|
is_dirty = 0;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
hd_size = header.total_sectors * SECTOR_SIZE;
|
2013-10-27 23:23:59 +04:00
|
|
|
cylinders = (unsigned)(header.total_sectors / (16 * 63));
|
2012-09-20 01:05:18 +04:00
|
|
|
heads = 16;
|
|
|
|
spt = 63;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
BX_DEBUG(("VMware 4 disk geometry:"));
|
|
|
|
BX_DEBUG((" .size = " FMT_LL "d", hd_size));
|
|
|
|
BX_DEBUG((" .cylinders = %d", cylinders));
|
|
|
|
BX_DEBUG((" .heads = %d", heads));
|
|
|
|
BX_DEBUG((" .sectors = %d", spt));
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
return 1;
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void vmware4_image_t::close()
|
|
|
|
{
|
2012-09-20 01:05:18 +04:00
|
|
|
if (file_descriptor == -1)
|
|
|
|
return;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
flush();
|
|
|
|
delete [] tlb; tlb = 0;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
::close(file_descriptor);
|
|
|
|
file_descriptor = -1;
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit64s vmware4_image_t::lseek(Bit64s offset, int whence)
|
|
|
|
{
|
2012-09-20 01:05:18 +04:00
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET:
|
|
|
|
current_offset = (off_t)offset;
|
|
|
|
return current_offset;
|
|
|
|
case SEEK_CUR:
|
|
|
|
current_offset += (off_t)offset;
|
|
|
|
return current_offset;
|
|
|
|
case SEEK_END:
|
|
|
|
current_offset = header.total_sectors * SECTOR_SIZE + (off_t)offset;
|
|
|
|
return current_offset;
|
|
|
|
default:
|
|
|
|
BX_DEBUG(("unknown 'whence' value (%d) when trying to seek vmware4 image", whence));
|
|
|
|
return INVALID_OFFSET;
|
|
|
|
}
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t vmware4_image_t::read(void * buf, size_t count)
|
|
|
|
{
|
2015-10-15 20:21:34 +03:00
|
|
|
char *cbuf = (char*)buf;
|
2012-09-20 01:05:18 +04:00
|
|
|
ssize_t total = 0;
|
|
|
|
while (count > 0) {
|
|
|
|
off_t readable = perform_seek();
|
|
|
|
if (readable == INVALID_OFFSET) {
|
|
|
|
BX_DEBUG(("vmware4 disk image read failed on %u bytes at " FMT_LL "d", (unsigned)count, current_offset));
|
|
|
|
return -1;
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
2012-09-20 01:05:18 +04:00
|
|
|
|
|
|
|
off_t copysize = ((off_t)count > readable) ? readable : count;
|
2015-10-15 20:21:34 +03:00
|
|
|
memcpy(cbuf, tlb + current_offset - tlb_offset, (size_t)copysize);
|
2012-09-20 01:05:18 +04:00
|
|
|
|
|
|
|
current_offset += copysize;
|
|
|
|
total += (long)copysize;
|
2015-10-15 20:21:34 +03:00
|
|
|
cbuf += copysize;
|
2012-09-20 01:05:18 +04:00
|
|
|
count -= (size_t)copysize;
|
|
|
|
}
|
|
|
|
return total;
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t vmware4_image_t::write(const void * buf, size_t count)
|
|
|
|
{
|
2015-10-15 20:21:34 +03:00
|
|
|
char *cbuf = (char*)buf;
|
2012-09-20 01:05:18 +04:00
|
|
|
ssize_t total = 0;
|
|
|
|
while (count > 0) {
|
|
|
|
off_t writable = perform_seek();
|
|
|
|
if (writable == INVALID_OFFSET) {
|
|
|
|
BX_DEBUG(("vmware4 disk image write failed on %u bytes at " FMT_LL "d", (unsigned)count, current_offset));
|
|
|
|
return -1;
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
2012-09-20 01:05:18 +04:00
|
|
|
|
|
|
|
off_t writesize = ((off_t)count > writable) ? writable : count;
|
2015-10-15 20:21:34 +03:00
|
|
|
memcpy(tlb + current_offset - tlb_offset, cbuf, (size_t)writesize);
|
2012-09-20 01:05:18 +04:00
|
|
|
|
|
|
|
current_offset += writesize;
|
|
|
|
total += (long)writesize;
|
2015-10-15 20:21:34 +03:00
|
|
|
cbuf += writesize;
|
2012-09-20 01:05:18 +04:00
|
|
|
count -= (size_t)writesize;
|
|
|
|
is_dirty = 1;
|
|
|
|
}
|
|
|
|
return total;
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
2012-10-06 14:12:36 +04:00
|
|
|
int vmware4_image_t::check_format(int fd, Bit64u imgsize)
|
2006-12-17 11:17:28 +03:00
|
|
|
{
|
2012-10-06 14:12:36 +04:00
|
|
|
VM4_Header temp_header;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-10-06 14:12:36 +04:00
|
|
|
if (bx_read_image(fd, 0, &temp_header, sizeof(VM4_Header)) != sizeof(VM4_Header)) {
|
|
|
|
return HDIMAGE_READ_ERROR;
|
2012-09-20 01:05:18 +04:00
|
|
|
}
|
2012-10-06 14:12:36 +04:00
|
|
|
if ((temp_header.id[0] != 'K') || (temp_header.id[1] != 'D') ||
|
|
|
|
(temp_header.id[2] != 'M') || (temp_header.id[3] != 'V')) {
|
|
|
|
return HDIMAGE_NO_SIGNATURE;
|
|
|
|
}
|
2012-10-07 15:38:55 +04:00
|
|
|
temp_header.version = dtoh32(temp_header.version);
|
2012-10-06 14:12:36 +04:00
|
|
|
if (temp_header.version != 1) {
|
|
|
|
return HDIMAGE_VERSION_ERROR;
|
2012-09-20 01:05:18 +04:00
|
|
|
}
|
2012-10-06 14:12:36 +04:00
|
|
|
return HDIMAGE_FORMAT_OK;
|
|
|
|
}
|
2012-09-20 01:05:18 +04:00
|
|
|
|
2012-10-06 14:12:36 +04:00
|
|
|
bx_bool vmware4_image_t::is_open() const
|
|
|
|
{
|
|
|
|
return (file_descriptor != -1);
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
bx_bool vmware4_image_t::read_header()
|
2006-12-17 11:17:28 +03:00
|
|
|
{
|
2012-10-06 14:12:36 +04:00
|
|
|
int ret;
|
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
if (!is_open())
|
|
|
|
BX_PANIC(("attempt to read vmware4 header from a closed file"));
|
|
|
|
|
2012-10-06 14:12:36 +04:00
|
|
|
if ((ret = check_format(file_descriptor, 0)) != HDIMAGE_FORMAT_OK) {
|
|
|
|
switch (ret) {
|
|
|
|
case HDIMAGE_READ_ERROR:
|
|
|
|
BX_ERROR(("vmware4 image read error"));
|
|
|
|
break;
|
|
|
|
case HDIMAGE_NO_SIGNATURE:
|
|
|
|
BX_ERROR(("not a vmware4 image"));
|
|
|
|
break;
|
|
|
|
case HDIMAGE_VERSION_ERROR:
|
|
|
|
BX_ERROR(("unsupported vmware4 image version"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bx_read_image(file_descriptor, 0, &header, sizeof(VM4_Header)) != sizeof(VM4_Header))
|
2012-09-20 01:05:18 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
header.version = dtoh32(header.version);
|
|
|
|
header.flags = dtoh32(header.flags);
|
|
|
|
header.total_sectors = dtoh64(header.total_sectors);
|
|
|
|
header.tlb_size_sectors = dtoh64(header.tlb_size_sectors);
|
|
|
|
header.description_offset_sectors = dtoh64(header.description_offset_sectors);
|
|
|
|
header.description_size_sectors = dtoh64(header.description_size_sectors);
|
|
|
|
header.slb_count = dtoh32(header.slb_count);
|
|
|
|
header.flb_offset_sectors = dtoh64(header.flb_offset_sectors);
|
|
|
|
header.flb_copy_offset_sectors = dtoh64(header.flb_copy_offset_sectors);
|
|
|
|
header.tlb_offset_sectors = dtoh64(header.tlb_offset_sectors);
|
|
|
|
|
|
|
|
BX_DEBUG(("VM4_Header (size=%u)", (unsigned)sizeof(VM4_Header)));
|
|
|
|
BX_DEBUG((" .version = %d", header.version));
|
|
|
|
BX_DEBUG((" .flags = %d", header.flags));
|
|
|
|
BX_DEBUG((" .total_sectors = " FMT_LL "d", header.total_sectors));
|
|
|
|
BX_DEBUG((" .tlb_size_sectors = " FMT_LL "d", header.tlb_size_sectors));
|
|
|
|
BX_DEBUG((" .description_offset_sectors = " FMT_LL "d", header.description_offset_sectors));
|
|
|
|
BX_DEBUG((" .description_size_sectors = " FMT_LL "d", header.description_size_sectors));
|
|
|
|
BX_DEBUG((" .slb_count = %d", header.slb_count));
|
|
|
|
BX_DEBUG((" .flb_offset_sectors = " FMT_LL "d", header.flb_offset_sectors));
|
|
|
|
BX_DEBUG((" .flb_copy_offset_sectors = " FMT_LL "d", header.flb_copy_offset_sectors));
|
|
|
|
BX_DEBUG((" .tlb_offset_sectors = " FMT_LL "d", header.tlb_offset_sectors));
|
|
|
|
|
|
|
|
return 1;
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Returns the number of bytes that can be read from the current offset before needing
|
|
|
|
// to perform another seek.
|
|
|
|
//
|
|
|
|
off_t vmware4_image_t::perform_seek()
|
|
|
|
{
|
2012-09-20 01:05:18 +04:00
|
|
|
if (current_offset == INVALID_OFFSET) {
|
|
|
|
BX_DEBUG(("invalid offset specified in vmware4 seek"));
|
|
|
|
return INVALID_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// The currently loaded tlb can service the request.
|
|
|
|
//
|
|
|
|
if (tlb_offset / (header.tlb_size_sectors * SECTOR_SIZE) == current_offset / (header.tlb_size_sectors * SECTOR_SIZE))
|
|
|
|
return (header.tlb_size_sectors * SECTOR_SIZE) - (current_offset - tlb_offset);
|
|
|
|
|
|
|
|
flush();
|
|
|
|
|
|
|
|
Bit64u index = current_offset / (header.tlb_size_sectors * SECTOR_SIZE);
|
|
|
|
Bit32u slb_index = (Bit32u)(index % header.slb_count);
|
|
|
|
Bit32u flb_index = (Bit32u)(index / header.slb_count);
|
|
|
|
|
|
|
|
Bit32u slb_sector = read_block_index(header.flb_offset_sectors, flb_index);
|
|
|
|
Bit32u slb_copy_sector = read_block_index(header.flb_copy_offset_sectors, flb_index);
|
|
|
|
|
|
|
|
if (slb_sector == 0 && slb_copy_sector == 0) {
|
|
|
|
BX_DEBUG(("loaded vmware4 disk image requires un-implemented feature"));
|
|
|
|
return INVALID_OFFSET;
|
|
|
|
}
|
|
|
|
if (slb_sector == 0)
|
|
|
|
slb_sector = slb_copy_sector;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
Bit32u tlb_sector = read_block_index(slb_sector, slb_index);
|
|
|
|
tlb_offset = index * header.tlb_size_sectors * SECTOR_SIZE;
|
|
|
|
if (tlb_sector == 0) {
|
2006-12-17 11:17:28 +03:00
|
|
|
//
|
2012-09-20 01:05:18 +04:00
|
|
|
// Allocate a new tlb
|
2006-12-17 11:17:28 +03:00
|
|
|
//
|
2012-09-20 01:05:18 +04:00
|
|
|
memset(tlb, 0, (size_t)header.tlb_size_sectors * SECTOR_SIZE);
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
//
|
|
|
|
// Instead of doing a write to increase the file size, we could use
|
|
|
|
// ftruncate but it is not portable.
|
|
|
|
//
|
|
|
|
off_t eof = ((::lseek(file_descriptor, 0, SEEK_END) + SECTOR_SIZE - 1) / SECTOR_SIZE) * SECTOR_SIZE;
|
|
|
|
::write(file_descriptor, tlb, (unsigned)header.tlb_size_sectors * SECTOR_SIZE);
|
|
|
|
tlb_sector = (Bit32u)eof / SECTOR_SIZE;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
write_block_index(slb_sector, slb_index, tlb_sector);
|
|
|
|
write_block_index(slb_copy_sector, slb_index, tlb_sector);
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
::lseek(file_descriptor, eof, SEEK_SET);
|
|
|
|
} else {
|
|
|
|
::lseek(file_descriptor, tlb_sector * SECTOR_SIZE, SEEK_SET);
|
|
|
|
::read(file_descriptor, tlb, (unsigned)header.tlb_size_sectors * SECTOR_SIZE);
|
|
|
|
::lseek(file_descriptor, tlb_sector * SECTOR_SIZE, SEEK_SET);
|
|
|
|
}
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
return (header.tlb_size_sectors * SECTOR_SIZE) - (current_offset - tlb_offset);
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void vmware4_image_t::flush()
|
|
|
|
{
|
2012-09-20 01:05:18 +04:00
|
|
|
if (!is_dirty)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Write dirty sectors to disk first. Assume that the file is already at the
|
|
|
|
// position for the current tlb.
|
|
|
|
//
|
|
|
|
::write(file_descriptor, tlb, (unsigned)header.tlb_size_sectors * SECTOR_SIZE);
|
|
|
|
is_dirty = 0;
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u vmware4_image_t::read_block_index(Bit64u sector, Bit32u index)
|
|
|
|
{
|
2012-09-20 01:05:18 +04:00
|
|
|
Bit32u ret;
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
bx_read_image(file_descriptor, sector * SECTOR_SIZE + index * sizeof(Bit32u),
|
|
|
|
&ret, sizeof(Bit32u));
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
return dtoh32(ret);
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void vmware4_image_t::write_block_index(Bit64u sector, Bit32u index, Bit32u block_sector)
|
|
|
|
{
|
2012-09-20 01:05:18 +04:00
|
|
|
block_sector = htod32(block_sector);
|
2006-12-17 11:17:28 +03:00
|
|
|
|
2012-09-20 01:05:18 +04:00
|
|
|
bx_write_image(file_descriptor, sector * SECTOR_SIZE + index * sizeof(Bit32u),
|
|
|
|
&block_sector, sizeof(Bit32u));
|
2006-12-17 11:17:28 +03:00
|
|
|
}
|
2010-12-22 00:47:41 +03:00
|
|
|
|
|
|
|
Bit32u vmware4_image_t::get_capabilities(void)
|
|
|
|
{
|
|
|
|
return HDIMAGE_HAS_GEOMETRY;
|
|
|
|
}
|
2012-09-20 01:05:18 +04:00
|
|
|
|
2013-10-13 18:33:55 +04:00
|
|
|
#ifndef BXIMAGE
|
2012-09-20 01:05:18 +04:00
|
|
|
bx_bool vmware4_image_t::save_state(const char *backup_fname)
|
|
|
|
{
|
|
|
|
return hdimage_backup_file(file_descriptor, backup_fname);
|
|
|
|
}
|
2012-09-25 20:24:19 +04:00
|
|
|
|
|
|
|
void vmware4_image_t::restore_state(const char *backup_fname)
|
|
|
|
{
|
2012-10-06 14:12:36 +04:00
|
|
|
int temp_fd;
|
|
|
|
Bit64u imgsize;
|
2012-09-25 20:24:19 +04:00
|
|
|
|
2012-10-06 14:12:36 +04:00
|
|
|
if ((temp_fd = hdimage_open_file(backup_fname, O_RDONLY, &imgsize, NULL)) < 0) {
|
|
|
|
BX_PANIC(("Cannot open vmware4 image backup '%s'", backup_fname));
|
2012-09-25 20:24:19 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-10-06 14:12:36 +04:00
|
|
|
|
|
|
|
if (check_format(temp_fd, imgsize) < HDIMAGE_FORMAT_OK) {
|
|
|
|
::close(temp_fd);
|
|
|
|
BX_PANIC(("Cannot detect vmware4 image header"));
|
2012-09-25 20:24:19 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-10-06 14:12:36 +04:00
|
|
|
::close(temp_fd);
|
2012-09-25 20:24:19 +04:00
|
|
|
close();
|
2012-09-26 20:20:38 +04:00
|
|
|
if (!hdimage_copy_file(backup_fname, pathname)) {
|
|
|
|
BX_PANIC(("Failed to restore vmware4 image '%s'", pathname));
|
|
|
|
return;
|
|
|
|
}
|
2012-10-07 22:36:22 +04:00
|
|
|
device_image_t::open(pathname);
|
2012-09-25 20:24:19 +04:00
|
|
|
}
|
2013-10-13 18:33:55 +04:00
|
|
|
#endif
|