summaryrefslogtreecommitdiff
path: root/frontend/file.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-05 14:08:00 +0200
committerJakob Unterwurzacher2015-09-05 14:08:00 +0200
commit4ab9862ccb5911836acda9834b0b25f892229533 (patch)
tree4c55e5b44ecf2b4d94e762b036a7c66ad225c68a /frontend/file.go
parent1257b4249d1473cd496e0b423c6aaa71b20aa41e (diff)
Fix read path
Diffstat (limited to 'frontend/file.go')
-rw-r--r--frontend/file.go51
1 files changed, 50 insertions, 1 deletions
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
}