aboutsummaryrefslogtreecommitdiff
path: root/test/fuse_integration/directio_darwin.go
blob: 67ccaf9a03b1c817a7f18afda3fbbfb04b077a9e (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
34
35
36
37
38
39
//go:build darwin

package fuse

import (
	"syscall"
)

// Direct I/O support for macOS

const (
	// macOS doesn't have O_DIRECT, but we can use fcntl with F_NOCACHE
	F_NOCACHE = 48
)

func openDirectIO(path string, flags int, mode uint32) (int, error) {
	// Open file normally first
	fd, err := syscall.Open(path, flags, mode)
	if err != nil {
		return -1, err
	}

	// Set F_NOCACHE to bypass buffer cache (similar to O_DIRECT)
	_, _, errno := syscall.Syscall(syscall.SYS_FCNTL,
		uintptr(fd),
		F_NOCACHE,
		1) // enable

	if errno != 0 {
		syscall.Close(fd)
		return -1, errno
	}

	return fd, nil
}

func isDirectIOSupported() bool {
	return true
}