1/*****************************************************************************
2
3Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
4Copyright (c) 2013, 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 include/fsp0fsp.ic
22File space management
23
24Created 12/18/1995 Heikki Tuuri
25*******************************************************/
26
27#ifndef UNIV_INNOCHECKSUM
28
29/** Checks if a page address is an extent descriptor page address.
30@param[in] page_id page id
31@param[in] page_size page size
32@return TRUE if a descriptor page */
33UNIV_INLINE
34ibool
35fsp_descr_page(
36 const page_id_t& page_id,
37 const page_size_t& page_size)
38{
39 return((page_id.page_no() & (page_size.physical() - 1))
40 == FSP_XDES_OFFSET);
41}
42
43/** Calculates the descriptor index within a descriptor page.
44@param[in] page_size page size
45@param[in] offset page offset
46@return descriptor index */
47UNIV_INLINE
48ulint
49xdes_calc_descriptor_index(
50 const page_size_t& page_size,
51 ulint offset)
52{
53 return(ut_2pow_remainder(offset, page_size.physical())
54 / FSP_EXTENT_SIZE);
55}
56#endif /*!UNIV_INNOCHECKSUM */
57
58/**********************************************************************//**
59Gets a descriptor bit of a page.
60@return TRUE if free */
61UNIV_INLINE
62ibool
63xdes_get_bit(
64/*=========*/
65 const xdes_t* descr, /*!< in: descriptor */
66 ulint bit, /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */
67 ulint offset) /*!< in: page offset within extent:
68 0 ... FSP_EXTENT_SIZE - 1 */
69{
70 ut_ad(offset < FSP_EXTENT_SIZE);
71 ut_ad(bit == XDES_FREE_BIT || bit == XDES_CLEAN_BIT);
72
73 ulint index = bit + XDES_BITS_PER_PAGE * offset;
74
75 ulint bit_index = index % 8;
76 ulint byte_index = index / 8;
77
78 return(ut_bit_get_nth(
79 mach_read_ulint(descr + XDES_BITMAP + byte_index,
80 MLOG_1BYTE),
81 bit_index));
82}
83
84#ifndef UNIV_INNOCHECKSUM
85/** Calculates the page where the descriptor of a page resides.
86@param[in] page_size page size
87@param[in] offset page offset
88@return descriptor page offset */
89UNIV_INLINE
90ulint
91xdes_calc_descriptor_page(
92 const page_size_t& page_size,
93 ulint offset)
94{
95 compile_time_assert(UNIV_PAGE_SIZE_MAX > XDES_ARR_OFFSET
96 + (UNIV_PAGE_SIZE_MAX / FSP_EXTENT_SIZE_MAX)
97 * XDES_SIZE_MAX);
98 compile_time_assert(UNIV_PAGE_SIZE_MIN > XDES_ARR_OFFSET
99 + (UNIV_PAGE_SIZE_MIN / FSP_EXTENT_SIZE_MIN)
100 * XDES_SIZE_MIN);
101
102 ut_ad(srv_page_size > XDES_ARR_OFFSET
103 + (srv_page_size / FSP_EXTENT_SIZE)
104 * XDES_SIZE);
105 ut_ad(UNIV_ZIP_SIZE_MIN > XDES_ARR_OFFSET
106 + (UNIV_ZIP_SIZE_MIN / FSP_EXTENT_SIZE)
107 * XDES_SIZE);
108
109#ifdef UNIV_DEBUG
110 if (page_size.is_compressed()) {
111 ut_a(page_size.physical() > XDES_ARR_OFFSET
112 + (page_size.physical() / FSP_EXTENT_SIZE) * XDES_SIZE);
113 }
114#endif /* UNIV_DEBUG */
115
116 return(ut_2pow_round(offset, page_size.physical()));
117}
118#endif /* !UNIV_INNOCHECKSUM */
119