Commit ce46e694 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Document and move ReadResult interface to api.go.

parent 24136e0d
...@@ -144,6 +144,7 @@ type PathNodeFsOptions struct { ...@@ -144,6 +144,7 @@ type PathNodeFsOptions struct {
ClientInodes bool ClientInodes bool
} }
// A File object should be returned from FileSystem.Open and // A File object should be returned from FileSystem.Open and
// FileSystem.Create. Include DefaultFile into the struct to inherit // FileSystem.Create. Include DefaultFile into the struct to inherit
// a default null implementation. // a default null implementation.
...@@ -176,6 +177,21 @@ type File interface { ...@@ -176,6 +177,21 @@ type File interface {
Utimens(atimeNs int64, mtimeNs int64) Status Utimens(atimeNs int64, mtimeNs int64) Status
} }
// The result of Read is an array of bytes, but for performance
// reasons, we can also return data as a file-descriptor/offset/size
// tuple. If the backing store for a file is another filesystem, this
// reduces the amount of copying between the kernel and the FUSE
// server. The ReadResult interface captures both cases.
type ReadResult interface {
// Returns the raw bytes for the read, possibly using the
// passed buffer. The buffer should be larger than the return
// value from Size.
Bytes(buf []byte) []byte
// Size returns how many bytes this return value takes at most.
Size() int
}
// Wrap a File return in this to set FUSE flags. Also used internally // Wrap a File return in this to set FUSE flags. Also used internally
// to store open file data. // to store open file data.
type WithFlags struct { type WithFlags struct {
......
...@@ -5,19 +5,9 @@ import ( ...@@ -5,19 +5,9 @@ import (
"syscall" "syscall"
) )
type ReadResult interface {
Bytes(buf []byte) []byte
Size() int
}
// The result of Read is an array of bytes, but for performance
// reasons, we can also return data as a file-descriptor/offset/size // ReadResultData is the read return for returning bytes directly.
// tuple. If the backing store for a file is another filesystem, this
// reduces the amount of copying between the kernel and the FUSE
// server
//
// If at any point, the raw data is needed, ReadResult.Read() will
// load the raw data into the Data member.
type ReadResultData struct { type ReadResultData struct {
// Raw bytes for the read. // Raw bytes for the read.
Data []byte Data []byte
...@@ -31,9 +21,9 @@ func (r *ReadResultData) Bytes(buf []byte) []byte { ...@@ -31,9 +21,9 @@ func (r *ReadResultData) Bytes(buf []byte) []byte {
return r.Data return r.Data
} }
// ReadResultFd is the read return for zero-copy file data.
type ReadResultFd struct { type ReadResultFd struct {
// If Data is nil and Status OK, splice from the following // Splice from the following file.
// file.
Fd uintptr Fd uintptr
// Offset within Fd, or -1 to use current offset. // Offset within Fd, or -1 to use current offset.
......
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