aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-03 23:54:12 +0200
committerJakob Unterwurzacher2015-09-03 23:54:12 +0200
commit6a110b8dde07a4bfa967547be8bf5b3756511a8b (patch)
tree045fd9015f0a83a38fafdfabd99cf5dde9d6d9df /frontend
parent4b98f74e3e875361436e57d870aed48c4bb44d77 (diff)
Mounts and show an empty dir
Diffstat (limited to 'frontend')
-rw-r--r--frontend/fs.go10
-rw-r--r--frontend/node.go79
2 files changed, 87 insertions, 2 deletions
diff --git a/frontend/fs.go b/frontend/fs.go
index 4ce3e5c..637d134 100644
--- a/frontend/fs.go
+++ b/frontend/fs.go
@@ -7,14 +7,20 @@ import (
type FS struct {
*cryptfs.FS
+ backing string
}
-func New(key [16]byte) *FS {
+func New(key [16]byte, b string) *FS {
return &FS {
FS: cryptfs.NewFS(key),
+ backing: b,
}
}
func (fs *FS) Root() (fs.Node, error) {
- return nil, nil
+ n := Node{
+ backing: "",
+ parentFS: fs,
+ }
+ return n, nil
}
diff --git a/frontend/node.go b/frontend/node.go
new file mode 100644
index 0000000..53ffb26
--- /dev/null
+++ b/frontend/node.go
@@ -0,0 +1,79 @@
+package frontend
+
+import (
+ "fmt"
+ "os"
+ "time"
+ "syscall"
+ "io/ioutil"
+ "path"
+
+ "golang.org/x/net/context"
+
+ //"github.com/rfjakob/gocryptfs/cryptfs"
+ "bazil.org/fuse"
+ "bazil.org/fuse/fs"
+)
+
+
+type Node struct {
+ fs.NodeRef
+ backing string
+ parentFS *FS
+}
+
+func StatToAttr(s *syscall.Stat_t, a *fuse.Attr) {
+ a.Inode = s.Ino
+ a.Size = uint64(s.Size)
+ a.Blocks = uint64(s.Blocks)
+ a.Atime = time.Unix(s.Atim.Sec, s.Atim.Nsec)
+ a.Mtime = time.Unix(s.Mtim.Sec, s.Mtim.Nsec)
+ a.Ctime = time.Unix(s.Ctim.Sec, s.Ctim.Nsec)
+ a.Mode = os.FileMode(s.Mode) | os.ModeDir
+ a.Nlink = uint32(s.Nlink)
+ a.Uid = uint32(s.Uid)
+ a.Gid = uint32(s.Gid)
+ a.Rdev = uint32(s.Rdev)
+}
+
+func (n Node) Attr(ctx context.Context, attr *fuse.Attr) error {
+ var err error
+ var st syscall.Stat_t
+ if n.backing == "" {
+ // When GetAttr is called for the toplevel directory, we always want
+ // to look through symlinks.
+ fmt.Printf("Attr %s\n", n.parentFS.backing)
+ //err = syscall.Stat(n.parentFS.backing, &st)
+ err = syscall.Stat("/", &st)
+ } else {
+ fmt.Printf("Attr %s\n", path.Join(n.parentFS.backing, n.backing))
+ p := path.Join(n.parentFS.backing, n.backing)
+ err = syscall.Lstat(p, &st)
+ }
+ if err != nil {
+ return err
+ }
+ StatToAttr(&st, attr)
+ return nil
+}
+
+func (n *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
+ entries, err := ioutil.ReadDir(n.backing)
+ if err != nil {
+ return nil, err
+ }
+ var fuseEntries []fuse.Dirent
+ for _, e := range entries {
+ var d fuse.Dirent
+ d.Name = e.Name()
+ fuseEntries = append(fuseEntries, d)
+ }
+ return fuseEntries, err
+}
+
+func (n *Node) Lookup(ctx context.Context, name string) (fs.Node, error) {
+ if name == "hello" {
+ return Node{}, nil
+ }
+ return nil, fuse.ENOENT
+}