aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/root_node.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-08-02 19:33:12 +0200
committerJakob Unterwurzacher2020-08-02 19:33:12 +0200
commit84ed139cd2cede9b773fe7892a0bc2515fc1f00f (patch)
tree9886e8fdce9450fd6232e532d5e8e939871dd2fc /internal/fusefrontend_reverse/root_node.go
parent4674bac8381838718f0defba0f2e0d9eba2a41a3 (diff)
v2api/reverse: implement Lookup for longname
Diffstat (limited to 'internal/fusefrontend_reverse/root_node.go')
-rw-r--r--internal/fusefrontend_reverse/root_node.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/fusefrontend_reverse/root_node.go b/internal/fusefrontend_reverse/root_node.go
index 726380f..4297ecf 100644
--- a/internal/fusefrontend_reverse/root_node.go
+++ b/internal/fusefrontend_reverse/root_node.go
@@ -1,10 +1,19 @@
package fusefrontend_reverse
import (
+ "log"
+ "strings"
+ "syscall"
+
+ "golang.org/x/sys/unix"
+
+ "github.com/hanwen/go-fuse/v2/fs"
+
"github.com/rfjakob/gocryptfs/internal/contentenc"
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
"github.com/rfjakob/gocryptfs/internal/inomap"
"github.com/rfjakob/gocryptfs/internal/nametransform"
+ "github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/sabhiram/go-gitignore"
)
@@ -37,3 +46,35 @@ func NewRootNode(args fusefrontend.Args, c *contentenc.ContentEnc, n nametransfo
excluder: prepareExcluder(args),
}
}
+
+// You can pass either gocryptfs.longname.XYZ.name or gocryptfs.longname.XYZ.
+func (rn *RootNode) findLongnameParent(fd int, diriv []byte, longname string) (pName string, cFullName string, errno syscall.Errno) {
+ if strings.HasSuffix(longname, nametransform.LongNameSuffix) {
+ longname = nametransform.RemoveLongNameSuffix(longname)
+ }
+ entries, err := syscallcompat.Getdents(fd)
+ if err != nil {
+ errno = fs.ToErrno(err)
+ return
+ }
+ for _, entry := range entries {
+ if len(entry.Name) <= shortNameMax {
+ continue
+ }
+ cFullName = rn.nameTransform.EncryptName(entry.Name, diriv)
+ if len(cFullName) <= unix.NAME_MAX {
+ // Entry should have been skipped by the "continue" above
+ log.Panic("logic error or wrong shortNameMax constant?")
+ }
+ hName := rn.nameTransform.HashLongName(cFullName)
+ if longname == hName {
+ pName = entry.Name
+ break
+ }
+ }
+ if pName == "" {
+ errno = syscall.ENOENT
+ return
+ }
+ return
+}