@@ -128,11 +128,15 @@ class CompressionFile : public VirtualReadOnlyFile {
128128 return get_flag_bit (FLAG_SHIFT_CALC_DIGEST );
129129 }
130130 bool is_valid () {
131- if (!is_digest_enabled ()) return true ;
131+ if (!is_digest_enabled ()) {
132+ LOG_WARN (" digest not found in current zfile." );
133+ return true ;
134+ }
132135 auto saved_crc = this ->digest ;
133136 this ->digest = 0 ;
134137 DEFER (this ->digest = saved_crc;);
135138 auto crc = crc32::crc32c (this , CompressionFile::HeaderTrailer::SPACE );
139+ LOG_INFO (" zfile digest: ` (` expected)" , HEX (crc).width (8 ), HEX (saved_crc).width (8 ));
136140 return crc == saved_crc;
137141 }
138142 void set_header () {
@@ -490,8 +494,8 @@ class CompressionFile : public VirtualReadOnlyFile {
490494 int reload_res = block.reload ();
491495 LOG_ERROR (
492496 " checksum failed {offset: `, length: `} (expected ` but got `), reload result: `" ,
493- block.m_reader ->m_buf_offset , block.compressed_size , block.crc32_code (),
494- c , reload_res);
497+ block.m_reader ->m_buf_offset , block.compressed_size , HEX ( block.crc32_code ()). width ( 8 ),
498+ HEX (c). width ( 8 ) , reload_res);
495499 if (reload_res < 0 ) {
496500 LOG_ERROR_RETURN (ECHECKSUM , -1 ,
497501 " checksum verification and reload failed" );
@@ -754,10 +758,12 @@ bool load_jump_table(IFile *file, CompressionFile::HeaderTrailer *pheader_traile
754758 LOG_ERRNO_RETURN (0 , false , " failed to read index" );
755759 }
756760 if (pht->is_digest_enabled ()) {
757- LOG_INFO (" check jumptable CRC32 (` expected)" , pht->index_crc );
761+ LOG_INFO (" check jumptable CRC32 (` expected)" , HEX ( pht->index_crc ). width ( 8 ) );
758762 auto crc = crc32::crc32c (ibuf.get (), index_bytes);
759763 if (crc != pht->index_crc ) {
760- LOG_ERRNO_RETURN (0 , false , " checksum of jumptable is incorrect" );
764+ LOG_ERRNO_RETURN (0 , false , " checksum of jumptable is incorrect. {got: `, expected: `}" ,
765+ HEX (crc).width (8 ), HEX (pht->index_crc ).width (8 )
766+ );
761767 }
762768 }
763769 ret = jump_table.build (ibuf.get (), pht->index_size ,
@@ -800,8 +806,8 @@ IFile *zfile_open_ro(IFile *file, bool verify, bool ownership) {
800806 zfile->m_jump_table = std::move (jump_table);
801807 CompressArgs args (ht.opt );
802808 ht.opt .verify = ht.opt .verify && verify;
803- LOG_DEBUG ( " compress type: `, bs: `, verify_checksum : `" , ht. opt . algo , ht. opt . block_size ,
804- ht.opt .verify );
809+ LOG_INFO ( " digest: `, compress type: `, bs: `, data_verify : `" ,
810+ HEX (ht. digest ). width ( 8 ), ht. opt . algo , ht. opt . block_size , ht.opt .verify );
805811
806812 zfile->m_compressor .reset (create_compressor (&args));
807813 zfile->m_ownership = ownership;
@@ -830,7 +836,7 @@ static int write_header_trailer(IFile *file, bool is_header, bool is_sealed, boo
830836 pht->set_digest_enable (); // by default
831837 pht->digest = 0 ;
832838 pht->digest = crc32::crc32c (pht, CompressionFile::HeaderTrailer::SPACE );
833- LOG_INFO (" save header/trailer with digest: `" , pht->digest );
839+ LOG_INFO (" save header/trailer with digest: `" , HEX ( pht->digest ). width ( 8 ) );
834840 if (offset == -1 ) {
835841 return (int )file->write (pht, CompressionFile::HeaderTrailer::SPACE );
836842 }
@@ -907,12 +913,12 @@ int zfile_compress(IFile *file, IFile *as, const CompressArgs *args) {
907913 if (crc32_verify) {
908914 auto crc32_code = crc32c (&compressed_data[j * buf_size], compressed_len[j]);
909915 LOG_DEBUG (" append ` bytes crc32_code: {offset: `, count: `, crc32: `}" ,
910- sizeof (uint32_t ), moffset, compressed_len[j], crc32_code);
916+ sizeof (uint32_t ), moffset, compressed_len[j], HEX ( crc32_code). width ( 8 ) );
911917 compressed_len[j] += sizeof (uint32_t );
912918 ret = as->write (&crc32_code, sizeof (uint32_t ));
913919 if (ret < (ssize_t )sizeof (uint32_t )) {
914920 LOG_ERRNO_RETURN (0 , -1 , " failed to write crc32code, offset: `, crc32: `" ,
915- moffset, crc32_code);
921+ moffset, HEX ( crc32_code). width ( 8 ) );
916922 }
917923 }
918924 block_len.push_back (compressed_len[j]);
@@ -927,6 +933,7 @@ int zfile_compress(IFile *file, IFile *as, const CompressArgs *args) {
927933 LOG_ERRNO_RETURN (0 , -1 , " failed to write index." );
928934 }
929935 pht->index_crc = crc32::crc32c (&block_len[0 ], index_bytes);
936+ LOG_INFO (" index checksum: `" , HEX (pht->index_crc ).width (8 ));
930937 pht->index_offset = index_offset;
931938 pht->index_size = index_size;
932939 pht->original_file_size = raw_data_size;
@@ -957,7 +964,7 @@ int zfile_decompress(IFile *src, IFile *dst) {
957964 for (off_t offset = 0 ; offset < raw_data_size; offset += block_size) {
958965 auto len = (ssize_t )std::min (block_size, (size_t )raw_data_size - offset);
959966 auto readn = file->pread (raw_buf.get (), len, offset);
960- LOG_DEBUG (" readn: `, crc32: `" , readn, crc32c (raw_buf.get (), len));
967+ LOG_DEBUG (" readn: `, crc32: `" , readn, HEX ( crc32c (raw_buf.get (), len)). width ( 8 ));
961968 if (readn != len)
962969 return -1 ;
963970 if (dst->write (raw_buf.get (), readn) != readn) {
0 commit comments