From 2be4ecc37deb36475b3c75ef6fb15c25dd184da4 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 26 Aug 2021 10:23:40 +0300 Subject: [PATCH] Fix examples to use vectored read --- samples/cachingfs/caching_fs.go | 4 +++- samples/dynamicfs/dynamic_fs.go | 3 ++- samples/errorfs/error_fs.go | 5 +++-- samples/flushfs/flush_fs.go | 7 ++++++- samples/hellofs/hello_fs.go | 3 ++- samples/memfs/memfs.go | 3 ++- samples/roloopbackfs/roloopbackfs.go | 9 +++++++-- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/samples/cachingfs/caching_fs.go b/samples/cachingfs/caching_fs.go index f2b9d2b..c4f3cd3 100644 --- a/samples/cachingfs/caching_fs.go +++ b/samples/cachingfs/caching_fs.go @@ -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 } diff --git a/samples/dynamicfs/dynamic_fs.go b/samples/dynamicfs/dynamic_fs.go index 0a2b48a..52faf25 100644 --- a/samples/dynamicfs/dynamic_fs.go +++ b/samples/dynamicfs/dynamic_fs.go @@ -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 } diff --git a/samples/errorfs/error_fs.go b/samples/errorfs/error_fs.go index 7acbbda..e2cb0df 100644 --- a/samples/errorfs/error_fs.go +++ b/samples/errorfs/error_fs.go @@ -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 } diff --git a/samples/flushfs/flush_fs.go b/samples/flushfs/flush_fs.go index 565afbb..8968867 100644 --- a/samples/flushfs/flush_fs.go +++ b/samples/flushfs/flush_fs.go @@ -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 } diff --git a/samples/hellofs/hello_fs.go b/samples/hellofs/hello_fs.go index dd6b767..7e9263b 100644 --- a/samples/hellofs/hello_fs.go +++ b/samples/hellofs/hello_fs.go @@ -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 { diff --git a/samples/memfs/memfs.go b/samples/memfs/memfs.go index a09e79f..e64c588 100644 --- a/samples/memfs/memfs.go +++ b/samples/memfs/memfs.go @@ -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 { diff --git a/samples/roloopbackfs/roloopbackfs.go b/samples/roloopbackfs/roloopbackfs.go index bd2e9da..ff7af14 100644 --- a/samples/roloopbackfs/roloopbackfs.go +++ b/samples/roloopbackfs/roloopbackfs.go @@ -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 }