aboutsummaryrefslogtreecommitdiff
path: root/test/fuse_integration/sendfile_linux.go
blob: b5a0c0d6107942e116be30c50036030eeb00b3be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//go:build linux

package fuse

import (
	"syscall"
	"unsafe"
)

// Sendfile support for Linux

func sendfileTransfer(outFd int, inFd int, offset *int64, count int) (int, error) {
	var offsetPtr uintptr
	if offset != nil {
		offsetPtr = uintptr(unsafe.Pointer(offset))
	}

	n, _, errno := syscall.Syscall6(syscall.SYS_SENDFILE,
		uintptr(outFd),
		uintptr(inFd),
		offsetPtr,
		uintptr(count),
		0, 0)

	if errno != 0 {
		return 0, errno
	}
	return int(n), nil
}

func isSendfileSupported() bool {
	return true
}