| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1995, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/fil0types.h |
| 29 |
The low-level file system page header & trailer offsets |
| 30 |
|
| 31 |
Created 10/25/1995 Heikki Tuuri |
| 32 |
*******************************************************/ |
| 33 |
|
| 34 |
#ifndef fil0types_h |
| 35 |
#define fil0types_h |
| 36 |
|
| 37 |
#include "univ.i" |
| 38 |
|
| 39 |
/** The byte offsets on a file page for various variables. */ |
| 40 |
|
| 41 |
/** MySQL-4.0.14 space id the page belongs to (== 0) but in later |
| 42 |
versions the 'new' checksum of the page */ |
| 43 |
constexpr uint32_t FIL_PAGE_SPACE_OR_CHKSUM = 0; |
| 44 |
|
| 45 |
/** page offset inside space */ |
| 46 |
constexpr uint32_t FIL_PAGE_OFFSET = 4; |
| 47 |
|
| 48 |
/** if there is a 'natural' predecessor of the page, its offset. |
| 49 |
Otherwise FIL_NULL. This field is not set on BLOB pages, which are stored as a |
| 50 |
singly-linked list. See also FIL_PAGE_NEXT. */ |
| 51 |
constexpr uint32_t FIL_PAGE_PREV = 8; |
| 52 |
|
| 53 |
/** On page 0 of the tablespace, this is the server version ID */ |
| 54 |
constexpr uint32_t FIL_PAGE_SRV_VERSION = 8; |
| 55 |
|
| 56 |
/** if there is a 'natural' successor of the page, its offset. Otherwise |
| 57 |
FIL_NULL. B-tree index pages(FIL_PAGE_TYPE contains FIL_PAGE_INDEX) on the |
| 58 |
same PAGE_LEVEL are maintained as a doubly linked list via FIL_PAGE_PREV and |
| 59 |
FIL_PAGE_NEXT in the collation order of the smallest user record on each |
| 60 |
page. */ |
| 61 |
constexpr uint32_t FIL_PAGE_NEXT = 12; |
| 62 |
|
| 63 |
/** On page 0 of the tablespace, this is the server version ID */ |
| 64 |
constexpr uint32_t FIL_PAGE_SPACE_VERSION = 12; |
| 65 |
|
| 66 |
/** lsn of the end of the newest modification log record to the page */ |
| 67 |
constexpr uint32_t FIL_PAGE_LSN = 16; |
| 68 |
|
| 69 |
/** file page type: FIL_PAGE_INDEX,..., 2 bytes. The contents of this field |
| 70 |
can only be trusted in the following case: if the page is an uncompressed |
| 71 |
B-tree index page, then it is guaranteed that the value is FIL_PAGE_INDEX. |
| 72 |
The opposite does not hold. |
| 73 |
|
| 74 |
In tablespaces created by MySQL/InnoDB 5.1.7 or later, the contents of this |
| 75 |
field is valid for all uncompressed pages. */ |
| 76 |
constexpr uint32_t FIL_PAGE_TYPE = 24; |
| 77 |
|
| 78 |
/** this is only defined for the first page of the system tablespace: the file |
| 79 |
has been flushed to disk at least up to this LSN. For FIL_PAGE_COMPRESSED |
| 80 |
pages, we store the compressed page control information in these 8 bytes. */ |
| 81 |
constexpr uint32_t FIL_PAGE_FILE_FLUSH_LSN = 26; |
| 82 |
|
| 83 |
/** If page type is FIL_PAGE_COMPRESSED then the 8 bytes starting at |
| 84 |
FIL_PAGE_FILE_FLUSH_LSN are broken down as follows: */ |
| 85 |
|
| 86 |
/** Control information version format (u8) */ |
| 87 |
constexpr uint32_t FIL_PAGE_VERSION = FIL_PAGE_FILE_FLUSH_LSN; |
| 88 |
|
| 89 |
/** Compression algorithm (u8) */ |
| 90 |
constexpr uint32_t FIL_PAGE_ALGORITHM_V1 = FIL_PAGE_VERSION + 1; |
| 91 |
|
| 92 |
/** Original page type (u16) */ |
| 93 |
constexpr uint32_t FIL_PAGE_ORIGINAL_TYPE_V1 = FIL_PAGE_ALGORITHM_V1 + 1; |
| 94 |
|
| 95 |
/** Original data size in bytes (u16)*/ |
| 96 |
constexpr uint32_t FIL_PAGE_ORIGINAL_SIZE_V1 = FIL_PAGE_ORIGINAL_TYPE_V1 + 2; |
| 97 |
|
| 98 |
/** Size after compression (u16) */ |
| 99 |
constexpr uint32_t FIL_PAGE_COMPRESS_SIZE_V1 = FIL_PAGE_ORIGINAL_SIZE_V1 + 2; |
| 100 |
|
| 101 |
/** This overloads FIL_PAGE_FILE_FLUSH_LSN for RTREE Split Sequence Number */ |
| 102 |
constexpr uint32_t FIL_RTREE_SPLIT_SEQ_NUM = FIL_PAGE_FILE_FLUSH_LSN; |
| 103 |
|
| 104 |
/** starting from 4.1.x this contains the space id of the page */ |
| 105 |
constexpr uint32_t FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID = 34; |
| 106 |
|
| 107 |
/** alias for space id */ |
| 108 |
constexpr uint32_t FIL_PAGE_SPACE_ID = FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID; |
| 109 |
|
| 110 |
/** start of the data on the page */ |
| 111 |
constexpr uint32_t FIL_PAGE_DATA = 38; |
| 112 |
|
| 113 |
/** File page trailer */ |
| 114 |
/** the low 4 bytes of this are used to store the page checksum, the |
| 115 |
last 4 bytes should be identical to the last 4 bytes of FIL_PAGE_LSN */ |
| 116 |
constexpr uint32_t FIL_PAGE_END_LSN_OLD_CHKSUM = 8; |
| 117 |
|
| 118 |
/** size of the page trailer */ |
| 119 |
constexpr uint32_t FIL_PAGE_DATA_END = 8; |
| 120 |
|
| 121 |
/** First in address is the page offset. */ |
| 122 |
constexpr size_t FIL_ADDR_PAGE = 0; |
| 123 |
|
| 124 |
/** Then comes 2-byte byte offset within page.*/ |
| 125 |
constexpr size_t FIL_ADDR_BYTE = 4; |
| 126 |
|
| 127 |
/** Address size is 6 bytes. */ |
| 128 |
constexpr size_t FIL_ADDR_SIZE = 6; |
| 129 |
|
| 130 |
/** Path separator e.g., 'dir;...;dirN' */ |
| 131 |
constexpr char FIL_PATH_SEPARATOR = ';'; |
| 132 |
|
| 133 |
/** A wrapper class to help print and inspect the file page header. */ |
| 134 |
struct Fil_page_header { |
| 135 |
/** The constructor that takes a pointer to page header as argument. |
| 136 |
@param[in] frame the pointer to the page header. */ |
| 137 |
explicit Fil_page_header(const byte *frame) : m_frame(frame) {} |
| 138 |
|
| 139 |
/** Get the space id from the page header. |
| 140 |
@return the space identifier. */ |
| 141 |
[[nodiscard]] space_id_t get_space_id() const noexcept; |
| 142 |
|
| 143 |
/** Get the page number from the page header. |
| 144 |
@return the page number. */ |
| 145 |
[[nodiscard]] page_no_t get_page_no() const noexcept; |
| 146 |
|
| 147 |
/** Get the page type from the page header. |
| 148 |
@return the page type. */ |
| 149 |
[[nodiscard]] uint16_t get_page_type() const noexcept; |
| 150 |
|
| 151 |
/** Print the page header to the given output stream. |
| 152 |
@param[in] out the output stream. |
| 153 |
@return the output stream. */ |
| 154 |
std::ostream &print(std::ostream &out) const noexcept; |
| 155 |
|
| 156 |
private: |
| 157 |
/** Pointer to the page header. */ |
| 158 |
const byte *m_frame{}; |
| 159 |
}; |
| 160 |
|
| 161 |
/** Overload the global output operator to handle an object of type |
| 162 |
Fil_page_header. |
| 163 |
@param[in] out the output stream. |
| 164 |
@param[in] header an object of type Fil_page_header. |
| 165 |
@return the output stream. */ |
| 166 |
inline std::ostream &operator<<(std::ostream &out, |
| 167 |
const Fil_page_header &header) noexcept { |
| 168 |
return (header.print(out)); |
| 169 |
} |
| 170 |
|
| 171 |
#endif /* fil0types_h */ |