2016-07-18 00:03:23 +02:00
|
|
|
// +build linux darwin freebsd
|
|
|
|
|
|
|
|
package mount
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bazil.org/fuse"
|
|
|
|
fusefs "bazil.org/fuse/fs"
|
2017-05-02 23:35:07 +02:00
|
|
|
"github.com/ncw/rclone/cmd/mountlib"
|
2016-07-18 00:03:23 +02:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ReadFileHandle is an open for read file handle on a File
|
|
|
|
type ReadFileHandle struct {
|
2017-05-02 23:35:07 +02:00
|
|
|
*mountlib.ReadFileHandle
|
|
|
|
// mu sync.Mutex
|
|
|
|
// closed bool // set if handle has been closed
|
|
|
|
// r *fs.Account
|
|
|
|
// o fs.Object
|
|
|
|
// readCalled bool // set if read has been called
|
|
|
|
// offset int64
|
2016-07-18 00:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check interface satisfied
|
|
|
|
var _ fusefs.Handle = (*ReadFileHandle)(nil)
|
|
|
|
|
|
|
|
// Check interface satisfied
|
|
|
|
var _ fusefs.HandleReader = (*ReadFileHandle)(nil)
|
|
|
|
|
|
|
|
// Read from the file handle
|
2017-01-17 17:32:04 +01:00
|
|
|
func (fh *ReadFileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) (err error) {
|
2017-05-02 23:35:07 +02:00
|
|
|
data, err := fh.ReadFileHandle.Read(int64(req.Size), req.Offset)
|
2017-01-17 17:32:04 +01:00
|
|
|
if err != nil {
|
2017-05-02 23:35:07 +02:00
|
|
|
return translateError(err)
|
2016-07-18 00:03:23 +02:00
|
|
|
}
|
2017-05-02 23:35:07 +02:00
|
|
|
resp.Data = data
|
|
|
|
return nil
|
2016-07-18 00:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check interface satisfied
|
|
|
|
var _ fusefs.HandleFlusher = (*ReadFileHandle)(nil)
|
|
|
|
|
|
|
|
// Flush is called each time the file or directory is closed.
|
|
|
|
// Because there can be multiple file descriptors referring to a
|
|
|
|
// single opened file, Flush can be called multiple times.
|
|
|
|
func (fh *ReadFileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error {
|
2017-05-02 23:35:07 +02:00
|
|
|
return translateError(fh.ReadFileHandle.Flush())
|
2016-07-18 00:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ fusefs.HandleReleaser = (*ReadFileHandle)(nil)
|
|
|
|
|
|
|
|
// Release is called when we are finished with the file handle
|
|
|
|
//
|
|
|
|
// It isn't called directly from userspace so the error is ignored by
|
|
|
|
// the kernel
|
|
|
|
func (fh *ReadFileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) error {
|
2017-05-02 23:35:07 +02:00
|
|
|
return translateError(fh.ReadFileHandle.Release())
|
2016-07-18 00:03:23 +02:00
|
|
|
}
|