From a6a7b424f8e8a0f8ddd1c94b7463250ef1337811 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 22 Sep 2016 23:28:11 +0200 Subject: 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. --- internal/fusefrontend_reverse/rfs.go | 38 ++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'internal/fusefrontend_reverse/rfs.go') 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 -- cgit v1.2.3