qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] qga: Improve Windows filesystem space info retrieval logic
@ 2025-09-23 11:32 Minglei Liu
  2025-09-24  8:09 ` Kostiantyn Kostiuk
  0 siblings, 1 reply; 2+ messages in thread
From: Minglei Liu @ 2025-09-23 11:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kostiantyn Kostiuk, Michael Roth, minglei.liu

From: "minglei.liu" <minglei.liu@smartx.com>

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

Signed-off-by: minglei.liu <minglei.liu@smartx.com>
---
 qga/commands-win32.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 8227480810..acc2c11589 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -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)



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] qga: Improve Windows filesystem space info retrieval logic
  2025-09-23 11:32 [PATCH] qga: Improve Windows filesystem space info retrieval logic Minglei Liu
@ 2025-09-24  8:09 ` Kostiantyn Kostiuk
  0 siblings, 0 replies; 2+ messages in thread
From: Kostiantyn Kostiuk @ 2025-09-24  8:09 UTC (permalink / raw)
  To: Minglei Liu; +Cc: qemu-devel, Michael Roth

[-- Attachment #1: Type: text/plain, Size: 2374 bytes --]

Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>

Best Regards,
Kostiantyn Kostiuk.


On Tue, Sep 23, 2025 at 2:33 PM Minglei Liu <minglei.liu@smartx.com> wrote:

> From: "minglei.liu" <minglei.liu@smartx.com>
>
> 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
>
> Signed-off-by: minglei.liu <minglei.liu@smartx.com>
> ---
>  qga/commands-win32.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 8227480810..acc2c11589 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -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)
>
>

[-- Attachment #2: Type: text/html, Size: 3493 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-24  8:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 11:32 [PATCH] qga: Improve Windows filesystem space info retrieval logic Minglei Liu
2025-09-24  8:09 ` Kostiantyn Kostiuk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).