Commit 928afa1c authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: use offset for MemRegularFile reads. Test it.

parent d1deed27
......@@ -47,7 +47,7 @@ func (f *MemRegularFile) Read(ctx context.Context, fh FileHandle, dest []byte, o
if end > len(f.Data) {
end = len(f.Data)
}
return fuse.ReadResultData(f.Data[:end]), OK
return fuse.ReadResultData(f.Data[off:end]), OK
}
// MemSymlink is an inode holding a symlink in memory.
......
......@@ -5,7 +5,10 @@
package nodefs
import (
"bytes"
"context"
"io/ioutil"
"math/rand"
"os"
"syscall"
"testing"
......@@ -86,6 +89,38 @@ func TestDataFile(t *testing.T) {
}
}
func TestDataFileLargeRead(t *testing.T) {
root := &Inode{}
data := make([]byte, 256*1024)
rand.Read(data[:])
mntDir, clean := testMount(t, root, &Options{
FirstAutomaticIno: 1,
OnAdd: func(ctx context.Context) {
n := root.EmbeddedInode()
ch := n.NewPersistentInode(
ctx,
&MemRegularFile{
Data: data,
Attr: fuse.Attr{
Mode: 0464,
},
},
NodeAttr{})
n.AddChild("file", ch, false)
},
})
defer clean()
got, err := ioutil.ReadFile(mntDir + "/file")
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
if !bytes.Equal(got, data) {
t.Errorf("roundtrip read had change")
}
}
type SymlinkerRoot struct {
Inode
}
......
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