| 1 | // FUSE error mapping helpers. go-fuse only builds on linux, darwin, and freebsd. |
| 2 | //go:build (linux || darwin || freebsd) && !nofuse |
| 3 | |
| 4 | package mount |
| 5 | |
| 6 | import ( |
| 7 | "context" |
| 8 | "syscall" |
| 9 | |
| 10 | "github.com/hanwen/go-fuse/v2/fs" |
| 11 | ) |
| 12 | |
| 13 | // ReadErrno maps an error from a context-aware read or write to a FUSE |
| 14 | // errno. It exists so context cancellation surfaces as EINTR rather than |
| 15 | // the unspecified code that fs.ToErrno produces for context.Canceled. |
| 16 | // |
| 17 | // The kernel sends FUSE_INTERRUPT when a userspace process is killed |
| 18 | // mid-syscall (Ctrl-C, SIGKILL on a stuck `cat`). go-fuse cancels the |
| 19 | // per-request context in response. Returning EINTR tells the kernel to |
| 20 | // abort the syscall with the right errno; without this, fs.ToErrno |
| 21 | // turns context.Canceled into something the caller can't act on. |
| 22 | func ReadErrno(err error) syscall.Errno { |
| 23 | if err == context.Canceled || err == context.DeadlineExceeded { |
| 24 | return syscall.EINTR |
| 25 | } |
| 26 | return fs.ToErrno(err) |
| 27 | } |