1/*****************************************************************************
2
3Copyright (C) 2013, 2017, MariaDB Corporation. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/******************************************************************//**
20@file include/fsp0pagecompress.ic
21Implementation for helper functions for extracting/storing page
22compression and atomic writes information to file space.
23
24Created 11/12/2013 Jan Lindström jan.lindstrom@mariadb.com
25
26***********************************************************************/
27
28/********************************************************************//**
29Determine the tablespace is page compression level from dict_table_t::flags.
30@return page compression level or 0 if not compressed*/
31UNIV_INLINE
32ulint
33fsp_flags_get_page_compression_level(
34/*=================================*/
35 ulint flags) /*!< in: tablespace flags */
36{
37 return(FSP_FLAGS_GET_PAGE_COMPRESSION_LEVEL(flags));
38}
39
40
41/*******************************************************************//**
42Find out wheather the page is index page or not
43@return true if page type index page, false if not */
44UNIV_INLINE
45bool
46fil_page_is_index_page(
47/*===================*/
48 byte* buf) /*!< in: page */
49{
50 return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_INDEX);
51}
52
53/*******************************************************************//**
54Find out wheather the page is page compressed
55@return true if page is page compressed, false if not */
56UNIV_INLINE
57bool
58fil_page_is_compressed(
59/*===================*/
60 const byte* buf) /*!< in: page */
61{
62 return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED);
63}
64
65/*******************************************************************//**
66Find out wheather the page is page compressed
67@return true if page is page compressed, false if not */
68UNIV_INLINE
69bool
70fil_page_is_compressed_encrypted(
71/*=============================*/
72 const byte* buf) /*!< in: page */
73{
74 return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED);
75}
76
77/****************************************************************//**
78Get the name of the compression algorithm used for page
79compression.
80@return compression algorithm name or "UNKNOWN" if not known*/
81UNIV_INLINE
82const char*
83fil_get_compression_alg_name(
84/*=========================*/
85 ib_uint64_t comp_alg) /*!<in: compression algorithm number */
86{
87 switch(comp_alg) {
88 case PAGE_UNCOMPRESSED:
89 return ("uncompressed");
90 break;
91 case PAGE_ZLIB_ALGORITHM:
92 return ("ZLIB");
93 break;
94 case PAGE_LZ4_ALGORITHM:
95 return ("LZ4");
96 break;
97 case PAGE_LZO_ALGORITHM:
98 return ("LZO");
99 break;
100 case PAGE_LZMA_ALGORITHM:
101 return ("LZMA");
102 break;
103 case PAGE_BZIP2_ALGORITHM:
104 return ("BZIP2");
105 break;
106 case PAGE_SNAPPY_ALGORITHM:
107 return ("SNAPPY");
108 break;
109 /* No default to get compiler warning */
110 }
111
112 return ("NULL");
113}
114
115#ifndef UNIV_INNOCHECKSUM
116/*******************************************************************//**
117Find out wheather the page is page compressed with lzo method
118@return true if page is page compressed with lzo method, false if not */
119UNIV_INLINE
120bool
121fil_page_is_lzo_compressed(
122/*=======================*/
123 byte* buf) /*!< in: page */
124{
125 return((mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED &&
126 mach_read_from_8(buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION) == PAGE_LZO_ALGORITHM) ||
127 (mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED &&
128 mach_read_from_2(buf+FIL_PAGE_DATA+FIL_PAGE_COMPRESSED_SIZE) == PAGE_LZO_ALGORITHM));
129}
130
131#endif /* UNIV_INNOCHECKSUM */
132