in internal/diskutil/types/partitions.go [18:40]
func (p *SystemPartitions) AvailableDiskSpace(id string) (uint64, error) {
// Loop through all the partitions in the system and attempt to find the struct with a matching ID
var target *DiskPart
for i, disk := range p.AllDisksAndPartitions {
if strings.EqualFold(disk.DeviceIdentifier, id) {
target = &p.AllDisksAndPartitions[i]
break
}
}
// Ensure a DiskPart struct was found
if target == nil {
return 0, fmt.Errorf("no partition information found for ID [%s]", id)
}
// Sum up disk's current allocations.
var allocated uint64
for _, p := range target.Partitions {
allocated += p.Size
}
return target.Size - allocated, nil
}