mirror of https://github.com/trapexit/mergerfs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.6 KiB
68 lines
1.6 KiB
#!/usr/bin/env python3
|
|
|
|
import errno
|
|
import fcntl
|
|
import os
|
|
import struct
|
|
import sys
|
|
import tempfile
|
|
|
|
from posix_parity import compare_calls
|
|
from posix_parity import fail
|
|
from posix_parity import join
|
|
from posix_parity import touch
|
|
|
|
|
|
FIBMAP = 1
|
|
|
|
|
|
def fibmap(fd, block=0):
|
|
buf = struct.pack("i", block)
|
|
out = fcntl.ioctl(fd, FIBMAP, buf)
|
|
return struct.unpack("i", out)[0]
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) != 2:
|
|
print("usage: TEST_posix_bmap <mountpoint>", file=sys.stderr)
|
|
return 1
|
|
|
|
mount = sys.argv[1]
|
|
|
|
with tempfile.TemporaryDirectory() as native:
|
|
merge_file = join(mount, "posix-bmap/file")
|
|
native_file = join(native, "posix-bmap/file")
|
|
touch(merge_file, b"x" * 8192)
|
|
touch(native_file, b"x" * 8192)
|
|
|
|
mfd = os.open(merge_file, os.O_RDONLY)
|
|
nfd = os.open(native_file, os.O_RDONLY)
|
|
try:
|
|
# FIBMAP often requires CAP_SYS_RAWIO; compare errno parity if denied.
|
|
err = compare_calls(
|
|
"ioctl FIBMAP block0",
|
|
lambda: fibmap(mfd, 0),
|
|
lambda: fibmap(nfd, 0),
|
|
lambda a, b: (a >= 0) == (b >= 0),
|
|
)
|
|
if err:
|
|
# If both denied by privilege checks, compare_calls already passes.
|
|
return fail(err)
|
|
finally:
|
|
os.close(mfd)
|
|
os.close(nfd)
|
|
|
|
# EBADF parity on closed fds.
|
|
err = compare_calls(
|
|
"ioctl FIBMAP EBADF",
|
|
lambda: fibmap(mfd, 0),
|
|
lambda: fibmap(nfd, 0),
|
|
)
|
|
if err:
|
|
return fail(err)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|