1 | /***************************************************************************** |
2 | |
3 | Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. |
4 | Copyright (c) 2017, MariaDB Corporation. |
5 | |
6 | This program is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU General Public License as published by the Free Software |
8 | Foundation; version 2 of the License. |
9 | |
10 | This program is distributed in the hope that it will be useful, but WITHOUT |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License along with |
15 | this program; if not, write to the Free Software Foundation, Inc., |
16 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
17 | |
18 | *****************************************************************************/ |
19 | |
20 | /**************************************************//** |
21 | @file buf/buf0checksum.h |
22 | Buffer pool checksum functions, also linked from /extra/innochecksum.cc |
23 | |
24 | Created 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 |
35 | when it is written to a file and also checked for a match when reading from |
36 | the file. When reading we allow both normal CRC32 and CRC-legacy-big-endian |
37 | variants. Note that we must be careful to calculate the same value on 32-bit |
38 | and 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 |
41 | byteorder when converting byte strings to integers |
42 | @return checksum */ |
43 | uint32_t |
44 | buf_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 |
49 | to a file. Note that we must be careful to calculate the same value on |
50 | 32-bit and 64-bit architectures. |
51 | @param[in] page file page (srv_page_size bytes) |
52 | @return checksum */ |
53 | uint32_t |
54 | buf_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 |
57 | the checksum only looked at the first few bytes of the page. |
58 | This calculates that old checksum. |
59 | NOTE: we must first store the new formula checksum to |
60 | FIL_PAGE_SPACE_OR_CHKSUM before calculating and storing this old checksum |
61 | because this takes that field as an input! |
62 | @param[in] page file page (srv_page_size bytes) |
63 | @return checksum */ |
64 | uint32_t |
65 | buf_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 */ |
70 | const char* |
71 | buf_checksum_algorithm_name(srv_checksum_algorithm_t algo); |
72 | |
73 | extern ulong srv_checksum_algorithm; |
74 | extern bool legacy_big_endian_checksum; |
75 | |
76 | #endif /* buf0checksum_h */ |
77 | |