Skip to content

Commit

Permalink
Fixes "zero optimization" bug
Browse files Browse the repository at this point in the history
The full VHD chain is now checked for absence of a block to keep virtual
  • Loading branch information
maxpat78 committed Oct 20, 2023
1 parent 99fac9a commit cf0d081
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/bios_disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class imageDiskVHD : public imageDisk {
virtual bool loadBlock(const uint32_t blockNumber);
static bool convert_UTF16_for_fopen(std::string &string, const void* data, const uint32_t dataLength);
bool is_zeroed_sector(const void* data);
bool is_block_allocated(uint32_t blockNumber);

imageDisk* parentDisk = NULL;
imageDisk* fixedDisk = NULL;
Expand Down
13 changes: 11 additions & 2 deletions src/ints/bios_vhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,23 @@ bool imageDiskVHD::is_zeroed_sector(const void* data) {
return true;
}

bool imageDiskVHD::is_block_allocated(uint32_t blockNumber) {
if(currentBlockAllocated) return true;
if(parentDisk && ((imageDiskVHD*) parentDisk)->is_block_allocated(blockNumber)) return true;
return false;
}

uint8_t imageDiskVHD::Write_AbsoluteSector(uint32_t sectnum, const void * data) {
if(vhdType == VHD_TYPE_FIXED) return fixedDisk->Write_AbsoluteSector(sectnum, data);
uint32_t blockNumber = sectnum / sectorsPerBlock;
uint32_t sectorOffset = sectnum % sectorsPerBlock;
if (!loadBlock(blockNumber)) return 0x05; //can't load block
if (!currentBlockAllocated) {
//an unallocated block is kept virtualized until zeroed
if(is_zeroed_sector(data)) return 0;
//an unallocated block is kept virtual until zeroed
if(is_zeroed_sector(data)) {
if(vhdType != VHD_TYPE_DIFFERENCING) return 0;
if(!is_block_allocated(blockNumber)) return 0;
}

if (!copiedFooter) {
//write backup of footer at start of file (should already exist, but we never checked to be sure it is readable or matches the footer we used)
Expand Down

0 comments on commit cf0d081

Please sign in to comment.