aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/rfs.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-09-22 23:28:11 +0200
committerJakob Unterwurzacher2016-09-25 16:43:17 +0200
commita6a7b424f8e8a0f8ddd1c94b7463250ef1337811 (patch)
tree2281d7062d893d70209ecb7a82589e49decac164 /internal/fusefrontend_reverse/rfs.go
parent35bcc2dca2dc928e3b7c31e34d785b7a42c06722 (diff)
reverse: resolve long names in Open and GetAttr
The last patch added functionality for generating gocryptfs.longname.* files, this patch adds support for mapping them back to the full filenames. Note that resolving a long name needs a full readdir. A cache will be implemented later on to improve performance.
Diffstat (limited to 'internal/fusefrontend_reverse/rfs.go')
-rw-r--r--internal/fusefrontend_reverse/rfs.go38
1 files changed, 34 insertions, 4 deletions
diff --git a/internal/fusefrontend_reverse/rfs.go b/internal/fusefrontend_reverse/rfs.go
index 9fac591..7305687 100644
--- a/internal/fusefrontend_reverse/rfs.go
+++ b/internal/fusefrontend_reverse/rfs.go
@@ -108,6 +108,13 @@ func isDirIV(relPath string) bool {
return filepath.Base(relPath) == nametransform.DirIVFilename
}
+// isNameFile determines if the path points to a gocryptfs.longname.*.name
+// file
+func isNameFile(relPath string) bool {
+ fileType := nametransform.NameType(filepath.Base(relPath))
+ return fileType == nametransform.LongNameFilename
+}
+
func (rfs *reverseFS) inoAwareStat(relPlainPath string) (*fuse.Attr, fuse.Status) {
absPath, err := rfs.abs(relPlainPath, nil)
if err != nil {
@@ -148,12 +155,32 @@ func (rfs *reverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr
if relPath == configfile.ConfDefaultName {
return rfs.inoAwareStat(configfile.ConfReverseName)
}
- if isDirIV(relPath) {
- return rfs.dirIVAttr(relPath, context)
- }
if rfs.isFiltered(relPath) {
return nil, fuse.EPERM
}
+
+ // Handle virtual files
+ var f nodefs.File
+ var status fuse.Status
+ virtual := false
+ if isDirIV(relPath) {
+ virtual = true
+ f, status = rfs.newDirIVFile(relPath)
+ }
+ if isNameFile(relPath) {
+ virtual = true
+ f, status = rfs.newNameFile(relPath)
+ }
+ if virtual {
+ if !status.Ok() {
+ fmt.Printf("GetAttr %q: newXFile failed: %v\n", relPath, status)
+ return nil, status
+ }
+ var a fuse.Attr
+ status = f.GetAttr(&a)
+ return &a, status
+ }
+
cPath, err := rfs.decryptPath(relPath)
if err != nil {
return nil, fuse.ToStatus(err)
@@ -191,7 +218,10 @@ func (rfs *reverseFS) Open(relPath string, flags uint32, context *fuse.Context)
return rfs.loopbackfs.Open(configfile.ConfReverseName, flags, context)
}
if isDirIV(relPath) {
- return NewDirIVFile(relDir(relPath))
+ return rfs.newDirIVFile(relPath)
+ }
+ if isNameFile(relPath) {
+ return rfs.newNameFile(relPath)
}
if rfs.isFiltered(relPath) {
return nil, fuse.EPERM