Commit fe2f8723 authored by Aaron Jacobs's avatar Aaron Jacobs

Implemented HelloFS.ReadFile.

parent 4ef670f8
......@@ -4,7 +4,9 @@
package samples
import (
"io"
"os"
"strings"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseutil"
......@@ -243,3 +245,23 @@ func (fs *HelloFS) OpenFile(
resp = &fuse.OpenFileResponse{}
return
}
func (fs *HelloFS) ReadFile(
ctx context.Context,
req *fuse.ReadFileRequest) (resp *fuse.ReadFileResponse, err error) {
resp = &fuse.ReadFileResponse{}
// Let io.ReaderAt deal with the semantics.
reader := strings.NewReader("Hello, world!")
resp.Data = make([]byte, req.Size)
n, err := reader.ReadAt(resp.Data, req.Offset)
resp.Data = resp.Data[:n]
// Special case: FUSE doesn't expect us to return io.EOF.
if err == io.EOF {
err = nil
}
return
}
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