Adding upstream version 3.60~pre3.
[syslinux-debian/hramrach.git] / checksumiso.pl
blobb55274287f59cb3385c93705392c996723f2a700
1 #!/usr/bin/perl
3 # Construct a checksum for isolinux*.bin, compatible
4 # with an mkisofs boot-info-table
7 use bytes;
8 use integer;
10 ($file) = @ARGV;
12 open(FILE, '+<', $file) or die "$0: Cannot open $file: $!\n";
13 binmode FILE;
15 if ( !seek(FILE,64,0) ) {
16 die "$0: Cannot seek past header\n";
19 $csum = 0;
20 $bytes = 64;
21 while ( ($n = read(FILE, $dw, 4)) > 0 ) {
22 $dw .= "\0\0\0\0"; # Pad to at least 32 bits
23 ($v) = unpack("V", $dw);
24 $csum = ($csum + $v) & 0xffffffff;
25 $bytes += $n;
28 if ( !seek(FILE,16,0) ) {
29 die "$0: Cannot seek to header\n";
32 print FILE pack("VV", $bytes, $csum);
34 close(FILE);
36 exit 0;