Wrap cluefs part I
This commit is contained in:
parent
6f90ec716a
commit
05a5c0a0ff
100
frontend/dir.go
100
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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
36
main.go
36
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
|
||||
|
Loading…
Reference in New Issue
Block a user