aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2006-06-14 15:32:10 +0000
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2006-06-14 15:32:10 +0000
commite8445331b61e3d253665e03d0b376e464216806f (patch)
treefb5abfa9fb5b543f0f7a74f48e5b2d65f37687ff
parent8f447cc753ac5f095be3cd9c404bf590319bc696 (diff)
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
-rw-r--r--qemu-img.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/qemu-img.c b/qemu-img.c
index 3a18c93254..44f9092e7d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -23,6 +23,10 @@
*/
#include "vl.h"
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
void *get_mmap_addr(unsigned long size)
{
return NULL;
@@ -598,7 +602,19 @@ static int img_convert(int argc, char **argv)
#ifdef _WIN32
static int64_t get_allocated_file_size(const char *filename)
{
+ typedef DWORD (WINAPI * get_compressed_t)(const char *filename, DWORD *high);
+ get_compressed_t get_compressed;
struct _stati64 st;
+
+ /* WinNT support GetCompressedFileSize to determine allocate size */
+ get_compressed = (get_compressed_t) GetProcAddress(GetModuleHandle("kernel32"), "GetCompressedFileSizeA");
+ if (get_compressed) {
+ DWORD high, low;
+ low = get_compressed(filename, &high);
+ if (low != 0xFFFFFFFFlu || GetLastError() == NO_ERROR)
+ return (((int64_t) high) << 32) + low;
+ }
+
if (_stati64(filename, &st) < 0)
return -1;
return st.st_size;