From 60bb258646981dc2f94faa9add45e988a36f9b44 Mon Sep 17 00:00:00 2001 From: maxpat78 Date: Tue, 17 Oct 2023 17:16:36 +0200 Subject: [PATCH] Bugs fixed in vhdutils and vdiutils - avoid infinite loop when searching for parent VDI - VHD block bitmap is now flushed only when a "real" block is written to - a virtual block in a Differencing VHD is now kept as such only if parent's block itself is virtual --- FATtools/vdiutils.py | 1 + FATtools/version.py | 2 +- FATtools/vhdutils.py | 11 ++++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/FATtools/vdiutils.py b/FATtools/vdiutils.py index 310ec9c..8302b96 100644 --- a/FATtools/vdiutils.py +++ b/FATtools/vdiutils.py @@ -210,6 +210,7 @@ def __init__ (self, name, mode='rb'): if self.header.dwImageType == 4: # Differencing VDI parent='' for vdi in glob.glob('./*.vdi'): + if vdi.lower() == name.lower(): continue parent=vdi o=Image(vdi, "rb") if o.header.sUuidCreate == self.header.sUuidLinkage: diff --git a/FATtools/version.py b/FATtools/version.py index a5ff605..9b6193c 100644 --- a/FATtools/version.py +++ b/FATtools/version.py @@ -1 +1 @@ -__version__ = '1.0.29' \ No newline at end of file +__version__ = '1.0.30' \ No newline at end of file diff --git a/FATtools/vhdutils.py b/FATtools/vhdutils.py index a96d3dd..cb341bb 100644 --- a/FATtools/vhdutils.py +++ b/FATtools/vhdutils.py @@ -586,8 +586,8 @@ def write1(self, s): put=size size=0 if block == 0xFFFFFFFF: - # we keep a block virtualized until we write zeros - if s[i:i+put] == self.zero[:put]: + # we can keep a block virtualized until PARENT'S IS VIRTUALIZED AND we write zeros + if self.Parent.bat[self._pos//self.block] == 0xFFFFFFFF and s[i:i+put] == self.zero[:put]: i+=put self._pos+=put if DEBUG&16: log("block #%d @0x%X is zeroed, virtualizing write", self._pos//self.block, (block*self.block)+self.header.u64TableOffset) @@ -632,9 +632,10 @@ def copysect(vpos, sec): self.stream.write(s[i:i+put]) i+=put self._pos+=put - if DEBUG&16: log("%s: flushing bitmap for block #%d at end", self.name, bmp.i) - self.stream.seek(bmp.i*512) - self.stream.write(bmp.bmp) + if bmp: # None if virtual writes only! + if DEBUG&16: log("%s: flushing bitmap for block #%d at end", self.name, bmp.i) + self.stream.seek(bmp.i*512) + self.stream.write(bmp.bmp)