diff options
| author | Jakob Unterwurzacher | 2026-07-22 21:49:43 +0200 |
|---|---|---|
| committer | Jakob Unterwurzacher | 2026-07-22 21:51:40 +0200 |
| commit | b3b292a8a3c1478b769e213e0e590f38cb1b923c (patch) | |
| tree | dec2501e680157d4c7538ce1c19b55a84227ad15 /internal | |
| parent | b8e34b1efcb27c772f0d2ca12f5ecdd6b7fc817b (diff) | |
fusefrontend: make translateSize Stat_t/Statx_t agnostic
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/fusefrontend/node.go | 6 | ||||
| -rw-r--r-- | internal/fusefrontend/node_helpers.go | 14 |
2 files changed, 10 insertions, 10 deletions
diff --git a/internal/fusefrontend/node.go b/internal/fusefrontend/node.go index 95be48d..28ebbd5 100644 --- a/internal/fusefrontend/node.go +++ b/internal/fusefrontend/node.go @@ -38,7 +38,7 @@ func (n *Node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (ch ch = n.newChild(ctx, st, out) // Translate ciphertext size in `out.Attr.Size` to plaintext size - n.translateSize(dirfd, cName, &out.Attr) + out.Size = n.translateSize(dirfd, cName, out.Mode, out.Size) rn := n.rootNode() if rn.args.ForceOwner != nil { @@ -116,7 +116,7 @@ func (n *Node) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) out.Attr.FromStat(st) // Translate ciphertext size in `out.Attr.Size` to plaintext size - n.translateSize(dirfd, cName, &out.Attr) + out.Size = n.translateSize(dirfd, cName, out.Mode, out.Size) out: if rn.args.ForceOwner != nil { @@ -371,7 +371,7 @@ func (n *Node) Link(ctx context.Context, target fs.InodeEmbedder, name string, o return } inode = n.newChild(ctx, st, out) - n.translateSize(dirfd, cName, &out.Attr) + out.Size = n.translateSize(dirfd, cName, out.Mode, out.Size) return inode, 0 } diff --git a/internal/fusefrontend/node_helpers.go b/internal/fusefrontend/node_helpers.go index e8fca80..96c0961 100644 --- a/internal/fusefrontend/node_helpers.go +++ b/internal/fusefrontend/node_helpers.go @@ -56,15 +56,15 @@ func (n *Node) readlink(dirfd int, cName string) (out []byte, errno syscall.Errn // translateSize translates the ciphertext size in `out` into plaintext size. // Handles regular files & symlinks (and finds out what is what by looking at // `out.Mode`). -func (n *Node) translateSize(dirfd int, cName string, out *fuse.Attr) { - if out.IsRegular() { - rn := n.rootNode() - out.Size = rn.contentEnc.CipherSizeToPlainSize(out.Size) - } else if out.IsSymlink() { - // read and decrypt target +func (n *Node) translateSize(dirfd int, cName string, mode uint32, cSize uint64) (pSize uint64) { + switch mode & syscall.S_IFMT { + case syscall.S_IFREG: + return n.rootNode().contentEnc.CipherSizeToPlainSize(cSize) + case syscall.S_IFLNK: target, _ := n.readlink(dirfd, cName) - out.Size = uint64(len(target)) + return uint64(len(target)) } + return cSize } // Path returns the relative plaintext path of this node |
