+ return -104 if ( sysread($fh2, $data, 1) != 1 );
+ if ( $data ne chr(0x78) && $data ne chr(0xd6) && $data ne chr(0xd7) ) {
+ &$Log(sprintf("digestAdd: $file has unexpected first char 0x%x",
+ ord($data)));
+ return -105;
+ }
+ return -106 if ( sysseek($fh2, $eofPosn, 0) != $eofPosn );
+ if ( $verify ) {
+ my $data3;
+
+ #
+ # Verify the cached checksums
+ #
+ return -107 if ( $data ne chr(0xd7) );
+ return -108 if ( sysread($fh2, $data3, length($data2) + 1) < 0 );
+ if ( $data2 eq $data3 ) {
+ return 1;
+ }
+ #
+ # Checksums don't agree - fall through so we rewrite the data
+ #
+ &$Log(sprintf("digestAdd: %s verify failed; redoing checksums; len = %d,%d; eofPosn = %d, fileSize = %d",
+ $file, length($data2), length($data3), $eofPosn, $fileSize));
+ #&$Log(sprintf("dataNew = %s", unpack("H*", $data2)));
+ #&$Log(sprintf("dataFile = %s", unpack("H*", $data3)));
+ return -109 if ( sysseek($fh2, $eofPosn, 0) != $eofPosn );
+ $retValue = 2;
+ return $retValue if ( $verify == 2 );
+ }
+ return -110 if ( syswrite($fh2, $data2) != length($data2) );
+ if ( $verify ) {
+ #
+ # Make sure there is no extraneous data on the end of
+ # the file. Seek to the end and truncate if it doesn't
+ # match our expected length.
+ #
+ return -111 if ( !defined(sysseek($fh2, 0, 2)) );
+ if ( sysseek($fh2, 0, 1) != $eofPosn + length($data2) ) {
+ if ( !truncate($fh2, $eofPosn + length($data2)) ) {
+ &$Log(sprintf("digestAdd: $file truncate from %d to %d failed",
+ sysseek($fh2, 0, 1), $eofPosn + length($data2)));
+ return -112;
+ } else {
+ &$Log(sprintf("digestAdd: %s truncated from %d to %d",
+ $file,
+ sysseek($fh2, 0, 1), $eofPosn + length($data2)));
+ }
+ }