summaryrefslogtreecommitdiff
path: root/storage/innobase/include/fsp0fsp.ic
blob: 9f28aacaff5da191b19f2f5c1e76fa673f1932fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*****************************************************************************

Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2013, 2017, MariaDB Corporation.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA

*****************************************************************************/

/**************************************************//**
@file include/fsp0fsp.ic
File space management

Created 12/18/1995 Heikki Tuuri
*******************************************************/

#ifndef UNIV_INNOCHECKSUM

/** Checks if a page address is an extent descriptor page address.
@param[in]	page_id		page id
@param[in]	page_size	page size
@return TRUE if a descriptor page */
UNIV_INLINE
ibool
fsp_descr_page(
	const page_id_t		page_id,
	const page_size_t&	page_size)
{
	return((page_id.page_no() & (page_size.physical() - 1))
	       == FSP_XDES_OFFSET);
}

/** Calculates the descriptor index within a descriptor page.
@param[in]	page_size	page size
@param[in]	offset		page offset
@return descriptor index */
UNIV_INLINE
ulint
xdes_calc_descriptor_index(
	const page_size_t&	page_size,
	ulint			offset)
{
	return(ut_2pow_remainder(offset, page_size.physical())
	       / FSP_EXTENT_SIZE);
}
#endif /*!UNIV_INNOCHECKSUM */

/**********************************************************************//**
Gets a descriptor bit of a page.
@return TRUE if free */
UNIV_INLINE
ibool
xdes_get_bit(
/*=========*/
	const xdes_t*	descr,	/*!< in: descriptor */
	ulint		bit,	/*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */
	ulint		offset)	/*!< in: page offset within extent:
				0 ... FSP_EXTENT_SIZE - 1 */
{
	ut_ad(offset < FSP_EXTENT_SIZE);
	ut_ad(bit == XDES_FREE_BIT || bit == XDES_CLEAN_BIT);

	ulint	index = bit + XDES_BITS_PER_PAGE * offset;

	ulint	bit_index = index % 8;
	ulint	byte_index = index / 8;

	return(ut_bit_get_nth(
			mach_read_ulint(descr + XDES_BITMAP + byte_index,
					MLOG_1BYTE),
			bit_index));
}

#ifndef UNIV_INNOCHECKSUM
/** Calculates the page where the descriptor of a page resides.
@param[in]	page_size	page size
@param[in]	offset		page offset
@return descriptor page offset */
UNIV_INLINE
ulint
xdes_calc_descriptor_page(
	const page_size_t&	page_size,
	ulint			offset)
{
	compile_time_assert(UNIV_PAGE_SIZE_MAX > XDES_ARR_OFFSET
			    + (UNIV_PAGE_SIZE_MAX / FSP_EXTENT_SIZE_MAX)
			    * XDES_SIZE_MAX);
	compile_time_assert(UNIV_PAGE_SIZE_MIN > XDES_ARR_OFFSET
			    + (UNIV_PAGE_SIZE_MIN / FSP_EXTENT_SIZE_MIN)
			    * XDES_SIZE_MIN);

	ut_ad(srv_page_size > XDES_ARR_OFFSET
	      + (srv_page_size / FSP_EXTENT_SIZE)
	      * XDES_SIZE);
	ut_ad(UNIV_ZIP_SIZE_MIN > XDES_ARR_OFFSET
	      + (UNIV_ZIP_SIZE_MIN / FSP_EXTENT_SIZE)
	      * XDES_SIZE);

#ifdef UNIV_DEBUG
	if (page_size.is_compressed()) {
		ut_a(page_size.physical() > XDES_ARR_OFFSET
		     + (page_size.physical() / FSP_EXTENT_SIZE) * XDES_SIZE);
	}
#endif /* UNIV_DEBUG */

	return(ut_2pow_round(offset, page_size.physical()));
}
#endif /* !UNIV_INNOCHECKSUM */