github.com/hanwen/go-fuse@v1.0.0/splice/pair_linux.go (about) 1 // Copyright 2016 the Go-FUSE 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 splice 6 7 import ( 8 "fmt" 9 "os" 10 "syscall" 11 ) 12 13 func (p *Pair) LoadFromAt(fd uintptr, sz int, off int64) (int, error) { 14 n, err := syscall.Splice(int(fd), &off, p.w, nil, sz, 0) 15 return int(n), err 16 } 17 18 func (p *Pair) LoadFrom(fd uintptr, sz int) (int, error) { 19 if sz > p.size { 20 return 0, fmt.Errorf("LoadFrom: not enough space %d, %d", 21 sz, p.size) 22 } 23 24 n, err := syscall.Splice(int(fd), nil, p.w, nil, sz, 0) 25 if err != nil { 26 err = os.NewSyscallError("Splice load from", err) 27 } 28 return int(n), err 29 } 30 31 func (p *Pair) WriteTo(fd uintptr, n int) (int, error) { 32 m, err := syscall.Splice(p.r, nil, int(fd), nil, int(n), 0) 33 if err != nil { 34 err = os.NewSyscallError("Splice write", err) 35 } 36 return int(m), err 37 } 38 39 const _SPLICE_F_NONBLOCK = 0x2 40 41 func (p *Pair) discard() { 42 _, err := syscall.Splice(p.r, nil, int(devNullFD), nil, int(p.size), _SPLICE_F_NONBLOCK) 43 if err == syscall.EAGAIN { 44 // all good. 45 } else if err != nil { 46 panic(err) 47 } 48 }