diff --git a/osbuild/loop.py b/osbuild/loop.py index eb89b7a0..9750be6e 100644 --- a/osbuild/loop.py +++ b/osbuild/loop.py @@ -208,8 +208,7 @@ class Loop: unchanged (default is None) """ - info = LoopInfo() - fcntl.ioctl(self.fd, self.LOOP_GET_STATUS64, info) + info = self.get_status() if offset: info.lo_offset = offset if sizelimit: @@ -226,6 +225,17 @@ class Loop: info.lo_flags &= ~self.LO_FLAGS_PARTSCAN fcntl.ioctl(self.fd, self.LOOP_SET_STATUS64, info) + def get_status(self) -> LoopInfo: + """Get properties of the loopback device + + Return a `LoopInfo` structure with the information of this + loopback device. See loop(4) for more information. + """ + + info = LoopInfo() + fcntl.ioctl(self.fd, self.LOOP_GET_STATUS64, info) + return info + def set_direct_io(self, dio=True): """Set the direct-IO property on the loopback device diff --git a/test/mod/test_loop.py b/test/mod/test_loop.py index e8ad1493..e5f9f730 100644 --- a/test/mod/test_loop.py +++ b/test/mod/test_loop.py @@ -4,8 +4,6 @@ import contextlib import os - - from tempfile import TemporaryDirectory import pytest @@ -39,9 +37,15 @@ def test_basic(tempdir): f.flush() lo = ctl.loop_for_fd(f.fileno()) + sb = os.fstat(f.fileno()) + assert lo assert lo.devname + info = lo.get_status() + assert info.lo_inode == sb.st_ino + assert info.lo_number == lo.minor + finally: if lo: with contextlib.suppress(OSError):