Download this file
| 1 | //go:build !windows |
| 2 | |
| 3 | package host |
| 4 | |
| 5 | import "syscall" |
| 6 | |
| 7 | // diskBytes reports the total and available bytes of the filesystem holding |
| 8 | // dir. |
| 9 | // |
| 10 | // It returns BYTES, not the raw statfs fields, and that is the point: Bsize |
| 11 | // is int64 on Linux and uint32 on darwin, a difference that already broke |
| 12 | // the CI build once (see .amadan/ci.d/20-cross@5's header) because the |
| 13 | // multiplication happened at every call site instead of once here. Callers |
| 14 | // now get two plain uint64s and no per-OS arithmetic. |
| 15 | func diskBytes(dir string) (total, avail uint64, err error) { |
| 16 | var st syscall.Statfs_t |
| 17 | if err := syscall.Statfs(dir, &st); err != nil { |
| 18 | return 0, 0, err |
| 19 | } |
| 20 | return uint64(st.Blocks) * uint64(st.Bsize), uint64(st.Bavail) * uint64(st.Bsize), nil |
| 21 | } |
| 22 | |