Log in

View Full Version : Waiting for DVD drive to become ready (small C program)


beandog
17th February 2014, 05:12
tl;dr - closing a tray doesn't mean it's ready to access, this can query the device and return proper status; useful for scripting

dvd_drive_status.c (https://raw2.github.com/beandog/dvd_tools/master/dvd_drive_status.c)

Long(er) version:

Okay, so, I'm a total noob at C, but I wrote a small program that polls a DVD drive to query its status.

I use my own DVD ripping scripts, and what they do is wait for the tray to be closed and have a DVD put in there.

Even though a tray can be closed, it's not necessarily ready to be accessed because the drive is still loading. Having that non-ready status breaks scripts that want to run something immediately.

One work-around is to just close the tray and wait a few seconds (do not like). So this little C program will query the drive status and return whether it is "ready" to access or not.

This avoids issues like this:

$ eject -t /dev/dvd # closes tray, drive begins polling
$ lsdvd /dev/dvd # barfs because tray is still polling

Anyway, I have justification / reasoning / documentation here on this page: http://dvds.beandog.org/doku.php/dvd_drive_status

This has fixed race conditions in my shell scripts that I've had for years, so it makes me very happy. :)

I hope this helps someone.