Commit d5249393efe472d50eb027e286566a57ba868bf2
1 parent
11c0315f
64 bit file I/O by default
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1040 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
7 changed files
with
32 additions
and
28 deletions
Makefile
1 | include config-host.mak | 1 | include config-host.mak |
2 | 2 | ||
3 | -CFLAGS=-Wall -O2 -g -fno-strict-aliasing | 3 | +CFLAGS=-Wall -O2 -g -fno-strict-aliasing |
4 | ifdef CONFIG_DARWIN | 4 | ifdef CONFIG_DARWIN |
5 | CFLAGS+= -mdynamic-no-pic | 5 | CFLAGS+= -mdynamic-no-pic |
6 | endif | 6 | endif |
@@ -9,7 +9,7 @@ CFLAGS+=-fpack-struct | @@ -9,7 +9,7 @@ CFLAGS+=-fpack-struct | ||
9 | endif | 9 | endif |
10 | LDFLAGS=-g | 10 | LDFLAGS=-g |
11 | LIBS= | 11 | LIBS= |
12 | -DEFINES+=-D_GNU_SOURCE | 12 | +DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE |
13 | TOOLS=qemu-img | 13 | TOOLS=qemu-img |
14 | ifdef CONFIG_STATIC | 14 | ifdef CONFIG_STATIC |
15 | LDFLAGS+=-static | 15 | LDFLAGS+=-static |
Makefile.target
@@ -159,7 +159,7 @@ endif | @@ -159,7 +159,7 @@ endif | ||
159 | 159 | ||
160 | ######################################################### | 160 | ######################################################### |
161 | 161 | ||
162 | -DEFINES+=-D_GNU_SOURCE | 162 | +DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE |
163 | LIBS+=-lm | 163 | LIBS+=-lm |
164 | ifndef CONFIG_USER_ONLY | 164 | ifndef CONFIG_USER_ONLY |
165 | LIBS+=-lz | 165 | LIBS+=-lz |
block-cow.c
@@ -173,7 +173,7 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, | @@ -173,7 +173,7 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, | ||
173 | 173 | ||
174 | while (nb_sectors > 0) { | 174 | while (nb_sectors > 0) { |
175 | if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) { | 175 | if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) { |
176 | - lseek64(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); | 176 | + lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); |
177 | ret = read(s->fd, buf, n * 512); | 177 | ret = read(s->fd, buf, n * 512); |
178 | if (ret != n * 512) | 178 | if (ret != n * 512) |
179 | return -1; | 179 | return -1; |
@@ -193,7 +193,7 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num, | @@ -193,7 +193,7 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num, | ||
193 | BDRVCowState *s = bs->opaque; | 193 | BDRVCowState *s = bs->opaque; |
194 | int ret, i; | 194 | int ret, i; |
195 | 195 | ||
196 | - lseek64(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); | 196 | + lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET); |
197 | ret = write(s->fd, buf, nb_sectors * 512); | 197 | ret = write(s->fd, buf, nb_sectors * 512); |
198 | if (ret != nb_sectors * 512) | 198 | if (ret != nb_sectors * 512) |
199 | return -1; | 199 | return -1; |
block-qcow.c
@@ -137,7 +137,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename) | @@ -137,7 +137,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename) | ||
137 | s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); | 137 | s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); |
138 | if (!s->l1_table) | 138 | if (!s->l1_table) |
139 | goto fail; | 139 | goto fail; |
140 | - lseek64(fd, s->l1_table_offset, SEEK_SET); | 140 | + lseek(fd, s->l1_table_offset, SEEK_SET); |
141 | if (read(fd, s->l1_table, s->l1_size * sizeof(uint64_t)) != | 141 | if (read(fd, s->l1_table, s->l1_size * sizeof(uint64_t)) != |
142 | s->l1_size * sizeof(uint64_t)) | 142 | s->l1_size * sizeof(uint64_t)) |
143 | goto fail; | 143 | goto fail; |
@@ -161,7 +161,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename) | @@ -161,7 +161,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename) | ||
161 | len = header.backing_file_size; | 161 | len = header.backing_file_size; |
162 | if (len > 1023) | 162 | if (len > 1023) |
163 | len = 1023; | 163 | len = 1023; |
164 | - lseek64(fd, header.backing_file_offset, SEEK_SET); | 164 | + lseek(fd, header.backing_file_offset, SEEK_SET); |
165 | if (read(fd, bs->backing_file, len) != len) | 165 | if (read(fd, bs->backing_file, len) != len) |
166 | goto fail; | 166 | goto fail; |
167 | bs->backing_file[len] = '\0'; | 167 | bs->backing_file[len] = '\0'; |
@@ -275,13 +275,13 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | @@ -275,13 +275,13 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
275 | if (!allocate) | 275 | if (!allocate) |
276 | return 0; | 276 | return 0; |
277 | /* allocate a new l2 entry */ | 277 | /* allocate a new l2 entry */ |
278 | - l2_offset = lseek64(s->fd, 0, SEEK_END); | 278 | + l2_offset = lseek(s->fd, 0, SEEK_END); |
279 | /* round to cluster size */ | 279 | /* round to cluster size */ |
280 | l2_offset = (l2_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); | 280 | l2_offset = (l2_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); |
281 | /* update the L1 entry */ | 281 | /* update the L1 entry */ |
282 | s->l1_table[l1_index] = l2_offset; | 282 | s->l1_table[l1_index] = l2_offset; |
283 | tmp = cpu_to_be64(l2_offset); | 283 | tmp = cpu_to_be64(l2_offset); |
284 | - lseek64(s->fd, s->l1_table_offset + l1_index * sizeof(tmp), SEEK_SET); | 284 | + lseek(s->fd, s->l1_table_offset + l1_index * sizeof(tmp), SEEK_SET); |
285 | if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp)) | 285 | if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp)) |
286 | return 0; | 286 | return 0; |
287 | new_l2_table = 1; | 287 | new_l2_table = 1; |
@@ -336,16 +336,16 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | @@ -336,16 +336,16 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
336 | overwritten */ | 336 | overwritten */ |
337 | if (decompress_cluster(s, cluster_offset) < 0) | 337 | if (decompress_cluster(s, cluster_offset) < 0) |
338 | return 0; | 338 | return 0; |
339 | - cluster_offset = lseek64(s->fd, 0, SEEK_END); | 339 | + cluster_offset = lseek(s->fd, 0, SEEK_END); |
340 | cluster_offset = (cluster_offset + s->cluster_size - 1) & | 340 | cluster_offset = (cluster_offset + s->cluster_size - 1) & |
341 | ~(s->cluster_size - 1); | 341 | ~(s->cluster_size - 1); |
342 | /* write the cluster content */ | 342 | /* write the cluster content */ |
343 | - lseek64(s->fd, cluster_offset, SEEK_SET); | 343 | + lseek(s->fd, cluster_offset, SEEK_SET); |
344 | if (write(s->fd, s->cluster_cache, s->cluster_size) != | 344 | if (write(s->fd, s->cluster_cache, s->cluster_size) != |
345 | s->cluster_size) | 345 | s->cluster_size) |
346 | return -1; | 346 | return -1; |
347 | } else { | 347 | } else { |
348 | - cluster_offset = lseek64(s->fd, 0, SEEK_END); | 348 | + cluster_offset = lseek(s->fd, 0, SEEK_END); |
349 | if (allocate == 1) { | 349 | if (allocate == 1) { |
350 | /* round to cluster size */ | 350 | /* round to cluster size */ |
351 | cluster_offset = (cluster_offset + s->cluster_size - 1) & | 351 | cluster_offset = (cluster_offset + s->cluster_size - 1) & |
@@ -364,7 +364,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | @@ -364,7 +364,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
364 | s->cluster_data, | 364 | s->cluster_data, |
365 | s->cluster_data + 512, 1, 1, | 365 | s->cluster_data + 512, 1, 1, |
366 | &s->aes_encrypt_key); | 366 | &s->aes_encrypt_key); |
367 | - lseek64(s->fd, cluster_offset + i * 512, SEEK_SET); | 367 | + lseek(s->fd, cluster_offset + i * 512, SEEK_SET); |
368 | if (write(s->fd, s->cluster_data, 512) != 512) | 368 | if (write(s->fd, s->cluster_data, 512) != 512) |
369 | return -1; | 369 | return -1; |
370 | } | 370 | } |
@@ -378,7 +378,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | @@ -378,7 +378,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
378 | /* update L2 table */ | 378 | /* update L2 table */ |
379 | tmp = cpu_to_be64(cluster_offset); | 379 | tmp = cpu_to_be64(cluster_offset); |
380 | l2_table[l2_index] = tmp; | 380 | l2_table[l2_index] = tmp; |
381 | - lseek64(s->fd, l2_offset + l2_index * sizeof(tmp), SEEK_SET); | 381 | + lseek(s->fd, l2_offset + l2_index * sizeof(tmp), SEEK_SET); |
382 | if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp)) | 382 | if (write(s->fd, &tmp, sizeof(tmp)) != sizeof(tmp)) |
383 | return 0; | 383 | return 0; |
384 | } | 384 | } |
@@ -437,7 +437,7 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset) | @@ -437,7 +437,7 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset) | ||
437 | if (s->cluster_cache_offset != coffset) { | 437 | if (s->cluster_cache_offset != coffset) { |
438 | csize = cluster_offset >> (63 - s->cluster_bits); | 438 | csize = cluster_offset >> (63 - s->cluster_bits); |
439 | csize &= (s->cluster_size - 1); | 439 | csize &= (s->cluster_size - 1); |
440 | - lseek64(s->fd, coffset, SEEK_SET); | 440 | + lseek(s->fd, coffset, SEEK_SET); |
441 | ret = read(s->fd, s->cluster_data, csize); | 441 | ret = read(s->fd, s->cluster_data, csize); |
442 | if (ret != csize) | 442 | if (ret != csize) |
443 | return -1; | 443 | return -1; |
@@ -470,7 +470,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, | @@ -470,7 +470,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num, | ||
470 | return -1; | 470 | return -1; |
471 | memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n); | 471 | memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n); |
472 | } else { | 472 | } else { |
473 | - lseek64(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); | 473 | + lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); |
474 | ret = read(s->fd, buf, n * 512); | 474 | ret = read(s->fd, buf, n * 512); |
475 | if (ret != n * 512) | 475 | if (ret != n * 512) |
476 | return -1; | 476 | return -1; |
@@ -503,7 +503,7 @@ static int qcow_write(BlockDriverState *bs, int64_t sector_num, | @@ -503,7 +503,7 @@ static int qcow_write(BlockDriverState *bs, int64_t sector_num, | ||
503 | index_in_cluster + n); | 503 | index_in_cluster + n); |
504 | if (!cluster_offset) | 504 | if (!cluster_offset) |
505 | return -1; | 505 | return -1; |
506 | - lseek64(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); | 506 | + lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); |
507 | if (s->crypt_method) { | 507 | if (s->crypt_method) { |
508 | encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1, | 508 | encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1, |
509 | &s->aes_encrypt_key); | 509 | &s->aes_encrypt_key); |
@@ -650,7 +650,7 @@ int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num, | @@ -650,7 +650,7 @@ int qcow_compress_cluster(BlockDriverState *bs, int64_t sector_num, | ||
650 | cluster_offset = get_cluster_offset(bs, sector_num << 9, 2, | 650 | cluster_offset = get_cluster_offset(bs, sector_num << 9, 2, |
651 | out_len, 0, 0); | 651 | out_len, 0, 0); |
652 | cluster_offset &= s->cluster_offset_mask; | 652 | cluster_offset &= s->cluster_offset_mask; |
653 | - lseek64(s->fd, cluster_offset, SEEK_SET); | 653 | + lseek(s->fd, cluster_offset, SEEK_SET); |
654 | if (write(s->fd, out_buf, out_len) != out_len) { | 654 | if (write(s->fd, out_buf, out_len) != out_len) { |
655 | qemu_free(out_buf); | 655 | qemu_free(out_buf); |
656 | return -1; | 656 | return -1; |
block-vmdk.c
@@ -239,7 +239,7 @@ static int vmdk_read(BlockDriverState *bs, int64_t sector_num, | @@ -239,7 +239,7 @@ static int vmdk_read(BlockDriverState *bs, int64_t sector_num, | ||
239 | if (!cluster_offset) { | 239 | if (!cluster_offset) { |
240 | memset(buf, 0, 512 * n); | 240 | memset(buf, 0, 512 * n); |
241 | } else { | 241 | } else { |
242 | - lseek64(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); | 242 | + lseek(s->fd, cluster_offset + index_in_cluster * 512, SEEK_SET); |
243 | ret = read(s->fd, buf, n * 512); | 243 | ret = read(s->fd, buf, n * 512); |
244 | if (ret != n * 512) | 244 | if (ret != n * 512) |
245 | return -1; | 245 | return -1; |
block.c
@@ -71,14 +71,22 @@ int bdrv_create(BlockDriver *drv, | @@ -71,14 +71,22 @@ int bdrv_create(BlockDriver *drv, | ||
71 | return drv->bdrv_create(filename, size_in_sectors, backing_file, flags); | 71 | return drv->bdrv_create(filename, size_in_sectors, backing_file, flags); |
72 | } | 72 | } |
73 | 73 | ||
74 | -/* XXX: race condition possible */ | 74 | +#ifdef _WIN32 |
75 | +static void get_tmp_filename(char *filename, int size) | ||
76 | +{ | ||
77 | + /* XXX: find a better function */ | ||
78 | + tmpnam(filename); | ||
79 | +} | ||
80 | +#else | ||
75 | static void get_tmp_filename(char *filename, int size) | 81 | static void get_tmp_filename(char *filename, int size) |
76 | { | 82 | { |
77 | int fd; | 83 | int fd; |
84 | + /* XXX: race condition possible */ | ||
78 | pstrcpy(filename, size, "/tmp/vl.XXXXXX"); | 85 | pstrcpy(filename, size, "/tmp/vl.XXXXXX"); |
79 | fd = mkstemp(filename); | 86 | fd = mkstemp(filename); |
80 | close(fd); | 87 | close(fd); |
81 | } | 88 | } |
89 | +#endif | ||
82 | 90 | ||
83 | static BlockDriver *find_image_format(const char *filename) | 91 | static BlockDriver *find_image_format(const char *filename) |
84 | { | 92 | { |
@@ -514,7 +522,7 @@ static int raw_open(BlockDriverState *bs, const char *filename) | @@ -514,7 +522,7 @@ static int raw_open(BlockDriverState *bs, const char *filename) | ||
514 | return -1; | 522 | return -1; |
515 | bs->read_only = 1; | 523 | bs->read_only = 1; |
516 | } | 524 | } |
517 | - size = lseek64(fd, 0, SEEK_END); | 525 | + size = lseek(fd, 0, SEEK_END); |
518 | bs->total_sectors = size / 512; | 526 | bs->total_sectors = size / 512; |
519 | s->fd = fd; | 527 | s->fd = fd; |
520 | return 0; | 528 | return 0; |
@@ -526,7 +534,7 @@ static int raw_read(BlockDriverState *bs, int64_t sector_num, | @@ -526,7 +534,7 @@ static int raw_read(BlockDriverState *bs, int64_t sector_num, | ||
526 | BDRVRawState *s = bs->opaque; | 534 | BDRVRawState *s = bs->opaque; |
527 | int ret; | 535 | int ret; |
528 | 536 | ||
529 | - lseek64(s->fd, sector_num * 512, SEEK_SET); | 537 | + lseek(s->fd, sector_num * 512, SEEK_SET); |
530 | ret = read(s->fd, buf, nb_sectors * 512); | 538 | ret = read(s->fd, buf, nb_sectors * 512); |
531 | if (ret != nb_sectors * 512) | 539 | if (ret != nb_sectors * 512) |
532 | return -1; | 540 | return -1; |
@@ -539,7 +547,7 @@ static int raw_write(BlockDriverState *bs, int64_t sector_num, | @@ -539,7 +547,7 @@ static int raw_write(BlockDriverState *bs, int64_t sector_num, | ||
539 | BDRVRawState *s = bs->opaque; | 547 | BDRVRawState *s = bs->opaque; |
540 | int ret; | 548 | int ret; |
541 | 549 | ||
542 | - lseek64(s->fd, sector_num * 512, SEEK_SET); | 550 | + lseek(s->fd, sector_num * 512, SEEK_SET); |
543 | ret = write(s->fd, buf, nb_sectors * 512); | 551 | ret = write(s->fd, buf, nb_sectors * 512); |
544 | if (ret != nb_sectors * 512) | 552 | if (ret != nb_sectors * 512) |
545 | return -1; | 553 | return -1; |
@@ -564,7 +572,7 @@ static int raw_create(const char *filename, int64_t total_size, | @@ -564,7 +572,7 @@ static int raw_create(const char *filename, int64_t total_size, | ||
564 | 0644); | 572 | 0644); |
565 | if (fd < 0) | 573 | if (fd < 0) |
566 | return -EIO; | 574 | return -EIO; |
567 | - ftruncate64(fd, total_size * 512); | 575 | + ftruncate(fd, total_size * 512); |
568 | close(fd); | 576 | close(fd); |
569 | return 0; | 577 | return 0; |
570 | } | 578 | } |
configure
@@ -429,10 +429,6 @@ echo "TARGET_DIRS=$target_list" >> $config_mak | @@ -429,10 +429,6 @@ echo "TARGET_DIRS=$target_list" >> $config_mak | ||
429 | # XXX: suppress that | 429 | # XXX: suppress that |
430 | if [ "$bsd" = "yes" ] ; then | 430 | if [ "$bsd" = "yes" ] ; then |
431 | echo "#define O_LARGEFILE 0" >> $config_h | 431 | echo "#define O_LARGEFILE 0" >> $config_h |
432 | - echo "#define lseek64 lseek" >> $config_h | ||
433 | - echo "#define mkstemp64 mkstemp" >> $config_h | ||
434 | - echo "#define ftruncate64 ftruncate" >> $config_h | ||
435 | - echo "#define off64_t off_t" >> $config_h | ||
436 | echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h | 432 | echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h |
437 | echo "#define _BSD 1" >> $config_h | 433 | echo "#define _BSD 1" >> $config_h |
438 | fi | 434 | fi |