Revision f5edb014 block.c
b/block.c | ||
---|---|---|
310 | 310 |
if (drv && strcmp(drv->format_name, "vvfat") == 0) |
311 | 311 |
return drv; |
312 | 312 |
|
313 |
ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
|
|
313 |
ret = bdrv_file_open(&bs, filename, 0);
|
|
314 | 314 |
if (ret < 0) |
315 | 315 |
return NULL; |
316 | 316 |
ret = bdrv_pread(bs, 0, buf, sizeof(buf)); |
... | ... | |
356 | 356 |
int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, |
357 | 357 |
BlockDriver *drv) |
358 | 358 |
{ |
359 |
int ret, open_flags, try_rw;
|
|
359 |
int ret, open_flags; |
|
360 | 360 |
char tmp_filename[PATH_MAX]; |
361 | 361 |
char backing_filename[PATH_MAX]; |
362 | 362 |
|
... | ... | |
446 | 446 |
|
447 | 447 |
/* Note: for compatibility, we open disk image files as RDWR, and |
448 | 448 |
RDONLY as fallback */ |
449 |
try_rw = !bs->read_only || bs->is_temporary; |
|
450 |
if (!(flags & BDRV_O_FILE)) |
|
451 |
open_flags = (try_rw ? BDRV_O_RDWR : 0) | |
|
452 |
(flags & (BDRV_O_CACHE_MASK|BDRV_O_NATIVE_AIO)); |
|
453 |
else |
|
449 |
bs->read_only = (flags & BDRV_O_RDWR) == 0; |
|
450 |
if (!(flags & BDRV_O_FILE)) { |
|
451 |
open_flags = (flags & (BDRV_O_RDWR | BDRV_O_CACHE_MASK|BDRV_O_NATIVE_AIO)); |
|
452 |
if (bs->is_temporary) { /* snapshot should be writeable */ |
|
453 |
open_flags |= BDRV_O_RDWR; |
|
454 |
} |
|
455 |
} else { |
|
454 | 456 |
open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT); |
455 |
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) |
|
457 |
} |
|
458 |
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) { |
|
456 | 459 |
ret = -ENOTSUP; |
457 |
else
|
|
460 |
} else {
|
|
458 | 461 |
ret = drv->bdrv_open(bs, filename, open_flags); |
459 |
if ((ret == -EACCES || ret == -EPERM) && !(flags & BDRV_O_FILE)) { |
|
460 |
ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR); |
|
461 |
bs->read_only = 1; |
|
462 |
if ((ret == -EACCES || ret == -EPERM) && !(flags & BDRV_O_FILE)) { |
|
463 |
ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR); |
|
464 |
bs->read_only = 1; |
|
465 |
} |
|
462 | 466 |
} |
463 | 467 |
if (ret < 0) { |
464 | 468 |
qemu_free(bs->opaque); |
... | ... | |
481 | 485 |
/* if there is a backing file, use it */ |
482 | 486 |
BlockDriver *back_drv = NULL; |
483 | 487 |
bs->backing_hd = bdrv_new(""); |
484 |
/* pass on read_only property to the backing_hd */ |
|
485 |
bs->backing_hd->read_only = bs->read_only; |
|
486 | 488 |
path_combine(backing_filename, sizeof(backing_filename), |
487 | 489 |
filename, bs->backing_file); |
488 | 490 |
if (bs->backing_format[0] != '\0') |
489 | 491 |
back_drv = bdrv_find_format(bs->backing_format); |
490 | 492 |
ret = bdrv_open2(bs->backing_hd, backing_filename, open_flags, |
491 | 493 |
back_drv); |
494 |
bs->backing_hd->read_only = (open_flags & BDRV_O_RDWR) == 0; |
|
492 | 495 |
if (ret < 0) { |
493 | 496 |
bdrv_close(bs); |
494 | 497 |
return ret; |
Also available in: Unified diff