Commit 95b00ce8 authored by Gerion Entrup's avatar Gerion Entrup
Browse files

clean testfiles

parent 0af84426
#!/usr/bin/env python3
import errno, llfuse, sys, logging, stat, os, time
log = logging.getLogger()
fse = sys.getfilesystemencoding()
def bytes2str(s):
return s.decode(fse, 'surrogateescape')
def str2bytes(s):
return s.encode(fse, 'surrogateescape')
class Testfs(llfuse.Operations):
def __init__(self):
super(llfuse.Operations, self).__init__()
self.hellopath = "/hello"
self.hellostring = "hello world"
self.inode2path = {llfuse.ROOT_INODE: "/",
llfuse.ROOT_INODE+1: self.hellopath}
self.path2inode = {"/": llfuse.ROOT_INODE,
self.hellopath: llfuse.ROOT_INODE+1}
def getattr(self, inode):
entry = llfuse.EntryAttributes()
if inode in self.inode2path:
if self.inode2path[inode] is "/":
entry.st_mode = (stat.S_IFDIR | 0o755)
entry.st_nlink = 2
entry.st_size = 4096
elif self.inode2path[inode] is self.hellopath:
entry.st_mode = (stat.S_IFREG | 0o644)
entry.st_nlink = 1
entry.st_size = len(self.hellostring) + 1
else:
raise(llfuse.FUSEError(errno.ENOENT))
entry.attr_timeout = 300
entry.entry_timeout = 300
entry.generation = 0
entry.st_atime = int(time.time())
entry.st_blksize = 512
entry.st_blocks = 1
entry.st_ctime = int(time.time())
entry.st_gid = os.getgid()
entry.st_ino = inode
entry.st_mtime = int(time.time())
entry.st_rdev = 1
entry.st_uid = os.getuid()
return entry
def lookup(self, parent_inode, name):
path = self.inode2path[parent_inode] + bytes2str(name)
if path != self.hellopath:
raise(llfuse.FUSEError(errno.ENOENT))
return self.getattr(self.path2inode[path])
def opendir(self, inode):
if inode not in self.inode2path or self.inode2path[inode] != '/':
raise(llfuse.FUSEError(errno.ENOENT))
return inode
def readdir(self, fh, off):
if fh not in self.inode2path or self.inode2path[fh] != "/":
raise(llfuse.FUSEError(errno.ENOENT))
#only one value
if off is 1:
return
yield (str2bytes(self.hellopath[1:]), self.getattr(self.path2inode[self.hellopath]), 1)
def open(self, inode, flags):
if self.inode2path[inode] != self.hellopath:
raise(llfuse.FUSEError(errno.ENOENT))
if flags&3 != os.O_RDONLY:
raise(llfuse.FUSEError(errno.EACCES))
return inode
def read(self, fh, off, size):
if self.inode2path[fh] != self.hellopath:
raise(llfuse.FUSEError(errno.ENOENT))
return str2bytes(self.hellostring[off:off+size])
def init_logging():
formatter = logging.Formatter('%(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
handler.setLevel(logging.INFO)
log.setLevel(logging.INFO)
log.addHandler(handler)
def main():
init_logging()
testfs = Testfs()
llfuse.init(testfs, sys.argv[1], [ 'fsname=hellofs' ])
try:
llfuse.main(single=True)
except:
llfuse.close(unmount=False)
raise
llfuse.close()
if __name__ == '__main__':
main()
import hlfuse, sys
def main():
root = hlfuse.FuseDir(0o755, root=True)
hellofile = hlfuse.FuseFile(0o644)
hellofile.set_content(b'hello world')
root.add_file('hello', hellofile)
subdir = hlfuse.FuseDir(0o500)
root.add_file('anderes Verzeichnis', subdir)
foofile = hlfuse.FuseFile(0o400)
subdir.add_file('foofile', foofile)
foofile.set_content(b'some string')
hlfuse.init(sys.argv[1], root)
if __name__ == '__main__':
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment