- implemented restore function for 'vmware4' mode images

- fixed restore function for 'sparse' mode images
- prepared restore functions for 'vmware3' and 'vpc' mode images
This commit is contained in:
Volker Ruppert 2012-09-25 16:24:19 +00:00
parent 08d0ef6dbf
commit 84cfd36d38
8 changed files with 60 additions and 5 deletions

View File

@ -1116,7 +1116,7 @@ void sparse_image_t::restore_state(const char *backup_fname)
sparse_header_t temp_header;
char *temp_pathname;
int backup_fd = ::open(pathname, O_RDWR
int backup_fd = ::open(backup_fname, O_RDONLY
#ifdef O_BINARY
| O_BINARY
#endif
@ -1126,15 +1126,16 @@ void sparse_image_t::restore_state(const char *backup_fname)
return;
}
if (::read(backup_fd, &temp_header, sizeof(header)) != sizeof(header)) {
::close(backup_fd);
BX_PANIC(("Could not read sparse image header"));
return;
}
::close(backup_fd);
if ((dtoh32(temp_header.magic) != SPARSE_HEADER_MAGIC) ||
(dtoh32(temp_header.version) != SPARSE_HEADER_VERSION)) {
BX_PANIC(("Could not detect sparse image header"));
return;
}
::close(backup_fd);
temp_pathname = strdup(pathname);
close();
if (!hdimage_copy_file(backup_fname, temp_pathname)) {

View File

@ -126,6 +126,7 @@
int bx_read_image(int fd, Bit64s offset, void *buf, int count);
int bx_write_image(int fd, Bit64s offset, void *buf, int count);
bx_bool hdimage_backup_file(int fd, const char *backup_fname);
bx_bool hdimage_copy_file(const char *src, const char *dst);
class device_image_t
{

View File

@ -183,7 +183,7 @@ char * vmware3_image_t::generate_cow_name(const char * filename, unsigned chain)
* file. Now if only I could use exceptions to handle the errors in an elegant
* fashion...
*/
int vmware3_image_t::open(const char * pathname)
int vmware3_image_t::open(const char* _pathname)
{
COW_Header header;
int file;
@ -192,6 +192,7 @@ int vmware3_image_t::open(const char * pathname)
flags |= O_BINARY;
#endif
pathname = _pathname;
// Set so close doesn't segfault, in case something goes wrong
images = NULL;
@ -535,3 +536,9 @@ bx_bool vmware3_image_t::save_state(const char *backup_fname)
}
return ret;
}
void vmware3_image_t::restore_state(const char *backup_fname)
{
// TODO
BX_ERROR(("vmware3_image_t::restore_state(): UNIMPLEMENTED"));
}

View File

@ -41,6 +41,7 @@ class vmware3_image_t : public device_image_t
ssize_t write(const void* buf, size_t count);
Bit32u get_capabilities();
bx_bool save_state(const char *backup_fname);
void restore_state(const char *backup_fname);
private:
static const off_t INVALID_OFFSET;
@ -123,5 +124,7 @@ class vmware3_image_t : public device_image_t
off_t requested_offset;
Bit32u slb_count;
Bit32u tlb_size;
const char *pathname;
};
#endif

View File

@ -54,8 +54,9 @@ vmware4_image_t::~vmware4_image_t()
close();
}
int vmware4_image_t::open(const char * pathname)
int vmware4_image_t::open(const char* _pathname)
{
pathname = _pathname;
close();
int flags = O_RDWR;
@ -324,3 +325,33 @@ bx_bool vmware4_image_t::save_state(const char *backup_fname)
{
return hdimage_backup_file(file_descriptor, backup_fname);
}
void vmware4_image_t::restore_state(const char *backup_fname)
{
VM4_Header temp_header;
int backup_fd = ::open(backup_fname, O_RDONLY
#ifdef O_BINARY
| O_BINARY
#endif
);
if (backup_fd < 0) {
BX_PANIC(("Could not open vmware4 image backup"));
return;
}
if (::read(backup_fd, &temp_header, sizeof(VM4_Header)) != sizeof(VM4_Header)) {
::close(backup_fd);
BX_PANIC(("Could not read vmware4 image header"));
return;
}
::close(backup_fd);
if ((temp_header.id[0] != 'K') || (temp_header.id[1] != 'D') ||
(temp_header.id[2] != 'M') || (temp_header.id[3] != 'V') ||
(header.version != 1)) {
BX_PANIC(("Could not detect vmware4 image header"));
return;
}
close();
hdimage_copy_file(backup_fname, pathname);
open(pathname);
}

View File

@ -42,6 +42,7 @@ class vmware4_image_t : public device_image_t
ssize_t write(const void* buf, size_t count);
Bit32u get_capabilities();
bx_bool save_state(const char *backup_fname);
void restore_state(const char *backup_fname);
private:
static const off_t INVALID_OFFSET;
@ -92,6 +93,7 @@ class vmware4_image_t : public device_image_t
off_t tlb_offset;
off_t current_offset;
bx_bool is_dirty;
const char *pathname;
};
#endif

View File

@ -52,7 +52,7 @@
#define cpu_to_be32(val) (val)
#endif
int vpc_image_t::open(const char* pathname)
int vpc_image_t::open(const char* _pathname)
{
int i;
vhd_footer_t *footer;
@ -62,6 +62,7 @@ int vpc_image_t::open(const char* pathname)
Bit64u imgsize;
int disk_type = VHD_DYNAMIC;
pathname = _pathname;
#ifdef WIN32
HANDLE hFile = CreateFile(pathname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
@ -296,6 +297,12 @@ bx_bool vpc_image_t::save_state(const char *backup_fname)
return hdimage_backup_file(fd, backup_fname);
}
void vpc_image_t::restore_state(const char *backup_fname)
{
// TODO
BX_ERROR(("vpc_image_t::restore_state(): UNIMPLEMENTED"));
}
Bit32u vpc_image_t::vpc_checksum(Bit8u *buf, size_t size)
{
Bit32u res = 0;

View File

@ -145,6 +145,7 @@ class vpc_image_t : public device_image_t
ssize_t write(const void* buf, size_t count);
Bit32u get_capabilities();
bx_bool save_state(const char *backup_fname);
void restore_state(const char *backup_fname);
private:
Bit32u vpc_checksum(Bit8u *buf, size_t size);
@ -164,6 +165,8 @@ class vpc_image_t : public device_image_t
Bit32u block_size;
Bit32u bitmap_size;
const char *pathname;
};
#endif