diff --git a/bochs/iodev/hdimage/hdimage.cc b/bochs/iodev/hdimage/hdimage.cc index 899e07f38..b576f9ac9 100644 --- a/bochs/iodev/hdimage/hdimage.cc +++ b/bochs/iodev/hdimage/hdimage.cc @@ -352,9 +352,9 @@ int concat_image_t::open(const char* pathname0) for (int i=0; i -1) { - ::close(fd); + for (int index = 0; index < maxfd; index++) { + if (fd_table[index] > -1) { + ::close(fd_table[index]); + } } } @@ -412,24 +414,24 @@ Bit64s concat_image_t::lseek(Bit64s offset, int whence) // no, look at previous images for (int i=index-1; i>=0; i--) { if (offset >= start_offset_table[i]) { - index = i; - fd = fd_table[i]; - thismin = start_offset_table[i]; - thismax = thismin + length_table[i] - 1; - BX_DEBUG(("concat_image_t.lseek to earlier image, index=%d", index)); - break; + index = i; + fd = fd_table[i]; + thismin = start_offset_table[i]; + thismax = thismin + length_table[i] - 1; + BX_DEBUG(("concat_image_t.lseek to earlier image, index=%d", index)); + break; } } } else if (offset > thismax) { // no, look at later images for (int i=index+1; i 0) ? 1 : 0; + } else { + return hdimage_backup_file(fd, backup_fname); + } +} + +int sparse_image_t::save_state_specific(int index, const char *backup_fname) +{ + char tempfn[BX_PATHNAME_LEN]; + + if (parent_image != NULL) { + index = parent_image->save_state_specific(index, backup_fname); + if (index < 0) return -1; + } + sprintf(tempfn, "%s%d", backup_fname, index); + if (hdimage_backup_file(fd, tempfn) != 0) { + return ++index; + } else { + return -1; + } +} + #if DLL_HD_SUPPORT /*** dll_image_t function definitions ***/ @@ -1688,6 +1729,7 @@ int volatile_image_t::open(const char* pathname) { int filedes; const char *logname=NULL; + Bit32u timestamp; if (ro_disk->open(pathname, O_RDONLY)<0) return -1; @@ -1726,6 +1768,10 @@ int volatile_image_t::open(const char* pathname) unlink(redolog_temp); #endif + // timestamp required for save/restore support + timestamp = ro_disk->get_timestamp(); + redolog->set_timestamp(timestamp); + BX_INFO(("'volatile' disk opened: ro-file is '%s', redolog is '%s'", pathname, redolog_temp)); return 0; diff --git a/bochs/iodev/hdimage/hdimage.h b/bochs/iodev/hdimage/hdimage.h index e3832b56b..73614c85a 100644 --- a/bochs/iodev/hdimage/hdimage.h +++ b/bochs/iodev/hdimage/hdimage.h @@ -229,6 +229,9 @@ class concat_image_t : public device_image_t // written (count). ssize_t write(const void* buf, size_t count); + // Save/restore support + bx_bool save_state(const char *backup_fname); + private: #define BX_CONCAT_MAX_IMAGES 8 int fd_table[BX_CONCAT_MAX_IMAGES]; @@ -281,6 +284,10 @@ class sparse_image_t : public device_image_t // written (count). ssize_t write(const void* buf, size_t count); + // Save/restore support + bx_bool save_state(const char *backup_fname); + int save_state_specific(int index, const char *backup_fname); + private: int fd;