| 116 | } |
| 117 | |
| 118 | void 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; |
no test coverage detected