2019-12-24 18:59:02 +00:00
|
|
|
// +build linux freebsd
|
2019-12-23 21:16:11 +00:00
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2020-01-30 13:03:24 +00:00
|
|
|
"fmt"
|
2019-12-23 21:16:11 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2020-01-30 13:03:24 +00:00
|
|
|
func fadviseSequentialRead(f *os.File, prefetch bool) error {
|
2019-12-23 21:16:11 +00:00
|
|
|
fd := int(f.Fd())
|
|
|
|
mode := unix.FADV_SEQUENTIAL
|
|
|
|
if prefetch {
|
|
|
|
mode |= unix.FADV_WILLNEED
|
|
|
|
}
|
|
|
|
if err := unix.Fadvise(int(fd), 0, 0, mode); err != nil {
|
2020-01-30 13:03:24 +00:00
|
|
|
return fmt.Errorf("error returned from unix.Fadvise(%d): %s", mode, err)
|
2019-12-23 21:16:11 +00:00
|
|
|
}
|
2020-01-30 13:03:24 +00:00
|
|
|
return nil
|
2019-12-23 21:16:11 +00:00
|
|
|
}
|