Commit 9dd4fe7f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Simplify open directory seeking.

Fix bug in MemNodeFs.
parent 2c972a0a
...@@ -106,7 +106,7 @@ func (n *DefaultFsNode) Flush(file File, openFlags uint32, context *Context) (co ...@@ -106,7 +106,7 @@ func (n *DefaultFsNode) Flush(file File, openFlags uint32, context *Context) (co
func (n *DefaultFsNode) OpenDir(context *Context) ([]DirEntry, Status) { func (n *DefaultFsNode) OpenDir(context *Context) ([]DirEntry, Status) {
ch := n.Inode().Children() ch := n.Inode().Children()
s := make([]DirEntry, len(ch)) s := make([]DirEntry, 0, len(ch))
for name, child := range ch { for name, child := range ch {
fi, code := child.FsNode().GetAttr(nil, context) fi, code := child.FsNode().GetAttr(nil, context)
if code.Ok() { if code.Ok() {
......
...@@ -4,13 +4,13 @@ package fuse ...@@ -4,13 +4,13 @@ package fuse
import ( import (
"bytes" "bytes"
"fmt" "log"
"unsafe" "unsafe"
"github.com/hanwen/go-fuse/raw" "github.com/hanwen/go-fuse/raw"
) )
var _ = fmt.Print var _ = log.Print
// DirEntry is a type for PathFileSystem and NodeFileSystem to return // DirEntry is a type for PathFileSystem and NodeFileSystem to return
// directory contents in. // directory contents in.
...@@ -21,11 +21,11 @@ type DirEntry struct { ...@@ -21,11 +21,11 @@ type DirEntry struct {
type DirEntryList struct { type DirEntryList struct {
buf bytes.Buffer buf bytes.Buffer
offset *uint64 offset uint64
maxSize int maxSize int
} }
func NewDirEntryList(max int, off *uint64) *DirEntryList { func NewDirEntryList(max int, off uint64) *DirEntryList {
return &DirEntryList{maxSize: max, offset: off} return &DirEntryList{maxSize: max, offset: off}
} }
...@@ -39,10 +39,10 @@ func (l *DirEntryList) AddDirEntry(e DirEntry) bool { ...@@ -39,10 +39,10 @@ func (l *DirEntryList) AddDirEntry(e DirEntry) bool {
func (l *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool { func (l *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
lastLen := l.buf.Len() lastLen := l.buf.Len()
(*l.offset)++
l.offset++
dirent := raw.Dirent{ dirent := raw.Dirent{
Off: *l.offset, Off: l.offset,
Ino: inode, Ino: inode,
NameLen: uint32(len(name)), NameLen: uint32(len(name)),
Typ: ModeToType(mode), Typ: ModeToType(mode),
...@@ -61,7 +61,7 @@ func (l *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool { ...@@ -61,7 +61,7 @@ func (l *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
if l.buf.Len() > l.maxSize { if l.buf.Len() > l.maxSize {
l.buf.Truncate(lastLen) l.buf.Truncate(lastLen)
(*l.offset)-- l.offset--
return false return false
} }
return true return true
...@@ -80,31 +80,21 @@ type rawDir interface { ...@@ -80,31 +80,21 @@ type rawDir interface {
type connectorDir struct { type connectorDir struct {
stream []DirEntry stream []DirEntry
leftOver DirEntry
lastOffset uint64
} }
// TODO - use index into []stream for seeking correctly.
func (d *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) { func (d *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
if d.stream == nil { if d.stream == nil {
return nil, OK return nil, OK
} }
list := NewDirEntryList(int(input.Size), &d.lastOffset) off := input.Offset
if d.leftOver.Name != "" { list := NewDirEntryList(int(input.Size), off)
success := list.AddDirEntry(d.leftOver)
if !success { todo := d.stream[off:]
panic("No space for single entry.") for _, e := range todo {
} if !list.AddDirEntry(e) {
d.leftOver.Name = "" break
}
for len(d.stream) > 0 {
e := d.stream[len(d.stream)-1]
success := list.AddDirEntry(e)
if !success {
return list, OK
} }
d.stream = d.stream[:len(d.stream)-1]
} }
return list, OK return list, OK
} }
......
...@@ -112,15 +112,11 @@ func (c *FileSystemConnector) OpenDir(header *raw.InHeader, input *raw.OpenIn) ( ...@@ -112,15 +112,11 @@ func (c *FileSystemConnector) OpenDir(header *raw.InHeader, input *raw.OpenIn) (
if err != OK { if err != OK {
return 0, 0, err return 0, 0, err
} }
stream = append(stream, node.getMountDirEntries()...) stream = append(stream, node.getMountDirEntries()...)
de := &connectorDir{ de := &connectorDir{
stream: append(stream, DirEntry{S_IFDIR, "."}, DirEntry{S_IFDIR, ".."}), stream: append(stream, DirEntry{S_IFDIR, "."}, DirEntry{S_IFDIR, ".."}),
} }
h, opened := node.mount.registerFileHandle(node, de, nil, input.Flags) h, opened := node.mount.registerFileHandle(node, de, nil, input.Flags)
// TODO - implement seekable directories
opened.FuseFlags |= raw.FOPEN_NONSEEKABLE
return opened.FuseFlags, h, OK return opened.FuseFlags, h, OK
} }
......
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