qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Basil Salman <basil@daynix.com>
To: qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: Yan Vugenfirer <yan@daynix.com>
Subject: Re: [PATCH 1/1] qga-win: fix "guest-get-fsinfo" wrong filesystem type
Date: Tue, 9 Jun 2020 12:23:17 +0300	[thread overview]
Message-ID: <CAMpN4hg+3BKY-oh-tSj4TnB7hqZzy7dTpsFP3rxjs90yM-zmaw@mail.gmail.com> (raw)
In-Reply-To: <1588248700-2715-1-git-send-email-basil@daynix.com>

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

Ping

On Thu, Apr 30, 2020 at 3:11 PM Basil Salman <basil@daynix.com> wrote:

> From: Basil Salman <bsalman@redhat.com>
>
> This patch handles the case where unmounted volumes exist,
> where in that case GetVolumePathNamesForVolumeName returns
> empty path, GetVolumeInformation will use the current working
> directory instead.
> This patch fixes the issue by opening a handle to the volumes,
> and using GetVolumeInformationByHandleW instead.
>
> Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1746667
>
> Signed-off-by: Basil Salman <bsalman@redhat.com>
> Signed-off-by: Basil Salman <basil@daynix.com>
> ---
>  qga/commands-win32.c | 21 +++++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 82cf053..be07712 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -1021,11 +1021,13 @@ static GuestFilesystemInfo
> *build_guest_fsinfo(char *guid, Error **errp)
>  {
>      DWORD info_size;
>      char mnt, *mnt_point;
> +    wchar_t wfs_name[32];
>      char fs_name[32];
> -    char vol_info[MAX_PATH+1];
> +    wchar_t vol_info[MAX_PATH + 1];
>      size_t len;
>      uint64_t i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
>      GuestFilesystemInfo *fs = NULL;
> +    HANDLE hLocalDiskHandle = NULL;
>
>      GetVolumePathNamesForVolumeName(guid, (LPCH)&mnt, 0, &info_size);
>      if (GetLastError() != ERROR_MORE_DATA) {
> @@ -1040,18 +1042,27 @@ static GuestFilesystemInfo
> *build_guest_fsinfo(char *guid, Error **errp)
>          goto free;
>      }
>
> +    hLocalDiskHandle = CreateFile(guid, 0 , 0, NULL, OPEN_EXISTING,
> +                                  FILE_ATTRIBUTE_NORMAL |
> +                                  FILE_FLAG_BACKUP_SEMANTICS, NULL);
> +    if (INVALID_HANDLE_VALUE == hLocalDiskHandle) {
> +        error_setg_win32(errp, GetLastError(), "failed to get volume
> name");
> +        goto free;
> +    }
> +
>      len = strlen(mnt_point);
>      mnt_point[len] = '\\';
>      mnt_point[len+1] = 0;
> -    if (!GetVolumeInformation(mnt_point, vol_info, sizeof(vol_info),
> NULL, NULL,
> -                              NULL, (LPSTR)&fs_name, sizeof(fs_name))) {
> +
> +    if (!GetVolumeInformationByHandleW(hLocalDiskHandle, vol_info,
> +                                       sizeof(vol_info), NULL, NULL, NULL,
> +                                       (LPWSTR) & wfs_name,
> sizeof(wfs_name))) {
>          if (GetLastError() != ERROR_NOT_READY) {
>              error_setg_win32(errp, GetLastError(), "failed to get volume
> info");
>          }
>          goto free;
>      }
>
> -    fs_name[sizeof(fs_name) - 1] = 0;
>      fs = g_malloc(sizeof(*fs));
>      fs->name = g_strdup(guid);
>      fs->has_total_bytes = false;
> @@ -1070,9 +1081,11 @@ static GuestFilesystemInfo *build_guest_fsinfo(char
> *guid, Error **errp)
>              fs->has_used_bytes = true;
>          }
>      }
> +    wcstombs(fs_name, wfs_name, sizeof(wfs_name));
>      fs->type = g_strdup(fs_name);
>      fs->disk = build_guest_disk_info(guid, errp);
>  free:
> +    CloseHandle(hLocalDiskHandle);
>      g_free(mnt_point);
>      return fs;
>  }
> --
> 1.8.3.1
>
>

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

      reply	other threads:[~2020-06-09  9:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 12:11 [PATCH 1/1] qga-win: fix "guest-get-fsinfo" wrong filesystem type Basil Salman
2020-06-09  9:23 ` Basil Salman [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMpN4hg+3BKY-oh-tSj4TnB7hqZzy7dTpsFP3rxjs90yM-zmaw@mail.gmail.com \
    --to=basil@daynix.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yan@daynix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).