7 "github.com/anacrolix/fuse"
8 "github.com/anacrolix/fuse/fs"
9 "github.com/anacrolix/missinggo/v2"
11 "github.com/anacrolix/torrent"
14 type fileHandle struct {
24 func (me fileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
25 torrentfsReadRequests.Add(1)
27 panic("read on directory")
29 r := me.tf.NewReader()
31 pos, err := r.Seek(req.Offset, io.SeekStart)
35 if pos != req.Offset {
38 resp.Data = resp.Data[:req.Size]
39 readDone := make(chan struct{})
40 ctx, cancel := context.WithCancel(ctx)
45 me.fn.FS.blockedReads++
46 me.fn.FS.event.Broadcast()
49 r := missinggo.ContextedReader{r, ctx}
50 // log.Printf("reading %v bytes at %v", len(resp.Data), req.Offset)
52 // A user reported on that on freebsd 12.2, the system requires that reads are
53 // completely filled. Their system only asks for 64KiB at a time. I've seen systems that
54 // can demand up to 16MiB at a time, so this gets tricky. For now, I'll restore the old
55 // behaviour from before 2a7352a, which nobody reported problems with.
56 n, readErr = io.ReadFull(r, resp.Data)
57 if readErr == io.ErrUnexpectedEOF {
61 n, readErr = r.Read(resp.Data)
62 if readErr == io.EOF {
66 resp.Data = resp.Data[:n]
71 me.fn.FS.blockedReads--
72 me.fn.FS.event.Broadcast()
80 case <-me.fn.FS.destroyed:
87 func (me fileHandle) Release(context.Context, *fuse.ReleaseRequest) error {