Commit 36625c28 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 56b8309c
package main
import (
"flag"
"fmt"
"log"
"os"
"time"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
)
// dir represents a directory in the filesystem.
type dir struct {
nodefs.Node
}
// file represents a file in the filesystem.
type file struct {
nodefs.Node
}
// fileHandle represents opened file.
type fileHandle struct {
nodefs.File
content []byte
}
/*
// 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)
if ientry == nil {
return nil, fuse.ENOENT
}
// XXX fill out
return ientry, fuse.OK
}
*/
var nopen = 0
func (f *file) Open(flags uint32, _ *fuse.Context) (nodefs.File, fuse.Status) {
_, name := f.Inode().Parent()
nopen++ // XXX -> atomic
data := fmt.Sprintf("%04d %s\n", nopen, name)
h := &fileHandle{File: nodefs.NewDefaultFile(), content: []byte(data)}
// force direct-io to disable pagecache: we alway return different data
// and st_size=0 (like in /proc).
// XXX + FOPEN_NONSEEKABLE - then it will be like socket
return &nodefs.WithFlags{
File: h,
FuseFlags: fuse.FOPEN_DIRECT_IO,
}, fuse.OK
}
func (fh *fileHandle) Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
l := int64(len(dest))
// XXX demonstrate we can indeed serve different content to different openings.
if l >= 1 {
l = 1
time.Sleep(1*time.Second)
}
end := off + l
if ldata := int64(len(fh.content)); end > ldata {
end = ldata
}
res := fh.content[off:end]
fmt.Printf("read [%d:%d] -> %q\n", off, end, res)
return fuse.ReadResultData(res), fuse.OK
}
func (d *dir) mkdir(name string) *dir {
child := &dir{Node: nodefs.NewDefaultNode()}
d.Inode().NewChild(name, true, child)
return child
}
func (d *dir) mkfile(name string) *file {
child := &file{Node: nodefs.NewDefaultNode()}
d.Inode().NewChild(name, false, child)
return child
}
func main() {
debug := flag.Bool("d", true, "debug")
flag.Parse()
if len(flag.Args()) != 1 {
log.Fatalf("Usage: %s mntpt", os.Args[0])
}
mntpt := flag.Args()[0]
root := &dir{Node: nodefs.NewDefaultNode()}
opts := nodefs.NewOptions()
if *debug {
opts.Debug = true
}
server, _, err := nodefs.MountRoot(mntpt, root, opts)
if err != nil {
log.Fatal(err) // XXX err ctx?
}
// NOTE cannot make entries before mount because Inode.AddChild does
// not work before that (panics on nil deref to mountRootXXX)
aaa := root.mkdir("aaa")
root.mkfile("hello.txt")
aaa.mkfile("world.txt")
server.Serve() // XXX error?
}
......@@ -44,6 +44,8 @@ def main():
root = conn.root()
# 0, 1, 2, ... as u32
#
# XXX also include hole inside and at tail.
data = arange(0, blksize32, dtype='>u4').tobytes()
root['zblk0'] = z0 = ZBlk0()
......
......@@ -118,8 +118,8 @@ def test_join_autostart():
# --- test access to data ----
# DF corresponds to ΔF in wcfs.
# it represents a change in files space.
# DF represents a change in files space.
# it corresponds to ΔF in wcfs.go .
class DF:
# .rev tid
# .byfile {} ZBigFile -> DFile
......@@ -127,8 +127,8 @@ class DF:
# rev set from outside
dF.byfile = {}
# DFile is similar to ΔFile in wcfs.
# represents a change to one file.
# DFile represents a change to one file.
# it is is similar to ΔFile in wcfs.go .
class DFile:
# .rev tid
# .ddata {} blk -> data XXX name
......@@ -646,6 +646,21 @@ def test_wcfs():
done.recv()
print('\nCCC\n')
# checkSetupWatch verifies setting up new watch for zf@at.
def checkSetupWatch(zf, at):
# all changes to zf
vdf = [_.byfile[zf] for _ in t.dFtail if zf in t.dFtail.byfile]
# changes to zf after at
vdfpost = [_ for _ in vdf if _.rev > at]
# open watch and check that we receive pins for blocks changed > at
w = t.openwatch()
for i in range(len(t.dFtail)):
return
# XXX test watch with all at variants
......
......@@ -70,6 +70,7 @@ type zBlk interface {
// inΔFtail returns pointer to struct zblkInΔFtail embedded into this ZBlk.
inΔFtail() *zblkInΔFtail
// XXX kill - in favour of inΔFtail
/*
// bindFile associates ZBlk as being used by file to store block #blk.
//
......@@ -100,6 +101,7 @@ type zBlk interface {
var _ zBlk = (*ZBlk0)(nil)
var _ zBlk = (*ZBlk1)(nil)
// XXX kill
/*
// ---- zBlkBase ----
......
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