github.com/geraldss/go/src@v0.0.0-20210511222824-ac7d0ebfc235/os/readfrom_linux.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package os 6 7 import ( 8 "internal/poll" 9 "io" 10 ) 11 12 var pollCopyFileRange = poll.CopyFileRange 13 14 func (f *File) readFrom(r io.Reader) (written int64, handled bool, err error) { 15 // copy_file_range(2) does not support destinations opened with 16 // O_APPEND, so don't even try. 17 if f.appendMode { 18 return 0, false, nil 19 } 20 21 remain := int64(1 << 62) 22 23 lr, ok := r.(*io.LimitedReader) 24 if ok { 25 remain, r = lr.N, lr.R 26 if remain <= 0 { 27 return 0, true, nil 28 } 29 } 30 31 src, ok := r.(*File) 32 if !ok { 33 return 0, false, nil 34 } 35 if src.checkValid("ReadFrom") != nil { 36 // Avoid returning the error as we report handled as false, 37 // leave further error handling as the responsibility of the caller. 38 return 0, false, nil 39 } 40 41 written, handled, err = pollCopyFileRange(&f.pfd, &src.pfd, remain) 42 if lr != nil { 43 lr.N -= written 44 } 45 return written, handled, NewSyscallError("copy_file_range", err) 46 }