aboutsummaryrefslogtreecommitdiffstats
path: root/c4groupfs.py
diff options
context:
space:
mode:
authorFulgen301 <tokmajigeorge@gmail.com>2018-06-11 20:32:35 +0200
committerFulgen301 <tokmajigeorge@gmail.com>2018-06-11 20:32:35 +0200
commit01076263953bd98d7f1621c5f7ba3265cc06692c (patch)
treede2d2778d6d7b033b09e360abc0ab0b7d686f541 /c4groupfs.py
downloadlcfs-01076263953bd98d7f1621c5f7ba3265cc06692c.tar.gz
lcfs-01076263953bd98d7f1621c5f7ba3265cc06692c.zip
Initial commit
Diffstat (limited to 'c4groupfs.py')
-rwxr-xr-xc4groupfs.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/c4groupfs.py b/c4groupfs.py
new file mode 100755
index 0000000..9f701b8
--- /dev/null
+++ b/c4groupfs.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+# 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.
+from base import *
+import sys
+sys.path.append("../c4group")
+import c4group
+
+class C4GroupOperations(LCOperations):
+ def __init__(self, path):
+ super().__init__()
+ self._grp = c4group.C4GroupDirectory(path)
+ self._grp.load(recursive=False)
+ self._add_grp_content(llfuse.ROOT_INODE, self._grp)
+
+ def _add_grp_content(self, inode, grp):
+ for i in grp.content:
+ i["title"] = os.fsdecode(i.filename)
+ self._add_entry(inode, i, isinstance(i, c4group.C4GroupDirectory))
+
+ def _is_dir(self, inode):
+ return isinstance(self._inode_list[inode], c4group.C4GroupDirectory) or super()._is_dir(inode)
+
+ def getattr(self, inode, ctx=None):
+ entry = self._inode_list[inode]
+ attr = super().getattr(inode, ctx)
+ if entry:
+ attr.st_size = entry.size
+ return attr
+
+ def opendir(self, inode, ctx=None):
+ if self._is_dir(inode):
+ try:
+ self._get_inode_by_parent(inode)
+ except IndexError:
+ grp = self._inode_list[inode]
+ grp.load(recursive=False)
+ self._add_grp_content(inode, grp)
+ return inode
+
+ def open(self, inode, flags, ctx=None):
+ entry = self._inode_list[inode]
+ if self._is_dir(inode):
+ raise llfuse.FUSEError(errno.EISDIR)
+ if flags & os.O_APPEND:
+ raise llfuse.FUSEError(errno.EROFS)
+ return inode
+
+ def read(self, inode, off, size):
+ entry = self._inode_list[inode]
+ return entry.content[off:off+size]
+
+if __name__ == "__main__":
+ # Usage: ./c4groupfs.py <file> <mountpoint>
+ fuse_options = set(llfuse.default_options)
+ fuse_options.add("fsname=c4groupfs")
+ fuse_options.add("debug")
+ fuse_options.discard("default_permissions")
+ op = C4GroupOperations(sys.argv[1])
+ llfuse.init(op, sys.argv[2], fuse_options)
+ try:
+ llfuse.main()
+ finally:
+ llfuse.close(unmount=True)