From 339bc03e5eb9233c132e86317b4c5d0206a123b6 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 29 Jul 2015 10:12:11 +1000 Subject: [PATCH] Attempted to fix memfs. --- samples/memfs/inode.go | 11 +++++------ samples/memfs/memfs.go | 10 +++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index 78eca0b..2ec2397 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -278,7 +278,7 @@ func (in *inode) RemoveChild(name string) { // Serve a ReadDir request. // // REQUIRES: in.isDir() -func (in *inode) ReadDir(offset int, size int) (data []byte) { +func (in *inode) ReadDir(p []byte, offset int) (n int) { if !in.isDir() { panic("ReadDir called on non-directory.") } @@ -291,13 +291,12 @@ func (in *inode) ReadDir(offset int, size int) (data []byte) { continue } - data = fuseutil.AppendDirent(data, in.entries[i]) - - // Trim and stop early if we've exceeded the requested size. - if len(data) > size { - data = data[:size] + tmp := fuseutil.WriteDirent(p[n:], in.entries[i]) + if n == 0 { break } + + n += tmp } return diff --git a/samples/memfs/memfs.go b/samples/memfs/memfs.go index e1bf030..b2499ae 100644 --- a/samples/memfs/memfs.go +++ b/samples/memfs/memfs.go @@ -428,7 +428,9 @@ func (fs *memFS) Rename( existingID, _, ok := newParent.LookUpChild(op.NewName) if ok { existing := fs.getInodeOrDie(existingID) - if existing.isDir() && len(existing.ReadDir(0, 1024)) > 0 { + + var buf [4096]byte + if existing.isDir() && existing.ReadDir(buf[:], 0) > 0 { err = fuse.ENOTEMPTY return } @@ -538,7 +540,7 @@ func (fs *memFS) ReadDir( inode := fs.getInodeOrDie(op.Inode) // Serve the request. - op.Data = inode.ReadDir(int(op.Offset), op.Size) + op.BytesRead = inode.ReadDir(op.Dst, int(op.Offset)) return } @@ -571,9 +573,7 @@ func (fs *memFS) ReadFile( inode := fs.getInodeOrDie(op.Inode) // Serve the request. - op.Data = make([]byte, op.Size) - n, err := inode.ReadAt(op.Data, op.Offset) - op.Data = op.Data[:n] + op.BytesRead, err = inode.ReadAt(op.Dst, op.Offset) // Don't return EOF errors; we just indicate EOF to fuse using a short read. if err == io.EOF {