Skip to contentSkip to conversation

qga: Improve Windows filesystem space info retrieval logic

PATCH In review Minglei Liu 2 participants 2 messages Sep 23, 2025 – Sep 24, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qga: Improve Windows filesystem space info retrieval logic

From: "minglei.liu" <[email protected]>

Previously, disk space reporting only worked for volumes with drive letters, skipping those without (e.g. System Reserved).

This change always calls GetDiskFreeSpaceEx with fs->name, which is a volume GUID path. Windows APIs accept both drive letters (e.g. "C:\") and volume GUIDs (e.g. "\\?\Volume{GUID}\") as valid lpDirectoryName parameters, so space reporting is now consistent across all volumes.

Reference:
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file

---
 qga/commands-win32.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
qga/commands-win32.c +9 -9
index 8227480810..acc2c11589 100644
@@ -1164,15 +1164,15 @@ static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp)
         fs->mountpoint = g_strdup("System Reserved");
     } else {
         fs->mountpoint = g_strndup(mnt_point, len);
-        if (GetDiskFreeSpaceEx(fs->mountpoint,
-                               (PULARGE_INTEGER) & i64FreeBytesToCaller,
-                               (PULARGE_INTEGER) & i64TotalBytes,
-                               (PULARGE_INTEGER) & i64FreeBytes)) {
-            fs->used_bytes = i64TotalBytes - i64FreeBytes;
-            fs->total_bytes = i64TotalBytes;
-            fs->has_total_bytes = true;
-            fs->has_used_bytes = true;
-        }
+    }
+    if (GetDiskFreeSpaceEx(fs->name,
+                            (PULARGE_INTEGER) & i64FreeBytesToCaller,
+                            (PULARGE_INTEGER) & i64TotalBytes,
+                            (PULARGE_INTEGER) & i64FreeBytes)) {
+        fs->used_bytes = i64TotalBytes - i64FreeBytes;
+        fs->total_bytes = i64TotalBytes;
+        fs->has_total_bytes = true;
+        fs->has_used_bytes = true;
     }
     wcstombs(fs_name, wfs_name, sizeof(wfs_name));
     fs->type = g_strdup(fs_name);
Signature · 1 line
2.39.5 (Apple Git-154)
Reviewed-by on v1 1/1
#1 lore raw

Best Regards,
Kostiantyn Kostiuk.

Quoted 53 lines · Minglei Liu

From: "minglei.liu" <[email protected]>

Previously, disk space reporting only worked for volumes with drive letters,
skipping those without (e.g. System Reserved).

This change always calls GetDiskFreeSpaceEx with fs->name, which is a volume GUID path. Windows APIs accept both drive letters (e.g. "C:\") and volume GUIDs (e.g. "\\?\Volume{GUID}\") as valid lpDirectoryName parameters, so space reporting is now consistent across all volumes.

Reference:
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file

---
 qga/commands-win32.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
qga/commands-win32.c +9 -9
index 8227480810..acc2c11589 100644
@@ -1164,15 +1164,15 @@ static GuestFilesystemInfo
 *build_guest_fsinfo(char *guid, Error **errp)
         fs->mountpoint = g_strdup("System Reserved");
     } else {
         fs->mountpoint = g_strndup(mnt_point, len);
-        if (GetDiskFreeSpaceEx(fs->mountpoint,
-                               (PULARGE_INTEGER) & i64FreeBytesToCaller,
-                               (PULARGE_INTEGER) & i64TotalBytes,
-                               (PULARGE_INTEGER) & i64FreeBytes)) {
-            fs->used_bytes = i64TotalBytes - i64FreeBytes;
-            fs->total_bytes = i64TotalBytes;
-            fs->has_total_bytes = true;
-            fs->has_used_bytes = true;
-        }
+    }
+    if (GetDiskFreeSpaceEx(fs->name,
+                            (PULARGE_INTEGER) & i64FreeBytesToCaller,
+                            (PULARGE_INTEGER) & i64TotalBytes,
+                            (PULARGE_INTEGER) & i64FreeBytes)) {
+        fs->used_bytes = i64TotalBytes - i64FreeBytes;
+        fs->total_bytes = i64TotalBytes;
+        fs->has_total_bytes = true;
+        fs->has_used_bytes = true;
     }
     wcstombs(fs_name, wfs_name, sizeof(wfs_name));
     fs->type = g_strdup(fs_name);

--
2.39.5 (Apple Git-154)