PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

uint16 pg_checksum_page ( char *  page,
BlockNumber  blkno 
)

Definition at line 179 of file checksum_impl.h.

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

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

180 {
181  PageHeader phdr = (PageHeader) page;
182  uint16 save_checksum;
183  uint32 checksum;
184 
185  /* We only calculate the checksum for properly-initialized pages */
186  Assert(!PageIsNew(page));
187 
188  /*
189  * Save pd_checksum and temporarily set it to zero, so that the checksum
190  * calculation isn't affected by the old checksum stored on the page.
191  * Restore it after, because actually updating the checksum is NOT part of
192  * the API of this function.
193  */
194  save_checksum = phdr->pd_checksum;
195  phdr->pd_checksum = 0;
196  checksum = pg_checksum_block(page, BLCKSZ);
197  phdr->pd_checksum = save_checksum;
198 
199  /* Mix in the block number to detect transposed pages */
200  checksum ^= blkno;
201 
202  /*
203  * Reduce to a uint16 (to fit in the pd_checksum field) with an offset of
204  * one. That avoids checksums of zero, which seems like a good idea.
205  */
206  return (checksum % 65535) + 1;
207 }
static uint32 pg_checksum_block(char *data, uint32 size)
uint16 pd_checksum
Definition: bufpage.h:152
unsigned short uint16
Definition: c.h:267
unsigned int uint32
Definition: c.h:268
PageHeaderData * PageHeader
Definition: bufpage.h:162
#define Assert(condition)
Definition: c.h:675
#define PageIsNew(page)
Definition: bufpage.h:226