chiark / gitweb /
cdrom_id: skip media tests if CDROM_DRIVE_STATUS != CDS_DISC_OK
[elogind.git] / extras / cdrom_id / cdrom_id.c
index c578f12921a0113ceb5180f6404634011ac0dee3..0d873ae8e5f847eaba7df3d0bc6cc846e948a75d 100644 (file)
@@ -76,6 +76,7 @@ static unsigned int cd_mrw;
 static unsigned int cd_mrw_w;
 
 /* media info */
+static unsigned int cd_media;
 static unsigned int cd_media_cd_rom;
 static unsigned int cd_media_cd_r;
 static unsigned int cd_media_cd_rw;
@@ -196,6 +197,16 @@ static int cd_capability_compat(struct udev *udev, int fd)
        return 0;
 }
 
+static int cd_media_compat(struct udev *udev, int fd)
+{
+       if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) {
+               info(udev, "CDROM_DRIVE_STATUS != CDS_DISC_OK\n");
+               return -1;
+       }
+       cd_media = 1;
+       return 0;
+}
+
 static int cd_inquiry(struct udev *udev, int fd) {
        struct scsi_cmd sc;
        unsigned char inq[128];
@@ -325,6 +336,8 @@ static int cd_profiles(struct udev *udev, int fd)
                return -1;
        }
 
+       cd_media = 1;
+
        switch (cur_profile) {
        case 0x03:
        case 0x04:
@@ -566,7 +579,11 @@ int main(int argc, char *argv[])
                goto exit;
        }
 
-       /* check drive */
+       /* check for media */
+       if (cd_media_compat(udev, fd) < 0)
+               goto print;
+
+       /* check if drive talks MMC */
        if (cd_inquiry(udev, fd) < 0)
                goto print;
 
@@ -625,6 +642,8 @@ print:
        if (cd_mrw_w)
                printf("ID_CDROM_MRW_W=1\n");
 
+       if (cd_media)
+               printf("ID_CDROM_MEDIA=1\n");
        if (cd_media_mo)
                printf("ID_CDROM_MEDIA_MO=1\n");
        if (cd_media_mrw)