summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok2025-01-18 16:31:18 +0100
committeruvok2025-01-18 16:31:18 +0100
commitebc1e8008b04a55338433d0534bb4367044789a3 (patch)
tree6247b98e0dbc3ec03a3014f74650d766252cd4e5
parentd52115ea028009b31761d67e32e3f5ca3e5eb47f (diff)
Add dir list
-rw-r--r--hello-fusepy.py42
1 files changed, 27 insertions, 15 deletions
diff --git a/hello-fusepy.py b/hello-fusepy.py
index ed5884f..41c30a5 100644
--- a/hello-fusepy.py
+++ b/hello-fusepy.py
@@ -1,31 +1,43 @@
import sys
import errno
import stat
-from fuse import FUSE, Operations
+from fuse import FUSE, Operations, FuseOSError
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
+ def __init__(self):
+ self.files = {'/hello': 'hello world'}
+ self.attr = {
+ '/': {
+ 'st_mode': (stat.S_IFDIR | 0o755), # Directory
+ 'st_nlink': 2
+ },
+ '/hello': {
+ 'st_mode': (stat.S_IFREG | 0o444), # Regular file, read-only
'st_nlink': 1,
- 'st_size': len("hello world"),
+ 'st_size': len(self.files['/hello']),
}
- else:
- raise OSError(errno.ENOENT, '')
+ }
+
+ def getattr(self, path, fh=None):
+ if path in self.attr:
+ return self.attr[path]
+ raise FuseOSError(errno.ENOENT)
def readdir(self, path, fh):
- return ['.', '..', 'hello']
+ if path == '/':
+ return ['.', '..'] + [file[1:] for file in self.files.keys()]
+ else:
+ raise FuseOSError(errno.ENOENT)
def open(self, path, flags):
- if path != '/hello':
- raise OSError(errno.ENOENT, '')
+ if path not in self.files:
+ raise FuseOSError(errno.ENOENT)
+ return 0
def read(self, path, size, offset, fh):
- if path == '/hello':
- return b"hello world"[offset:offset + size]
- else:
- raise OSError(errno.ENOENT, '')
+ if path in self.files:
+ return self.files[path][offset:offset + size]
+ raise FuseOSError(errno.ENOENT)
def main(mountpoint):
FUSE(HelloWorld(), mountpoint, nothreads=True, foreground=True)