|
@@ -33,6 +33,12 @@ import qubes.utils
|
|
|
|
|
|
BLKSIZE = 512
|
|
|
|
|
|
+# 256 KiB chunk, same as in block-snapshot script. Header created by
|
|
|
+# struct.pack('<4I', 0x70416e53, 1, 1, 256) mimicking write_header()
|
|
|
+# in linux/drivers/md/dm-snap-persistent.c
|
|
|
+EMPTY_SNAPSHOT = b'SnAp\x01\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00' \
|
|
|
+ + bytes(262128)
|
|
|
+
|
|
|
|
|
|
class FilePool(qubes.storage.Pool):
|
|
|
''' File based 'original' disk implementation
|
|
@@ -217,7 +223,10 @@ class FileVolume(qubes.storage.Volume):
|
|
|
if self.save_on_stop:
|
|
|
with suppress(FileNotFoundError), open(self.path_cow, 'rb') as cow:
|
|
|
cow_used = os.fstat(cow.fileno()).st_blocks * BLKSIZE
|
|
|
- return cow_used > 0
|
|
|
+ return (cow_used > 0 and
|
|
|
+ (cow_used > len(EMPTY_SNAPSHOT) or
|
|
|
+ cow.read(len(EMPTY_SNAPSHOT)) != EMPTY_SNAPSHOT or
|
|
|
+ cow_used > cow.seek(0, os.SEEK_HOLE)))
|
|
|
return False
|
|
|
|
|
|
def resize(self, size):
|