fix(win): report the home root's capacity on Windows too
root_total_bytes/root_used_bytes came out zero for a Windows home scan because the statvfs block was compiled out for _WIN32 and nothing replaced it; the panel therefore showed a 0% share for every folder. GetDiskFreeSpaceExA on the drive root (C:\ for C:\Users\admin) fills the same fields.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-11 07:05:57
Commit373cae83
Parents0687152a
Changed files
src/plugin_disks.c+18−1■■■■■
1 file+18−1
Diff
src/plugin_disks.c+18−1■■■■■
index 8a51b22..438fa22 100644
--- a/src/plugin_disks.c
+++ b/src/plugin_disks.c
@@ -838,7 +838,24 @@ static int mode_json(const char *qs)
838838 }
839839 }
840840
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
842859 {
843860 struct statvfs vfs;
844861 if (statvfs(root, &vfs) == 0) {
845862
src/plugin_disks.c+18−1■■■■■
index 8a51b22..438fa22 100644index 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) {
845862