# Copyright (c) 2018, George Tokmaji # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. import os, errno, stat import llfuse class LCOperations(llfuse.Operations): _inode_list = None def __init__(self): super().__init__() self._inode_list = [None, None] def _add_entry(self, parent_inode, entry, is_dir=False): entry["parent_inode"] = parent_inode entry["inode"] = len(self._inode_list) entry["stat"] = stat.S_IFDIR if is_dir else stat.S_IFREG entry["title"] = entry["title"].replace("/", chr(8260)) #⁄ self._inode_list.append(entry) def _get_inode_by_parent(self, inode_p): return [i["inode"] for i in self._inode_list if i and i["parent_inode"] == inode_p][0] def _is_dir(self, inode): return inode == llfuse.ROOT_INODE def lookup(self, inode_p, name, ctx=None): if name == ".": inode = inode_p elif name == "..": inode = [i["inode"] for i in self._inode_list if i and i["inode"] == inode_p][0] else: for i in filter(None, self._inode_list): if i["title"] == os.fsdecode(name) and i["parent_inode"] == inode_p: inode = i["inode"] break else: raise llfuse.FUSEError(errno.ENOENT) return self.getattr(inode, ctx) def getattr(self, inode, ctx=None): attr = llfuse.EntryAttributes() attr.st_ino = inode attr.st_mode = stat.S_IFDIR if self._is_dir(inode) else stat.S_IFREG attr.st_nlink = 1 attr.st_uid = os.getuid() attr.st_gid = os.getgid() attr.st_rdev = 0 attr.st_size = 0 attr.st_blksize = 1 attr.st_blocks = 1 attr.generation = 0 attr.attr_timeout = 1 attr.entry_timeout = 1 attr.st_atime_ns = 0 attr.st_ctime_ns = 0 attr.st_mtime_ns = 0 return attr def readdir(self, inode, off): entries = [i for i in self._inode_list if i and i["parent_inode"] == inode] for i in range(off, len(entries)): yield (os.fsencode(entries[i]["title"]), self.getattr(entries[i]["inode"]), i + 1) def opendir(self, inode, ctx=None): return inode