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.

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

Referenced by page_checksum(), PageIsVerified(), PageSetChecksumCopy(), PageSetChecksumInplace(), rewriteVisibilityMap(), scan_file(), and sendFile().

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(&cpage->phdr));
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 (checksum % 65535) + 1;
215 }
static uint32 pg_checksum_block(const PGChecksummablePage *page)
uint16 pd_checksum
Definition: bufpage.h:156
unsigned short uint16
Definition: c.h:357
unsigned int uint32
Definition: c.h:358
#define Assert(condition)
Definition: c.h:732
#define PageIsNew(page)
Definition: bufpage.h:229
PageHeaderData phdr