aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/node_helpers.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-08-01 21:13:00 +0200
committerJakob Unterwurzacher2020-08-01 21:14:33 +0200
commitf54d21c38427e68b598546c1c870a289cb5e99bb (patch)
treeeeb3a55f70a3cb105a0da8e46ad6423f98da0401 /internal/fusefrontend_reverse/node_helpers.go
parent18b3bdb1584fd8e3dde89a95c0dfff910dd95ae1 (diff)
v2api/reverse: implement Lookup & Getattr
Diffstat (limited to 'internal/fusefrontend_reverse/node_helpers.go')
-rw-r--r--internal/fusefrontend_reverse/node_helpers.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/internal/fusefrontend_reverse/node_helpers.go b/internal/fusefrontend_reverse/node_helpers.go
new file mode 100644
index 0000000..a26ee81
--- /dev/null
+++ b/internal/fusefrontend_reverse/node_helpers.go
@@ -0,0 +1,67 @@
+package fusefrontend_reverse
+
+import (
+ "context"
+ "path/filepath"
+ "syscall"
+
+ "github.com/hanwen/go-fuse/v2/fs"
+ "github.com/hanwen/go-fuse/v2/fuse"
+)
+
+// translateSize translates the ciphertext size in `out` into plaintext size.
+func (n *Node) translateSize(dirfd int, cName string, out *fuse.Attr) {
+ if out.IsRegular() {
+ rn := n.rootNode()
+ out.Size = rn.contentEnc.PlainSizeToCipherSize(out.Size)
+ } else if out.IsSymlink() {
+ panic("todo: call readlink once it is implemented")
+ }
+}
+
+// Path returns the relative plaintext path of this node
+func (n *Node) Path() string {
+ return n.Inode.Path(n.Root())
+}
+
+// rootNode returns the Root Node of the filesystem.
+func (n *Node) rootNode() *RootNode {
+ return n.Root().Operations().(*RootNode)
+}
+
+// prepareAtSyscall returns a (dirfd, cName) pair that can be used
+// with the "___at" family of system calls (openat, fstatat, unlinkat...) to
+// access the backing encrypted directory.
+//
+// If you pass a `child` file name, the (dirfd, cName) pair will refer to
+// a child of this node.
+// If `child` is empty, the (dirfd, cName) pair refers to this node itself.
+func (n *Node) prepareAtSyscall(child string) (dirfd int, cName string, errno syscall.Errno) {
+ p := n.Path()
+ if child != "" {
+ p = filepath.Join(p, child)
+ }
+ rn := n.rootNode()
+ dirfd, cName, err := rn.openBackingDir(p)
+ if err != nil {
+ errno = fs.ToErrno(err)
+ }
+ return
+}
+
+// newChild attaches a new child inode to n.
+// The passed-in `st` will be modified to get a unique inode number.
+func (n *Node) newChild(ctx context.Context, st *syscall.Stat_t, out *fuse.EntryOut) *fs.Inode {
+ // Get unique inode number
+ rn := n.rootNode()
+ rn.inoMap.TranslateStat(st)
+ out.Attr.FromStat(st)
+ // Create child node
+ id := fs.StableAttr{
+ Mode: uint32(st.Mode),
+ Gen: 1,
+ Ino: st.Ino,
+ }
+ node := &Node{}
+ return n.NewInode(ctx, node, id)
+}