summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cryptfs/cryptfile.go (renamed from cryptfs/file.go)0
-rw-r--r--cryptfs/cryptfs.go (renamed from cryptfs/fs.go)0
-rw-r--r--frontend/dir.go100
-rw-r--r--frontend/fs.go9
-rw-r--r--frontend/node.go8
-rw-r--r--main.go36
6 files changed, 148 insertions, 5 deletions
diff --git a/cryptfs/file.go b/cryptfs/cryptfile.go
index 5645f3c..5645f3c 100644
--- a/cryptfs/file.go
+++ b/cryptfs/cryptfile.go
diff --git a/cryptfs/fs.go b/cryptfs/cryptfs.go
index f5781e2..f5781e2 100644
--- a/cryptfs/fs.go
+++ b/cryptfs/cryptfs.go
diff --git a/frontend/dir.go b/frontend/dir.go
index 4703df9..8e11837 100644
--- a/frontend/dir.go
+++ b/frontend/dir.go
@@ -1,10 +1,108 @@
package frontend
import (
- //"github.com/rfjakob/gocryptfs/cryptfs"
+ "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 Dir struct {
*cluefs.Dir
+ crfs *cryptfs.CryptFS
+}
+
+func NewDir(parent string, name string, fs *FS) *Dir {
+ fmt.Printf("NewDir parent=%s name=%s\n", parent, name)
+ return &Dir {
+ Dir: cluefs.NewDir(parent, name, fs.ClueFS),
+ crfs: fs.CryptFS,
+ }
+}
+
+func (d *Dir) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fusefs.Handle, error) {
+ fmt.Printf("Open\n")
+ h, err := d.Dir.Open(ctx, req, resp)
+ if err != nil {
+ return nil, err
+ }
+ clueDir := h.(*cluefs.Dir)
+
+ return Dir {
+ Dir: clueDir,
+ crfs: d.crfs,
+ }, nil
+}
+
+func (d *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fusefs.Node, error) {
+ fmt.Printf("Lookup %s\n", req.Name)
+ req.Name = d.crfs.EncryptPath(req.Name)
+ n, err := d.Dir.Lookup(ctx, req, resp)
+ if err != nil {
+ return nil, err
+ }
+ clueDir, ok := n.(*cluefs.Dir)
+ if ok {
+ return &Dir { Dir: clueDir }, nil
+ } else {
+ clueFile := n.(*cluefs.File)
+ return &File { File: clueFile }, nil
+ }
+}
+
+func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
+ fmt.Printf("ReadDirAll\n")
+ entries, err := d.Dir.ReadDirAll(ctx)
+ if err != nil {
+ return nil, err
+ }
+ var decrypted []fuse.Dirent
+ for _, e := range entries {
+ if e.Name == "." || e.Name == ".." {
+ decrypted = append(decrypted, e)
+ continue
+ }
+ newName, err := d.crfs.DecryptPath(e.Name)
+ if err != nil {
+ fmt.Printf("ReadDirAll: Error decoding \"%s\": %s\n", e.Name, err.Error())
+ continue
+ }
+ e.Name = newName
+ decrypted = append(decrypted, e)
+ }
+ return decrypted, nil
+}
+
+func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fusefs.Node, error) {
+ fmt.Printf("Mkdir %s\n", req.Name)
+ req.Name = d.crfs.EncryptPath(req.Name)
+ n, err := d.Dir.Mkdir(ctx, req)
+ if err != nil {
+ return nil, err
+ }
+ clueDir := n.(*cluefs.Dir)
+ return &Dir {
+ Dir: clueDir,
+ crfs: d.crfs,
+ }, nil
+}
+
+func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
+ fmt.Printf("Remove\n")
+ req.Name = d.crfs.EncryptPath(req.Name)
+ return d.Dir.Remove(ctx, req)
+}
+
+func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fusefs.Node, fusefs.Handle, error) {
+ fmt.Printf("Create\n")
+ req.Name = d.crfs.EncryptPath(req.Name)
+ n, _, err := d.Dir.Create(ctx, req, resp)
+ if err != nil {
+ return nil, nil, err
+ }
+ clueFile := n.(*cluefs.File)
+ cryptFile := &File {File: clueFile}
+ return cryptFile, cryptFile, nil
}
diff --git a/frontend/fs.go b/frontend/fs.go
index ba6ad09..83d1953 100644
--- a/frontend/fs.go
+++ b/frontend/fs.go
@@ -1,13 +1,16 @@
package frontend
import (
+ "fmt"
"github.com/rfjakob/gocryptfs/cryptfs"
"github.com/rfjakob/cluefs/lib/cluefs"
+ fusefs "bazil.org/fuse/fs"
)
type FS struct {
*cryptfs.CryptFS
*cluefs.ClueFS
+ backing string
}
type nullTracer struct {}
@@ -23,5 +26,11 @@ func NewFS(key [16]byte, backing string) *FS {
return &FS {
CryptFS: cryptfs.NewCryptFS(key),
ClueFS: clfs,
+ backing: backing,
}
}
+
+func (fs *FS) Root() (fusefs.Node, error) {
+ fmt.Printf("Root\n")
+ return NewDir("", fs.backing, fs), nil
+}
diff --git a/frontend/node.go b/frontend/node.go
index 7218d54..f9b630c 100644
--- a/frontend/node.go
+++ b/frontend/node.go
@@ -1,9 +1,17 @@
package frontend
import (
+ "fmt"
"github.com/rfjakob/cluefs/lib/cluefs"
)
type Node struct {
*cluefs.Node
}
+
+func NewNode(parent string, name string, fs *FS) *Node {
+ fmt.Printf("NewNode\n")
+ return &Node{
+ Node: cluefs.NewNode(parent, name, fs.ClueFS),
+ }
+}
diff --git a/main.go b/main.go
index af7bd21..6857b61 100644
--- a/main.go
+++ b/main.go
@@ -1,11 +1,18 @@
package main
import (
+ "bazil.org/fuse"
+ fusefs "bazil.org/fuse/fs"
+ "fmt"
"github.com/rfjakob/cluefs/lib/cluefs"
"github.com/rfjakob/gocryptfs/frontend"
"os"
)
+const (
+ PROGRAM_NAME = "gocryptfs"
+)
+
func main() {
// Parse command line arguments
conf, err := cluefs.ParseArguments()
@@ -17,10 +24,31 @@ func main() {
var key [16]byte
cfs := frontend.NewFS(key, conf.GetShadowDir())
- // Mount and serve file system requests
- if err = cfs.MountAndServe(conf.GetMountPoint(), conf.GetReadOnly()); err != nil {
- cluefs.ErrlogMain.Printf("could not mount file system [%s]", err)
- os.Exit(3)
+ // Mount the file system
+ mountOpts := []fuse.MountOption{
+ fuse.FSName(PROGRAM_NAME),
+ fuse.Subtype(PROGRAM_NAME),
+ fuse.VolumeName(PROGRAM_NAME),
+ fuse.LocalVolume(),
+ }
+ conn, err := fuse.Mount(conf.GetMountPoint(), mountOpts...)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ defer conn.Close()
+
+ // Start serving requests
+ if err = fusefs.Serve(conn, cfs); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ // Check for errors when mounting the file system
+ <-conn.Ready
+ if err = conn.MountError; err != nil {
+ fmt.Println(err)
+ os.Exit(1)
}
// We are done