diff options
-rw-r--r-- | include/migration/qemu-file.h | 1 | ||||
-rw-r--r-- | savevm.c | 9 |
2 files changed, 8 insertions, 2 deletions
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 68deefbcfb..46fc11dc99 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -81,6 +81,7 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); +int64_t qemu_ftell(QEMUFile *f); void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); void qemu_put_byte(QEMUFile *f, int v); @@ -673,9 +673,14 @@ int qemu_get_byte(QEMUFile *f) return result; } -static int64_t qemu_ftell(QEMUFile *f) +int64_t qemu_ftell(QEMUFile *f) { - return f->buf_offset - f->buf_size + f->buf_index; + /* buf_offset excludes buffer for writing but includes it for reading */ + if (f->is_write) { + return f->buf_offset + f->buf_index; + } else { + return f->buf_offset - f->buf_size + f->buf_index; + } } int qemu_file_rate_limit(QEMUFile *f) |