~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to block-vmdk.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno, Aurelien Jarno
  • Date: 2009-03-22 10:13:17 UTC
  • mfrom: (1.2.1 upstream) (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090322101317-iigjtnu5qil35dtb
Tags: 0.10.1-1
[ Aurelien Jarno ]
* New upstream stable release:
  - patches/80_stable-branch.patch: remove.
* debian/control: 
  - Remove depends on proll.
  - Move depends on device-tree-compiler to build-depends.
  - Bump Standards-Version to 3.8.1 (no changes).
* patches/82_qemu-img_decimal.patch: new patch from upstream to make
  qemu-img accept sizes with decimal values (closes: bug#501400).

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
    BDRVVmdkState *s = bs->opaque;
120
120
    char desc[DESC_SIZE];
121
121
    uint32_t cid;
122
 
    char *p_name, *cid_str;
 
122
    const char *p_name, *cid_str;
123
123
    size_t cid_str_size;
124
124
 
125
125
    /* the descriptor offset = 0x200 */
153
153
        return -1;
154
154
 
155
155
    tmp_str = strstr(desc,"parentCID");
156
 
    strcpy(tmp_desc, tmp_str);
 
156
    pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str);
157
157
    if ((p_name = strstr(desc,"CID")) != 0) {
158
158
        p_name += sizeof("CID");
159
 
        sprintf(p_name,"%x\n",cid);
160
 
        strcat(desc,tmp_desc);
 
159
        snprintf(p_name, sizeof(desc) - (p_name - desc), "%x\n", cid);
 
160
        pstrcat(desc, sizeof(desc), tmp_desc);
161
161
    }
162
162
 
163
163
    if (bdrv_pwrite(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE)
193
193
    uint32_t gde_entries, gd_size;
194
194
    int64_t gd_offset, rgd_offset, capacity, gt_size;
195
195
    char p_desc[DESC_SIZE], s_desc[DESC_SIZE], hdr[HEADER_SIZE];
196
 
    char *desc_template =
 
196
    static const char desc_template[] =
197
197
    "# Disk DescriptorFile\n"
198
198
    "version=1\n"
199
199
    "CID=%x\n"
202
202
    "parentFileNameHint=\"%s\"\n"
203
203
    "\n"
204
204
    "# Extent description\n"
205
 
    "RW %lu SPARSE \"%s\"\n"
 
205
    "RW %u SPARSE \"%s\"\n"
206
206
    "\n"
207
207
    "# The Disk Data Base \n"
208
208
    "#DDB\n"
252
252
    if ((temp_str = strrchr(real_filename, ':')) != NULL)
253
253
        real_filename = temp_str + 1;
254
254
 
255
 
    sprintf(s_desc, desc_template, p_cid, p_cid, backing_file
256
 
            , (uint32_t)header.capacity, real_filename);
 
255
    snprintf(s_desc, sizeof(s_desc), desc_template, p_cid, p_cid, backing_file,
 
256
             (uint32_t)header.capacity, real_filename);
257
257
 
258
258
    /* write the descriptor */
259
259
    if (lseek(snp_fd, 0x200, SEEK_SET) == -1)
276
276
 
277
277
    /* write RGD */
278
278
    rgd_buf = qemu_malloc(gd_size);
279
 
    if (!rgd_buf)
280
 
        goto fail;
281
279
    if (lseek(p_fd, rgd_offset, SEEK_SET) == -1)
282
280
        goto fail_rgd;
283
281
    if (read(p_fd, rgd_buf, gd_size) != gd_size)
290
288
 
291
289
    /* write GD */
292
290
    gd_buf = qemu_malloc(gd_size);
293
 
    if (!gd_buf)
294
 
        goto fail_rgd;
295
291
    if (lseek(p_fd, gd_offset, SEEK_SET) == -1)
296
292
        goto fail_gd;
297
293
    if (read(p_fd, gd_buf, gd_size) != gd_size)
322
318
        bdrv_close(bs->backing_hd);
323
319
}
324
320
 
325
 
int parent_open = 0;
 
321
static int parent_open = 0;
326
322
static int vmdk_parent_open(BlockDriverState *bs, const char * filename)
327
323
{
328
324
    BDRVVmdkState *s = bs->opaque;
341
337
        p_name += sizeof("parentFileNameHint") + 1;
342
338
        if ((end_name = strchr(p_name,'\"')) == 0)
343
339
            return -1;
 
340
        if ((end_name - p_name) > sizeof (s->hd->backing_file) - 1)
 
341
            return -1;
344
342
 
345
 
        strncpy(s->hd->backing_file, p_name, end_name - p_name);
 
343
        pstrcpy(s->hd->backing_file, end_name - p_name + 1, p_name);
346
344
        if (stat(s->hd->backing_file, &file_buf) != 0) {
347
345
            path_combine(parent_img_name, sizeof(parent_img_name),
348
346
                         filename, s->hd->backing_file);
349
347
        } else {
350
 
            strcpy(parent_img_name, s->hd->backing_file);
 
348
            pstrcpy(parent_img_name, sizeof(parent_img_name),
 
349
                    s->hd->backing_file);
351
350
        }
352
351
 
353
352
        s->hd->backing_hd = bdrv_new("");
374
373
    if (parent_open)
375
374
        // Parent must be opened as RO.
376
375
        flags = BDRV_O_RDONLY;
377
 
    fprintf(stderr, "(VMDK) image open: flags=0x%x filename=%s\n", flags, bs->filename);
378
376
 
379
377
    ret = bdrv_file_open(&s->hd, filename, flags);
380
378
    if (ret < 0)
428
426
    /* read the L1 table */
429
427
    l1_size = s->l1_size * sizeof(uint32_t);
430
428
    s->l1_table = qemu_malloc(l1_size);
431
 
    if (!s->l1_table)
432
 
        goto fail;
433
429
    if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, l1_size) != l1_size)
