Revision 3b46e624 block-qcow.c

b/block-qcow.c
80 80
static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
81 81
{
82 82
    const QCowHeader *cow_header = (const void *)buf;
83
   
83

  
84 84
    if (buf_size >= sizeof(QCowHeader) &&
85 85
        be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
86 86
        be32_to_cpu(cow_header->version) == QCOW_VERSION)
......
108 108
    be64_to_cpus(&header.size);
109 109
    be32_to_cpus(&header.crypt_method);
110 110
    be64_to_cpus(&header.l1_table_offset);
111
   
111

  
112 112
    if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
113 113
        goto fail;
114 114
    if (header.size <= 1 || header.cluster_bits < 9)
......
151 151
    if (!s->cluster_data)
152 152
        goto fail;
153 153
    s->cluster_cache_offset = -1;
154
   
154

  
155 155
    /* read the backing file name */
156 156
    if (header.backing_file_offset != 0) {
157 157
        len = header.backing_file_size;
......
177 177
    BDRVQcowState *s = bs->opaque;
178 178
    uint8_t keybuf[16];
179 179
    int len, i;
180
   
180

  
181 181
    memset(keybuf, 0, 16);
182 182
    len = strlen(key);
183 183
    if (len > 16)
......
262 262
    uint64_t l2_offset, *l2_table, cluster_offset, tmp;
263 263
    uint32_t min_count;
264 264
    int new_l2_table;
265
   
265

  
266 266
    l1_index = offset >> (s->l2_bits + s->cluster_bits);
267 267
    l2_offset = s->l1_table[l1_index];
268 268
    new_l2_table = 0;
......
420 420
    inflateEnd(strm);
421 421
    return 0;
422 422
}
423
                             
423

  
424 424
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
425 425
{
426 426
    int ret, csize;
......
450 450
    BDRVQcowState *s = bs->opaque;
451 451
    int ret, index_in_cluster, n;
452 452
    uint64_t cluster_offset;
453
   
453

  
454 454
    while (nb_sectors > 0) {
455 455
        cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
456 456
        index_in_cluster = sector_num & (s->cluster_sectors - 1);
......
493 493
    BDRVQcowState *s = bs->opaque;
494 494
    int ret, index_in_cluster, n;
495 495
    uint64_t cluster_offset;
496
   
496

  
497 497
    while (nb_sectors > 0) {
498 498
        index_in_cluster = sector_num & (s->cluster_sectors - 1);
499 499
        n = s->cluster_sectors - index_in_cluster;
......
572 572
        qemu_aio_release(acb);
573 573
        return;
574 574
    }
575
   
575

  
576 576
    /* prepare next AIO request */
577 577
    acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9,
578 578
                                             0, 0, 0, 0);
......
627 627
    acb->buf = buf;
628 628
    acb->nb_sectors = nb_sectors;
629 629
    acb->n = 0;
630
    acb->cluster_offset = 0;   
630
    acb->cluster_offset = 0;
631 631

  
632 632
    qcow_aio_read_cb(acb, 0);
633 633
    return &acb->common;
......
661 661
        qemu_aio_release(acb);
662 662
        return;
663 663
    }
664
   
664

  
665 665
    index_in_cluster = acb->sector_num & (s->cluster_sectors - 1);
666 666
    acb->n = s->cluster_sectors - index_in_cluster;
667 667
    if (acb->n > acb->nb_sectors)
......
701 701
{
702 702
    BDRVQcowState *s = bs->opaque;
703 703
    QCowAIOCB *acb;
704
   
704

  
705 705
    s->cluster_cache_offset = -1; /* disable compressed cache */
706 706

  
707 707
    acb = qemu_aio_get(bs, cb, opaque);
......
712 712
    acb->buf = (uint8_t *)buf;
713 713
    acb->nb_sectors = nb_sectors;
714 714
    acb->n = 0;
715
   
715

  
716 716
    qcow_aio_write_cb(acb, 0);
717 717
    return &acb->common;
718 718
}
......
774 774
    } else {
775 775
        header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
776 776
    }
777
   
777

  
778 778
    /* write all the data */
779 779
    write(fd, &header, sizeof(header));
780 780
    if (backing_file) {
......
864 864
            return -1;
865 865
        }
866 866
    }
867
   
867

  
868 868
    qemu_free(out_buf);
869 869
    return 0;
870 870
}

Also available in: Unified diff