Commit 6d86fb8e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ac8296b6
......@@ -29,6 +29,7 @@ type fileHandle struct {
}
/*
// XXX recheck whether Lookup is needed
func (d *dir) Lookup(out *fuse.Attr, name string, _ *fuse.Context) (*nodefs.Inode, fuse.Status) {
ientry := d.Inode().GetChild(name)
......@@ -38,6 +39,7 @@ func (d *dir) Lookup(out *fuse.Attr, name string, _ *fuse.Context) (*nodefs.Inod
// XXX fill out
return ientry, fuse.OK
}
*/
var nopen = 0
......@@ -106,8 +108,9 @@ func main() {
// NOTE cannot make entries before mount because Inode.AddChild does
// not work before that (panics on nil deref to mountRootXXX)
root.mkdir("aaa")
aaa := root.mkdir("aaa")
root.mkfile("hello.txt")
aaa.mkfile("world.txt")
server.Serve() // XXX error?
}
......@@ -241,9 +241,71 @@ package main
// link above), but better we have proper FUSE flag for filesystem server to
// tell the kernel it is fully responsible for invalidating pagecache.
// usage: wcfs zurl mountpoint
import (
"flag"
"log"
"os"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
)
// /.wcfs + option to prevent starting if wcfs was already started ?
// /zurl ?
type StaticFile struct {
nodefs.Node
data []byte
}
func NewStaticFile(data []byte) *StaticFile {
return &StaticFile{Node: nodefs.NewDefaultNode(), data: data}
}
func (f *StaticFile) Read(_ nodefs.File, dest []byte, off int64, _ *fuse.Context) (fuse.ReadResult, fuse.Status) {
l := int64(len(f.data))
end := off + l
if end > l {
end = l
}
return fuse.ReadResultData(f.data[off:end]), fuse.OK
}
// mkdir adds child to parent as directory.
func mkdir(parent nodefs.Node, name string, child nodefs.Node) {
parent.Inode().NewChild(name, true, child)
}
// mkfile adds child to parent as file.
func mkfile(parent nodefs.Node, name string, child nodefs.Node) {
parent.Inode().NewChild(name, false, child)
}
func main() {
log.SetPrefix("wcfs: ")
debug := flag.Bool("d", false, "debug")
flag.Parse()
if len(flag.Args()) != 2 {
log.Fatalf("Usage: %s zurl mntpt", os.Args[0])
}
zurl := flag.Args()[0]
mntpt := flag.Args()[1]
opts := nodefs.NewOptions()
opts.Debug = *debug
root := nodefs.NewDefaultNode()
server, _, err := nodefs.MountRoot(mntpt, root, opts)
if err != nil {
log.Fatal(err) // XXX err ctx?
}
// add entries to /
mkfile(root, ".wcfs", NewStaticFile([]byte(zurl)))
server.Serve() // XXX Serve returns no eror
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment