1/*****************************************************************************
2
3Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
4Copyright (c) 2017, MariaDB Corporation.
5
6This program is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free Software
8Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful, but WITHOUT
11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program; if not, write to the Free Software Foundation, Inc.,
1651 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
17
18*****************************************************************************/
19
20/**************************************************//**
21@file buf/buf0checksum.h
22Buffer pool checksum functions, also linked from /extra/innochecksum.cc
23
24Created Aug 11, 2011 Vasil Dimov
25*******************************************************/
26
27#ifndef buf0checksum_h
28#define buf0checksum_h
29
30#include "univ.i"
31
32#include "buf0types.h"
33
34/** Calculate the CRC32 checksum of a page. The value is stored to the page
35when it is written to a file and also checked for a match when reading from
36the file. When reading we allow both normal CRC32 and CRC-legacy-big-endian
37variants. Note that we must be careful to calculate the same value on 32-bit
38and 64-bit architectures.
39@param[in] page buffer page (srv_page_size bytes)
40@param[in] use_legacy_big_endian if true then use big endian
41byteorder when converting byte strings to integers
42@return checksum */
43uint32_t
44buf_calc_page_crc32(
45 const byte* page,
46 bool use_legacy_big_endian = false);
47
48/** Calculate a checksum which is stored to the page when it is written
49to a file. Note that we must be careful to calculate the same value on
5032-bit and 64-bit architectures.
51@param[in] page file page (srv_page_size bytes)
52@return checksum */
53uint32_t
54buf_calc_page_new_checksum(const byte* page);
55
56/** In MySQL before 4.0.14 or 4.1.1 there was an InnoDB bug that
57the checksum only looked at the first few bytes of the page.
58This calculates that old checksum.
59NOTE: we must first store the new formula checksum to
60FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum
61because this takes that field as an input!
62@param[in] page file page (srv_page_size bytes)
63@return checksum */
64uint32_t
65buf_calc_page_old_checksum(const byte* page);
66
67/** Return a printable string describing the checksum algorithm.
68@param[in] algo algorithm
69@return algorithm name */
70const char*
71buf_checksum_algorithm_name(srv_checksum_algorithm_t algo);
72
73extern ulong srv_checksum_algorithm;
74extern bool legacy_big_endian_checksum;
75
76#endif /* buf0checksum_h */
77