#!/usr/bin/env python from __future__ import print_function from ctypes import * import threading import time import os import subprocess import errno # Change this according to your FUSE version import libfuse28 as libfuse #import libfuse26 as libfuse # Set up do_mount and get_args function from hello_ll.so lib = CDLL('./hello_ll.so') lib.do_mount.args = [ c_int, POINTER(c_char_p), POINTER(libfuse.fuse_lowlevel_ops) ] lib.do_mount.restype = None lib.get_ops.args = [] lib.get_ops.restype = POINTER(libfuse.fuse_lowlevel_ops) # Set up argc and argv args = [ 'hello_ll', 'mnt', '-o', 'debug' ] argv = (POINTER(c_char) * len(args))(*[cast(c_char_p(x), POINTER(c_char)) for x in args]) argc = len(args) # This should do exactly the same as the C function def fuse_opendir(req, inode, fi): libfuse.fuse_reply_err(req, errno.ENOSYS) opendir_t = CFUNCTYPE(None, libfuse.fuse_req_t, libfuse.fuse_ino_t, POINTER(libfuse.fuse_file_info)) fuse_ops = lib.get_ops() # The opendir implementation in hello_ll.c works fine, # the Python implementation freezes the process #fuse_ops.contents.opendir = opendir_t(fuse_opendir) # Mount file system, wait, access it and umount def run(): print('Mounting...') lib.do_mount(argc, argv, fuse_ops) t1 = threading.Thread(target=run) t1.start() time.sleep(1) try: print('Listing mountpoint...') os.listdir(args[1]) except OSError as e: if e.errno == errno.ENOSYS: pass else: raise print('Unmounting...') subprocess.call(['fusermount', '-u', args[1]])