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

Move DirEntryList into its own file.

parent 34c84d1c
......@@ -6,6 +6,7 @@ TARG=github.com/hanwen/go-fuse/fuse
GOFILES=misc.go\
fuse.go\
direntry.go\
mount.go\
types.go\
pathfilesystem.go \
......
package fuse
// all of the code for DirEntryList.
import (
"encoding/binary"
"bytes"
)
// Should make interface ?
type DirEntryList struct {
buf bytes.Buffer
offset uint64
maxSize int
}
func NewDirEntryList(max int) *DirEntryList {
return &DirEntryList{maxSize: max}
}
func (de *DirEntryList) AddString(name string, inode uint64, mode uint32) bool {
return de.Add([]byte(name), inode, mode)
}
func (de *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
lastLen := de.buf.Len()
de.offset++
dirent := new(Dirent)
dirent.Off = de.offset
dirent.Ino = inode
dirent.NameLen = uint32(len(name))
dirent.Typ = (mode & 0170000) >> 12
err := binary.Write(&de.buf, binary.LittleEndian, dirent)
if err != nil {
panic("Serialization of Dirent failed")
}
de.buf.Write(name)
padding := 8 - len(name)&7
if padding < 8 {
de.buf.Write(make([]byte, padding))
}
if de.buf.Len() > de.maxSize {
de.buf.Truncate(lastLen)
de.offset--
return false
}
return true
}
func (de *DirEntryList) Bytes() []byte {
return de.buf.Bytes()
}
......@@ -540,47 +540,3 @@ func doReadDir(state *MountState, header *InHeader, input *ReadIn) (out Empty, c
func doFsyncDir(state *MountState, header *InHeader, input *FsyncIn) (code Status) {
return state.FindDir(input.Fh).FsyncDir(input)
}
////////////////////////////////////////////////////////////////
// DentryList.
func NewDirEntryList(max int) *DirEntryList {
return &DirEntryList{maxSize: max}
}
func (de *DirEntryList) AddString(name string, inode uint64, mode uint32) bool {
return de.Add([]byte(name), inode, mode)
}
func (de *DirEntryList) Add(name []byte, inode uint64, mode uint32) bool {
lastLen := de.buf.Len()
de.offset++
dirent := new(Dirent)
dirent.Off = de.offset
dirent.Ino = inode
dirent.NameLen = uint32(len(name))
dirent.Typ = (mode & 0170000) >> 12
err := binary.Write(&de.buf, binary.LittleEndian, dirent)
if err != nil {
panic("Serialization of Dirent failed")
}
de.buf.Write(name)
padding := 8 - len(name)&7
if padding < 8 {
de.buf.Write(make([]byte, padding))
}
if de.buf.Len() > de.maxSize {
de.buf.Truncate(lastLen)
de.offset--
return false
}
return true
}
func (de *DirEntryList) Bytes() []byte {
return de.buf.Bytes()
}
......@@ -2,7 +2,6 @@ package fuse
import (
"syscall"
"bytes"
)
const (
......@@ -543,13 +542,6 @@ type RawFuseDir interface {
FsyncDir(input *FsyncIn) (code Status)
}
// Should make interface ?
type DirEntryList struct {
buf bytes.Buffer
offset uint64
maxSize int
}
type PathFilesystem interface {
GetAttr(name string) (*Attr, Status)
Readlink(name string) (string, Status)
......
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