chiark / gitweb /
cdrom_id: Fix DVD-RW media detection
[elogind.git] / extras / cdrom_id / cdrom_id.c
index 5086bfa64fc1d42aded694d725f047dfad2f527c..8480d7b334d1ecdb2ccbaa16141561a1e7099b32 100644 (file)
@@ -297,14 +297,9 @@ static int feature_profiles(struct udev *udev, const unsigned char *profiles, si
                        cd_dvd_ram = 1;
                        break;
                case 0x13:
-                       info(udev, "profile 0x%02x media_dvd_rw\n", profile);
-                       cd_media_dvd_rw = 1;
-                       cd_media_dvd_rw_ro = 1;
-                       break;
                case 0x14:
                        info(udev, "profile 0x%02x dvd_rw\n", profile);
                        cd_dvd_rw = 1;
-                       cd_media_dvd_rw_seq = 1;
                        break;
                case 0x1B:
                        info(udev, "profile 0x%02x dvd_plus_r\n", profile);
@@ -486,10 +481,16 @@ static int cd_profiles(struct udev *udev, int fd)
                cd_media_dvd_ram = 1;
                break;
        case 0x13:
+               info(udev, "profile 0x%02x media_dvd_rw_ro\n", cur_profile);
+               cd_media = 1;
+               cd_media_dvd_rw = 1;
+               cd_media_dvd_rw_ro = 1;
+               break;
        case 0x14:
-               info(udev, "profile 0x%02x media_dvd_rw\n", cur_profile);
+               info(udev, "profile 0x%02x media_dvd_rw_seq\n", cur_profile);
                cd_media = 1;
                cd_media_dvd_rw = 1;
+               cd_media_dvd_rw_seq = 1;
                break;
        case 0x1B:
                info(udev, "profile 0x%02x media_dvd_plus_r\n", cur_profile);
@@ -573,6 +574,7 @@ static int cd_media_info(struct udev *udev, int fd)
 
        cd_media = 1;
        info(udev, "disk type %02x\n", header[8]);
+       info(udev, "hardware reported media status: %s\n", media_status[header[2] & 3]);
 
        /* exclude plain CDROM, some fake cdroms return 0 for "blank" media here */
        if (!cd_media_cd_rom)
@@ -689,8 +691,9 @@ static int cd_media_info(struct udev *udev, int fd)
        }
 
 determined:
-       /* "other" is e. g. DVD-RAM, can't append sessions there either */
-       if ((header[2] & 3) < 2)
+       /* "other" is e. g. DVD-RAM, can't append sessions there; DVDs in
+        * restricted overwrite mode can never append, only in sequential mode */
+       if ((header[2] & 3) < 2 && !cd_media_dvd_rw_ro)
                cd_media_session_next = header[10] << 8 | header[5];
        cd_media_session_count = header[9] << 8 | header[4];
        cd_media_track_count = header[11] << 8 | header[6];
@@ -868,13 +871,11 @@ int main(int argc, char *argv[])
        if (cd_profiles(udev, fd) < 0)
                goto print;
 
-       /* get writable media state */
-       if (cd_media_info(udev, fd) < 0)
-               goto print;
-
        /* get session/track info */
-       if (cd_media_toc(udev, fd) < 0)
-               goto print;
+       cd_media_toc(udev, fd);
+
+       /* get writable media state */
+       cd_media_info(udev, fd);
 
 print:
        printf("ID_CDROM=1\n");