Files
admin 5ff5f8e0ab v0.59.0: report backing device + capacity for a registry-sourced /disks row
Agent-view showed "—" device + no size for a raw (no-PVE-storage) drive because
the registry union row never set backing_device/total_bytes/used_bytes (Observe
drives get those from pvesm status). Resolve BackingDevice via ByUUIDDevicePath +
read capacity via statfsCapacity (build-tagged syscall.Statfs; no-op off-Linux).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 21:34:11 +02:00

27 lines
703 B
Go

//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
}