summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hello-fusepy.py38
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])