aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/dir.go15
-rw-r--r--frontend/file.go51
2 files changed, 62 insertions, 4 deletions
diff --git a/frontend/dir.go b/frontend/dir.go
index eca3cf5..ce64a5a 100644
--- a/frontend/dir.go
+++ b/frontend/dir.go
@@ -45,10 +45,16 @@ func (d *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.Lo
}
clueDir, ok := n.(*cluefs.Dir)
if ok {
- return &Dir { Dir: clueDir }, nil
+ return &Dir {
+ Dir: clueDir,
+ crfs: d.crfs,
+ }, nil
} else {
clueFile := n.(*cluefs.File)
- return &File { File: clueFile }, nil
+ return &File {
+ File: clueFile,
+ crfs: d.crfs,
+ }, nil
}
}
@@ -103,6 +109,9 @@ func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.Cr
return nil, nil, err
}
clueFile := n.(*cluefs.File)
- cryptFile := &File {File: clueFile}
+ cryptFile := &File {
+ File: clueFile,
+ crfs: d.crfs,
+ }
return cryptFile, cryptFile, nil
}
diff --git a/frontend/file.go b/frontend/file.go
index 81590e8..c5a02be 100644
--- a/frontend/file.go
+++ b/frontend/file.go
@@ -1,11 +1,60 @@
package frontend
import (
+ "fmt"
"github.com/rfjakob/gocryptfs/cryptfs"
"github.com/rfjakob/cluefs/lib/cluefs"
+
+ "bazil.org/fuse"
+ fusefs "bazil.org/fuse/fs"
+ "golang.org/x/net/context"
)
type File struct {
- *cryptfs.CryptFile
*cluefs.File
+ crfs *cryptfs.CryptFS
+}
+
+func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fusefs.Handle, error) {
+ fmt.Printf("File.Open: f.crfs=%p\n", f.crfs)
+ h, err := f.File.Open(ctx, req, resp)
+ if err != nil {
+ return nil, err
+ }
+ clueFile := h.(*cluefs.File)
+ return &File {
+ File: clueFile,
+ crfs: f.crfs,
+ }, nil
+}
+
+func (f *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
+ fmt.Printf("File.Read: f.crfs=%p\n", f.crfs)
+ iblocks := f.crfs.SplitRange(req.Offset, int64(req.Size))
+ for _, ib := range iblocks {
+ var partReq fuse.ReadRequest
+ var partResp fuse.ReadResponse
+ o, l := ib.CiphertextRange()
+ partReq.Size = int(l)
+ partResp.Data = make([]byte, int(l))
+ partReq.Offset = o
+ err := f.File.Read(ctx, &partReq, &partResp)
+ if err != nil {
+ return err
+ }
+ plaintext, err := f.crfs.DecryptBlock(partResp.Data)
+ if err != nil {
+ fmt.Printf("Read: Block %d: %s\n", ib.BlockNo, err.Error())
+ return err
+ }
+ plaintext = ib.CropBlock(partResp.Data)
+ resp.Data = append(resp.Data, plaintext...)
+ }
+ return nil
+}
+
+func (f *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
+ iblocks := f.crfs.SplitRange(req.Offset, int64(len(req.Data)))
+ iblocks = iblocks
+ return nil
}