don't fail if cd is not in a drive

add used and usedPercent back in
This commit is contained in:
Ben Aldrich 2015-09-04 11:51:34 -06:00
parent 5c8a03100e
commit 6c000b035d
1 changed files with 9 additions and 5 deletions

View File

@ -41,11 +41,11 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
return nil, err return nil, err
} }
ret = &DiskUsageStat{ ret = &DiskUsageStat{
Path: path, Path: path,
Total: uint64(lpTotalNumberOfBytes), Total: uint64(lpTotalNumberOfBytes),
Free: uint64(lpTotalNumberOfFreeBytes), Free: uint64(lpTotalNumberOfFreeBytes),
// Used: uint64(lpTotalNumberOfBytes) - uint64(lpTotalNumberOfFreeBytes) Used: uint64(lpTotalNumberOfBytes) - uint64(lpTotalNumberOfFreeBytes),
// UsedPercent: (float64(lpTotalNumberOfBytes) - float64(lpTotalNumberOfFreeBytes)) / float64(lpTotalNumberOfBytes) * 100 UsedPercent: (float64(lpTotalNumberOfBytes) - float64(lpTotalNumberOfFreeBytes)) / float64(lpTotalNumberOfBytes) * 100,
// InodesTotal: 0, // InodesTotal: 0,
// InodesFree: 0, // InodesFree: 0,
// InodesUsed: 0, // InodesUsed: 0,
@ -55,6 +55,7 @@ func DiskUsage(path string) (*DiskUsageStat, error) {
} }
func DiskPartitions(all bool) ([]DiskPartitionStat, error) { func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
fmt.Println("IN DISK PARTITIONS")
var ret []DiskPartitionStat var ret []DiskPartitionStat
lpBuffer := make([]byte, 254) lpBuffer := make([]byte, 254)
diskret, _, err := procGetLogicalDriveStringsW.Call( diskret, _, err := procGetLogicalDriveStringsW.Call(
@ -93,6 +94,9 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
uintptr(unsafe.Pointer(&lpFileSystemNameBuffer[0])), uintptr(unsafe.Pointer(&lpFileSystemNameBuffer[0])),
uintptr(len(lpFileSystemNameBuffer))) uintptr(len(lpFileSystemNameBuffer)))
if driveret == 0 { if driveret == 0 {
if typeret == 5 {
continue //device is not ready will happen if there is no disk in the drive
}
return ret, err return ret, err
} }
opts := "rw" opts := "rw"