我已经将 python 代码写入点安装上的安装保险丝。它总是给出无效的参数错误。我在 C 中尝试过相同的程序,它运行良好。任何python Guru都可以帮助我找出问题所在,我已将代码粘贴在这里。
#!/usr/bin/python
import stat
import os
import ctypes
from ctypes.util import find_library
libc = ctypes.CDLL (find_library ("c"))
def fuse_mount_sys (mountpoint, fsname):
fd = file.fileno (file ("/dev/fuse", 'w+'))
if fd < 0:
raise OSError("Could not open /dev/fuse")
mnt_param = "%s,fd=%i,rootmode=%o,user_id=%i,group_id=%i" \
% ("allow_other,default_permissions,max_read=131072", \
fd, stat.S_IFDIR, os.getuid(), os.getgid())
ret = libc.mount ("fuse", "/mount", "fuse", 0, mnt_param)
if ret < 0:
raise OSError("mount failed with code " + str(ret))
return fd
fds = fuse_mount_sys ("/mount", "fuse")
挂载语法是:
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
我尝试使用 swig 并使用 C 编写程序,然后从中创建一个 .so 并且他们工作。但我对用纯 python 编写感兴趣。提前致谢。
strace 的输出:
$ strace -s 100 -v -e mount python fuse-mount.py
mount("fuse", "/mount", "fuse", 0, "allow_other,default_permissions,max_read=131072,fd=3,rootmode=40000,user_id=0,group_id=0") = -1 EINVAL (Invalid argument)
$ strace -s 100 -v -e mount ./a.out
mount("fuse", "/mount", "fuse", 0, "allow_other,default_permissions,max_read=131072,fd=3,rootmode=40000,user_id=0,group_id=0") = 0