bcrc32 cannot do incremental crc32 calculations. Adopt bcrc32 to do support incremental crc32 calculations to ease unit testing.
Signed-off-by: Joakim Tjernlund <joakim.tjernl...@transmode.se> --- It is really hard to do any serious unit testing program of random files when one has to read the whole file into memory to calculate its crc32. The change makes it easier. Only compile tested. bacula/src/lib/crc32.c | 5 ++--- bacula/src/lib/protos.h | 2 +- bacula/src/stored/block.c | 12 ++++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/bacula/src/lib/crc32.c b/bacula/src/lib/crc32.c index a9c18a9..506976f 100644 --- a/bacula/src/lib/crc32.c +++ b/bacula/src/lib/crc32.c @@ -128,13 +128,12 @@ static uint32_t crc_table[256] = { /* * Calculate the PNG 32 bit CRC on a buffer */ -uint32_t bcrc32(uint8_t *buf, int len) +uint32_t bcrc32(uint32_t crc, uint8_t *buf, int len) { - uint32_t crc = 0xFFFFFFFFL; int i; for (i=0; i < len; i++) { crc = crc_table[(crc ^ buf[i]) & 0xFF] ^ (crc >> 8); } - return crc ^ 0xFFFFFFFFL; + return crc; } diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 450a70a..bfb8c7d 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -133,7 +133,7 @@ void hmac_md5(uint8_t* text, int text_len, uint8_t* key, int key_len, uint8_t *h /* crc32.c */ -uint32_t bcrc32(uint8_t *buf, int len); +uint32_t bcrc32(uint32_t crc, uint8_t *buf, int len); /* crypto.c */ int init_crypto (void); diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 313a3dd..7472af9 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -84,8 +84,8 @@ void dump_block(DEV_BLOCK *b, const char *msg) return; } - BlockCheckSum = bcrc32((uint8_t *)b->buf+BLKHDR_CS_LENGTH, - block_len-BLKHDR_CS_LENGTH); + BlockCheckSum = ~bcrc32(~0, (uint8_t *)b->buf+BLKHDR_CS_LENGTH, + block_len-BLKHDR_CS_LENGTH); Pmsg6(000, _("Dump block %s %x: size=%d BlkNum=%d\n" " Hdrcksum=%x cksum=%x\n"), msg, b, block_len, BlockNumber, CheckSum, BlockCheckSum); @@ -206,8 +206,8 @@ static void ser_block_header(DEV_BLOCK *block, bool do_checksum) /* Checksum whole block except for the checksum */ if (do_checksum) { - CheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH, - block_len-BLKHDR_CS_LENGTH); + CheckSum = ~bcrc32(~0, (uint8_t *)block->buf+BLKHDR_CS_LENGTH, + block_len-BLKHDR_CS_LENGTH); } Dmsg1(1390, "ser_bloc_header: checksum=%x\n", CheckSum); ser_begin(block->buf, BLKHDR2_LENGTH); @@ -308,8 +308,8 @@ static bool unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) Dmsg3(390, "Read binbuf = %d %d block_len=%d\n", block->binbuf, bhl, block_len); if (block_len <= block->read_len && dev->do_checksum()) { - BlockCheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH, - block_len-BLKHDR_CS_LENGTH); + BlockCheckSum = ~bcrc32(~0, (uint8_t *)block->buf+BLKHDR_CS_LENGTH, + block_len-BLKHDR_CS_LENGTH); if (BlockCheckSum != CheckSum) { dev->dev_errno = EIO; Mmsg6(dev->errmsg, _("Volume data error at %u:%u!\n" -- 1.7.1 ------------------------------------------------------------------------------ The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details: http://p.sf.net/sfu/dev2dev-palm _______________________________________________ Bacula-devel mailing list Bacula-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bacula-devel