Commit e8445331b61e3d253665e03d0b376e464216806f

Authored by bellard
1 parent 8f447cc7

show real allocated disk image size on Windows (Frediano Ziglio)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1973 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 16 additions and 0 deletions
qemu-img.c
... ... @@ -23,6 +23,10 @@
23 23 */
24 24 #include "vl.h"
25 25  
  26 +#ifdef _WIN32
  27 +#include <windows.h>
  28 +#endif
  29 +
26 30 void *get_mmap_addr(unsigned long size)
27 31 {
28 32 return NULL;
... ... @@ -598,7 +602,19 @@ static int img_convert(int argc, char **argv)
598 602 #ifdef _WIN32
599 603 static int64_t get_allocated_file_size(const char *filename)
600 604 {
  605 + typedef DWORD (WINAPI * get_compressed_t)(const char *filename, DWORD *high);
  606 + get_compressed_t get_compressed;
601 607 struct _stati64 st;
  608 +
  609 + /* WinNT support GetCompressedFileSize to determine allocate size */
  610 + get_compressed = (get_compressed_t) GetProcAddress(GetModuleHandle("kernel32"), "GetCompressedFileSizeA");
  611 + if (get_compressed) {
  612 + DWORD high, low;
  613 + low = get_compressed(filename, &high);
  614 + if (low != 0xFFFFFFFFlu || GetLastError() == NO_ERROR)
  615 + return (((int64_t) high) << 32) + low;
  616 + }
  617 +
602 618 if (_stati64(filename, &st) < 0)
603 619 return -1;
604 620 return st.st_size;
... ...