diff options
| author | uvok | 2025-01-18 16:29:02 +0100 | 
|---|---|---|
| committer | uvok | 2025-01-18 16:29:02 +0100 | 
| commit | d52115ea028009b31761d67e32e3f5ca3e5eb47f (patch) | |
| tree | 5017215ae8de43c29fcec0bebe5629ce3af9ac21 | |
Init version
| -rw-r--r-- | hello-fusepy.py | 38 | 
1 files changed, 38 insertions, 0 deletions
diff --git a/hello-fusepy.py b/hello-fusepy.py new file mode 100644 index 0000000..ed5884f --- /dev/null +++ b/hello-fusepy.py @@ -0,0 +1,38 @@ +import sys +import errno +import stat +from fuse import FUSE, Operations + +class HelloWorld(Operations): +    def getattr(self, path, fh=None): +        if path == '/' or path == '/hello': +            return { +                'st_mode': stat.S_IFREG | 0o444,  # Regular file, read-only +                'st_nlink': 1, +                'st_size': len("hello world"), +            } +        else: +            raise OSError(errno.ENOENT, '') + +    def readdir(self, path, fh): +        return ['.', '..', 'hello'] + +    def open(self, path, flags): +        if path != '/hello': +            raise OSError(errno.ENOENT, '') + +    def read(self, path, size, offset, fh): +        if path == '/hello': +            return b"hello world"[offset:offset + size] +        else: +            raise OSError(errno.ENOENT, '') + +def main(mountpoint): +    FUSE(HelloWorld(), mountpoint, nothreads=True, foreground=True) + +if __name__ == '__main__': +    if len(sys.argv) != 2: +        print(f'Usage: {sys.argv[0]} <mountpoint>') +        sys.exit(1) + +    main(sys.argv[1])  | 
