Fix examples to use vectored read
parent
ac82ada21e
commit
2be4ecc37d
|
@ -368,6 +368,8 @@ func (fs *cachingFS) ReadFile(
|
|||
ctx context.Context,
|
||||
op *fuseops.ReadFileOp) error {
|
||||
var err error
|
||||
op.BytesRead, err = io.ReadFull(rand.Reader, op.Dst)
|
||||
dst := make([]byte, op.Size)
|
||||
op.BytesRead, err = io.ReadFull(rand.Reader, dst)
|
||||
op.Data = [][]byte{dst}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -246,7 +246,8 @@ func (fs *dynamicFS) ReadFile(
|
|||
}
|
||||
reader := strings.NewReader(contents)
|
||||
var err error
|
||||
op.BytesRead, err = reader.ReadAt(op.Dst, op.Offset)
|
||||
op.Data = [][]byte{ make([]byte, op.Size) }
|
||||
op.BytesRead, err = reader.ReadAt(op.Data[0], op.Offset)
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
"github.com/jacobsa/fuse/fuseutil"
|
||||
)
|
||||
|
||||
const FooContents = "xxxx"
|
||||
var FooContents = []byte("xxxx")
|
||||
|
||||
const fooInodeID = fuseops.RootInodeID + 1
|
||||
|
||||
|
@ -171,7 +171,8 @@ func (fs *errorFS) ReadFile(
|
|||
return fmt.Errorf("Unexpected request: %#v", op)
|
||||
}
|
||||
|
||||
op.BytesRead = copy(op.Dst, FooContents)
|
||||
op.Data = [][]byte{FooContents}
|
||||
op.BytesRead = len(FooContents)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -196,7 +196,12 @@ func (fs *flushFS) ReadFile(
|
|||
}
|
||||
|
||||
// Read what we can.
|
||||
op.BytesRead = copy(op.Dst, fs.fooContents[op.Offset:])
|
||||
end := op.Offset+op.Size
|
||||
if end > int64(len(fs.fooContents)) {
|
||||
end = int64(len(fs.fooContents))
|
||||
}
|
||||
op.Data = [][]byte{ fs.fooContents[op.Offset : end] }
|
||||
op.BytesRead = int(end-op.Offset)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -250,7 +250,8 @@ func (fs *helloFS) ReadFile(
|
|||
reader := strings.NewReader("Hello, world!")
|
||||
|
||||
var err error
|
||||
op.BytesRead, err = reader.ReadAt(op.Dst, op.Offset)
|
||||
op.Data = [][]byte{ make([]byte, op.Size) }
|
||||
op.BytesRead, err = reader.ReadAt(op.Data[0], op.Offset)
|
||||
|
||||
// Special case: FUSE doesn't expect us to return io.EOF.
|
||||
if err == io.EOF {
|
||||
|
|
|
@ -692,7 +692,8 @@ func (fs *memFS) ReadFile(
|
|||
|
||||
// Serve the request.
|
||||
var err error
|
||||
op.BytesRead, err = inode.ReadAt(op.Dst, op.Offset)
|
||||
op.Data = [][]byte{ make([]byte, op.Size) }
|
||||
op.BytesRead, err = inode.ReadAt(op.Data[0], op.Offset)
|
||||
|
||||
// Don't return EOF errors; we just indicate EOF to fuse using a short read.
|
||||
if err == io.EOF {
|
||||
|
|
|
@ -160,8 +160,13 @@ func (fs *readonlyLoopbackFs) ReadFile(
|
|||
return fuse.EIO
|
||||
}
|
||||
|
||||
contents = contents[op.Offset:]
|
||||
op.BytesRead = copy(op.Dst, contents)
|
||||
end := op.Offset+op.Size
|
||||
if end > int64(len(contents)) {
|
||||
end = int64(len(contents))
|
||||
}
|
||||
|
||||
op.Data = [][]byte{ contents[op.Offset : end] }
|
||||
op.BytesRead = int(end-op.Offset)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue