April 17, 2006

CLI Magic: Is that CD still fresh?

Author: Joe Barr

Ever wonder if that ISO or backup CD or DVD you burned last year is still good? This week we'll take a look at a small command-line utility called cdck that checks the condition of data on the media and let you know if it's still good.

User Level: Intermediate

Grab the latest cdck tarball -- 0.5.1 at this writing -- from the author's Web site, decompress it, enter the resulting subdirectory, and chant the magic chant:

make install

Using cdck is a little more difficult than building it, at least at first. I didn't find any documentation in the tarball, and make install didn't add any man pages for help. But this is free software, and the source code is right there in front of us. A quick look at code from main.cpp shows, among other things, that an argument of -h should produce some kind of help. Let's give that a try:

$ cdck -h
Usage: cdck [-d /dev/devname] [-i] [-v] [-o plot-file.dat]
   -d CD/DVD device name, default is /dev/devname
   -i Print CD/DVD information and quit, perform no timings
   -p Save data for gnuplot(1) program
   -o specify plot file, ./plot-file.dat is default
   -V Print version
   -v Verbose operations

That's a little easier to parse than the source code. Let's try the -i option and see what it can tell us about the CD currently in the drive:

$ cdck -i
Track list (1-1):
  1: 00:02:00 (sec: 000000) data
170: 77:00:01 (sec: 346351) data (leadout)

Disc status: data mode 1
Multisession: 0
Audio status: no status

Try to find out what sort of CD this is...
CD-ROM with iso9660 fs
iso9660: 676 MB size, label >Ubuntu 6.04 amd64            

Dead on. OK, enough foreplay. Let's check the CD:

$ cdck
Reading sectors 1-346351
346348 ok

CD overall:
   Sectors total: 346351:
   Good sectors: 346351:
   Bad sectors (incl. with poor timing): 0
CD timings:
   Minimal = 5 usec (0.000005s)
   Maximal = 584120 usec (0.584120s)
   Average = 589 usec (0.000589s)

   Satisfactory disc

I ran cdck on the same disk about half a dozen times while preparing this story. All but one of the runs gave the same answer, "Satisfactory disc," but the Average timing varied from test to test. Once, cdck told me that the CD was unstable and should not be used. From this I conclude that cdck's results may not provide more than a general indication of the goodness or lack of same of your CDs.

Click to enlarge

I replaced the Ubuntu ISO CD with a retail music CD and asked cdck what it knew about it, using the -i option:

$ cdck -i
Track list (1-10):
  1: 00:02:00 (sec: 000000) audio
  2: 03:50:47 (sec: 017147) audio
  3: 06:48:42 (sec: 030492) audio
  4: 11:38:07 (sec: 052207) audio
  5: 16:27:16 (sec: 073891) audio
  6: 21:08:16 (sec: 094966) audio
  7: 24:10:51 (sec: 108651) audio
  8: 28:36:20 (sec: 128570) audio
  9: 33:48:50 (sec: 152000) audio
 10: 40:01:31 (sec: 179956) audio
170: 43:43:26 (sec: 196601) audio(leadout)

Disc status: audio
Multisession: 0
Audio status: no status

Try to find out what sort of CD this is...
Audio CD

But when I tried to actually check the CD, cdck complained that it was "Unable to read disc because disc_status != CDS_DATA_1."

I decided to try one of the other options and let Gnuplot illustrate the findings. After running cdck on my ISO CD with the -p option, which created a data file suitable for input to Gnuplot, I started Gnuplot and told it plot the data in cdck-plot.dat. That opened a new window containing the graph to the left.

So there you have it, a nifty little tool that might tell you that it's time to recreate a backup or an ISO, in words or pictures.

Click Here!