CDROM api in Linux

Some info

Programming cdroms in Linux is not as hard as you might think. Some general quick hints are:

  • Open using O_NONBLOCK, so you don't get an error code when opening the cdrom without a disk present.
  • cdrom might have several names depening on devfs, scsi and/or ide. In general you would need to test /dev/hd* /dev/scd* /dev/cdroms/* .
  • Some ioctlcalls return -1 on error and 0 or bigger as values. Errors like no media, not supported etc are defined exit values in many cases.
  • To read a tocentry, you need to prefill the struct with track number and what format you want the start offset returned.
  • The end of the track, you can detect by where the track after starts.
  • Last track length you can see by the LEADOUT track.

findcdroms.c displays some info about all cdroms and discs found.