Implementing a passthrough file system (fuse-fusepy)

122 Views Asked by At

I want to create a filesystem that will hold both clear and encrypted versions of each file. It will then serve one or another depending on user authentication. I'm using fusepy for this. I'm starting with a simple passthrough fs. It must simply provides the files in the mountpoint. I can't reach that first goal.

I cant' figure out what's wrong. Can you please provide as much as information or resource as possible ? here's my code :

#!usr/bin/env python3

import os
import sys
import errno
from fuse import FUSE, FuseOSError, Operations, fuse_get_context
from toycipher import *
import pdb




class Cfs (Operations) :
    def __init__(self, path, content) :
        print(f"chemin : {path}")
        #self.root = os.path.abspath(path)
        self.files = content

    def rpath (self, path) :
        return os.path.join(self.root, path.lstrip('/'))

    def getattr(self, path, fh=None) :
        #path = self.rpath(path)

        attr = ["st_mode", "st_ino", "st_dev", "st_nlink", "st_uid", "st_gid", "st_size", "st_atime", "st_mtime", "st_ctime"]
        attr = dict.fromkeys(attr)
        stat  = os.stat(path)
        i=0
        for key in attr :
            attr[key] = stat[i]
            i+=1
        return attr

def readdir (self, path , fh) :
        print(f"listing :  {path}")
        return ['.', '..'] + self.files

    def statfs (self, path) :
        statfs = ["f_bsize", "f_frsize", "f_blocks", "f_bfree", "f_bavail", "f_files", "f_ffree", "f_favail", "f_flag", "f_namemax"]
        statfs = dict.fromkeys(statfs)
        stat = os.statfs(path)
        i = 0
        for key in statfs :
            statfs[key] = stat[i]
            i+=1
        return statfs




def main(path) :
    content = ["un.txt", "deux.txt"]
    cfs = FUSE(Cfs(path, content), path, foreground = True, nonempty=True)



if __name__ == '__main__' :
    print(f"pid : {os.getpid()}")
    main(sys.argv[1])

Errors : I'm mounting a test folder holding one.txt and two.txt the first call of ls is before the mounting and the second one, is after.

owik@fedora:~/Work/cfs$ ls test
one.txt  two.txt

lowik@fedora:~/Work/cfs$ ls test
ls: impossible d'accéder à 'test/one.txt': Aucun fichier ou dossier de ce type
ls: impossible d'accéder à 'test/two.txt': Aucun fichier ou dossier de ce type
one.txt  two.txt

