int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags)
{
BlockDriverState *bs;
+ BlockDriver *drv;
int ret;
+ drv = find_protocol(filename);
+ if (!drv) {
+ return -ENOENT;
+ }
+
bs = bdrv_new("");
- ret = bdrv_open(bs, filename, flags | BDRV_O_FILE, NULL);
+ ret = bdrv_open(bs, filename, flags, drv);
if (ret < 0) {
bdrv_delete(bs);
return ret;
}
pstrcpy(bs->filename, sizeof(bs->filename), filename);
- if (flags & BDRV_O_FILE) {
- drv = find_protocol(filename);
- } else if (!drv) {
+
+ if (!drv) {
drv = find_hdev_driver(filename);
if (!drv) {
drv = find_image_format(filename);
* Clear flags that are internal to the block layer before opening the
* image.
*/
- open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
+ open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
/*
* Snapshots should be writeable.
- *
- * XXX(hch): and what is the point of a snapshot during a read-only open?
*/
- if (!(flags & BDRV_O_FILE) && bs->is_temporary) {
+ if (bs->is_temporary) {
open_flags |= BDRV_O_RDWR;
}
#define BDRV_O_RDWR 0x0002
#define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */
-#define BDRV_O_FILE 0x0010 /* open as a raw file (do not try to
- use a disk image format on top of
- it (default for
- bdrv_file_open()) */
#define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */
#define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */
#define BDRV_O_NATIVE_AIO 0x0080 /* use native AIO instead of the thread pool */
return 1;
}
- bs = bdrv_new("hda");
- if (!bs)
- return 1;
-
if (growable) {
- flags |= BDRV_O_FILE;
- }
-
- if (bdrv_open(bs, name, flags, NULL) < 0) {
- fprintf(stderr, "%s: can't open device %s\n", progname, name);
- bs = NULL;
- return 1;
+ if (bdrv_file_open(&bs, name, flags)) {
+ fprintf(stderr, "%s: can't open device %s\n", progname, name);
+ return 1;
+ }
+ } else {
+ bs = bdrv_new("hda");
+ if (!bs)
+ return 1;
+
+ if (bdrv_open(bs, name, flags, NULL) < 0) {
+ fprintf(stderr, "%s: can't open device %s\n", progname, name);
+ bs = NULL;
+ return 1;
+ }
}
- if (growable) {
- bs->growable = 1;
- }
return 0;
}