loop: add autoclear propert to LoopInfo

Small convenience property to check if the autoclear flag is set
in the `lo_flags` member of the `LoopInfo`.
Also add a corresponding test for it.
This commit is contained in:
Christian Kellner 2021-08-08 09:11:40 +00:00 committed by Tom Gundersen
parent 62082733e9
commit 61d5f15420
2 changed files with 13 additions and 1 deletions

View file

@ -38,6 +38,11 @@ class LoopInfo(ctypes.Structure):
('lo_init', ctypes.c_uint64 * 2)
]
@property
def autoclear(self) -> bool:
"""Return if `LO_FLAGS_AUTOCLEAR` is set in `lo_flags`"""
return bool(self.lo_flags & Loop.LO_FLAGS_AUTOCLEAR)
class Loop:
"""Loopback device

View file

@ -35,7 +35,7 @@ def test_basic(tempdir):
f = open(path, "wb+")
f.truncate(1024)
f.flush()
lo = ctl.loop_for_fd(f.fileno())
lo = ctl.loop_for_fd(f.fileno(), autoclear=True)
sb = os.fstat(f.fileno())
@ -46,6 +46,13 @@ def test_basic(tempdir):
assert info.lo_inode == sb.st_ino
assert info.lo_number == lo.minor
# check for autoclear flags setting and helpers
assert info.autoclear
lo.set_status(autoclear=False)
info = lo.get_status()
assert not info.autoclear
finally:
if lo:
with contextlib.suppress(OSError):