Revision 9bc378c1

b/qemu-img.c
189 189
#endif
190 190

  
191 191
static BlockDriverState *bdrv_new_open(const char *filename,
192
                                       const char *fmt)
192
                                       const char *fmt,
193
                                       int readonly)
193 194
{
194 195
    BlockDriverState *bs;
195 196
    BlockDriver *drv;
196 197
    char password[256];
198
    int flags = BRDV_O_FLAGS;
197 199

  
198 200
    bs = bdrv_new("");
199 201
    if (!bs)
......
205 207
    } else {
206 208
        drv = NULL;
207 209
    }
208
    if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_RDWR, drv) < 0) {
210
    if (!readonly) {
211
        flags |= BDRV_O_RDWR;
212
    }
213
    if (bdrv_open2(bs, filename, flags, drv) < 0) {
209 214
        error("Could not open '%s'", filename);
210 215
    }
211 216
    if (bdrv_is_encrypted(bs)) {
......
344 349
                }
345 350
            }
346 351

  
347
            bs = bdrv_new_open(backing_file->value.s, fmt);
352
            bs = bdrv_new_open(backing_file->value.s, fmt, 1);
348 353
            bdrv_get_geometry(bs, &size);
349 354
            size *= 512;
350 355
            bdrv_delete(bs);
......
628 633

  
629 634
    total_sectors = 0;
630 635
    for (bs_i = 0; bs_i < bs_n; bs_i++) {
631
        bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt);
636
        bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, 1);
632 637
        if (!bs[bs_i])
633 638
            error("Could not open '%s'", argv[optind + bs_i]);
634 639
        bdrv_get_geometry(bs[bs_i], &bs_sectors);
......
686 691
        }
687 692
    }
688 693

  
689
    out_bs = bdrv_new_open(out_filename, out_fmt);
694
    out_bs = bdrv_new_open(out_filename, out_fmt, 0);
690 695

  
691 696
    bs_i = 0;
692 697
    bs_offset = 0;

Also available in: Unified diff