Revision 707c0dbc block.c
b/block.c | ||
---|---|---|
225 | 225 |
{ |
226 | 226 |
BlockDriver *drv1; |
227 | 227 |
char protocol[128]; |
228 |
int len; |
|
228 |
int len = strnlen(filename, 127)+1;
|
|
229 | 229 |
const char *p; |
230 | 230 |
|
231 | 231 |
#ifdef _WIN32 |
... | ... | |
233 | 233 |
is_windows_drive_prefix(filename)) |
234 | 234 |
return bdrv_find_format("raw"); |
235 | 235 |
#endif |
236 |
p = strchr(filename, ':');
|
|
237 |
if (!p)
|
|
236 |
p = fill_token(protocol, len, filename, ':');
|
|
237 |
if (*p != ':')
|
|
238 | 238 |
return bdrv_find_format("raw"); |
239 |
len = p - filename; |
|
240 |
if (len > sizeof(protocol) - 1) |
|
241 |
len = sizeof(protocol) - 1; |
|
242 |
memcpy(protocol, filename, len); |
|
243 |
protocol[len] = '\0'; |
|
244 | 239 |
for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) { |
245 | 240 |
if (drv1->protocol_name && |
246 | 241 |
!strcmp(drv1->protocol_name, protocol)) |
... | ... | |
414 | 409 |
open_flags = BDRV_O_RDWR | (flags & BDRV_O_CACHE_MASK); |
415 | 410 |
else |
416 | 411 |
open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT); |
417 |
ret = drv->bdrv_open(bs, filename, open_flags);
|
|
412 |
ret = bdrv_open3(bs, filename, open_flags, drv);
|
|
418 | 413 |
if ((ret == -EACCES || ret == -EPERM) && !(flags & BDRV_O_FILE)) { |
419 |
ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR);
|
|
414 |
ret = bdrv_open3(bs, filename, open_flags & ~BDRV_O_RDWR, drv);
|
|
420 | 415 |
bs->read_only = 1; |
421 | 416 |
} |
422 | 417 |
if (ret < 0) { |
... | ... | |
461 | 456 |
return 0; |
462 | 457 |
} |
463 | 458 |
|
459 |
int bdrv_open3(BlockDriverState *bs, const char *filename, int flags, BlockDriver *drv) |
|
460 |
{ |
|
461 |
char myfile[PATH_MAX]; |
|
462 |
const char *f; |
|
463 |
|
|
464 |
if (!strstart(filename, "file:", &f)) { |
|
465 |
fill_token(myfile, PATH_MAX, filename, '\0'); |
|
466 |
return drv->bdrv_open(bs,myfile,flags); |
|
467 |
} |
|
468 |
return drv->bdrv_open(bs,f,flags); |
|
469 |
} |
|
470 |
|
|
464 | 471 |
void bdrv_close(BlockDriverState *bs) |
465 | 472 |
{ |
466 | 473 |
if (bs->drv) { |
Also available in: Unified diff