Signed-off-by: Tomáš Golembiovský <tgole...@redhat.com> --- qga/commands-win32.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 5ebacd241f..e7d9cdea62 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -609,6 +609,31 @@ static void get_disk_properties(HANDLE vol_h, GuestDiskAddress *disk, disk->bus_type = find_bus_type(dev_desc->BusType); g_debug("bus type %d", disk->bus_type); + /* Query once more. Now with long enough buffer. */ + size = dev_desc->Size; + dev_desc = g_malloc0(size); + if (!DeviceIoControl(vol_h, IOCTL_STORAGE_QUERY_PROPERTY, &query, + sizeof(STORAGE_PROPERTY_QUERY), dev_desc, + size, &received, NULL)) { + error_setg_win32(errp, GetLastError(), "failed to get serial number"); + goto out_free; + } + if (dev_desc->SerialNumberOffset > 0) { + if (dev_desc->SerialNumberOffset >= received) { + error_setg(errp, "offset outside the buffer"); + goto out_free; + } + const char *serial = (char *)dev_desc + dev_desc->SerialNumberOffset; + size_t len = received - dev_desc->SerialNumberOffset; + if (*serial != 0) { + disk->serial = g_strndup(serial, len); + disk->has_serial = true; + g_debug("serial number %s", disk->serial); + } + } +out_free: + g_free(dev_desc); + return; } -- 2.19.0