carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package assetcache
4
5import "golang.org/x/sys/unix"
6
7type statfsFS struct{}
8
9// Statfs is the real FS: the kernel's answer for the filesystem holding dir.
10// free counts the blocks an unprivileged writer may use (Bavail).
11var Statfs FS = statfsFS{}
12
13func (statfsFS) Space(dir string) (total, free uint64, err error) {
14 var st unix.Statfs_t
15 if err := unix.Statfs(dir, &st); err != nil {
16 return 0, 0, err
17 }
18 bsize := uint64(st.Bsize)
19 return st.Blocks * bsize, st.Bavail * bsize, nil
20}
21