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.
59 lines
1.4 KiB
59 lines
1.4 KiB
#!/usr/bin/env python3
|
|
|
|
import ctypes
|
|
import os
|
|
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
|
|
|
|
|
|
libc = ctypes.CDLL(None, use_errno=True)
|
|
libc.syncfs.argtypes = [ctypes.c_int]
|
|
libc.syncfs.restype = ctypes.c_int
|
|
|
|
|
|
def syncfs_fd(fd):
|
|
ctypes.set_errno(0)
|
|
rv = libc.syncfs(fd)
|
|
if rv == 0:
|
|
return 0
|
|
err = ctypes.get_errno()
|
|
raise OSError(err, os.strerror(err))
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) != 2:
|
|
print("usage: TEST_posix_syncfs <mountpoint>", file=sys.stderr)
|
|
return 1
|
|
|
|
mount = sys.argv[1]
|
|
|
|
with tempfile.TemporaryDirectory() as native:
|
|
merge_file = join(mount, "posix-syncfs/file")
|
|
native_file = join(native, "posix-syncfs/file")
|
|
touch(merge_file, b"x")
|
|
touch(native_file, b"x")
|
|
|
|
mfd = os.open(merge_file, os.O_RDONLY)
|
|
nfd = os.open(native_file, os.O_RDONLY)
|
|
try:
|
|
err = compare_calls("syncfs success", lambda: syncfs_fd(mfd), lambda: syncfs_fd(nfd))
|
|
if err:
|
|
return fail(err)
|
|
finally:
|
|
os.close(mfd)
|
|
os.close(nfd)
|
|
|
|
err = compare_calls("syncfs EBADF", lambda: syncfs_fd(-1), lambda: syncfs_fd(-1))
|
|
if err:
|
|
return fail(err)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|