Skip to content

Commit

Permalink
fadvise
Browse files Browse the repository at this point in the history
  • Loading branch information
davies committed Oct 29, 2024
1 parent 4aa490a commit ae2f617
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
17 changes: 16 additions & 1 deletion splice/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@
package splice

import (
"fmt"
"io"
"os"
)

// NOTE: DEPRECIATED
const (
FADVISE_NORMAL = 0x0
FADVISE_RANDOM = 0x1
FADVISE_SEQUENTIAL = 0x2
FADVISE_WILLNEED = 0x3
FADVISE_DONTNEED = 0x4
FADVISE_NOREUSE = 0x5
)

func SpliceCopy(dst *os.File, src *os.File, p *Pair) (int64, error) {
total := int64(0)

st, _ := src.Stat()
err := Fadvise64(int(src.Fd()), 0, st.Size(), FADVISE_SEQUENTIAL)
if err != nil {
fmt.Println("Fadvise64 error:", err)
}
for {
n, err := p.LoadFrom(src.Fd(), p.size)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions splice/pair_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ func (p *Pair) WriteTo(fd uintptr, n int) (int, error) {
func (p *Pair) discard() {
panic("not implemented")
}

func Fadvise64(fd int, offset int64, length int64, advice int) error {
return nil
}
13 changes: 13 additions & 0 deletions splice/pair_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ func (p *Pair) discard() {
log.Panicf("splicing into /dev/null: %v (close R %d '%v', close W %d '%v')", err, p.r, errR, p.w, errW)
}
}

// NOTE: DEPRECIATED
func Fadvise64(fd int, offset int64, length int64, advice int) error {
_, _, errno := syscall.Syscall6(syscall.SYS_FADVISE64,
uintptr(fd),
uintptr(offset),
uintptr(length),
uintptr(advice), 0, 0)
if errno != 0 {
return errno
}
return nil
}

0 comments on commit ae2f617

Please sign in to comment.