summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-06-12 08:28:41 +0300
committerDevaev Maxim <[email protected]>2019-06-12 08:28:41 +0300
commitf21f1d28365dcc6dc692eb1625f8079f4e583d68 (patch)
tree4cbde72324cb967855adf81098c996918c926f68 /kvmd
parent81a9e1fa07c4f37dd41737c821d161ba3e875e7c (diff)
Using BLKGETSIZE * BLKSSZGET instead of BLKGETSIZE64
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/kvmd/msd.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/kvmd/apps/kvmd/msd.py b/kvmd/apps/kvmd/msd.py
index 166a9cac..5f85662c 100644
--- a/kvmd/apps/kvmd/msd.py
+++ b/kvmd/apps/kvmd/msd.py
@@ -30,6 +30,7 @@ import dataclasses
import types
from typing import Dict
+from typing import IO
from typing import Callable
from typing import Type
from typing import AsyncGenerator
@@ -145,15 +146,21 @@ def _parse_image_info_bytes(data: bytes) -> Optional[_ImageInfo]:
return None
+def _ioctl_uint32(device_file: IO, request: int) -> int:
+ buf = b"\0" * 4
+ buf = fcntl.ioctl(device_file.fileno(), request, buf)
+ result = struct.unpack("I", buf)[0]
+ assert result > 0, (device_file, request, buf)
+ return result
+
+
def _explore_device(device_path: str) -> _MassStorageDeviceInfo:
if not stat.S_ISBLK(os.stat(device_path).st_mode):
raise RuntimeError("Not a block device: %s" % (device_path))
with open(device_path, "rb") as device_file:
- buf = b"\0" * 8
- buf = fcntl.ioctl(device_file.fileno(), 0x80081272, buf) # BLKGETSIZE64
- size = struct.unpack("L", buf)[0]
- assert size > 0, (size, buf)
+ # size = BLKGETSIZE * BLKSSZGET
+ size = _ioctl_uint32(device_file, 0x1260) * _ioctl_uint32(device_file, 0x1268)
device_file.seek(size - _IMAGE_INFO_SIZE)
image_info = _parse_image_info_bytes(device_file.read())