Commit 20b92a9a authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Fix bpb around end-of-file.

parent ce101c4f
package fuse
import (
"bytes"
"fmt"
"io"
"io/ioutil"
......@@ -530,18 +529,38 @@ func TestReadLarge(t *testing.T) {
ts := NewTestCase(t)
defer ts.Cleanup()
// Add a bit more to test the splicing at the end.
content := make([]byte, 1024*1024+43)
for i := range content {
content[i] = byte(i)
// Make blocks that are not period on 1024 bytes, so we can
// catch errors due to misalignments.
block := make([]byte, 1023)
content := make([]byte, 385*1023)
for i := range block {
block[i] = byte(i)
}
start := 0
for start < len(content) {
left := len(content) - start
if left < len(block) {
block = block[:left]
}
copy(content[start:], block)
start += len(block)
}
err := ioutil.WriteFile(ts.origFile, []byte(content), 0644)
CheckSuccess(err)
back, err := ioutil.ReadFile(ts.mountFile)
CheckSuccess(err)
if bytes.Compare(content, back) != 0 {
t.Errorf("content comparison failed")
if len(back) != len(content) {
t.Errorf("content length: got %d want %d", len(back), len(content))
}
for i := range content {
if content[i] != back[i] {
t.Errorf("content mismatch byte %d, got %d want %d.", i, back[i], content[i])
break
}
}
}
......
......@@ -364,7 +364,7 @@ func (ms *MountState) write(req *request) Status {
if err := ms.TrySplice(header, req, req.flatData.Fd, req.flatData.FdSize, req.flatData.FdOff); err == nil {
return OK
} else {
log.Println("Splice error", err)
log.Println("TrySplice:", err)
buf := ms.AllocOut(req, uint32(req.flatData.FdSize))
req.flatData.Read(buf)
header = req.serializeHeader(req.flatData.Size())
......@@ -406,9 +406,8 @@ func (ms *MountState) TrySplice(header []byte, req *request,
return err
}
// TODO - fix debug output.
header = req.serializeHeader(n)
return ms.TrySplice(header, req, fd, n, -1)
return ms.TrySplice(header, req, finalSplice.ReadFd(), n, -1)
}
if err != nil {
......@@ -417,7 +416,7 @@ func (ms *MountState) TrySplice(header []byte, req *request,
}
if n != size {
return fmt.Errorf("splice: wrote %d, want %d", n, req.flatData.FdSize)
return fmt.Errorf("wrote %d, want %d", n, req.flatData.FdSize)
}
_, err = finalSplice.WriteTo(ms.mountFile.Fd(), total)
......
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