Truncate the result of Getfsstat to the item count that is returned.

This count may be less than what was returned by the first call to Getfsstat.
pull/1392/head
Brian Ryner 2 years ago
parent 3b918ebd29
commit c5e42b972f

@ -20,9 +20,11 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
return ret, err
}
fs := make([]unix.Statfs_t, count)
if _, err = unix.Getfsstat(fs, unix.MNT_WAIT); err != nil {
count, err := unix.Getfsstat(fs, unix.MNT_WAIT)
if err != nil {
return ret, err
}
fs = fs[:count] // Actual count may be less than from the first call.
for _, stat := range fs {
opts := []string{"rw"}
if stat.Flags&unix.MNT_RDONLY != 0 {

Loading…
Cancel
Save