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

Small polish in direntry.go

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