Commit 350acb3a authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Update offset during readdir.

parent ec443730
...@@ -18,12 +18,12 @@ type DirEntry struct { ...@@ -18,12 +18,12 @@ 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) *DirEntryList { func NewDirEntryList(max int, off *uint64) *DirEntryList {
return &DirEntryList{maxSize: max} return &DirEntryList{maxSize: max, offset: off}
} }
func (me *DirEntryList) AddString(name string, inode uint64, mode uint32) bool { func (me *DirEntryList) AddString(name string, inode uint64, mode uint32) bool {
...@@ -36,10 +36,10 @@ func (me *DirEntryList) AddDirEntry(e DirEntry) bool { ...@@ -36,10 +36,10 @@ func (me *DirEntryList) AddDirEntry(e DirEntry) bool {
func (me *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool { func (me *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
lastLen := me.buf.Len() lastLen := me.buf.Len()
me.offset++ (*me.offset)++
dirent := Dirent{ dirent := Dirent{
Off: me.offset, Off: *me.offset,
Ino: inode, Ino: inode,
NameLen: uint32(len(name)), NameLen: uint32(len(name)),
Typ: ModeToType(mode), Typ: ModeToType(mode),
...@@ -58,7 +58,7 @@ func (me *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool { ...@@ -58,7 +58,7 @@ func (me *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
if me.buf.Len() > me.maxSize { if me.buf.Len() > me.maxSize {
me.buf.Truncate(lastLen) me.buf.Truncate(lastLen)
me.offset-- (*me.offset)--
return false return false
} }
return true return true
...@@ -79,6 +79,7 @@ type connectorDir struct { ...@@ -79,6 +79,7 @@ type connectorDir struct {
extra []DirEntry extra []DirEntry
stream chan DirEntry stream chan DirEntry
leftOver DirEntry leftOver DirEntry
lastOffset uint64
} }
func (me *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) { func (me *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
...@@ -86,7 +87,7 @@ func (me *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) { ...@@ -86,7 +87,7 @@ func (me *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
return nil, OK return nil, OK
} }
list := NewDirEntryList(int(input.Size)) list := NewDirEntryList(int(input.Size), &me.lastOffset)
if me.leftOver.Name != "" { if me.leftOver.Name != "" {
success := list.AddDirEntry(me.leftOver) success := list.AddDirEntry(me.leftOver)
if !success { if !success {
......
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