//go:build linux

package localapi

import "syscall"

// statfsCapacity returns the total + used bytes of the filesystem mounted at path (Linux statvfs). A
// registry-sourced drive (no PVE storage) has no `pvesm status` usage, so /disks reads capacity here
// instead. ok=false on any error → the caller leaves the size fields zero.
func statfsCapacity(path string) (total, used int64, ok bool) {
	var st syscall.Statfs_t
	if err := syscall.Statfs(path, &st); err != nil {
		return 0, 0, false
	}
	bs := int64(st.Bsize)
	total = int64(st.Blocks) * bs
	if total <= 0 {
		return 0, 0, false
	}
	free := int64(st.Bfree) * bs
	used = total - free
	if used < 0 {
		used = 0
	}
	return total, used, true
}
