diff --git a/Makefile b/Makefile index b9d8e690c7..17ee449801 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ include config-host.mak -CFLAGS=-Wall -O2 -g -fno-strict-aliasing +CFLAGS=-Wall -O2 -g -fno-strict-aliasing ifdef CONFIG_DARWIN CFLAGS+= -mdynamic-no-pic endif @@ -9,7 +9,7 @@ CFLAGS+=-fpack-struct endif LDFLAGS=-g LIBS= -DEFINES+=-D_GNU_SOURCE +DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE TOOLS=qemu-img ifdef CONFIG_STATIC LDFLAGS+=-static diff --git a/Makefile.target b/Makefile.target index 9c9cfcfead..0e70065112 100644 --- a/Makefile.target +++ b/Makefile.target @@ -159,7 +159,7 @@ endif ######################################################### -DEFINES+=-D_GNU_SOURCE +DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE LIBS+=-lm ifndef CONFIG_USER_ONLY LIBS+=-lz diff --git a/block-cow.c b/block-cow.c index ab62c2a868..affeefa3f0 100644 --- a/block-cow.c +++ b/block-cow.c @@ -173,7 +173,7 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, while (nb_sectors > 0) { if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) { - lseek64(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); + lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); ret = read(s->fd, buf, n * 512); if (ret != n * 512) return -1; @@ -193,7 +193,7 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num, BDRVCowState *s = bs->opaque; int ret, i; - lseek64(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); + lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); ret = write(s->fd, buf, nb_sectors * 512); if (ret != nb_sectors * 512) return -1; diff --git a/block-qcow.c b/block-qcow.c index ed6359f74c..953f42c7b6 100644 --- a/block-qcow.c +++ b/block-qcow.c @@ -137,7 +137,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename) s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); if (!s->l1_table) goto fail; - lseek64(fd, s->l1_table_offset, SEEK_SET); + lseek(fd, s->l1_table_offset, SEEK_SET); if (read(fd, s->l1_table, s->l1_size * sizeof(uint64_t)) != s->l1_size * sizeof(uint64_t)) goto fail; @@ -161,7 +161,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename) len = header.backing_file_size; if (len > 1023) len = 1023; - lseek64(fd, header.backing_file_offset, SEEK_SET); + lseek(fd, header.backing_file_offset, SEEK_SET); if (read(fd, bs->backing_file, len) != len) goto fail; bs->backing_file[len] = '\0'; @@ -275,13 +275,13 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, if (!allocate) return 0; /* allocate a new l2 entry */ - l2_offset = lseek64(s->fd, 0, SEEK_END); + l2_offset = lseek(s->fd, 0, SEEK_END); /* round to cluster size */ l2_offset = (l2_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); /* update the L1 entry */ s->l1_table[l1_index] = l2_offset; tmp = cpu_to_be64(l2_offset); - lseek64(s->fd, s->l1_table_offset + l1_index * sizeof(tmp), SEEK_SET); + lseek(s->fd, s->l1_table_offset + l1_index * sizeof(tmp), SEEK_SET); if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp)) return 0; new_l2_table = 1; @@ -336,16 +336,16 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, overwritten */ if (decompress_cluster(s, cluster_offset) < 0) return 0; - cluster_offset = lseek64(s->fd, 0, SEEK_END); + cluster_offset = lseek(s->fd, 0, SEEK_END); cluster_offset = (cluster_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); /* write the cluster content */ - lseek64(s->fd, cluster_offset, SEEK_SET); + lseek(s->fd, cluster_offset, SEEK_SET); if (write(s->fd, s->cluster_cache, s->cluster_size) != s->cluster_size) return -1; } else { - cluster_offset = lseek64(s->fd, 0, SEEK_END); + cluster_offset = lseek(s->fd, 0, SEEK_END); if (allocate == 1) { /* round to cluster size */ cluster_offset = (cluster_offset + s->cluster_size - 1) & @@ -364,7 +364,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, s->cluster_data, s->cluster_data + 512, 1, 1, &s->aes_encrypt_key); - lseek64(s->fd, cluster_offset + i * 512, SEEK_SET); + lseek(s->fd, cluster_offset + i * 512, SEEK_SET); if (write(s->fd, s->cluster_data, 512) != 512) return -1; } @@ -378,7 +378,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, /* update L2 table */ tmp = cpu_to_be64(cluster_offset); l2_table[l2_index] = tmp; - lseek64(s->fd, l2_offset + l2_index * sizeof(tmp), SEEK_SET); + lseek(s->fd, l2_offset + l2_index * sizeof(tmp), SEEK_SET); if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp)) return 0; } @@ -437,7 +437,7 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset) if (s->cluster_cache_offset != coffset) { csize = cluster_offset >> (63 - s->cluster_bits); csize &= (s->cluster_size - 1); - lseek64(s->fd, coffset, SEEK_SET); + lseek(s->fd, coffset, SEEK_SET); ret = read(s->fd, s->cluster_data, csize); if (ret != csize) return -1; @@ -470,7 +470,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, return -1; memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n); } else { - lseek64(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); + lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); ret = read(s->fd, buf, n * 512); if (ret != n * 512) return -1; @@ -503,7 +503,7 @@ static int qcow_write(BlockDriverState *bs, int64_t sector_num, index_in_cluster + n); if (!cluster_offset) return -1; - lseek64(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); + lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); if (s->crypt_method) { encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1, &s->aes_encrypt_key); @@ -650,7 +650,7 @@ int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num, cluster_offset = get_cluster_offset(bs, sector_num << 9, 2, out_len, 0, 0); cluster_offset &= s->cluster_offset_mask; - lseek64(s->fd, cluster_offset, SEEK_SET); + lseek(s->fd, cluster_offset, SEEK_SET); if (write(s->fd, out_buf, out_len) != out_len) { qemu_free(out_buf); return -1; diff --git a/block-vmdk.c b/block-vmdk.c index d1414e4309..36653fb2ff 100644 --- a/block-vmdk.c +++ b/block-vmdk.c @@ -239,7 +239,7 @@ static int vmdk_read(BlockDriverState *bs, int64_t sector_num, if (!cluster_offset) { memset(buf, 0, 512 * n); } else { - lseek64(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); + lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); ret = read(s->fd, buf, n * 512); if (ret != n * 512) return -1; diff --git a/block.c b/block.c index 43b0188142..8dea3c9320 100644 --- a/block.c +++ b/block.c @@ -71,14 +71,22 @@ int bdrv_create(BlockDriver *drv, return drv->bdrv_create(filename, size_in_sectors, backing_file, flags); } -/* XXX: race condition possible */ +#ifdef _WIN32 +static void get_tmp_filename(char *filename, int size) +{ + /* XXX: find a better function */ + tmpnam(filename); +} +#else static void get_tmp_filename(char *filename, int size) { int fd; + /* XXX: race condition possible */ pstrcpy(filename, size, "/tmp/vl.XXXXXX"); fd = mkstemp(filename); close(fd); } +#endif static BlockDriver *find_image_format(const char *filename) { @@ -514,7 +522,7 @@ static int raw_open(BlockDriverState *bs, const char *filename) return -1; bs->read_only = 1; } - size = lseek64(fd, 0, SEEK_END); + size = lseek(fd, 0, SEEK_END); bs->total_sectors = size / 512; s->fd = fd; return 0; @@ -526,7 +534,7 @@ static int raw_read(BlockDriverState *bs, int64_t sector_num, BDRVRawState *s = bs->opaque; int ret; - lseek64(s->fd, sector_num * 512, SEEK_SET); + lseek(s->fd, sector_num * 512, SEEK_SET); ret = read(s->fd, buf, nb_sectors * 512); if (ret != nb_sectors * 512) return -1; @@ -539,7 +547,7 @@ static int raw_write(BlockDriverState *bs, int64_t sector_num, BDRVRawState *s = bs->opaque; int ret; - lseek64(s->fd, sector_num * 512, SEEK_SET); + lseek(s->fd, sector_num * 512, SEEK_SET); ret = write(s->fd, buf, nb_sectors * 512); if (ret != nb_sectors * 512) return -1; @@ -564,7 +572,7 @@ static int raw_create(const char *filename, int64_t total_size, 0644); if (fd < 0) return -EIO; - ftruncate64(fd, total_size * 512); + ftruncate(fd, total_size * 512); close(fd); return 0; } diff --git a/configure b/configure index 9cf6a2ec5e..54f1a9fbdd 100755 --- a/configure +++ b/configure @@ -429,10 +429,6 @@ echo "TARGET_DIRS=$target_list" >> $config_mak # XXX: suppress that if [ "$bsd" = "yes" ] ; then echo "#define O_LARGEFILE 0" >> $config_h - echo "#define lseek64 lseek" >> $config_h - echo "#define mkstemp64 mkstemp" >> $config_h - echo "#define ftruncate64 ftruncate" >> $config_h - echo "#define off64_t off_t" >> $config_h echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h echo "#define _BSD 1" >> $config_h fi