Skip to contentSkip to conversation

block: Assume raw for drives without media

PATCH In review Kevin Wolf 2 participants 2 messages Jun 1, 2010

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 block: Assume raw for drives without media

qemu -cdrom /dev/cdrom with an empty CD-ROM drive doesn't work any more because we try to guess the format and when this fails (because there is no medium) we exit with an error message.

This patch should restore the old behaviour by assuming raw format for such drives.

---
 block.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
block.c +2 -2
index d789d02..7dded4e 100644
@@ -331,8 +331,8 @@ static BlockDriver *find_image_format(const char *filename)
     if (ret < 0)
         return NULL;
 
-    /* Return the raw BlockDriver * to scsi-generic devices */
-    if (bs->sg) {
+    /* Return the raw BlockDriver * to scsi-generic devices or empty drives */
+    if (bs->sg || !bdrv_is_inserted(bs)) {
         bdrv_delete(bs);
         return bdrv_find_format("raw");
     }
Signature · 1 line
1.6.6.1
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Kevin Wolf

qemu -cdrom /dev/cdrom with an empty CD-ROM drive doesn't work any more because we try to guess the format and when this fails (because there is no medium) we exit with an error message.

This patch should restore the old behaviour by assuming raw format for such drives.

---
 block.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
block.c +0 -0
index d789d02..7dded4e 100644

block.c static BlockDriver *find_image_format(const char *filename) · line 338

Quoted 10 lines
block.c +2 -2
@@ -331,8 +331,8 @@ static BlockDriver *find_image_format(const char *filename)
     if (ret < 0)
         return NULL;
 
-    /* Return the raw BlockDriver * to scsi-generic devices */
-    if (bs->sg) {
+    /* Return the raw BlockDriver * to scsi-generic devices or empty drives */
+    if (bs->sg || !bdrv_is_inserted(bs)) {
         bdrv_delete(bs);
         return bdrv_find_format("raw");
     }

Makes sense to me.