diff options
Diffstat (limited to 'hello-fusepy.py')
-rw-r--r-- | hello-fusepy.py | 42 |
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) |