PostgreSQL Source Code git master
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 
)

Definition at line 187 of file checksum_impl.h.

188{
190 uint16 save_checksum;
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:234
PageData * Page
Definition: bufpage.h:82
#define Assert(condition)
Definition: c.h:815
uint16_t uint16
Definition: c.h:487
uint32_t uint32
Definition: c.h:488
static uint32 pg_checksum_block(const PGChecksummablePage *page)
uint16 pd_checksum
Definition: bufpage.h:164
PageHeaderData phdr

References Assert, PageIsNew(), PageHeaderData::pd_checksum, pg_checksum_block(), and PGChecksummablePage::phdr.

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