Wednesday, 5 February 2014

Optical Drive Testing

For the past couple of weeks I have been focusing my efforts on adding tests to Checkbox for Blu-ray media. This highlighted some interesting differences in the support that various Linux tools have for the broad range of optical media out there. Up until now we only had tests for CD and DVD media, and we were able to muddle by with just one tool - wodim. This enabled us to query drive capabilities such as whether the drive and media in it support writing. Throwing Blu-Ray into the mix complicated things upon a couple of discoveries:


  • wodim doesn't recognize the Blu-Ray capabilities of optical drives.
  • wodim can't write Blu-Ray media.
My first task was to try and figure out how to determine if 'X' drive was a Blu-Ray drive. This was fairly straightforward as the first suspect, udev, turned up the necessary capabilities:


~$ /lib/udev/cdrom_id /dev/cdrom
ID_CDROM=1
ID_CDROM_CD=1
ID_CDROM_CD_R=1
ID_CDROM_CD_RW=1
ID_CDROM_DVD=1
ID_CDROM_DVD_R=1
ID_CDROM_DVD_RW=1
ID_CDROM_DVD_RAM=1
ID_CDROM_DVD_PLUS_R=1
ID_CDROM_DVD_PLUS_RW=1
ID_CDROM_DVD_PLUS_R_DL=1
ID_CDROM_BD=1
ID_CDROM_BD_R=1
ID_CDROM_BD_RE=1
ID_CDROM_MRW=1
ID_CDROM_MRW_W=1
ID_CDROM_MEDIA=1
ID_CDROM_MEDIA_BD_RE=1
ID_CDROM_MEDIA_STATE=complete
ID_CDROM_MEDIA_SESSION_COUNT=1
ID_CDROM_MEDIA_TRACK_COUNT=1
ID_CDROM_MEDIA_TRACK_COUNT_DATA=1

As you can probably see, drive capabilities are reflected by 'ID_CDROM' followed by something like '_<TYPE>_<CAPABILITY>', e.g. '_BD_RE' for re-writable Blu-Ray media. It's useful that capabilities are also distinct from each other so that if a drive purports to support DVD re-writable media then we don't have to assume that it supports reading or writing (although we probably could quite safely!). With this data at hand I proceeded to write some simple Python code which parsed the output of cdrom_id and turned it into a format usable by Checkbox.

With this in place I was almost there, but I needed to create a test for writing Blu-Ray media. Obviously wodim couldn't do this, but I had to find a solution. It turned out that the tool growisofs supports burning DVD and BD media, but not CD - with wodim supported CD and DVD but not BD! Once this was determined, it was fairly simple to refactor the existing test script for optical media writing to use growisofs in the case of DVD and BD tests, but still use wodim for CDs.