Y The Blog ?

Sunday, May 15, 2005

Cyclic Redundancy !

I was toying with my new iRiver H320 mp3 player. Well, not really toying but was trying to upload all my mp3 music from CDs to the player. I would have completed couple of CDs and soon hit a problem. I could not copy few songs and kept getting the CRC error. However, I could play them using winamp, abosolutely no issues. I tried to figure out if there was a copy utility that just verbatim copies a file from a source to a destination, surprisingly couldn't find one.
All the copy utilities simply refused, cp on cygwin had the same effect. I wasn't sure if cp was only a wrapper over the regular windows copy utility. Though cp did not explitcitly say CRC error it bombed calling it an I/O error. I was quickly running out of options. I couldn't ignore these songs for there were many and were fairly good ones to be carried around. So, wrote this very simple perl script to get it done :-)




#!c:/perl/bin/perl -s
#file : cp_ignore_crc.pl
#If you are stuck with copying some file from you old cd, particularly you old mp3 files
#due to a CRC error. This script will verbatim copy source file to the destination

my $numArgs = $#ARGV + 1;

if($numArgs < 3)
{
print "Show me the money !\n";
print "USAGE : cp_ignore_crc.pl < source file > < destination file >";
exit 1;
}

my $horrible_cd_file=$ARGV[0];
my $dest=$ARGV[1];

open(FR,$horrible_cd_file) or die "an error occured: $!";
open(FW,'>:unix',$dest);
binmode FR,raw;

while(< FR >)
{
print FW $_;
}

close(FW);
close(FR);

That makes me wonder why these basic file copy utilities don't have a method to turn off CRC. I think it makes sense to make CRC optional for non-executable files, because even if a few blocks are corrupt we can still make sense out of the data.

3 Comments:

  • I feel cp would have been implemented very low level copying block by block. So if a block is corrupt it would fail at that point.

    Help me understand how
    print FW $_; solves the
    issue.

    By Blogger Selvam, at 10:40 pm, May 17, 2005  

  • Just reading and writing byte-by-byte. I guess the corresponding read sys call doesn't do anything fancy like CRC.

    By Blogger ~ythee~, at 1:51 pm, May 18, 2005  

  • perl to the rescue. true binary mode. did you try flipping the most significant bits and hearing the result.

    the least significant bits. all the bits. try it. go wild.
    --ramesh

    By Anonymous Anonymous, at 3:58 am, May 20, 2005  

Post a Comment

<< Home