- implemented restore function for 'vmeare3' mode images

- 'vmware4' image mode: handle restore failure
This commit is contained in:
Volker Ruppert 2012-09-26 16:20:38 +00:00
parent 8189a5ed20
commit 35ec96f740
2 changed files with 44 additions and 3 deletions

View File

@ -539,6 +539,44 @@ bx_bool vmware3_image_t::save_state(const char *backup_fname)
void vmware3_image_t::restore_state(const char *backup_fname)
{
// TODO
BX_ERROR(("vmware3_image_t::restore_state(): UNIMPLEMENTED"));
int backup_fd;
bx_bool ret = 1;
COW_Header temp_header;
char tempfn[BX_PATHNAME_LEN];
backup_fd = ::open(backup_fname, O_RDONLY
#ifdef O_BINARY
| O_BINARY
#endif
);
if (backup_fd < 0) {
BX_PANIC(("Could not open vmware3 image backup"));
return;
}
if (read_header(backup_fd, temp_header) < 0) {
::close(backup_fd);
BX_PANIC(("Could not read vmware3 image header"));
return;
}
::close(backup_fd);
if (!is_valid_header(temp_header)) {
BX_PANIC(("invalid vmware3 COW Disk image"));
return;
}
unsigned count = current->header.number_of_chains;
close();
if (count < 1) count = 1;
for (unsigned i = 0; i < count; ++i) {
sprintf(tempfn, "%s%d", backup_fname, i);
char *filename = generate_cow_name(pathname, i);
ret &= hdimage_copy_file(tempfn, filename);
delete [] filename;
if (ret == 0) {
BX_PANIC(("Failed to restore vmware3 image '%s'", filename));
break;
}
}
if (ret == 1) {
open(pathname);
}
}

View File

@ -352,6 +352,9 @@ void vmware4_image_t::restore_state(const char *backup_fname)
return;
}
close();
hdimage_copy_file(backup_fname, pathname);
if (!hdimage_copy_file(backup_fname, pathname)) {
BX_PANIC(("Failed to restore vmware4 image '%s'", pathname));
return;
}
open(pathname);
}