PostgreSQL Source Code git master
Loading...
Searching...
No Matches
checksum.h File Reference
#include "storage/block.h"
Include dependency graph for checksum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uint16 pg_checksum_page (char *page, BlockNumber blkno)
 

Function Documentation

◆ pg_checksum_page()

uint16 pg_checksum_page ( char page,
BlockNumber  blkno 
)
extern

Definition at line 187 of file checksum_impl.h.

188{
191 uint32 checksum;
192
193 /* We only calculate the checksum for properly-initialized pages */
194 Assert(!PageIsNew((Page) page));
195
196 /*
197 * Save pd_checksum and temporarily set it to zero, so that the checksum
198 * calculation isn't affected by the old checksum stored on the page.
199 * Restore it after, because actually updating the checksum is NOT part of
200 * the API of this function.
201 */
202 save_checksum = cpage->phdr.pd_checksum;
203 cpage->phdr.pd_checksum = 0;
204 checksum = pg_checksum_block(cpage);
205 cpage->phdr.pd_checksum = save_checksum;
206
207 /* Mix in the block number to detect transposed pages */
208 checksum ^= blkno;
209
210 /*
211 * Reduce to a uint16 (to fit in the pd_checksum field) with an offset of
212 * one. That avoids checksums of zero, which seems like a good idea.
213 */
214 return (uint16) ((checksum % 65535) + 1);
215}
static bool PageIsNew(const PageData *page)
Definition bufpage.h:233
PageData * Page
Definition bufpage.h:81
#define Assert(condition)
Definition c.h:873
uint16_t uint16
Definition c.h:545
uint32_t uint32
Definition c.h:546
static uint32 pg_checksum_block(const PGChecksummablePage *page)
static int fb(int x)

References Assert, fb(), PageIsNew(), and pg_checksum_block().

Referenced by modify_rel_block(), page_checksum_internal(), PageIsVerified(), PageSetChecksumCopy(), PageSetChecksumInplace(), rewriteVisibilityMap(), scan_file(), and verify_page_checksum().