]> Git Repo - qemu.git/blobdiff - block/raw-posix.c
raw-posix: Detect CDROM via ioctl on linux
[qemu.git] / block / raw-posix.c
index 5a6a22bee6b1c58203ba20e4e9c0f720a0702bdc..a2c750885683a6e295d663273130a31cb8b1e2f0 100644 (file)
@@ -1140,9 +1140,25 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, int flags)
 
 static int cdrom_probe_device(const char *filename)
 {
+    int fd, ret;
+    int prio = 0;
+
     if (strstart(filename, "/dev/cd", NULL))
-        return 100;
-    return 0;
+        prio = 50;
+
+    fd = open(filename, O_RDONLY | O_NONBLOCK);
+    if (fd < 0) {
+        goto out;
+    }
+
+    /* Attempt to detect via a CDROM specific ioctl */
+    ret = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
+    if (ret >= 0)
+        prio = 100;
+
+    close(fd);
+out:
+    return prio;
 }
 
 static int cdrom_is_inserted(BlockDriverState *bs)
This page took 0.023629 seconds and 4 git commands to generate.