diff options
author | Blue Swirl <blauwirbel@gmail.com> | 2009-06-17 18:27:44 +0300 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2009-06-17 18:27:44 +0300 |
commit | 19a3da7f4dcc70557077aff0d7d44754bc177cd9 (patch) | |
tree | 494dbf8d223743a14d2f97f353bd07339771ffe0 /block | |
parent | 5c55ff99fa88158871d5b9f619c485deae5f3d5b (diff) | |
download | qemu-19a3da7f4dcc70557077aff0d7d44754bc177cd9.zip qemu-19a3da7f4dcc70557077aff0d7d44754bc177cd9.tar.gz qemu-19a3da7f4dcc70557077aff0d7d44754bc177cd9.tar.bz2 |
Fix opening of read only raw images
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/raw-posix.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/block/raw-posix.c b/block/raw-posix.c index ccb014a..fa1a394 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -123,7 +123,7 @@ static int cdrom_reopen(BlockDriverState *bs); #endif static int raw_open_common(BlockDriverState *bs, const char *filename, - int flags) + int bdrv_flags, int open_flags) { BDRVRawState *s = bs->opaque; int fd, ret; @@ -132,9 +132,9 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, s->lseek_err_cnt = 0; - s->open_flags |= O_BINARY; + s->open_flags = open_flags | O_BINARY; s->open_flags &= ~O_ACCMODE; - if ((flags & BDRV_O_ACCESS) == BDRV_O_RDWR) { + if ((bdrv_flags & BDRV_O_ACCESS) == BDRV_O_RDWR) { s->open_flags |= O_RDWR; } else { s->open_flags |= O_RDONLY; @@ -143,9 +143,9 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, /* Use O_DSYNC for write-through caching, no flags for write-back caching, * and O_DIRECT for no caching. */ - if ((flags & BDRV_O_NOCACHE)) + if ((bdrv_flags & BDRV_O_NOCACHE)) s->open_flags |= O_DIRECT; - else if (!(flags & BDRV_O_CACHE_WB)) + else if (!(bdrv_flags & BDRV_O_CACHE_WB)) s->open_flags |= O_DSYNC; s->fd = -1; @@ -158,7 +158,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, } s->fd = fd; s->aligned_buf = NULL; - if ((flags & BDRV_O_NOCACHE)) { + if ((bdrv_flags & BDRV_O_NOCACHE)) { s->aligned_buf = qemu_blockalign(bs, ALIGNED_BUFFER_SIZE); if (s->aligned_buf == NULL) { ret = -errno; @@ -172,12 +172,13 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, static int raw_open(BlockDriverState *bs, const char *filename, int flags) { BDRVRawState *s = bs->opaque; + int open_flags = 0; s->type = FTYPE_FILE; if (flags & BDRV_O_CREAT) - s->open_flags |= O_CREAT | O_TRUNC; + open_flags = O_CREAT | O_TRUNC; - return raw_open_common(bs, filename, flags); + return raw_open_common(bs, filename, flags, open_flags); } /* XXX: use host sector size if necessary with: @@ -1008,7 +1009,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) } #endif - return raw_open_common(bs, filename, flags); + return raw_open_common(bs, filename, flags, 0); } #if defined(__linux__) @@ -1186,10 +1187,9 @@ static int floppy_open(BlockDriverState *bs, const char *filename, int flags) posix_aio_init(); s->type = FTYPE_FD; - /* open will not fail even if no floppy is inserted */ - s->open_flags |= O_NONBLOCK; - ret = raw_open_common(bs, filename, flags); + /* open will not fail even if no floppy is inserted, so add O_NONBLOCK */ + ret = raw_open_common(bs, filename, flags, O_NONBLOCK); if (ret) return ret; @@ -1279,11 +1279,10 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags) { BDRVRawState *s = bs->opaque; - /* open will not fail even if no CD is inserted */ - s->open_flags |= O_NONBLOCK; s->type = FTYPE_CD; - return raw_open_common(bs, filename, flags); + /* open will not fail even if no CD is inserted, so add O_NONBLOCK */ + return raw_open_common(bs, filename, flags, O_NONBLOCK); } static int cdrom_probe_device(const char *filename) @@ -1373,7 +1372,7 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags) s->type = FTYPE_CD; - ret = raw_open_common(bs, filename, flags); + ret = raw_open_common(bs, filename, flags, 0); if (ret) return ret; |