| index 8a51b22..438fa22 100644 | | index 8a51b22..438fa22 100644 |
| --- a/src/plugin_disks.c | | --- a/src/plugin_disks.c |
| +++ b/src/plugin_disks.c | | +++ b/src/plugin_disks.c |
| @@ -838,7 +838,24 @@ static int mode_json(const char *qs) | | @@ -838,7 +838,24 @@ static int mode_json(const char *qs) |
| 838 | } | 838 | } |
| 839 | } | 839 | } |
| 840 | | 840 | |
| 841 | -#if !defined(_WIN32) | 841 | +#if defined(_WIN32) |
| | 842 | + { |
| | 843 | + /* GetDiskFreeSpaceExA needs a drive root, not a deep path. */ |
| | 844 | + char drive[8]; |
| | 845 | + ULARGE_INTEGER avail, total, totalfree; |
| | 846 | + if (root[0] && root[1] == ':') { |
| | 847 | + drive[0] = root[0]; drive[1] = ':'; drive[2] = '\\'; drive[3] = '\0'; |
| | 848 | + if (GetDiskFreeSpaceExA(drive, &avail, &total, &totalfree)) { |
| | 849 | + total_bytes = (unsigned long long)total.QuadPart; |
| | 850 | + free_bytes = (unsigned long long)totalfree.QuadPart; |
| | 851 | + used_bytes = total_bytes >= free_bytes ? total_bytes - free_bytes : 0; |
| | 852 | + if (used_bytes + (unsigned long long)avail.QuadPart > 0) |
| | 853 | + root_pct = (double)used_bytes * 100.0 / |
| | 854 | + (double)(used_bytes + (unsigned long long)avail.QuadPart); |
| | 855 | + } |
| | 856 | + } |
| | 857 | + } |
| | 858 | +#else |
| 842 | { | 859 | { |
| 843 | struct statvfs vfs; | 860 | struct statvfs vfs; |
| 844 | if (statvfs(root, &vfs) == 0) { | 861 | if (statvfs(root, &vfs) == 0) { |
| 845 | | 862 | |