Revision 6a8dc042
b/block/raw-posix.c | ||
---|---|---|
185 | 185 |
} |
186 | 186 |
#endif |
187 | 187 |
|
188 |
static void raw_parse_flags(int bdrv_flags, int *open_flags) |
|
189 |
{ |
|
190 |
assert(open_flags != NULL); |
|
191 |
|
|
192 |
*open_flags |= O_BINARY; |
|
193 |
*open_flags &= ~O_ACCMODE; |
|
194 |
if (bdrv_flags & BDRV_O_RDWR) { |
|
195 |
*open_flags |= O_RDWR; |
|
196 |
} else { |
|
197 |
*open_flags |= O_RDONLY; |
|
198 |
} |
|
199 |
|
|
200 |
/* Use O_DSYNC for write-through caching, no flags for write-back caching, |
|
201 |
* and O_DIRECT for no caching. */ |
|
202 |
if ((bdrv_flags & BDRV_O_NOCACHE)) { |
|
203 |
*open_flags |= O_DIRECT; |
|
204 |
} |
|
205 |
if (!(bdrv_flags & BDRV_O_CACHE_WB)) { |
|
206 |
*open_flags |= O_DSYNC; |
|
207 |
} |
|
208 |
} |
|
209 |
|
|
188 | 210 |
#ifdef CONFIG_LINUX_AIO |
189 | 211 |
static int raw_set_aio(void **aio_ctx, int *use_aio, int bdrv_flags) |
190 | 212 |
{ |
... | ... | |
228 | 250 |
return ret; |
229 | 251 |
} |
230 | 252 |
|
231 |
s->open_flags = open_flags | O_BINARY; |
|
232 |
s->open_flags &= ~O_ACCMODE; |
|
233 |
if (bdrv_flags & BDRV_O_RDWR) { |
|
234 |
s->open_flags |= O_RDWR; |
|
235 |
} else { |
|
236 |
s->open_flags |= O_RDONLY; |
|
237 |
} |
|
238 |
|
|
239 |
/* Use O_DSYNC for write-through caching, no flags for write-back caching, |
|
240 |
* and O_DIRECT for no caching. */ |
|
241 |
if ((bdrv_flags & BDRV_O_NOCACHE)) |
|
242 |
s->open_flags |= O_DIRECT; |
|
243 |
if (!(bdrv_flags & BDRV_O_CACHE_WB)) |
|
244 |
s->open_flags |= O_DSYNC; |
|
253 |
s->open_flags = open_flags; |
|
254 |
raw_parse_flags(bdrv_flags, &s->open_flags); |
|
245 | 255 |
|
246 | 256 |
s->fd = -1; |
247 | 257 |
fd = qemu_open(filename, s->open_flags, 0644); |
b/block/raw-win32.c | ||
---|---|---|
77 | 77 |
NULL, 0, NULL, 0, &returned, NULL); |
78 | 78 |
} |
79 | 79 |
|
80 |
static void raw_parse_flags(int flags, int *access_flags, DWORD *overlapped) |
|
81 |
{ |
|
82 |
assert(access_flags != NULL); |
|
83 |
assert(overlapped != NULL); |
|
84 |
|
|
85 |
if (flags & BDRV_O_RDWR) { |
|
86 |
*access_flags = GENERIC_READ | GENERIC_WRITE; |
|
87 |
} else { |
|
88 |
*access_flags = GENERIC_READ; |
|
89 |
} |
|
90 |
|
|
91 |
*overlapped = FILE_ATTRIBUTE_NORMAL; |
|
92 |
if (flags & BDRV_O_NOCACHE) { |
|
93 |
*overlapped |= FILE_FLAG_NO_BUFFERING; |
|
94 |
} |
|
95 |
if (!(flags & BDRV_O_CACHE_WB)) { |
|
96 |
*overlapped |= FILE_FLAG_WRITE_THROUGH; |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
80 | 100 |
static int raw_open(BlockDriverState *bs, const char *filename, int flags) |
81 | 101 |
{ |
82 | 102 |
BDRVRawState *s = bs->opaque; |
... | ... | |
85 | 105 |
|
86 | 106 |
s->type = FTYPE_FILE; |
87 | 107 |
|
88 |
if (flags & BDRV_O_RDWR) { |
|
89 |
access_flags = GENERIC_READ | GENERIC_WRITE; |
|
90 |
} else { |
|
91 |
access_flags = GENERIC_READ; |
|
92 |
} |
|
108 |
raw_parse_flags(flags, &access_flags, &overlapped); |
|
93 | 109 |
|
94 |
overlapped = FILE_ATTRIBUTE_NORMAL; |
|
95 |
if (flags & BDRV_O_NOCACHE) |
|
96 |
overlapped |= FILE_FLAG_NO_BUFFERING; |
|
97 |
if (!(flags & BDRV_O_CACHE_WB)) |
|
98 |
overlapped |= FILE_FLAG_WRITE_THROUGH; |
|
99 | 110 |
s->hfile = CreateFile(filename, access_flags, |
100 | 111 |
FILE_SHARE_READ, NULL, |
101 | 112 |
OPEN_EXISTING, overlapped, NULL); |
... | ... | |
374 | 385 |
} |
375 | 386 |
s->type = find_device_type(bs, filename); |
376 | 387 |
|
377 |
if (flags & BDRV_O_RDWR) { |
|
378 |
access_flags = GENERIC_READ | GENERIC_WRITE; |
|
379 |
} else { |
|
380 |
access_flags = GENERIC_READ; |
|
381 |
} |
|
388 |
raw_parse_flags(flags, &access_flags, &overlapped); |
|
389 |
|
|
382 | 390 |
create_flags = OPEN_EXISTING; |
383 | 391 |
|
384 |
overlapped = FILE_ATTRIBUTE_NORMAL; |
|
385 |
if (flags & BDRV_O_NOCACHE) |
|
386 |
overlapped |= FILE_FLAG_NO_BUFFERING; |
|
387 |
if (!(flags & BDRV_O_CACHE_WB)) |
|
388 |
overlapped |= FILE_FLAG_WRITE_THROUGH; |
|
389 | 392 |
s->hfile = CreateFile(filename, access_flags, |
390 | 393 |
FILE_SHARE_READ, NULL, |
391 | 394 |
create_flags, overlapped, NULL); |
Also available in: Unified diff