--- trunk/mkinitrd-magellan/isolinux/checksumiso.pl 2010/08/19 08:27:19 1132 +++ trunk/mkinitrd-magellan/isolinux/checksumiso.pl 2010/08/19 09:50:43 1133 @@ -9,11 +9,25 @@ ($file) = @ARGV; -open(FILE, '+<', $file) or die "$0: Cannot open $file: $!\n"; +open(FILE, '+<', $file) or die "$0: cannot open $file: $!\n"; binmode FILE; +@fstat = stat(FILE) or die "$0: stat $file: $!\n"; +if (!$fstat[7]) { + die "$0: $file: cannot query length\n"; +} + +# Pad file to a multiple of 2048 bytes +$frac = $fstat[7] % 2048; +if ($frac) { + seek(FILE,$fstat[7],0) + or die "$0: $file: cannot seek to end\n"; + print FILE "\0" x (2048-$frac); +} + +# Checksum the file post header if ( !seek(FILE,64,0) ) { - die "$0: Cannot seek past header\n"; + die "$0: $file: cannot seek past header\n"; } $csum = 0; @@ -25,8 +39,9 @@ $bytes += $n; } +# Update header if ( !seek(FILE,16,0) ) { - die "$0: Cannot seek to header\n"; + die "$0: $file: cannot seek to header\n"; } print FILE pack("VV", $bytes, $csum);