Commit b6e23e54 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5a5aa765
...@@ -118,7 +118,6 @@ type defaultNode struct{ ...@@ -118,7 +118,6 @@ type defaultNode struct{
} }
func (n *defaultNode) Open(flags uint32, fctx *fuse.Context) (nodefs.File, fuse.Status) { func (n *defaultNode) Open(flags uint32, fctx *fuse.Context) (nodefs.File, fuse.Status) {
// XXX return something else for directory?
return &nodefs.WithFlags{ return &nodefs.WithFlags{
File: nil, File: nil,
FuseFlags: fuse.FOPEN_KEEP_CACHE, FuseFlags: fuse.FOPEN_KEEP_CACHE,
...@@ -134,21 +133,38 @@ func newDefaultNode() nodefs.Node { ...@@ -134,21 +133,38 @@ func newDefaultNode() nodefs.Node {
// NewStaticFile creates nodefs.Node for file with static data. // NewStaticFile creates nodefs.Node for file with static data.
func NewStaticFile(data []byte) *SmallFile { func NewStaticFile(data []byte) *SmallFile {
return NewSmallFile(func() []byte { return newSmallFile(func() []byte {
return data return data
}) }, fuse.FOPEN_KEEP_CACHE /*see ^^^*/)
} }
// SmallFile is a nodefs.Node for file with dynamic, but always small, data. // SmallFile is a nodefs.Node for file with potentially dynamic, but always small, data.
type SmallFile struct { type SmallFile struct {
nodefs.Node nodefs.Node
fuseFlags uint32 // fuse.FOPEN_*
// readData gives whole file data // readData gives whole file data
readData func() []byte readData func() []byte
} }
func newSmallFile(readData func() []byte, fuseFlags uint32) *SmallFile {
return &SmallFile{
Node: newDefaultNode(),
fuseFlags: fuseFlags,
readData: readData,
}
}
// NewSmallFile creates nodefs.Node for file with dynamic, but always small, data.
func NewSmallFile(readData func() []byte) *SmallFile { func NewSmallFile(readData func() []byte) *SmallFile {
return &SmallFile{Node: newDefaultNode(), readData: readData} return newSmallFile(readData, fuse.FOPEN_DIRECT_IO)
}
func (f *SmallFile) Open(flags uint32, fctx *fuse.Context) (nodefs.File, fuse.Status) {
return &nodefs.WithFlags{
File: nil,
FuseFlags: f.fuseFlags,
}, fuse.OK
} }
func (f *SmallFile) GetAttr(out *fuse.Attr, _ nodefs.File, _ *fuse.Context) fuse.Status { func (f *SmallFile) GetAttr(out *fuse.Attr, _ nodefs.File, _ *fuse.Context) fuse.Status {
......
...@@ -1418,7 +1418,6 @@ func main() { ...@@ -1418,7 +1418,6 @@ func main() {
mkdir(root, "head", head) mkdir(root, "head", head)
mkdir(head, "bigfile", bfdir) mkdir(head, "bigfile", bfdir)
mkfile(head, "at", NewSmallFile(head.readAt)) // TODO mtime(at) = tidtime(at) mkfile(head, "at", NewSmallFile(head.readAt)) // TODO mtime(at) = tidtime(at)
// XXX ^^^ invalidate cache or direct io XXX no FOPEN_KEEP_CACHE -> direct io
// for debugging/testing // for debugging/testing
_wcfs := newDefaultNode() _wcfs := newDefaultNode()
......
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