dep ensure
This commit is contained in:
parent
1158ac4760
commit
c8c18403e4
371 changed files with 168673 additions and 1 deletions
70
vendor/github.com/hanwen/go-fuse/splice/copy.go
generated
vendored
Normal file
70
vendor/github.com/hanwen/go-fuse/splice/copy.go
generated
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package splice
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func SpliceCopy(dst *os.File, src *os.File, p *Pair) (int64, error) {
|
||||
total := int64(0)
|
||||
|
||||
for {
|
||||
n, err := p.LoadFrom(src.Fd(), p.size)
|
||||
if err != nil {
|
||||
return total, err
|
||||
}
|
||||
if n == 0 {
|
||||
break
|
||||
}
|
||||
m, err := p.WriteTo(dst.Fd(), n)
|
||||
total += int64(m)
|
||||
if err != nil {
|
||||
return total, err
|
||||
}
|
||||
if m < n {
|
||||
return total, err
|
||||
}
|
||||
if int(n) < p.size {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// Argument ordering follows io.Copy.
|
||||
func CopyFile(dstName string, srcName string, mode int) error {
|
||||
src, err := os.Open(srcName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dst, err := os.OpenFile(dstName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(mode))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dst.Close()
|
||||
|
||||
return CopyFds(dst, src)
|
||||
}
|
||||
|
||||
func CopyFds(dst *os.File, src *os.File) (err error) {
|
||||
p, err := splicePool.get()
|
||||
if p != nil {
|
||||
p.Grow(256 * 1024)
|
||||
_, err := SpliceCopy(dst, src, p)
|
||||
splicePool.done(p)
|
||||
return err
|
||||
} else {
|
||||
_, err = io.Copy(dst, src)
|
||||
}
|
||||
if err == io.EOF {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
68
vendor/github.com/hanwen/go-fuse/splice/pair.go
generated
vendored
Normal file
68
vendor/github.com/hanwen/go-fuse/splice/pair.go
generated
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package splice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Pair struct {
|
||||
r, w *os.File
|
||||
size int
|
||||
}
|
||||
|
||||
func (p *Pair) MaxGrow() {
|
||||
for p.Grow(2*p.size) == nil {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pair) Grow(n int) error {
|
||||
if n <= p.size {
|
||||
return nil
|
||||
}
|
||||
if !resizable {
|
||||
return fmt.Errorf("splice: want %d bytes, but not resizable", n)
|
||||
}
|
||||
if n > maxPipeSize {
|
||||
return fmt.Errorf("splice: want %d bytes, max pipe size %d", n, maxPipeSize)
|
||||
}
|
||||
|
||||
newsize, errNo := fcntl(p.r.Fd(), F_SETPIPE_SZ, n)
|
||||
if errNo != 0 {
|
||||
return fmt.Errorf("splice: fcntl returned %v", errNo)
|
||||
}
|
||||
p.size = newsize
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Pair) Cap() int {
|
||||
return p.size
|
||||
}
|
||||
|
||||
func (p *Pair) Close() error {
|
||||
err1 := p.r.Close()
|
||||
err2 := p.w.Close()
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
return err2
|
||||
}
|
||||
|
||||
func (p *Pair) Read(d []byte) (n int, err error) {
|
||||
return p.r.Read(d)
|
||||
}
|
||||
|
||||
func (p *Pair) ReadFd() uintptr {
|
||||
return p.r.Fd()
|
||||
}
|
||||
|
||||
func (p *Pair) WriteFd() uintptr {
|
||||
return p.w.Fd()
|
||||
}
|
||||
|
||||
func (p *Pair) Write(d []byte) (n int, err error) {
|
||||
return p.w.Write(d)
|
||||
}
|
||||
22
vendor/github.com/hanwen/go-fuse/splice/pair_darwin.go
generated
vendored
Normal file
22
vendor/github.com/hanwen/go-fuse/splice/pair_darwin.go
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package splice
|
||||
|
||||
import ()
|
||||
|
||||
func (p *Pair) LoadFromAt(fd uintptr, sz int, off int64) (int, error) {
|
||||
panic("not implemented")
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (p *Pair) LoadFrom(fd uintptr, sz int) (int, error) {
|
||||
panic("not implemented")
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (p *Pair) WriteTo(fd uintptr, n int) (int, error) {
|
||||
panic("not implemented")
|
||||
return 0, nil
|
||||
}
|
||||
37
vendor/github.com/hanwen/go-fuse/splice/pair_linux.go
generated
vendored
Normal file
37
vendor/github.com/hanwen/go-fuse/splice/pair_linux.go
generated
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package splice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func (p *Pair) LoadFromAt(fd uintptr, sz int, off int64) (int, error) {
|
||||
n, err := syscall.Splice(int(fd), &off, int(p.w.Fd()), nil, sz, 0)
|
||||
return int(n), err
|
||||
}
|
||||
|
||||
func (p *Pair) LoadFrom(fd uintptr, sz int) (int, error) {
|
||||
if sz > p.size {
|
||||
return 0, fmt.Errorf("LoadFrom: not enough space %d, %d",
|
||||
sz, p.size)
|
||||
}
|
||||
|
||||
n, err := syscall.Splice(int(fd), nil, int(p.w.Fd()), nil, sz, 0)
|
||||
if err != nil {
|
||||
err = os.NewSyscallError("Splice load from", err)
|
||||
}
|
||||
return int(n), err
|
||||
}
|
||||
|
||||
func (p *Pair) WriteTo(fd uintptr, n int) (int, error) {
|
||||
m, err := syscall.Splice(int(p.r.Fd()), nil, int(fd), nil, int(n), 0)
|
||||
if err != nil {
|
||||
err = os.NewSyscallError("Splice write", err)
|
||||
}
|
||||
return int(m), err
|
||||
}
|
||||
119
vendor/github.com/hanwen/go-fuse/splice/pool.go
generated
vendored
Normal file
119
vendor/github.com/hanwen/go-fuse/splice/pool.go
generated
vendored
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package splice
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var splicePool *pairPool
|
||||
|
||||
type pairPool struct {
|
||||
sync.Mutex
|
||||
unused []*Pair
|
||||
usedCount int
|
||||
}
|
||||
|
||||
func ClearSplicePool() {
|
||||
splicePool.clear()
|
||||
}
|
||||
|
||||
func Get() (*Pair, error) {
|
||||
return splicePool.get()
|
||||
}
|
||||
|
||||
func Total() int {
|
||||
return splicePool.total()
|
||||
}
|
||||
|
||||
func Used() int {
|
||||
return splicePool.used()
|
||||
}
|
||||
|
||||
// Return pipe pair to pool
|
||||
func Done(p *Pair) {
|
||||
splicePool.done(p)
|
||||
}
|
||||
|
||||
// Closes and discards pipe pair.
|
||||
func Drop(p *Pair) {
|
||||
splicePool.drop(p)
|
||||
}
|
||||
|
||||
func newSplicePairPool() *pairPool {
|
||||
return &pairPool{}
|
||||
}
|
||||
|
||||
func (me *pairPool) clear() {
|
||||
me.Lock()
|
||||
for _, p := range me.unused {
|
||||
p.Close()
|
||||
}
|
||||
me.unused = me.unused[:0]
|
||||
me.Unlock()
|
||||
}
|
||||
|
||||
func (me *pairPool) used() (n int) {
|
||||
me.Lock()
|
||||
n = me.usedCount
|
||||
me.Unlock()
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func (me *pairPool) total() int {
|
||||
me.Lock()
|
||||
n := me.usedCount + len(me.unused)
|
||||
me.Unlock()
|
||||
return n
|
||||
}
|
||||
|
||||
func (me *pairPool) drop(p *Pair) {
|
||||
p.Close()
|
||||
me.Lock()
|
||||
me.usedCount--
|
||||
me.Unlock()
|
||||
}
|
||||
|
||||
func (me *pairPool) get() (p *Pair, err error) {
|
||||
me.Lock()
|
||||
defer me.Unlock()
|
||||
|
||||
me.usedCount++
|
||||
l := len(me.unused)
|
||||
if l > 0 {
|
||||
p := me.unused[l-1]
|
||||
me.unused = me.unused[:l-1]
|
||||
return p, nil
|
||||
}
|
||||
|
||||
return newSplicePair()
|
||||
}
|
||||
|
||||
var discardBuffer [32 * 1024]byte
|
||||
|
||||
func DiscardAll(r io.Reader) {
|
||||
buf := discardBuffer[:]
|
||||
for {
|
||||
n, _ := r.Read(buf)
|
||||
if n < len(buf) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (me *pairPool) done(p *Pair) {
|
||||
DiscardAll(p.r)
|
||||
|
||||
me.Lock()
|
||||
me.usedCount--
|
||||
me.unused = append(me.unused, p)
|
||||
me.Unlock()
|
||||
}
|
||||
|
||||
func init() {
|
||||
splicePool = newSplicePairPool()
|
||||
}
|
||||
90
vendor/github.com/hanwen/go-fuse/splice/splice.go
generated
vendored
Normal file
90
vendor/github.com/hanwen/go-fuse/splice/splice.go
generated
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package splice
|
||||
|
||||
// Routines for efficient file to file copying.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var maxPipeSize int
|
||||
var resizable bool
|
||||
|
||||
func Resizable() bool {
|
||||
return resizable
|
||||
}
|
||||
|
||||
func MaxPipeSize() int {
|
||||
return maxPipeSize
|
||||
}
|
||||
|
||||
// From manpage on ubuntu Lucid:
|
||||
//
|
||||
// Since Linux 2.6.11, the pipe capacity is 65536 bytes.
|
||||
const DefaultPipeSize = 16 * 4096
|
||||
|
||||
func init() {
|
||||
content, err := ioutil.ReadFile("/proc/sys/fs/pipe-max-size")
|
||||
if err != nil {
|
||||
maxPipeSize = DefaultPipeSize
|
||||
} else {
|
||||
fmt.Sscan(string(content), &maxPipeSize)
|
||||
}
|
||||
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
log.Panicf("cannot create pipe: %v", err)
|
||||
}
|
||||
sz, errNo := fcntl(r.Fd(), F_GETPIPE_SZ, 0)
|
||||
resizable = (errNo == 0)
|
||||
_, errNo = fcntl(r.Fd(), F_SETPIPE_SZ, 2*sz)
|
||||
resizable = resizable && (errNo == 0)
|
||||
r.Close()
|
||||
w.Close()
|
||||
}
|
||||
|
||||
// copy & paste from syscall.
|
||||
func fcntl(fd uintptr, cmd int, arg int) (val int, errno syscall.Errno) {
|
||||
r0, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, fd, uintptr(cmd), uintptr(arg))
|
||||
val = int(r0)
|
||||
errno = syscall.Errno(e1)
|
||||
return
|
||||
}
|
||||
|
||||
const F_SETPIPE_SZ = 1031
|
||||
const F_GETPIPE_SZ = 1032
|
||||
|
||||
func newSplicePair() (p *Pair, err error) {
|
||||
p = &Pair{}
|
||||
p.r, p.w, err = os.Pipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
errNo := syscall.Errno(0)
|
||||
for _, f := range []*os.File{p.r, p.w} {
|
||||
_, errNo = fcntl(f.Fd(), syscall.F_SETFL, syscall.O_NONBLOCK)
|
||||
if errNo != 0 {
|
||||
p.Close()
|
||||
return nil, os.NewSyscallError("fcntl setfl", errNo)
|
||||
}
|
||||
}
|
||||
|
||||
p.size, errNo = fcntl(p.r.Fd(), F_GETPIPE_SZ, 0)
|
||||
if errNo == syscall.EINVAL {
|
||||
p.size = DefaultPipeSize
|
||||
return p, nil
|
||||
}
|
||||
if errNo != 0 {
|
||||
p.Close()
|
||||
return nil, os.NewSyscallError("fcntl getsize", errNo)
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue