Commit 57d1a2b62c3a89533bf50297a606ed028068e18e
1 parent
d5249393
win32 port
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1041 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
36 additions
and
9 deletions
qemu-img.c
... | ... | @@ -113,7 +113,7 @@ void __attribute__((noreturn)) error(const char *fmt, ...) |
113 | 113 | { |
114 | 114 | va_list ap; |
115 | 115 | va_start(ap, fmt); |
116 | - fprintf(stderr, "qemuimg: "); | |
116 | + fprintf(stderr, "qemu-img: "); | |
117 | 117 | vfprintf(stderr, fmt, ap); |
118 | 118 | fprintf(stderr, "\n"); |
119 | 119 | exit(1); |
... | ... | @@ -127,8 +127,8 @@ static void format_print(void *opaque, const char *name) |
127 | 127 | |
128 | 128 | void help(void) |
129 | 129 | { |
130 | - printf("qemuimg version " QEMU_VERSION ", Copyright (c) 2004 Fabrice Bellard\n" | |
131 | - "usage: qemuimg command [command options]\n" | |
130 | + printf("qemu-img version " QEMU_VERSION ", Copyright (c) 2004 Fabrice Bellard\n" | |
131 | + "usage: qemu-img command [command options]\n" | |
132 | 132 | "QEMU disk image utility\n" |
133 | 133 | "\n" |
134 | 134 | "Command syntax:\n" |
... | ... | @@ -592,6 +592,24 @@ static int img_convert(int argc, char **argv) |
592 | 592 | return 0; |
593 | 593 | } |
594 | 594 | |
595 | +#ifdef _WIN32 | |
596 | +static int64_t get_allocated_file_size(const char *filename) | |
597 | +{ | |
598 | + struct _stati64 st; | |
599 | + if (_stati64(filename, &st) < 0) | |
600 | + return -1; | |
601 | + return st.st_size; | |
602 | +} | |
603 | +#else | |
604 | +static int64_t get_allocated_file_size(const char *filename) | |
605 | +{ | |
606 | + struct stat st; | |
607 | + if (stat(filename, &st) < 0) | |
608 | + return -1; | |
609 | + return (int64_t)st.st_blocks * 512; | |
610 | +} | |
611 | +#endif | |
612 | + | |
595 | 613 | static int img_info(int argc, char **argv) |
596 | 614 | { |
597 | 615 | int c; |
... | ... | @@ -599,8 +617,7 @@ static int img_info(int argc, char **argv) |
599 | 617 | BlockDriver *drv; |
600 | 618 | BlockDriverState *bs; |
601 | 619 | char fmt_name[128], size_buf[128], dsize_buf[128]; |
602 | - int64_t total_sectors; | |
603 | - struct stat st; | |
620 | + int64_t total_sectors, allocated_size; | |
604 | 621 | |
605 | 622 | fmt = NULL; |
606 | 623 | for(;;) { |
... | ... | @@ -637,10 +654,11 @@ static int img_info(int argc, char **argv) |
637 | 654 | bdrv_get_format(bs, fmt_name, sizeof(fmt_name)); |
638 | 655 | bdrv_get_geometry(bs, &total_sectors); |
639 | 656 | get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512); |
640 | - if (stat(filename, &st) < 0) | |
641 | - error("Could not stat '%s'", filename); | |
657 | + allocated_size = get_allocated_file_size(filename); | |
658 | + if (allocated_size < 0) | |
659 | + error("Could not get file size '%s'", filename); | |
642 | 660 | get_human_readable_size(dsize_buf, sizeof(dsize_buf), |
643 | - (int64_t)st.st_blocks * 512); | |
661 | + allocated_size); | |
644 | 662 | printf("image: %s\n" |
645 | 663 | "file format: %s\n" |
646 | 664 | "virtual size: %s (%lld bytes)\n" | ... | ... |
vl.h
... | ... | @@ -45,7 +45,16 @@ |
45 | 45 | #endif |
46 | 46 | |
47 | 47 | #ifdef _WIN32 |
48 | -#define lseek64 _lseeki64 | |
48 | +#define lseek _lseeki64 | |
49 | +#define ENOTSUP 4096 | |
50 | +/* XXX: find 64 bit version */ | |
51 | +#define ftruncate chsize | |
52 | + | |
53 | +static inline char *realpath(const char *path, char *resolved_path) | |
54 | +{ | |
55 | + _fullpath(resolved_path, path, _MAX_PATH); | |
56 | + return resolved_path; | |
57 | +} | |
49 | 58 | #endif |
50 | 59 | |
51 | 60 | #ifdef QEMU_TOOL | ... | ... |