lowik@fedora:~/Work/cfs$ strace ls -l test
execve("/usr/bin/ls", ["ls", "-l", "test"], 0x7ffd04ab09a0 /* 46 vars */) = 0
brk(NULL)                               = 0x558644ac8000
arch_prctl(0x3001 /* ARCH_??? */, 0x7fffa463c890) = -1 EINVAL (Argument invalide)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=72295, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 72295, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f636b60a000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=180016, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f636b608000
mmap(NULL, 181880, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f636b5db000
mmap(0x7f636b5e2000, 114688, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7000) = 0x7f636b5e2000
mmap(0x7f636b5fe000, 24576, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x23000) = 0x7f636b5fe000
mmap(0x7f636b604000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x29000) = 0x7f636b604000
mmap(0x7f636b606000, 5752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f636b606000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libcap.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=36616, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 36920, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f636b5d1000
mmap(0x7f636b5d3000, 16384, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f636b5d3000
mmap(0x7f636b5d7000, 8192, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f636b5d7000
mmap(0x7f636b5d9000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x7000) = 0x7f636b5d9000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \203\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=2250400, ...}, AT_EMPTY_PATH) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 1973104, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f636b3ef000
mmap(0x7f636b415000, 1441792, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26000) = 0x7f636b415000
mmap(0x7f636b575000, 319488, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x186000) = 0x7f636b575000
mmap(0x7f636b5c3000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1d3000) = 0x7f636b5c3000
mmap(0x7f636b5c9000, 31600, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f636b5c9000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libpcre2-8.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=632968, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 631344, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f636b354000
mmap(0x7f636b357000, 450560, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f636b357000
mmap(0x7f636b3c5000, 163840, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x71000) = 0x7f636b3c5000
mmap(0x7f636b3ed000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x98000) = 0x7f636b3ed000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f636b352000
arch_prctl(ARCH_SET_FS, 0x7f636b352c40) = 0
set_tid_address(0x7f636b352f10)         = 3141
set_robust_list(0x7f636b352f20, 24)     = 0
rseq(0x7f636b353560, 0x20, 0, 0x53053053) = 0
mprotect(0x7f636b5c3000, 16384, PROT_READ) = 0
mprotect(0x7f636b3ed000, 4096, PROT_READ) = 0
mprotect(0x7f636b5d9000, 4096, PROT_READ) = 0
mprotect(0x7f636b604000, 4096, PROT_READ) = 0
mprotect(0x558642d35000, 8192, PROT_READ) = 0
mprotect(0x7f636b64e000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7f636b60a000, 72295)           = 0
prctl(PR_CAPBSET_READ, CAP_MAC_OVERRIDE) = 1
prctl(PR_CAPBSET_READ, 0x30 /* CAP_??? */) = -1 EINVAL (Argument invalide)
prctl(PR_CAPBSET_READ, CAP_CHECKPOINT_RESTORE) = 1
prctl(PR_CAPBSET_READ, 0x2c /* CAP_??? */) = -1 EINVAL (Argument invalide)
prctl(PR_CAPBSET_READ, 0x2a /* CAP_??? */) = -1 EINVAL (Argument invalide)
prctl(PR_CAPBSET_READ, 0x29 /* CAP_??? */) = -1 EINVAL (Argument invalide)
statfs("/sys/fs/selinux", {f_type=SELINUX_MAGIC, f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={val=[0, 0]}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_NOSUID|ST_NOEXEC|ST_RELATIME}) = 0
statfs("/sys/fs/selinux", {f_type=SELINUX_MAGIC, f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={val=[0, 0]}, f_namelen=255, f_frsize=4096, f_flags=ST_VALID|ST_NOSUID|ST_NOEXEC|ST_RELATIME}) = 0
getrandom("\xc6\x3e\xc8\xa8\xb3\x71\x57\xab", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x558644ac8000
brk(0x558644ae9000)                     = 0x558644ae9000
access("/etc/selinux/config", F_OK)     = 0
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=224366320, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 224366320, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f635dc00000
close(3)                                = 0
ioctl(1, TCGETS, {c_iflag=ICRNL|IXON|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2998, ...}, AT_EMPTY_PATH) = 0
read(3, "# Locale name alias data base.\n#"..., 4096) = 2998
read(3, "", 4096)                       = 0
close(3)                                = 0
openat(AT_FDCWD, "/usr/share/locale/fr_FR.UTF-8/LC_TIME/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr_FR.utf8/LC_TIME/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr_FR/LC_TIME/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr.UTF-8/LC_TIME/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr.utf8/LC_TIME/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr/LC_TIME/coreutils.mo", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=400055, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 400055, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f636b2f0000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib64/gconv/gconv-modules.cache", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=27012, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 27012, PROT_READ, MAP_SHARED, 3, 0) = 0x7f636b615000
close(3)                                = 0
futex(0x7f636b5c872c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
statx(AT_FDCWD, "test", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_MODE|STATX_NLINK|STATX_UID|STATX_GID|STATX_MTIME|STATX_SIZE, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=STATX_ATTR_MOUNT_ROOT, stx_mode=S_IFDIR|0555, stx_size=158, ...}) = 0
lgetxattr("test", "security.selinux", "system_u:object_r:fusefs_t:s0", 255) = 30
access("/var/run/setrans/.setrans-unix", F_OK) = -1 ENOENT (Aucun fichier ou dossier de ce type)
futex(0x7f636b607648, FUTEX_WAKE_PRIVATE, 2147483647) = 0
listxattr("test", "", 152)              = 0
newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=675, ...}, 0) = 0
newfstatat(AT_FDCWD, "/", {st_mode=S_IFDIR|0555, st_size=158, ...}, 0) = 0
openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=675, ...}, AT_EMPTY_PATH) = 0
read(3, "# Generated by authselect\n# Do n"..., 4096) = 675
read(3, "", 4096)                       = 0
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=675, ...}, AT_EMPTY_PATH) = 0
close(3)                                = 0
openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2691, ...}, AT_EMPTY_PATH) = 0
lseek(3, 0, SEEK_SET)                   = 0
read(3, "root:x:0:0:Super User:/root:/bin"..., 4096) = 2691
close(3)                                = 0
newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=675, ...}, 0) = 0
openat(AT_FDCWD, "/etc/group", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=1024, ...}, AT_EMPTY_PATH) = 0
lseek(3, 0, SEEK_SET)                   = 0
read(3, "root:x:0:\nbin:x:1:\ndaemon:x:2:\ns"..., 4096) = 1024
close(3)                                = 0
openat(AT_FDCWD, "test", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
newfstatat(3, "", {st_mode=S_IFDIR|0555, st_size=158, ...}, AT_EMPTY_PATH) = 0
getdents64(3, 0x558644ad5e10 /* 4 entries */, 32768) = 112
statx(AT_FDCWD, "test/one.txt", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_MODE|STATX_NLINK|STATX_UID|STATX_GID|STATX_MTIME|STATX_SIZE, 0x7fffa463bff0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr_FR.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr_FR.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr_FR/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr/LC_MESSAGES/coreutils.mo", O_RDONLY) = 4
newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=400055, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 400055, PROT_READ, MAP_PRIVATE, 4, 0) = 0x7f636b28e000
close(4)                                = 0
write(2, "ls: ", 4ls: )                     = 4
write(2, "impossible d'acc\303\251der \303\240 'test/o"..., 39impossible d'accéder à 'test/one.txt') = 39
openat(AT_FDCWD, "/usr/share/locale/fr_FR.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr_FR.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr_FR/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (Aucun fichier ou dossier de ce type)
openat(AT_FDCWD, "/usr/share/locale/fr/LC_MESSAGES/libc.mo", O_RDONLY) = 4
newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=153073, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 153073, PROT_READ, MAP_PRIVATE, 4, 0) = 0x7f636b268000
close(4)                                = 0
write(2, ": Aucun fichier ou dossier de ce"..., 37: Aucun fichier ou dossier de ce type) = 37
write(2, "\n", 1
)                       = 1
statx(AT_FDCWD, "test/two.txt", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_MODE|STATX_NLINK|STATX_UID|STATX_GID|STATX_MTIME|STATX_SIZE, 0x7fffa463bff0) = -1 ENOENT (Aucun fichier ou dossier de ce type)
write(2, "ls: ", 4ls: )                     = 4
write(2, "impossible d'acc\303\251der \303\240 'test/t"..., 39impossible d'accéder à 'test/two.txt') = 39
write(2, ": Aucun fichier ou dossier de ce"..., 37: Aucun fichier ou dossier de ce type) = 37
write(2, "\n", 1
)                       = 1
getdents64(3, 0x558644ad5e10 /* 0 entries */, 32768) = 0
close(3)                                = 0
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, AT_EMPTY_PATH) = 0
write(1, "total 0\n", 8total 0
)                = 8
openat(AT_FDCWD, "/etc/localtime", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2962, ...}, AT_EMPTY_PATH) = 0
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2962, ...}, AT_EMPTY_PATH) = 0
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\r\0\0\0\r\0\0\0\0"..., 4096) = 2962
lseek(3, -1863, SEEK_CUR)               = 1099
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\r\0\0\0\r\0\0\0\0"..., 4096) = 1863
close(3)                                = 0
write(1, "?????????? ? ? ? ?              "..., 42?????????? ? ? ? ?              ? one.txt
) = 42
write(1, "?????????? ? ? ? ?              "..., 42?????????? ? ? ? ?              ? two.txt
) = 42
close(1)                                = 0
close(2)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++
0

There are 0 best solutions below