diskStats returns information about the amount of space that is available on a current disk volume for the user who calls this function.
()
| 15 | // diskStats returns information about the amount of space that is available on |
| 16 | // a current disk volume for the user who calls this function. |
| 17 | func diskStats() (*disk, error) { |
| 18 | var ( |
| 19 | freeBytes uint64 = 0 |
| 20 | totalBytes uint64 = 0 |
| 21 | ) |
| 22 | |
| 23 | // windows sets return value to 0 when function fails. |
| 24 | ret, _, err := procGetDiskFreeSpaceExW.Call( |
| 25 | 0, |
| 26 | uintptr(unsafe.Pointer(&freeBytes)), |
| 27 | uintptr(unsafe.Pointer(&totalBytes)), |
| 28 | 0, |
| 29 | ) |
| 30 | if ret == 0 { |
| 31 | return nil, err |
| 32 | } |
| 33 | |
| 34 | // diskStats functions from other platforms return disk usage in kiB. |
| 35 | return &disk{ |
| 36 | Usage: (totalBytes - freeBytes) / 1024, |
| 37 | Total: totalBytes / 1024, |
| 38 | }, nil |
| 39 | } |
| 40 | |
| 41 | // memoryStatus retrieves information about the system's current usage of |
| 42 | // physical memory. |