Skip site navigation (1)Skip section navigation (2)
Date:      06 Dec 2001 12:37:12 -0800
From:      swear@blarg.net (Gary W. Swearingen)
To:        Christopher Farley <chris@northernbrewer.com>
Cc:        legg@iastate.edu, freebsd-questions@FreeBSD.ORG
Subject:   Re: Verifying CDs with ISO image
Message-ID:  <kgy9kghypz.9kg@localhost.localdomain>
In-Reply-To: <20011206001130.A17899@northernbrewer.com>
References:  <Pine.OSF.3.95.1011205150415.22193B-100000@isua1.iastate.edu> <20011206001130.A17899@northernbrewer.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Christopher Farley <chris@northernbrewer.com> writes:

> legg@iastate.edu (legg@iastate.edu) wrote:
> > 
> > I still have my ISOs and CHECKSUM.MD5 on my FreeBSD 4.3 box.  Is there
> > any way I can verify the integrity of this CD on my FreeBSD box?  My
> > FreeBSD box has a read-only CD-ROM.
> 
> Sure, try:
> # cat /dev/cd0c | md5
> 
> or this:
> # cat /dev/cd0c | diff iso-image.iso -

I wonder why the device isn't treated like a file in the UNIX WAY as in
"md5 /dev/cd0c"?

But the reason for this message is that I've had failures checking CDs
because "burncd" (I don't know about "cdrecord") puts some padding on
the CD after the ISO image.  Compare their sizes first and then use "dd"
or something to do the md5 or diff on the non-padding part.

Here is a barely-tested (on only one ISO) script to do the check.
It does a "diff", but you could make it do "md5" maybe.


#!/bin/ksh

## This compares the file named by the first argument to the beginning of the CD.
#  Note that the CD burning software (burncd) often writes an ISO CD at least a block bigger than the file.
#  I'm not sure why. (It's not a hard disk file system block size thing.)

iso_file=$1

if [ ! -r ${iso_file} -o ! -f ${iso_file} ]; then
    echo "ERROR: The argument, \"${iso_file}\", is not a readable regular file. Aborting with nothing done."
    exit 1
fi

blocksize=2048  ## Block size of ISO CDs. Nothing else will work (esp, in dd command).

blocks=$(( $(ls -l ${iso_file} | awk '{print $5;}') / 2048 ))

bytes=$(( ${blocks} * ${blocksize} ))

echo "WARNING: About to compare this file (${bytes} bytes, ${blocks} blocks) to CD."
ls -l ${iso_file}
echo -n "Enter \"y\" to continue, else to abort: "

read
if [ "$REPLY" != "y" ]; then
    echo "You entered \"$REPLY\", so the command is aborting with nothing done."
    exit 1
fi

echo "NOTICE: Comparing \"${iso_file}\" to the just-written CD. Please wait..."
if dd if=/dev/acd0a count=${blocks} bs=${blocksize} | diff - ${iso_file}; then
    echo "NOTICE: Comparison OK.  The CD seems OK."
else
    echo "ERROR: The CD and file differred."
fi

echo done

beep 3&

exit 0

## Note: The "ls -s" command gives a size rounded up to even multiple of fs block size -- no good.

## Note: Another, slower, more awkward way to compare the file and CD is this:
# vnconfig -c /dev/vn0a ${iso_file}
# mount -r -t cd9660 /dev/vn0a /mnt/tmp
# mount /cdrom
# diff -r /mnt/tmp /cdrom
# umount /cdrom; eject acd0
# umount /mnt/tmp
# vnconfig -u /dev/vn0a

## The End.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?kgy9kghypz.9kg>