434
430
        goto fail;
435
431
    for(i = 0; i < s->l1_size; i++) {
438
434
 
439
435
    if (s->l1_backup_table_offset) {
440
436
        s->l1_backup_table = qemu_malloc(l1_size);
441
 
        if (!s->l1_backup_table)
442
 
            goto fail;
443
437
        if (bdrv_pread(s->hd, s->l1_backup_table_offset, s->l1_backup_table, l1_size) != l1_size)
444
438
            goto fail;
445
439
        for(i = 0; i < s->l1_size; i++) {
448
442
    }
449
443
 
450
444
    s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint32_t));
451
 
    if (!s->l2_cache)
452
 
        goto fail;
453
445
    return 0;
454
446
 fail:
455
447
    qemu_free(s->l1_backup_table);
700
692
    int fd, i;
701
693
    VMDK4Header header;
702
694
    uint32_t tmp, magic, grains, gd_size, gt_size, gt_count;
703
 
    char *desc_template =
 
695
    static const char desc_template[] =
704
696
        "# Disk DescriptorFile\n"
705
697
        "version=1\n"
706
698
        "CID=%x\n"
708
700
        "createType=\"monolithicSparse\"\n"
709
701
        "\n"
710
702
        "# Extent description\n"
711
 
        "RW %lu SPARSE \"%s\"\n"
 
703
        "RW %" PRId64 " SPARSE \"%s\"\n"
712
704
        "\n"
713
705
        "# The Disk Data Base \n"
714
706
        "#DDB\n"
715
707
        "\n"
716
708
        "ddb.virtualHWVersion = \"%d\"\n"
717
 
        "ddb.geometry.cylinders = \"%lu\"\n"
 
709
        "ddb.geometry.cylinders = \"%" PRId64 "\"\n"
718
710
        "ddb.geometry.heads = \"16\"\n"
719
711
        "ddb.geometry.sectors = \"63\"\n"
720
712
        "ddb.adapterType = \"ide\"\n";
789
781
        real_filename = temp_str + 1;
790
782
    if ((temp_str = strrchr(real_filename, ':')) != NULL)
791
783
        real_filename = temp_str + 1;
792
 
    sprintf(desc, desc_template, time(NULL), (unsigned long)total_size,
793
 
            real_filename, (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4), total_size / (63 * 16));
 
784
    snprintf(desc, sizeof(desc), desc_template, (unsigned int)time(NULL),
 
785
             total_size, real_filename,
 
786
             (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
 
787
             total_size / (int64_t)(63 * 16));
794
788
 
795
789
    /* write the descriptor */
796
790
    lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET);
806
800
 
807
801
    qemu_free(s->l1_table);
808
802
    qemu_free(s->l2_cache);
809
 
    bdrv_delete(s->hd);
810
803
    // try to close parent image, if exist
811
804
    vmdk_parent_close(s->hd);
 
805
    bdrv_delete(s->hd);
812
806
}
813
807
 
814
808
static void vmdk_flush(BlockDriverState *bs)