md5sum of umounted cd-rom (warning: 'orrible perl code ahead)

R

Robert Lynch

How do you compute the md5sum of a cdrom you have burned? Googling
seems to reveal this to be a "difficult" problem. The complaint is
something like: "I burned the CD, but now the md5sum is different than
the one posted on the download site!"

It appears to me that the problem is related to file block size,
padding, etc.

One can find the size of a cd-rom in linux using the command "isosize"
(from util-linux package). Then you can (hack, hack, chop, mangle...)
compute it as follows:
===
# $Id: md5.pl,v 1.2 2003/07/17 17:15:11 user Exp user $
# reads md5sum from unmounted CD-ROM in drive
# run as perl -w md5.pl

use Digest::MD5;

# CD-ROM device file on my system.
$file = "/dev/scd0";

# Install/adjust path to isosize depending on distro
my $size = `/usr/bin/isosize $file`;
#print "Size of $file: $size\n";

# Read $size bytes into a variable
# Perl Cookbook, p. 276
# TODO - read chunks, compute md5sum
# so as not to bog down system.
open FH, $file or die "Couldn't open $file: $!\n";
my $read = sysread(FH, $data, $size, 0);
close FH;

# Lifted from Digest::MD5 man page
my $md5 = Digest::MD5->new;
$md5->add($data);
$digest = $md5->hexdigest;

print "$digest - $file\n";
===
I'm sure you whizzes will take one whiff of this (while holding your
noses) and then immediately come up with something neater and perlish.

But in the meantime: "There's More Than One Way To Do It."

Bob L.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top