Skip to content

Commit

Permalink
test fastcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
davies committed Oct 26, 2024
1 parent db8bc80 commit 4aa490a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
27 changes: 27 additions & 0 deletions fastcopy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"
"os"
"time"

"github.com/hanwen/go-fuse/v2/splice"
)

func main() {
if len(os.Args) < 3 {
fmt.Println("Usage: fastcopy <src> <dst>")
return
}
src, arg := os.Args[1], os.Args[2]
start := time.Now()
st, err := os.Stat(src)
if err != nil {
fmt.Println("Error:", err)
return
}
err = splice.CopyFile(arg, src, 0644)
used := time.Since(start)
speed := float64(st.Size()) / used.Seconds() / 1024 / 1024
fmt.Printf("Copied %s to %s in %v, speed: %.1f MiB/s\n", src, arg, used, speed)
}
14 changes: 13 additions & 1 deletion splice/pair_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

package splice

import ()
import (
"syscall"
)

func osPipe() (int, int, error) {
var fds [2]int
err := syscall.Pipe(fds[:])
return fds[0], fds[1], err
}

func (p *Pair) LoadFromAt(fd uintptr, sz int, off int64) (int, error) {
panic("not implemented")
Expand All @@ -20,3 +28,7 @@ func (p *Pair) WriteTo(fd uintptr, n int) (int, error) {
panic("not implemented")
return 0, nil
}

func (p *Pair) discard() {
panic("not implemented")
}
6 changes: 6 additions & 0 deletions splice/pair_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"syscall"
)

func osPipe() (int, int, error) {
var fds [2]int
err := syscall.Pipe2(fds[:], syscall.O_NONBLOCK)
return fds[0], fds[1], err
}

func (p *Pair) LoadFromAt(fd uintptr, sz int, off int64) (int, error) {
n, err := syscall.Splice(int(fd), &off, p.w, nil, sz, 0)
return int(n), err
Expand Down
6 changes: 0 additions & 6 deletions splice/splice.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ func fcntl(fd uintptr, cmd int, arg int) (val int, errno syscall.Errno) {
const F_SETPIPE_SZ = 1031
const F_GETPIPE_SZ = 1032

func osPipe() (int, int, error) {
var fds [2]int
err := syscall.Pipe2(fds[:], syscall.O_NONBLOCK)
return fds[0], fds[1], err
}

func newSplicePair() (p *Pair, err error) {
p = &Pair{}
p.r, p.w, err = osPipe()
Expand Down

0 comments on commit 4aa490a

Please sign in to comment.