File: poll_darwin.go

package info (click to toggle)
golang-github-hanwen-go-fuse 2.1.0%2Bgit20220822.58a7e14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,292 kB
  • sloc: cpp: 78; sh: 43; makefile: 16
file content (49 lines) | stat: -rw-r--r-- 904 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45
46
47
48
49
package fuse

import (
	"path/filepath"
	"syscall"
	"unsafe"
)

type pollFd struct {
	Fd      int32
	Events  int16
	Revents int16
}

func sysPoll(fds []pollFd, timeout int) (n int, err error) {
	r0, _, e1 := syscall.Syscall(syscall.SYS_POLL, uintptr(unsafe.Pointer(&fds[0])),
		uintptr(len(fds)), uintptr(timeout))
	n = int(r0)
	if e1 != 0 {
		err = syscall.Errno(e1)
	}
	return n, err
}

func pollHack(mountPoint string) error {
	const (
		POLLIN    = 0x1
		POLLPRI   = 0x2
		POLLOUT   = 0x4
		POLLRDHUP = 0x2000
		POLLERR   = 0x8
		POLLHUP   = 0x10
	)

	fd, err := syscall.Open(filepath.Join(mountPoint, pollHackName), syscall.O_RDONLY, 0)
	if err != nil {
		return err
	}
	pollData := []pollFd{{
		Fd:     int32(fd),
		Events: POLLIN | POLLPRI | POLLOUT,
	}}

	// Trigger _OP_POLL, so we can say ENOSYS. We don't care about
	// the return value.
	sysPoll(pollData, 0)
	syscall.Close(fd)
	return nil
}