Skip to content

Commit

Permalink
Fix getSizePhys and size in calcOverheadEmpty
Browse files Browse the repository at this point in the history
getSizePhys now uses os.stat instead of du, it would not have worked on
a block device instead of a file
calcOverheadEmpty used hardcoded value for cluster size

Signed-off-by: Damien Thenot <[email protected]>
  • Loading branch information
Nambrok committed Jan 23, 2025
1 parent 5e4f9e9 commit c39ba90
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions drivers/qcow2util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import struct
from pathlib import Path
import zlib
import os

import util
from cowutil import CowUtil, CowImageInfo
Expand Down Expand Up @@ -424,8 +425,8 @@ def getMaxChainLength(self) -> int:

@override
def calcOverheadEmpty(self, virtual_size: int) -> int:
size_l1 = 64 * 1024
size_header = 64 * 1024
size_l1 = QCOW_CLUSTER_SIZE
size_header = QCOW_CLUSTER_SIZE
size_l2 = (virtual_size * 8) / QCOW_CLUSTER_SIZE #It is only an estimation

size = size_l1 + size_l2 + size_header
Expand Down Expand Up @@ -588,9 +589,7 @@ def getMaxResizeSize(self, path: str) -> int:

@override
def getSizePhys(self, path: str) -> int:
cmd = ["du", "-b", path] #TODO: use os.stat instead since it won't work with a block device
ret = cast(str, self._ioretry(cmd))
return int(ret.split()[0])
return os.stat(path).st_size

@override
def setSizePhys(self, path: str, size: int, debug: bool = True) -> None:
Expand Down

0 comments on commit c39ba90

Please sign in to comment.