MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / verify_checksum

Function verify_checksum

tools/comdb2ar/db_wrap.cpp:118–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118void verify_checksum(uint8_t *page, size_t pagesize, bool crypto, bool swapped,
119 bool *verify_bool, uint32_t *verify_cksum)
120// Verify the checksum on a regular Berkeley DB page. Returns true if
121// the checksum is correct, false otherwise
122//
123// Also call storeIncrData to store the LSN + Checksum in a file to be
124// compared against
125{
126 PAGE *pagep = (PAGE *)page;
127 uint8_t *chksum_ptr = page;
128
129 switch (PTYPE(pagep)) {
130 case P_HASHMETA:
131 case P_BTREEMETA:
132 case P_QAMMETA:
133 chksum_ptr = ((BTMETA *)page)->chksum;
134 pagesize = DBMETASIZE;
135 break;
136 default:
137 chksum_ptr += crypto ? SIZEOF_PAGE + SSZA(PG_CRYPTO, chksum)
138 : SIZEOF_PAGE + SSZA(PG_CHKSUM, chksum);
139 break;
140 }
141
142
143 uint32_t orig_chksum, chksum;
144 orig_chksum = chksum = *(uint32_t *)chksum_ptr;
145 if (swapped)
146 chksum = myflip(chksum);
147 *(uint32_t *)chksum_ptr = 0;
148 uint32_t calc = IS_CRC32C(page) ? crc32c(page, pagesize)
149 : __ham_func4(page, pagesize);
150 *verify_cksum = calc;
151 *(uint32_t *)chksum_ptr = orig_chksum;
152 *verify_bool = (calc == chksum);
153 return;
154}
155
156// uint32_t calculate_checksum(uint8_t *page, size_t pagesize){
157// PAGE *pagep = (PAGE *)page;

Callers 4

assert_cksum_lsnFunction · 0.85
serialise_incr_fileFunction · 0.85
serialise_fileFunction · 0.85
write_incremental_fileFunction · 0.85

Calls 3

myflipFunction · 0.85
crc32cFunction · 0.85
__ham_func4Function · 0.70

Tested by

no test coverage detected