Minor but important changes to minivhd's dynamic/diff vhd handling
1. Changed the first seek_end in create_block to seek_set. 2. Avoid expansion overflow through a check if the block offset is below the total sectors.
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
#ifndef _FILE_OFFSET_BITS
|
#ifndef _FILE_OFFSET_BITS
|
||||||
# define _FILE_OFFSET_BITS 64
|
# define _FILE_OFFSET_BITS 64
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -45,6 +46,10 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "minivhd.h"
|
#include "minivhd.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#define HAVE_STDARG_H
|
||||||
|
|
||||||
|
#include "cpu.h"
|
||||||
|
#include <86box/86box.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following bit array macros adapted from:
|
* The following bit array macros adapted from:
|
||||||
@@ -158,7 +163,7 @@ create_block(MVHDMeta *vhdm, int blk)
|
|||||||
uint8_t footer[MVHD_FOOTER_SIZE] = { 0 };
|
uint8_t footer[MVHD_FOOTER_SIZE] = { 0 };
|
||||||
|
|
||||||
/* Seek to where the footer SHOULD be */
|
/* Seek to where the footer SHOULD be */
|
||||||
mvhd_fseeko64(vhdm->f, -MVHD_FOOTER_SIZE, SEEK_END);
|
mvhd_fseeko64(vhdm->f, -MVHD_FOOTER_SIZE, SEEK_SET);
|
||||||
(void) !fread(footer, sizeof footer, 1, vhdm->f);
|
(void) !fread(footer, sizeof footer, 1, vhdm->f);
|
||||||
mvhd_fseeko64(vhdm->f, -MVHD_FOOTER_SIZE, SEEK_END);
|
mvhd_fseeko64(vhdm->f, -MVHD_FOOTER_SIZE, SEEK_END);
|
||||||
|
|
||||||
@@ -334,6 +339,7 @@ mvhd_sparse_diff_write(MVHDMeta *vhdm, uint32_t offset, int num_sectors, void *i
|
|||||||
int sib = 0;
|
int sib = 0;
|
||||||
ls = offset + transfer_sectors;
|
ls = offset + transfer_sectors;
|
||||||
|
|
||||||
|
if (offset < total_sectors) {
|
||||||
for (s = offset; s < ls; s++) {
|
for (s = offset; s < ls; s++) {
|
||||||
blk = s / vhdm->sect_per_block;
|
blk = s / vhdm->sect_per_block;
|
||||||
sib = s % vhdm->sect_per_block;
|
sib = s % vhdm->sect_per_block;
|
||||||
@@ -365,6 +371,7 @@ mvhd_sparse_diff_write(MVHDMeta *vhdm, uint32_t offset, int num_sectors, void *i
|
|||||||
VHD_SETBIT(vhdm->bitmap.curr_bitmap, sib);
|
VHD_SETBIT(vhdm->bitmap.curr_bitmap, sib);
|
||||||
buff += MVHD_SECTOR_SIZE;
|
buff += MVHD_SECTOR_SIZE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* And write the sector bitmap for the last block we visited to disk */
|
/* And write the sector bitmap for the last block we visited to disk */
|
||||||
write_curr_sect_bitmap(vhdm);
|
write_curr_sect_bitmap(vhdm);
|
||||||
|
Reference in New Issue
Block a user