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 ...@@ -47,7 +47,7 @@ func (f *MemRegularFile) Read(ctx context.Context, fh FileHandle, dest []byte, o
if end > len(f.Data) { if end > len(f.Data) {
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. // MemSymlink is an inode holding a symlink in memory.
......
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
package nodefs package nodefs
import ( import (
"bytes"
"context" "context"
"io/ioutil"
"math/rand"
"os" "os"
"syscall" "syscall"
"testing" "testing"
...@@ -86,6 +89,38 @@ func TestDataFile(t *testing.T) { ...@@ -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 { type SymlinkerRoot struct {
Inode 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