PostgreSQL Source Code
git master
Loading...
Searching...
No Matches
checksum_block.inc.c
Go to the documentation of this file.
1
/*-------------------------------------------------------------------------
2
*
3
* checksum_block.inc.c
4
* Core algorithm for page checksums, semi-private to checksum_impl.h
5
* and checksum.c.
6
*
7
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
9
*
10
* src/include/storage/checksum_block.inc.c
11
*
12
*-------------------------------------------------------------------------
13
*/
14
15
/* there is deliberately not an #ifndef CHECKSUM_BLOCK_INC_C here */
16
17
uint32
sums
[
N_SUMS
];
18
uint32
result
= 0;
19
uint32
i
,
20
j
;
21
22
/* ensure that the size is compatible with the algorithm */
23
Assert
(
sizeof
(
PGChecksummablePage
) ==
BLCKSZ
);
24
25
/* initialize partial checksums to their corresponding offsets */
26
memcpy
(
sums
,
checksumBaseOffsets
,
sizeof
(
checksumBaseOffsets
));
27
28
/* main checksum calculation */
29
for
(
i
= 0;
i
< (
uint32
) (
BLCKSZ
/ (
sizeof
(
uint32
) *
N_SUMS
));
i
++)
30
for
(
j
= 0;
j
<
N_SUMS
;
j
++)
31
CHECKSUM_COMP
(
sums
[
j
], page->data[
i
][
j
]);
32
33
/* finally add in two rounds of zeroes for additional mixing */
34
for
(
i
= 0;
i
< 2;
i
++)
35
for
(
j
= 0;
j
<
N_SUMS
;
j
++)
36
CHECKSUM_COMP
(
sums
[
j
], 0);
37
38
/* xor fold partial checksums together */
39
for
(
i
= 0;
i
<
N_SUMS
;
i
++)
40
result
^=
sums
[
i
];
41
42
return
result
;
Assert
#define Assert(condition)
Definition
c.h:943
uint32
uint32_t uint32
Definition
c.h:624
sums
uint32 sums[N_SUMS]
Definition
checksum_block.inc.c:17
j
uint32 j
Definition
checksum_block.inc.c:20
result
uint32 result
Definition
checksum_block.inc.c:18
i
uint32 i
Definition
checksum_block.inc.c:19
memcpy
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
checksumBaseOffsets
static const uint32 checksumBaseOffsets[N_SUMS]
Definition
checksum_impl.h:123
CHECKSUM_COMP
#define CHECKSUM_COMP(checksum, value)
Definition
checksum_impl.h:137
N_SUMS
#define N_SUMS
Definition
checksum_impl.h:108
fb
static int fb(int x)
Definition
preproc-init.c:92
PGChecksummablePage
Definition
checksum_impl.h:114
src
include
storage
checksum_block.inc.c
Generated on Sun Apr 5 2026 13:13:16 for PostgreSQL Source Code by
1.9.8