summaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2004-08-03 21:15:11 +0000
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2004-08-03 21:15:11 +0000
commit57d1a2b62c3a89533bf50297a606ed028068e18e (patch)
treed4f80630c7a9d299c892e67753c7f3c147dee438 /qemu-img.c
parentd5249393efe472d50eb027e286566a57ba868bf2 (diff)
downloadqemu-57d1a2b62c3a89533bf50297a606ed028068e18e.tar.gz
win32 port
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1041 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/qemu-img.c b/qemu-img.c
index 480dff95fd..cdb0ea1244 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -113,7 +113,7 @@ void __attribute__((noreturn)) error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- fprintf(stderr, "qemuimg: ");
+ fprintf(stderr, "qemu-img: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
exit(1);
@@ -127,8 +127,8 @@ static void format_print(void *opaque, const char *name)
void help(void)
{
- printf("qemuimg version " QEMU_VERSION ", Copyright (c) 2004 Fabrice Bellard\n"
- "usage: qemuimg command [command options]\n"
+ printf("qemu-img version " QEMU_VERSION ", Copyright (c) 2004 Fabrice Bellard\n"
+ "usage: qemu-img command [command options]\n"
"QEMU disk image utility\n"
"\n"
"Command syntax:\n"
@@ -592,6 +592,24 @@ static int img_convert(int argc, char **argv)
return 0;
}
+#ifdef _WIN32
+static int64_t get_allocated_file_size(const char *filename)
+{
+ struct _stati64 st;
+ if (_stati64(filename, &st) < 0)
+ return -1;
+ return st.st_size;
+}
+#else
+static int64_t get_allocated_file_size(const char *filename)
+{
+ struct stat st;
+ if (stat(filename, &st) < 0)
+ return -1;
+ return (int64_t)st.st_blocks * 512;
+}
+#endif
+
static int img_info(int argc, char **argv)
{
int c;
@@ -599,8 +617,7 @@ static int img_info(int argc, char **argv)
BlockDriver *drv;
BlockDriverState *bs;
char fmt_name[128], size_buf[128], dsize_buf[128];
- int64_t total_sectors;
- struct stat st;
+ int64_t total_sectors, allocated_size;
fmt = NULL;
for(;;) {
@@ -637,10 +654,11 @@ static int img_info(int argc, char **argv)
bdrv_get_format(bs, fmt_name, sizeof(fmt_name));
bdrv_get_geometry(bs, &total_sectors);
get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512);
- if (stat(filename, &st) < 0)
- error("Could not stat '%s'", filename);
+ allocated_size = get_allocated_file_size(filename);
+ if (allocated_size < 0)
+ error("Could not get file size '%s'", filename);
get_human_readable_size(dsize_buf, sizeof(dsize_buf),
- (int64_t)st.st_blocks * 512);
+ allocated_size);
printf("image: %s\n"
"file format: %s\n"
"virtual size: %s (%lld bytes)\n"