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

fuse: cleanup DirEntryList.

* document methods
* hide Offset
* hide Bytes method.
parent a7349e99
......@@ -25,40 +25,41 @@ func (d DirEntry) String() string {
}
type DirEntryList struct {
buf []byte
size int
// TODO - hide this again.
Offset uint64
buf []byte
size int
offset uint64
}
func NewDirEntryList(data []byte, off uint64) *DirEntryList {
return &DirEntryList{
buf: data[:0],
size: len(data),
Offset: off,
offset: off,
}
}
// AddDirEntry tries to add an entry.
func (l *DirEntryList) AddDirEntry(e DirEntry) bool {
// AddDirEntry tries to add an entry, and reports whether it
// succeeded.
func (l *DirEntryList) AddDirEntry(e DirEntry) (bool, uint64) {
return l.Add(nil, e.Name, uint64(raw.FUSE_UNKNOWN_INO), e.Mode)
}
func (l *DirEntryList) Add(prefix []byte, name string, inode uint64, mode uint32) bool {
// Add adds a direntry to the DirEntryList, returning whether it
// succeeded.
func (l *DirEntryList) Add(prefix []byte, name string, inode uint64, mode uint32) (bool, uint64) {
padding := (8 - len(name)&7) & 7
delta := padding + direntSize + len(name) + len(prefix)
oldLen := len(l.buf)
newLen := delta + oldLen
if newLen > l.size {
return false
return false, l.offset
}
l.buf = l.buf[:newLen]
copy(l.buf[oldLen:], prefix)
oldLen += len(prefix)
dirent := (*raw.Dirent)(unsafe.Pointer(&l.buf[oldLen]))
dirent.Off = l.Offset + 1
dirent.Off = l.offset + 1
dirent.Ino = inode
dirent.NameLen = uint32(len(name))
dirent.Typ = ModeToType(mode)
......@@ -70,18 +71,19 @@ func (l *DirEntryList) Add(prefix []byte, name string, inode uint64, mode uint32
copy(l.buf[oldLen:], eightPadding[:padding])
}
l.Offset = dirent.Off
return true
l.offset = dirent.Off
return true, l.offset
}
func (l *DirEntryList) AddDirLookupEntry(e DirEntry, entryOut *raw.EntryOut) bool {
// AddDirLookupEntry is used for ReadDirPlus. It serializes a DirEntry
// and its corresponding lookup. Pass a null EntryOut if the lookup
// data should be ignored.
func (l *DirEntryList) AddDirLookupEntry(e DirEntry, entryOut *raw.EntryOut) (bool, uint64) {
var lookup []byte
toSlice(&lookup, unsafe.Pointer(entryOut), unsafe.Sizeof(raw.EntryOut{}))
return l.Add(lookup, e.Name, uint64(raw.FUSE_UNKNOWN_INO), e.Mode)
}
func (l *DirEntryList) Bytes() []byte {
func (l *DirEntryList) bytes() []byte {
return l.buf
}
////////////////////////////////////////////////////////////////
......@@ -34,11 +34,12 @@ func (d *connectorDir) ReadDir(list *fuse.DirEntryList, input *raw.ReadIn, conte
log.Printf("got emtpy directory entry, mode %o.", e.Mode)
continue
}
if !list.AddDirEntry(e) {
ok, off := list.AddDirEntry(e)
d.lastOffset = off
if !ok {
break
}
}
d.lastOffset = list.Offset
return fuse.OK
}
......@@ -76,11 +77,12 @@ func (d *connectorDir) ReadDirPlus(list *fuse.DirEntryList, input *raw.ReadIn, c
log.Printf("got empty directory entry, mode %o.", e.Mode)
continue
}
if !list.AddDirLookupEntry(e, &d.lookups[input.Offset+uint64(i)]) {
ok, off := list.AddDirLookupEntry(e, &d.lookups[input.Offset+uint64(i)])
d.lastOffset = off
if !ok {
break
}
}
d.lastOffset = list.Offset
return fuse.OK
}
......
......@@ -128,7 +128,7 @@ func doReadDir(state *Server, req *request) {
entries := NewDirEntryList(buf, uint64(in.Offset))
code := state.fileSystem.ReadDir(entries, &req.context, in)
req.flatData = entries.Bytes()
req.flatData = entries.bytes()
req.status = code
}
......@@ -138,7 +138,7 @@ func doReadDirPlus(server *Server, req *request) {
entries := NewDirEntryList(buf, uint64(in.Offset))
code := server.fileSystem.ReadDirPlus(entries, &req.context, in)
req.flatData = entries.Bytes()
req.flatData = entries.bytes()
req.status = code
}
......
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