summaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/rfs.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/fusefrontend_reverse/rfs.go')
-rw-r--r--internal/fusefrontend_reverse/rfs.go52
1 files changed, 34 insertions, 18 deletions
diff --git a/internal/fusefrontend_reverse/rfs.go b/internal/fusefrontend_reverse/rfs.go
index 914dccb..68a5ac8 100644
--- a/internal/fusefrontend_reverse/rfs.go
+++ b/internal/fusefrontend_reverse/rfs.go
@@ -2,6 +2,7 @@ package fusefrontend_reverse
import (
"os"
+ "syscall"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
@@ -13,9 +14,11 @@ import (
"github.com/rfjakob/gocryptfs/internal/nametransform"
)
-type FS struct {
- // loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go
+type reverseFS struct {
+ // Embed pathfs.defaultFileSystem for a ENOSYS implementation of all methods
pathfs.FileSystem
+ // pathfs.loopbackFileSystem, see go-fuse/fuse/pathfs/loopback.go
+ loopbackfs pathfs.FileSystem
// Stores configuration arguments
args fusefrontend.Args
// Filename encryption helper
@@ -25,43 +28,56 @@ type FS struct {
}
// Encrypted FUSE overlay filesystem
-func NewFS(args fusefrontend.Args) *FS {
+func NewFS(args fusefrontend.Args) *reverseFS {
cryptoCore := cryptocore.New(args.Masterkey, args.OpenSSL, true)
contentEnc := contentenc.New(cryptoCore, contentenc.DefaultBS)
nameTransform := nametransform.New(cryptoCore, args.LongNames)
- return &FS{
- FileSystem: pathfs.NewLoopbackFileSystem(args.Cipherdir),
+ return &reverseFS{
+ // pathfs.defaultFileSystem returns ENOSYS for all operations
+ FileSystem: pathfs.NewDefaultFileSystem(),
+ loopbackfs: pathfs.NewLoopbackFileSystem(args.Cipherdir),
args: args,
nameTransform: nameTransform,
contentEnc: contentEnc,
}
}
-func (fs *FS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
- if fs.isFiltered(relPath) {
+func (rfs *reverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
+ if rfs.isFiltered(relPath) {
return nil, fuse.EPERM
}
- relPath, err := fs.decryptPath(relPath)
+ relPath, err := rfs.decryptPath(relPath)
if err != nil {
return nil, fuse.ToStatus(err)
}
- a, status := fs.FileSystem.GetAttr(relPath, context)
+ a, status := rfs.loopbackfs.GetAttr(relPath, context)
if a == nil {
return a, status
}
// Calculate encrypted file size
if a.IsRegular() {
- a.Size = fs.contentEnc.PlainSizeToCipherSize(a.Size)
+ a.Size = rfs.contentEnc.PlainSizeToCipherSize(a.Size)
}
return a, fuse.OK
}
-func (fs *FS) Open(relPath string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {
- if fs.isFiltered(relPath) {
+func (rfs *reverseFS) Access(relPath string, mode uint32, context *fuse.Context) fuse.Status {
+ if rfs.isFiltered(relPath) {
+ return fuse.EPERM
+ }
+ cPath, err := rfs.abs(rfs.encryptPath(relPath))
+ if err != nil {
+ return fuse.ToStatus(err)
+ }
+ return fuse.ToStatus(syscall.Access(cPath, mode))
+}
+
+func (rfs *reverseFS) Open(relPath string, flags uint32, context *fuse.Context) (fuseFile nodefs.File, status fuse.Status) {
+ if rfs.isFiltered(relPath) {
return nil, fuse.EPERM
}
- absPath, err := fs.abs(fs.decryptPath(relPath))
+ absPath, err := rfs.abs(rfs.decryptPath(relPath))
if err != nil {
return nil, fuse.ToStatus(err)
}
@@ -69,22 +85,22 @@ func (fs *FS) Open(relPath string, flags uint32, context *fuse.Context) (fuseFil
if err != nil {
return nil, fuse.ToStatus(err)
}
- return NewFile(f, fs.contentEnc)
+ return NewFile(f, rfs.contentEnc)
}
-func (fs *FS) OpenDir(relPath string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) {
- relPath, err := fs.decryptPath(relPath)
+func (rfs *reverseFS) OpenDir(relPath string, context *fuse.Context) ([]fuse.DirEntry, fuse.Status) {
+ relPath, err := rfs.decryptPath(relPath)
if err != nil {
return nil, fuse.ToStatus(err)
}
// Read plaintext dir
- entries, status := fs.FileSystem.OpenDir(relPath, context)
+ entries, status := rfs.loopbackfs.OpenDir(relPath, context)
if entries == nil {
return nil, status
}
// Encrypt names
for i := range entries {
- entries[i].Name, err = fs.encryptPath(entries[i].Name)
+ entries[i].Name, err = rfs.encryptPath(entries[i].Name)
if err != nil {
return nil, fuse.ToStatus(err)
}