aboutsummaryrefslogtreecommitdiff
path: root/block/vvfat.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/vvfat.c')
-rw-r--r--block/vvfat.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/block/vvfat.c b/block/vvfat.c
index af5153d..b509d55 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1156,8 +1156,6 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
s->current_cluster=0xffffffff;
- /* read only is the default for safety */
- bs->read_only = true;
s->qcow = NULL;
s->qcow_filename = NULL;
s->fat2 = NULL;
@@ -1169,11 +1167,24 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
s->sector_count = cyls * heads * secs - (s->first_sectors_number - 1);
if (qemu_opt_get_bool(opts, "rw", false)) {
- ret = enable_write_target(bs, errp);
+ if (!bdrv_is_read_only(bs)) {
+ ret = enable_write_target(bs, errp);
+ if (ret < 0) {
+ goto fail;
+ }
+ } else {
+ ret = -EPERM;
+ error_setg(errp,
+ "Unable to set VVFAT to 'rw' when drive is read-only");
+ goto fail;
+ }
+ } else {
+ /* read only is the default for safety */
+ ret = bdrv_set_read_only(bs, true, &local_err);
if (ret < 0) {
+ error_propagate(errp, local_err);
goto fail;
}
- bs->read_only = false;
}
bs->total_sectors = cyls * heads * secs;