~bdrung/qemu-kvm/caps-lock-key-up-event

« back to all changes in this revision

Viewing changes to block/vpc.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2010-08-10 08:51:54 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810085154-ok0jzlkr75dplmc7
Tags: 0.12.5+noroms-0ubuntu1
* New upstream release
* Removed patch which is now upstream:
  0001-Fix-missing-symbols-in-.rel-.rela.plt-sections.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
266
266
 
267
267
        s->last_bitmap_offset = bitmap_offset;
268
268
        memset(bitmap, 0xff, s->bitmap_size);
269
 
        bdrv_pwrite(s->hd, bitmap_offset, bitmap, s->bitmap_size);
 
269
        bdrv_pwrite_sync(s->hd, bitmap_offset, bitmap, s->bitmap_size);
270
270
    }
271
271
 
272
272
//    printf("sector: %" PRIx64 ", index: %x, offset: %x, bioff: %" PRIx64 ", bloff: %" PRIx64 "\n",
316
316
    BDRVVPCState *s = bs->opaque;
317
317
    int64_t offset = s->free_data_block_offset;
318
318
 
319
 
    ret = bdrv_pwrite(s->hd, offset, s->footer_buf, HEADER_SIZE);
 
319
    ret = bdrv_pwrite_sync(s->hd, offset, s->footer_buf, HEADER_SIZE);
320
320
    if (ret < 0)
321
321
        return ret;
322
322
 
351
351
 
352
352
    // Initialize the block's bitmap
353
353
    memset(bitmap, 0xff, s->bitmap_size);
354
 
    bdrv_pwrite(s->hd, s->free_data_block_offset, bitmap, s->bitmap_size);
 
354
    bdrv_pwrite_sync(s->hd, s->free_data_block_offset, bitmap,
 
355
        s->bitmap_size);
355
356
 
356
357
    // Write new footer (the old one will be overwritten)
357
358
    s->free_data_block_offset += s->block_size + s->bitmap_size;
362
363
    // Write BAT entry to disk
363
364
    bat_offset = s->bat_offset + (4 * index);
364
365
    bat_value = be32_to_cpu(s->pagetable[index]);
365
 
    ret = bdrv_pwrite(s->hd, bat_offset, &bat_value, 4);
 
366
    ret = bdrv_pwrite_sync(s->hd, bat_offset, &bat_value, 4);
366
367
    if (ret < 0)
367
368
        goto fail;
368
369
 
470
471
        }
471
472
    }
472
473
 
473
 
    // Note: Rounding up deviates from the Virtual PC behaviour
474
 
    // However, we need this to avoid truncating images in qemu-img convert
475
 
    *cyls = (cyls_times_heads + *heads - 1) / *heads;
 
474
    *cyls = cyls_times_heads / *heads;
476
475
 
477
476
    return 0;
478
477
}
484
483
    struct vhd_dyndisk_header* dyndisk_header =
485
484
        (struct vhd_dyndisk_header*) buf;
486
485
    int fd, i;
487
 
    uint16_t cyls;
488
 
    uint8_t heads;
489
 
    uint8_t secs_per_cyl;
 
486
    uint16_t cyls = 0;
 
487
    uint8_t heads = 0;
 
488
    uint8_t secs_per_cyl = 0;
490
489
    size_t block_size, num_bat_entries;
491
490
    int64_t total_sectors = 0;
492
491
 
503
502
    if (fd < 0)
504
503
        return -EIO;
505
504
 
506
 
    // Calculate matching total_size and geometry
507
 
    if (calculate_geometry(total_sectors, &cyls, &heads, &secs_per_cyl))
508
 
        return -EFBIG;
 
505
    /* Calculate matching total_size and geometry. Increase the number of
 
506
       sectors requested until we get enough (or fail). */
 
507
    for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; i++) {
 
508
        if (calculate_geometry(total_sectors + i,
 
509
                               &cyls, &heads, &secs_per_cyl)) {
 
510
            return -EFBIG;
 
511
        }
 
512
    }
509
513
    total_sectors = (int64_t) cyls * heads * secs_per_cyl;
510
514
 
511
515
    // Prepare the Hard Disk Footer