|
|
@ -79,21 +79,10 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
|
|
|
return ret, nil
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type errorCollector []error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *errorCollector) collect(e error) { *c = append(*c, e) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *errorCollector) Error() (err string) {
|
|
|
|
|
|
|
|
err = ""
|
|
|
|
|
|
|
|
for i, e := range *c {
|
|
|
|
|
|
|
|
err += fmt.Sprintf("\tError %d: %s\n", i, e.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
|
|
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
|
|
|
collector := new(errorCollector)
|
|
|
|
warnings := common.Warnings{
|
|
|
|
|
|
|
|
Verbose: true,
|
|
|
|
|
|
|
|
}
|
|
|
|
var ret []PartitionStat
|
|
|
|
var ret []PartitionStat
|
|
|
|
lpBuffer := make([]byte, 254)
|
|
|
|
lpBuffer := make([]byte, 254)
|
|
|
|
diskret, _, err := procGetLogicalDriveStringsW.Call(
|
|
|
|
diskret, _, err := procGetLogicalDriveStringsW.Call(
|
|
|
@ -109,7 +98,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|
|
|
typeret, _, _ := procGetDriveType.Call(uintptr(unsafe.Pointer(typepath)))
|
|
|
|
typeret, _, _ := procGetDriveType.Call(uintptr(unsafe.Pointer(typepath)))
|
|
|
|
if typeret == 0 {
|
|
|
|
if typeret == 0 {
|
|
|
|
err := windows.GetLastError()
|
|
|
|
err := windows.GetLastError()
|
|
|
|
collector.collect(err)
|
|
|
|
warnings.Add(err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 2: DRIVE_REMOVABLE 3: DRIVE_FIXED 4: DRIVE_REMOTE 5: DRIVE_CDROM
|
|
|
|
// 2: DRIVE_REMOVABLE 3: DRIVE_FIXED 4: DRIVE_REMOTE 5: DRIVE_CDROM
|
|
|
@ -134,7 +123,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|
|
|
if typeret == 5 || typeret == 2 {
|
|
|
|
if typeret == 5 || typeret == 2 {
|
|
|
|
continue // device is not ready will happen if there is no disk in the drive
|
|
|
|
continue // device is not ready will happen if there is no disk in the drive
|
|
|
|
}
|
|
|
|
}
|
|
|
|
collector.collect(err)
|
|
|
|
warnings.Add(err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opts := []string{"rw"}
|
|
|
|
opts := []string{"rw"}
|
|
|
@ -155,11 +144,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(*collector) == 0 {
|
|
|
|
return ret, warnings.Reference()
|
|
|
|
return ret, nil
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return ret, collector
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
|
|
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
|
|
|