Commit a9652704 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Small polish in direntry.go

parent 3e687784
......@@ -9,6 +9,7 @@ import (
)
var _ = fmt.Print
// For FileSystemConnector. The connector determines inodes.
type DirEntry struct {
Mode uint32
......@@ -29,6 +30,10 @@ func (me *DirEntryList) AddString(name string, inode uint64, mode uint32) bool {
return me.Add([]byte(name), inode, mode)
}
func (me *DirEntryList) AddDirEntry(e DirEntry) bool {
return me.Add([]byte(e.Name), uint64(FUSE_UNKNOWN_INO), e.Mode)
}
func (me *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
lastLen := me.buf.Len()
me.offset++
......@@ -65,27 +70,25 @@ func (me *DirEntryList) Bytes() []byte {
////////////////////////////////////////////////////////////////
type Dir struct {
type rawDir interface {
ReadDir(input *ReadIn) (*DirEntryList, Status)
Release()
}
type connectorDir struct {
extra []DirEntry
stream chan DirEntry
leftOver DirEntry
}
func (me *Dir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
func (me *connectorDir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
if me.stream == nil && len(me.extra) == 0 {
return nil, OK
}
// We could also return
// me.connector.lookupUpdate(me.parentIno, name).NodeId but it
// appears FUSE will issue a LOOKUP afterwards for the entry
// anyway, so we skip hash table update here.
inode := uint64(FUSE_UNKNOWN_INO)
list := NewDirEntryList(int(input.Size))
if me.leftOver.Name != "" {
n := me.leftOver.Name
success := list.AddString(n, inode, me.leftOver.Mode)
success := list.AddDirEntry(me.leftOver)
if !success {
panic("No space for single entry.")
}
......@@ -94,7 +97,7 @@ func (me *Dir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
for len(me.extra) > 0 {
e := me.extra[len(me.extra)-1]
me.extra = me.extra[:len(me.extra)-1]
success := list.AddString(e.Name, inode, e.Mode)
success := list.AddDirEntry(e)
if !success {
me.leftOver = e
return list, OK
......@@ -106,7 +109,7 @@ func (me *Dir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
me.stream = nil
break
}
if !list.AddString(d.Name, inode, d.Mode) {
if !list.AddDirEntry(d) {
me.leftOver = d
break
}
......@@ -115,7 +118,7 @@ func (me *Dir) ReadDir(input *ReadIn) (*DirEntryList, Status) {
}
// Read everything so we make goroutines exit.
func (me *Dir) Release() {
func (me *connectorDir) Release() {
for ok := true; ok && me.stream != nil; {
_, ok = <-me.stream
if !ok {
......
......@@ -317,10 +317,6 @@ func (me *FileSystemConnector) getOpenedFile(h uint64) *openedFile {
return b
}
type rawDir interface {
ReadDir(input *ReadIn) (*DirEntryList, Status)
Release()
}
func (me *FileSystemConnector) verify() {
if !paranoia {
......
......@@ -140,7 +140,7 @@ func (me *FileSystemConnector) OpenDir(header *InHeader, input *OpenIn) (flags u
return 0, 0, err
}
de := &Dir{
de := &connectorDir{
extra: node.GetMountDirEntries(),
stream: stream,
}
......
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