From d52115ea028009b31761d67e32e3f5ca3e5eb47f Mon Sep 17 00:00:00 2001 From: uvok Date: Sat, 18 Jan 2025 16:29:02 +0100 Subject: Init version --- hello-fusepy.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 hello-fusepy.py 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]} ') + sys.exit(1) + + main(sys.argv[1]) -- cgit v1.2.3