diff options
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 ccb014a4d1..fa1a39462a 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; |