PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 {
189  PGChecksummablePage *cpage = (PGChecksummablePage *) page;
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 }
Pointer Page
Definition: bufpage.h:81
static bool PageIsNew(Page page)
Definition: bufpage.h:233
unsigned short uint16
Definition: c.h:517
unsigned int uint32
Definition: c.h:518
#define Assert(condition)
Definition: c.h:863
static uint32 pg_checksum_block(const PGChecksummablePage *page)
uint16 pd_checksum
Definition: bufpage.h:163
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().