[Commits] 4c3cb5f1904: MDEV-11939: innochecksum mistakes a file for an encrypted one

jan jan.lindstrom at mariadb.com
Thu Mar 16 08:47:51 EET 2017


revision-id: 4c3cb5f19047b2d11d190d632cdccde1b3081437 (mariadb-10.2.4-61-g4c3cb5f1904)
parent(s): b5285bd7e201ce522b42d18664f171a4e47f5ecd
author: Jan Lindström
committer: Jan Lindström
timestamp: 2017-03-16 08:47:47 +0200
message:

MDEV-11939: innochecksum mistakes a file for an encrypted one

(page 0 invalid)

Always read full page 0 to determine does tablespace contain
encryption metadata. Tablespaces that are page compressed or
page compressed and encrypted do not compare checksum as
it does not exists. For encrypted tables use checksum
verification written for encrypted tables and normal tables
use normal method.

---
 extra/CMakeLists.txt                |  32 +-
 extra/innochecksum.cc               | 720 ++++++++++++++----------------------
 storage/innobase/buf/buf0buf.cc     | 258 +++++--------
 storage/innobase/include/buf0buf.h  |  19 +-
 storage/innobase/include/page0zip.h |  32 +-
 storage/innobase/page/page0zip.cc   | 192 +++-------
 storage/xtradb/buf/buf0buf.cc       |   2 +-
 7 files changed, 478 insertions(+), 777 deletions(-)

diff --git a/extra/CMakeLists.txt b/extra/CMakeLists.txt
index 9cc5e7faa86..0d3ad61233d 100644
--- a/extra/CMakeLists.txt
+++ b/extra/CMakeLists.txt
@@ -65,27 +65,33 @@ ENDIF()
 ENDIF()
 
 IF(WITH_INNOBASE_STORAGE_ENGINE OR WITH_XTRADB_STORAGE_ENGINE)
+  SET(MUTEXTYPE "event" CACHE STRING "Mutex type: event, sys or futex")
+
+  IF(MUTEXTYPE MATCHES "event")
+    ADD_DEFINITIONS(-DMUTEX_EVENT)
+  ELSEIF(MUTEXTYPE MATCHES "futex" AND DEFINED HAVE_IB_LINUX_FUTEX)
+    ADD_DEFINITIONS(-DMUTEX_FUTEX)
+  ELSE()
+   ADD_DEFINITIONS(-DMUTEX_SYS)
+  ENDIF()
+
   # Add path to the InnoDB headers
   INCLUDE_DIRECTORIES(
     ${CMAKE_SOURCE_DIR}/storage/innobase/include
     ${CMAKE_SOURCE_DIR}/sql)
 
-  # We use the InnoDB code directly in case the code changes.
-  ADD_DEFINITIONS("-DUNIV_INNOCHECKSUM")
+  ADD_DEFINITIONS(-UMYSQL_SERVER)
+
+  MYSQL_ADD_EXECUTABLE(innochecksum
+    innochecksum.cc
+    ${PROJECT_SOURCE_DIR}/libmysqld/libmysql.c
+    COMPONENT checksum)
 
-  SET(INNOBASE_SOURCES
-      ../storage/innobase/buf/buf0checksum.cc
-      ../storage/innobase/ut/ut0crc32.cc
-      ../storage/innobase/ut/ut0ut.cc
-      ../storage/innobase/buf/buf0buf.cc
-      ../storage/innobase/page/page0zip.cc
-      ../storage/innobase/os/os0file.cc
-      ../storage/innobase/fil/fil0crypt.cc
-      )
+  # Export all symbols on Unix, for better crash callstacks
+  SET_TARGET_PROPERTIES(innochecksum PROPERTIES ENABLE_EXPORTS TRUE)
 
+  TARGET_LINK_LIBRARIES(innochecksum sql)
 
-  MYSQL_ADD_EXECUTABLE(innochecksum innochecksum.cc ${INNOBASE_SOURCES})
-  TARGET_LINK_LIBRARIES(innochecksum mysys mysys_ssl)
   ADD_DEPENDENCIES(innochecksum GenError)
 ENDIF()
 
diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc
index 393b1af062c..21b301b8683 100644
--- a/extra/innochecksum.cc
+++ b/extra/innochecksum.cc
@@ -40,25 +40,25 @@
 #include <m_string.h>
 #include <welcome_copyright_notice.h>	/* ORACLE_WELCOME_COPYRIGHT_NOTICE */
 
-/* Only parts of these files are included from the InnoDB codebase.
-The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */
-
 #include "univ.i"			/* include all of this */
 #include "page0size.h"			/* page_size_t */
+#include "ut0byte.h"			/* ut_align */
 #include "page0zip.h"			/* page_zip_calc_checksum() */
+#include "fil0fil.h"			/* FIL_* */
+#include "fut0lst.h"			/* FLST_NODE_SIZE */
+#include "fsp0fsp.h"			/* fsp_flags_get_page_size() &
+					   fsp_flags_get_zip_size() */
 #include "page0page.h"			/* PAGE_* */
 #include "trx0undo.h"			/* TRX_UNDO_* */
 #include "fut0lst.h"			/* FLST_NODE_SIZE */
 #include "buf0checksum.h"		/* buf_calc_page_*() */
-#include "fil0fil.h"			/* FIL_* */
 #include "os0file.h"
-#include "fsp0fsp.h"			/* fsp_flags_get_page_size() &
-					   fsp_flags_get_zip_size() */
 #include "mach0data.h"			/* mach_read_from_4() */
 #include "ut0crc32.h"			/* ut_crc32_init() */
-#include "fsp0pagecompress.h"    /* fil_get_compression_alg_name */
+#include "fsp0pagecompress.h"		/* fil_get_compression_alg_name */
 #include "ut0byte.h"
-#include "mach0data.h"
+#include "fil0crypt.h"
+#include "btr0btr.h"
 
 #ifdef UNIV_NONINL
 # include "fsp0fsp.ic"
@@ -70,24 +70,6 @@ The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */
 #define PRIuMAX   "llu"
 #endif
 
-/*********************************************************************
-Verify checksum for a page (iff it's encrypted)
-NOTE: currently this function can only be run in single threaded mode
-as it modifies srv_checksum_algorithm (temporarily)
- at param[in]	src_fame	page to verify
- at param[in]	page_size	page_size
- at param[in]	page_no		page number of given read_buf
- at param[in]	strict_check	true if strict-check option is enabled
- at return true if page is encrypted AND OK, false otherwise */
-UNIV_INTERN
-bool
-fil_space_verify_crypt_checksum(
-/*============================*/
-	const byte* 		src_frame,	/*!< in: page the verify */
-	const page_size_t&	page_size	/*!< in: page size */
-	,uintmax_t 		page_no,
-	bool			strict_check);
-
 /* Global variables */
 static bool			verbose;
 static bool			just_count;
@@ -96,10 +78,11 @@ static uintmax_t		end_page;
 static uintmax_t		do_page;
 static bool			use_end_page;
 static bool			do_one_page;
-/* replaces declaration in srv0srv.c */
-ulong				srv_page_size;
-page_size_t			univ_page_size(0, 0, false);
+static my_bool do_leaf;
+static my_bool per_page_details;
+static ulong n_merge;
 extern ulong			srv_checksum_algorithm;
+page_size_t			iuniv_page_size(0, 0, false);
 /* Current page number (0 based). */
 uintmax_t			cur_page_num;
 /* Skip the checksum verification. */
@@ -122,8 +105,7 @@ char*				log_filename = NULL;
 FILE*				log_file = NULL;
 /* Enabled for log write option. */
 static bool			is_log_enabled = false;
-static my_bool do_leaf;
-static ulong n_merge;
+
 #ifndef _WIN32
 /* advisory lock for non-window system. */
 struct flock			lk;
@@ -221,75 +203,6 @@ struct per_index_stats {
 
 std::map<unsigned long long, per_index_stats> index_ids;
 
-bool encrypted = false;
-
-ulint
-page_is_comp(
-/*=========*/
-	const page_t*	page)	/*!< in: index page */
-{
-	return(page_header_get_field(page, PAGE_N_HEAP) & 0x8000);
-}
-
-bool
-page_is_leaf(
-/*=========*/
-	const page_t*	page)	/*!< in: page */
-{
-	return(!*(const uint16*) (page + (PAGE_HEADER + PAGE_LEVEL)));
-}
-
-ulint
-page_get_page_no(
-/*=============*/
-	const page_t*	page)	/*!< in: page */
-{
-	return(mach_read_from_4(page + FIL_PAGE_OFFSET));
-}
-#define FSEG_HEADER_SIZE	10	/*!< Length of the file system
-					header, in bytes */
-#define REC_N_NEW_EXTRA_BYTES	5
-#define REC_N_OLD_EXTRA_BYTES	6
-#define PAGE_DATA	(PAGE_HEADER + 36 + 2 * FSEG_HEADER_SIZE)
-				/* start of data on the page */
-#define PAGE_NEW_SUPREMUM	(PAGE_DATA + 2 * REC_N_NEW_EXTRA_BYTES + 8)
-				/* offset of the page supremum record on a
-				new-style compact page */
-#define PAGE_NEW_SUPREMUM_END (PAGE_NEW_SUPREMUM + 8)
-#define PAGE_OLD_SUPREMUM	(PAGE_DATA + 2 + 2 * REC_N_OLD_EXTRA_BYTES + 8)
-				/* offset of the page supremum record on an
-				old-style page */
-#define PAGE_OLD_SUPREMUM_END (PAGE_OLD_SUPREMUM + 9)
-				/* offset of the page supremum record end on
-				an old-style page */
-#define	FLST_BASE_NODE_SIZE	(4 + 2 * 6)
-#define	XDES_ARR_OFFSET		(FSP_HEADER_OFFSET + FSP_HEADER_SIZE)
-#define	XDES_FREE_BIT		0
-#define	XDES_BITMAP		(FLST_NODE_SIZE + 12)
-#define	XDES_BITS_PER_PAGE	2
-#define UT_BITS_IN_BYTES(b) (((b) + 7) / 8)
-#define	XDES_SIZE							\
-	(XDES_BITMAP							\
-	+ UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE))
-
-ulint
-page_get_data_size(
-/*===============*/
-	const page_t*	page)	/*!< in: index page */
-{
-	ulint	ret;
-
-	ret = (ulint)(page_header_get_field(page, PAGE_HEAP_TOP)
-		      - (page_is_comp(page)
-			 ? PAGE_NEW_SUPREMUM_END
-			 : PAGE_OLD_SUPREMUM_END)
-		      - page_header_get_field(page, PAGE_GARBAGE));
-
-	ut_ad(ret < UNIV_PAGE_SIZE);
-
-	return(ret);
-}
-
 void print_index_leaf_stats(
 	unsigned long long id,
 	const per_index_stats& index,
@@ -329,6 +242,7 @@ void defrag_analysis(
 				break;
 			}
 		}
+
 		if (index.max_data_size) {
 			n_pages += data_size_total / index.max_data_size;
 			if (data_size_total % index.max_data_size != 0) {
@@ -341,6 +255,10 @@ void defrag_analysis(
 		fprintf(fil_out, "count = %lu free = %lu\n", index.count, index.free_pages);
 	}
 
+	if (!n_leaf_pages) {
+		n_leaf_pages = 1;
+	}
+
 	fprintf(fil_out, "%llu\t\t%llu\t\t%lu\t\t%lu\t\t%lu\t\t%.2f\t%lu\n",
 		id, index.leaf_pages, n_leaf_pages, n_merge, n_pages,
 		1.0 - (double)n_pages / (double)n_leaf_pages, index.max_data_size);
@@ -366,54 +284,6 @@ void print_leaf_stats(
 	}
 }
 
-/** Get the page size of the filespace from the filespace header.
- at param[in]	buf	buffer used to read the page.
- at return page size */
-static
-const page_size_t
-get_page_size(
-	byte*	buf)
-{
-	const ulint	flags = mach_read_from_4(buf + FIL_PAGE_DATA
-						 + FSP_SPACE_FLAGS);
-
-	const ulint	ssize = FSP_FLAGS_GET_PAGE_SSIZE(flags);
-
-	if (ssize == 0) {
-		srv_page_size = UNIV_PAGE_SIZE_ORIG;
-	} else {
-		srv_page_size = ((UNIV_ZIP_SIZE_MIN >> 1) << ssize);
-	}
-
-	univ_page_size.copy_from(
-		page_size_t(srv_page_size, srv_page_size, false));
-
-	return(page_size_t(flags));
-}
-
-#ifdef MYSQL_COMPRESSION
-/** Decompress a page
- at param[in,out]	buf		Page read from disk, uncompressed data will
-				also be copied to this page
- at param[in, out] scratch		Page to use for temporary decompress
- at param[in]	page_size	scratch physical size
- at return true if decompress succeeded */
-static
-bool page_decompress(
-	byte*		buf,
-	byte*		scratch,
-	page_size_t	page_size)
-{
-	dberr_t		err;
-
-	/* Set the dblwr recover flag to false. */
-	err = os_file_decompress_page(
-		false, buf, scratch, page_size.physical());
-
-	return(err == DB_SUCCESS);
-}
-#endif
-
 #ifdef _WIN32
 /***********************************************//*
  @param		[in] error	error no. from the getLastError().
@@ -458,6 +328,7 @@ open_file(
 		access = GENERIC_READ;
 		flags = _O_RDONLY | _O_BINARY;
 	}
+
 	/* CreateFile() also provide advisory lock with the usage of
 	access and share mode of the file.*/
 	hFile = CreateFile(
@@ -481,8 +352,7 @@ open_file(
 	if (do_write) {
 		create_flag = O_RDWR;
 		lk.l_type = F_WRLCK;
-	}
-	else {
+	} else {
 		create_flag = O_RDONLY;
 		lk.l_type = F_RDLCK;
 	}
@@ -544,12 +414,18 @@ ulong read_file(
 /** Check if page is corrupted or not.
 @param[in]	buf		page frame
 @param[in]	page_size	page size
+ at param[in]	is_encrypted	true if page0 contained cryp_data
+				with crypt_scheme encrypted
+ at param[in]	is_compressed	true if page0 fsp_flags contained
+				page compression flag
 @retval true if page is corrupted otherwise false. */
 static
 bool
 is_page_corrupted(
-	const byte*		buf,
-	const page_size_t&	page_size)
+	byte*		buf,
+	const page_size_t&	page_size,
+	bool		is_encrypted,
+	bool		is_compressed)
 {
 
 	/* enable if page is corrupted. */
@@ -557,49 +433,54 @@ is_page_corrupted(
 	/* use to store LSN values. */
 	ulint logseq;
 	ulint logseqfield;
+	ulint page_type = mach_read_from_2(buf+FIL_PAGE_TYPE);
+	ulint key_version = mach_read_from_4(buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
+	ulint space_id = mach_read_from_4(
+		buf + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
+
+	/* We can't trust only a page type, thus we take account
+	also fsp_flags or crypt_data on page 0 */
+	if ((page_type == FIL_PAGE_PAGE_COMPRESSED && is_compressed) ||
+	    (page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED &&
+	     is_compressed && is_encrypted)) {
+		/* Page compressed tables do not contain post compression
+		checksum. */
+		return (false);
+	}
 
 	if (!page_size.is_compressed()) {
 		/* check the stored log sequence numbers
 		for uncompressed tablespace. */
 		logseq = mach_read_from_4(buf + FIL_PAGE_LSN + 4);
 		logseqfield = mach_read_from_4(
-				buf + page_size.logical() -
-				FIL_PAGE_END_LSN_OLD_CHKSUM + 4);
+			buf + page_size.physical() -
+			FIL_PAGE_END_LSN_OLD_CHKSUM + 4);
 
 		if (is_log_enabled) {
 			fprintf(log_file,
-				"page::%" PRIuMAX
+				"space::%" PRIuMAX " page::%" PRIuMAX
 				"; log sequence number:first = " ULINTPF
 				"; second = " ULINTPF "\n",
-				cur_page_num, logseq, logseqfield);
+				space_id, cur_page_num, logseq, logseqfield);
 			if (logseq != logseqfield) {
 				fprintf(log_file,
-					"Fail; page %" PRIuMAX
+					"Fail; space %" PRIuMAX " page %" PRIuMAX
 					" invalid (fails log "
 					"sequence number check)\n",
-					cur_page_num);
+					space_id, cur_page_num);
 			}
 		}
 	}
 
-	/* If page is encrypted, use different checksum calculation
-	as innochecksum can't decrypt pages. Note that some old InnoDB
-	versions did not initialize FIL_PAGE_FILE_FLUSH_LSN field
-	so if crypt checksum does not match we verify checksum using
-	normal method.
-	*/
-	if (mach_read_from_4(buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION) != 0) {
-		is_corrupted = fil_space_verify_crypt_checksum(buf, page_size,
-			cur_page_num, strict_verify);
+	/* Again we can't trust only FIL_PAGE_FILE_FLUSH_LSN field
+	now repurposed as FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION,
+	we need to check also crypt_data contents. */
+	if (is_encrypted && key_version != 0) {
+		is_corrupted = !fil_space_verify_crypt_checksum(buf,
+			page_size);
 	} else {
-		is_corrupted = true;
-	}
-
-	if (is_corrupted) {
 		is_corrupted = buf_page_is_corrupted(
-			true, buf, page_size, false,
-			cur_page_num, strict_verify,
-			is_log_enabled, log_file);
+			true, buf, page_size, false);
 	}
 
 	return(is_corrupted);
@@ -643,8 +524,8 @@ is_page_empty(
 		if (*page++) {
 			return (false);
 		}
-        }
-        return (true);
+	}
+	return (true);
 }
 
 /********************************************************************//**
@@ -748,7 +629,7 @@ update_checksum(
 
 	}
 
-func_exit:
+	func_exit:
 	/* The following code is to check the stored checksum with the
 	calculated checksum. If it matches, then return FALSE to skip
 	the rewrite of checksum, otherwise return TRUE. */
@@ -834,93 +715,29 @@ write_file(
 	return(true);
 }
 
-/********************************************************//**
-Gets the next index page number.
- at return	next page number */
-ulint
-btr_page_get_next(
-/*==============*/
-  const page_t* page) /*!< in: index page */
-{
-  return(mach_read_from_4(page + FIL_PAGE_NEXT));
-}
-
-/********************************************************//**
-Gets the previous index page number.
- at return	prev page number */
-ulint
-btr_page_get_prev(
-/*==============*/
-  const page_t* page) /*!< in: index page */
-{
-  return(mach_read_from_4(page + FIL_PAGE_PREV));
-}
-
-ulint
-mach_read_ulint(
-	const byte*	ptr,
-	mlog_id_t	type)
-{
-	switch (type) {
-	case MLOG_1BYTE:
-		return(mach_read_from_1(ptr));
-	case MLOG_2BYTES:
-		return(mach_read_from_2(ptr));
-	case MLOG_4BYTES:
-		return(mach_read_from_4(ptr));
-	default:
-		break;
-	}
-
-	ut_error;
-	return(0);
-}
-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 */
-{
-	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));
-}
-
 /*
 Parse the page and collect/dump the information about page type
 @param [in] page	buffer page
- at param [in] xdes	xdes page
+ at param [out] xdes	extend descriptor page
 @param [in] file	file for diagnosis.
- at param [in] page_size	page size
 */
 void
 parse_page(
 	const byte*	page,
-	const byte*	xdes,
-	FILE*		file,
-	page_size_t	page_size)
+	byte*		xdes,
+	FILE*		file)
 {
-	unsigned long long id=0;
-	ulint undo_page_type=0;
-	ulint n_recs;
-	ulint page_no=0;
-	ulint right_page_no=0;
-	ulint left_page_no=0;
-	ulint data_bytes=0;
-	bool is_leaf=false;
-	ulint size_range_id=0;
-	ulint data_types=0;
-	ulint key_version = 0;
-
+	unsigned long long id;
+	ulint undo_page_type;
 	char str[20]={'\0'};
+	ulint n_recs;
+	ulint page_no;
+	ulint left_page_no;
+	ulint right_page_no;
+	ulint data_bytes;
+	int is_leaf;
+	int size_range_id;
+	mtr_t mtr;
 
 	/* Check whether page is doublewrite buffer. */
 	if(skip_page) {
@@ -934,92 +751,74 @@ parse_page(
 	case FIL_PAGE_INDEX:
 		page_type.n_fil_page_index++;
 		id = mach_read_from_8(page + PAGE_HEADER + PAGE_INDEX_ID);
-		n_recs = page_header_get_field(page, PAGE_N_RECS);
+		id = btr_page_get_index_id(page);
+		n_recs = page_get_n_recs(page);
 		page_no = page_get_page_no(page);
-		left_page_no = btr_page_get_prev(page);
-		right_page_no = btr_page_get_next(page);
-		key_version = mach_read_from_4(page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
-
-		/* If page is encrypted we can't read index header */
-		if (!key_version) {
-			data_bytes = page_get_data_size(page);
-		} else {
-			data_bytes = 0;
-		}
-
+		left_page_no = btr_page_get_prev(page, &mtr);
+		right_page_no = btr_page_get_next(page, &mtr);
+		data_bytes = page_get_data_size(page);
 		is_leaf = page_is_leaf(page);
+		size_range_id = (data_bytes * SIZE_RANGES_FOR_PAGE
+			+ iuniv_page_size.logical() - 1) /
+			iuniv_page_size.logical();
+               if (size_range_id > SIZE_RANGES_FOR_PAGE + 1) {
+		       /* data_bytes is bigger than logical_page_size */
+		       size_range_id = SIZE_RANGES_FOR_PAGE + 1;
+               }
+               if (per_page_details) {
+		       printf("index %llu page %lu leaf %u n_recs %lu data_bytes %lu"
+			       "\n", id, page_no, is_leaf, n_recs, data_bytes);
+               }
+               /* update per-index statistics */
+               {
+		       if (index_ids.count(id) == 0) {
+			       index_ids[id] = per_index_stats();
+		       }
+		       std::map<unsigned long long, per_index_stats>::iterator it;
+		       it = index_ids.find(id);
+		       per_index_stats &index = (it->second);
+		       const byte* des = xdes + XDES_ARR_OFFSET
+			       + XDES_SIZE * ((page_no & (iuniv_page_size.physical() - 1))
+				       / FSP_EXTENT_SIZE);
+		       if (xdes_get_bit(des, XDES_FREE_BIT,
+				       page_no % FSP_EXTENT_SIZE)) {
+			       index.free_pages++;
+			       return;
+		       }
+		       index.pages++;
+		       if (is_leaf) {
+			       index.leaf_pages++;
+			       if (data_bytes > index.max_data_size) {
+				       index.max_data_size = data_bytes;
+			       }
+			       struct per_page_stats pp(n_recs, data_bytes,
+				       left_page_no, right_page_no);
+
+			       index.leaves[page_no] = pp;
+
+			       if (left_page_no == ULINT32_UNDEFINED) {
+				       index.first_leaf_page = page_no;
+				       index.count++;
+			       }
+		       }
+		       index.total_n_recs += n_recs;
+		       index.total_data_bytes += data_bytes;
+		       index.pages_in_size_range[size_range_id] ++;
+               }
 
-		if (page_type_dump) {
+	       if (page_type_dump) {
 			fprintf(file, "#::%8" PRIuMAX "\t\t|\t\tIndex page\t\t\t|"
 				"\tindex id=%llu,", cur_page_num, id);
 
 			fprintf(file,
-				" page level=" ULINTPF " leaf %u"
+				" page level=" ULINTPF
 				", No. of records=" ULINTPF
-				", garbage=" ULINTPF
-				", n_recs=" ULINTPF
-				", %s\n",
+				", garbage=" ULINTPF ", %s\n",
 				page_header_get_field(page, PAGE_LEVEL),
-				is_leaf,
-				n_recs,
-				page_header_get_field(page, PAGE_GARBAGE),
-				data_types,
-				str);
-		}
-
-		size_range_id = (data_bytes * SIZE_RANGES_FOR_PAGE
-			+ page_size.logical() - 1) /
-			page_size.logical();
-
-		if (size_range_id > SIZE_RANGES_FOR_PAGE + 1) {
-			/* data_bytes is bigger than logical_page_size */
-			size_range_id = SIZE_RANGES_FOR_PAGE + 1;
-		}
-
-		/* update per-index statistics */
-		{
-			if (index_ids.count(id) == 0) {
-				index_ids[id] = per_index_stats();
-			}
-
-			std::map<unsigned long long, per_index_stats>::iterator it;
-			it = index_ids.find(id);
-			per_index_stats &index = (it->second);
-			uchar* des = (uchar *)(xdes + XDES_ARR_OFFSET
-				+ XDES_SIZE * ((page_no & (page_size.physical() - 1))
-					/ FSP_EXTENT_SIZE));
-
-			if (xdes_get_bit(des, XDES_FREE_BIT,
-					page_no % FSP_EXTENT_SIZE)) {
-				index.free_pages++;
-				return;
-			}
-
-			index.pages++;
-
-			if (is_leaf) {
-				index.leaf_pages++;
-				if (data_bytes > index.max_data_size) {
-					index.max_data_size = data_bytes;
-				}
-
-				struct per_page_stats pp(n_recs, data_bytes,
-					left_page_no, right_page_no);
-
-				index.leaves[page_no] = pp;
-
-				if (left_page_no == ULINT32_UNDEFINED) {
-					index.first_leaf_page = page_no;
-					index.count++;
-				}
-			}
-
-			index.total_n_recs += n_recs;
-			index.total_data_bytes += data_bytes;
-			index.pages_in_size_range[size_range_id] ++;
-		}
-
-		break;
+				page_header_get_field(page, PAGE_N_RECS),
+				page_header_get_field(page, PAGE_GARBAGE), str);
+	       }
+	       break;
 
 	case FIL_PAGE_UNDO_LOG:
 		page_type.n_fil_page_undo_log++;
@@ -1147,7 +946,7 @@ parse_page(
 
 	case FIL_PAGE_TYPE_FSP_HDR:
 		page_type.n_fil_page_type_fsp_hdr++;
-		memcpy((void *)xdes, (void *)page, page_size.physical());
+		memcpy(xdes, page, iuniv_page_size.physical());
 		if (page_type_dump) {
 			fprintf(file, "#::%8" PRIuMAX "\t\t|\t\tFile Space "
 				"Header\t\t|\t%s\n", cur_page_num, str);
@@ -1156,7 +955,7 @@ parse_page(
 
 	case FIL_PAGE_TYPE_XDES:
 		page_type.n_fil_page_type_xdes++;
-		memcpy((void *)xdes, (void *)page, page_size.physical());
+		memcpy(xdes, page, iuniv_page_size.physical());
 		if (page_type_dump) {
 			fprintf(file, "#::%8" PRIuMAX "\t\t|\t\tExtent descriptor "
 				"page\t\t|\t%s\n", cur_page_num, str);
@@ -1187,20 +986,21 @@ parse_page(
 		}
 			break;
 
-       case FIL_PAGE_PAGE_COMPRESSED:
-	       page_type.n_fil_page_type_page_compressed++;
-	       if (page_type_dump) {
+	case FIL_PAGE_PAGE_COMPRESSED:
+		page_type.n_fil_page_type_page_compressed++;
+		if (page_type_dump) {
 			fprintf(file, "#::%8" PRIuMAX "\t\t|\t\tPage compressed "
 				"page\t|\t%s\n", cur_page_num, str);
-	       }
-	       break;
-       case FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED:
-	       page_type.n_fil_page_type_page_compressed_encrypted++;
-	       if (page_type_dump) {
-		       fprintf(file, "#::%8" PRIuMAX "\t\t|\t\tPage compressed encrypted "
+		}
+		break;
+
+	case FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED:
+		page_type.n_fil_page_type_page_compressed_encrypted++;
+		if (page_type_dump) {
+			fprintf(file, "#::%8" PRIuMAX "\t\t|\t\tPage compressed encrypted "
 				"page\t|\t%s\n", cur_page_num, str);
-	       }
-	       break;
+		}
+		break;
 	default:
 		page_type.n_fil_page_type_other++;
 		break;
@@ -1284,13 +1084,12 @@ print_summary(
 		page_type.n_fil_page_type_blob);
 	fprintf(fil_out, "%8d\tCompressed BLOB page\n",
 		page_type.n_fil_page_type_zblob);
+	fprintf(fil_out, "%8d\tOther type of page\n",
+		page_type.n_fil_page_type_other);
 	fprintf(fil_out, "%8d\tPage compressed page\n",
 		page_type.n_fil_page_type_page_compressed);
 	fprintf(fil_out, "%8d\tPage compressed encrypted page\n",
 		page_type.n_fil_page_type_page_compressed_encrypted);
-	fprintf(fil_out, "%8d\tOther type of page",
-		page_type.n_fil_page_type_other);
-
 	fprintf(fil_out, "\n===============================================\n");
 	fprintf(fil_out, "Additional information:\n");
 	fprintf(fil_out, "Undo page type: %d insert, %d update, %d other\n",
@@ -1346,8 +1145,10 @@ static struct my_option innochecksum_options[] = {
     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"verbose", 'v', "Verbose (prints progress every 5 seconds).",
     &verbose, &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+#ifndef DBUG_OFF
   {"debug", '#', "Output debug log. See " REFMAN "dbug-package.html",
     &dbug_setting, &dbug_setting, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+#endif /* !DBUG_OFF */
   {"count", 'c', "Print the count of pages in the file and exits.",
     &just_count, &just_count, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"start_page", 's', "Start on this page number (0 based).",
@@ -1376,10 +1177,12 @@ static struct my_option innochecksum_options[] = {
   {"page-type-dump", 'D', "Dump the page type info for each page in a "
    "tablespace.", &page_dump_filename, &page_dump_filename, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"per-page-details", 'i', "Print out per-page detail information.",
+   &per_page_details, &per_page_details, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
    {"log", 'l', "log output.",
      &log_filename, &log_filename, 0,
       GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"leaf", 'e', "Examine leaf index pages",
+  {"leaf", 'f', "Examine leaf index pages",
     &do_leaf, &do_leaf, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"merge", 'm', "leaf page count if merge given number of consecutive pages",
    &n_merge, &n_merge, 0, GET_ULONG, REQUIRED_ARG, 0, 0, (longlong)10L, 0, 1, 0},
@@ -1407,9 +1210,9 @@ static void usage(void)
 	puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000"));
 	printf("InnoDB offline file checksum utility.\n");
 	printf("Usage: %s [-c] [-s <start page>] [-e <end page>] "
-		"[-p <page>] [-v]  [-a <allow mismatches>] [-n] "
+		"[-p <page>] [-i] [-v]  [-a <allow mismatches>] [-n] "
 		"[-C <strict-check>] [-w <write>] [-S] [-D <page type dump>] "
-		"[-l <log>] [-e] <filename or [-]>\n", my_progname);
+		"[-l <log>] [-l] [-m <merge pages>] <filename or [-]>\n", my_progname);
 	printf("See " REFMAN "innochecksum.html for usage hints.\n");
 	my_print_help(innochecksum_options);
 	my_print_variables(innochecksum_options);
@@ -1441,7 +1244,6 @@ innochecksum_get_one_option(
 		break;
 	case 'V':
 		print_version();
-		my_end(0);
 		exit(EXIT_SUCCESS);
 		break;
 	case 'C':
@@ -1502,21 +1304,61 @@ get_options(
 	char	***argv)
 {
 	if (handle_options(argc, argv, innochecksum_options,
-			   innochecksum_get_one_option)) {
-		my_end(0);
+		innochecksum_get_one_option))
 		exit(true);
-	}
 
 	/* The next arg must be the filename */
 	if (!*argc) {
 		usage();
-		my_end(0);
 		return (true);
 	}
 
 	return (false);
 }
 
+/** Check from page 0 if table is encrypted. */
+static
+bool check_encryption(
+	const char* filename,
+	const page_size_t& page_size,
+	byte * page)
+{
+	os_offset_t	offset = FSP_HEADER_OFFSET +
+		fsp_header_get_encryption_offset(page_size);
+
+	if (memcmp(page + offset, CRYPT_MAGIC, MAGIC_SZ) != 0) {
+		return false;
+	}
+
+	ulint type = mach_read_from_1(page + offset + MAGIC_SZ + 0);
+
+	if (! (type == CRYPT_SCHEME_UNENCRYPTED ||
+	       type == CRYPT_SCHEME_1)) {
+		return false;
+	}
+
+	ulint iv_length = mach_read_from_1(page + offset + MAGIC_SZ + 1);
+
+	if (iv_length != CRYPT_SCHEME_1_IV_LEN) {
+		return false;
+	}
+
+	uint min_key_version = mach_read_from_4
+		(page + offset + MAGIC_SZ + 2 + iv_length);
+
+	uint key_id = mach_read_from_4
+		(page + offset + MAGIC_SZ + 2 + iv_length + 4);
+
+	if (type == CRYPT_SCHEME_1) {
+		if (is_log_enabled) {
+			fprintf(log_file,"Tablespace %s encrypted key_version %u key_id %u\n",
+				filename, min_key_version, key_id);
+		}
+	}
+
+	return (type == CRYPT_SCHEME_1);
+}
+
 int main(
 	int	argc,
 	char	**argv)
@@ -1527,14 +1369,9 @@ int main(
 	char*		filename;
 	/* Buffer to store pages read. */
 	byte*		buf = NULL;
-	/* Buffer for xdes */
 	byte*		xdes = NULL;
 	/* bytes read count */
 	ulong		bytes;
-	/* Buffer to decompress page.*/
-#ifdef MYSQL_COMPRESSION
-	byte*		tbuf = NULL;
-#endif
 	/* current time */
 	time_t		now;
 	/* last time */
@@ -1546,6 +1383,8 @@ int main(
 	struct stat	st;
 #endif /* _WIN32 */
 
+	int exit_status = 0;
+
 	/* size of file (has to be 64 bits) */
 	unsigned long long int	size		= 0;
 	/* number of pages in file */
@@ -1575,32 +1414,37 @@ int main(
 	DBUG_PROCESS(argv[0]);
 
 	if (get_options(&argc,&argv)) {
-		DBUG_RETURN(1);
+		exit_status = 1;
+		goto my_exit;
 	}
 
 	if (strict_verify && no_check) {
 		fprintf(stderr, "Error: --strict-check option cannot be used "
 			"together with --no-check option.\n");
-		DBUG_RETURN(1);
+		exit_status = 1;
+		goto my_exit;
 	}
 
 	if (no_check && !do_write) {
 		fprintf(stderr, "Error: --no-check must be associated with "
 			"--write option.\n");
-		DBUG_RETURN(1);
+		exit_status = 1;
+		goto my_exit;
 	}
 
 	if (page_type_dump) {
 		fil_page_type = create_file(page_dump_filename);
 		if (!fil_page_type) {
-			DBUG_RETURN(1);
+			exit_status = 1;
+			goto my_exit;
 		}
 	}
 
 	if (is_log_enabled) {
 		log_file = create_file(log_filename);
 		if (!log_file) {
-			DBUG_RETURN(1);
+			exit_status = 1;
+			goto my_exit;
 		}
 		fprintf(log_file, "InnoDB File Checksum Utility.\n");
 	}
@@ -1611,10 +1455,8 @@ int main(
 
 
 	buf = (byte*) malloc(UNIV_PAGE_SIZE_MAX * 2);
-	xdes = (byte *) malloc(UNIV_PAGE_SIZE_MAX *2);
-#ifdef MYSQL_COMPRESSION
-	tbuf = buf + UNIV_PAGE_SIZE_MAX;
-#endif
+	xdes = (byte*)malloc(UNIV_PAGE_SIZE_MAX * 2);
+
 	/* The file name is not optional. */
 	for (int i = 0; i < argc; ++i) {
 		/* Reset parameters for each file. */
@@ -1645,7 +1487,8 @@ int main(
 			fprintf(stderr, "Error: %s cannot be found\n",
 				filename);
 
-			goto err_exit;
+			exit_status = 1;
+			goto my_exit;
 		}
 
 		if (!read_from_stdin) {
@@ -1653,35 +1496,17 @@ int main(
 			fil_in = open_file(filename);
 			/*If fil_in is NULL, terminate as some error encountered */
 			if(fil_in == NULL) {
-				goto err_exit;
+				exit_status = 1;
+				goto my_exit;
 			}
 			/* Save the current file pointer in pos variable.*/
 			if (0 != fgetpos(fil_in, &pos)) {
 				perror("fgetpos");
-				goto err_exit;
+				exit_status = 1;
+				goto my_exit;
 			}
 		}
 
-		/* Testing for lock mechanism. The innochecksum
-		acquire lock on given file. So other tools accessing the same
-		file for processsing must fail. */
-#ifdef _WIN32
-		DBUG_EXECUTE_IF("innochecksum_cause_mysqld_crash",
-			ut_ad(page_dump_filename);
-			while((_access( page_dump_filename, 0)) == 0) {
-				sleep(1);
-			}
-			DBUG_RETURN(0); );
-#else
-		DBUG_EXECUTE_IF("innochecksum_cause_mysqld_crash",
-			ut_ad(page_dump_filename);
-			struct stat status_buf;
-			while(stat(page_dump_filename, &status_buf) == 0) {
-				sleep(1);
-			}
-			DBUG_RETURN(0); );
-#endif /* _WIN32 */
-
 		/* Read the minimum page size. */
 		bytes = ulong(fread(buf, 1, UNIV_ZIP_SIZE_MIN, fil_in));
 		partial_page_read = true;
@@ -1692,7 +1517,8 @@ int main(
 			fprintf(stderr, "of %d bytes.  Bytes read was %lu\n",
 				UNIV_ZIP_SIZE_MIN, bytes);
 
-			goto err_exit;
+			exit_status = 1;
+			goto my_exit;
 		}
 
 		/* enable variable is_system_tablespace when space_id of given
@@ -1702,7 +1528,31 @@ int main(
 					FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 4))
 					? true : false;
 
-		const page_size_t&	page_size = get_page_size(buf);
+		/* Determine page size, zip_size and page compression
+		from fsp_flags and encryption metadata from page 0 */
+		ulint flags = fsp_header_get_flags(buf);
+		const page_size_t&	page_size = page_size_t(flags);
+		bool is_compressed = FSP_FLAGS_HAS_PAGE_COMPRESSION(flags);
+		iuniv_page_size.copy_from(page_size);
+
+		if (page_size.physical() > UNIV_ZIP_SIZE_MIN) {
+			/* Read rest of the page 0 to determine crypt_data */
+			bytes = ulong(read_file(buf, partial_page_read, page_size.physical(), fil_in));
+
+			if (bytes != page_size.physical()) {
+				fprintf(stderr, "Error: Was not able to read the "
+					"rest of the page ");
+				fprintf(stderr, "of %lu bytes.  Bytes read was %lu\n",
+					page_size.physical() - UNIV_ZIP_SIZE_MIN, bytes);
+
+				exit_status = 1;
+				goto my_exit;
+			}
+			partial_page_read = false;
+		}
+
+		/* Now that we have full page 0 in buffer, check encryption */
+		bool is_encrypted = check_encryption(filename, page_size, buf);
 
 		pages = (ulint) (size / page_size.physical());
 
@@ -1750,14 +1600,16 @@ int main(
 					perror("Error: Unable to seek to "
 						"necessary offset");
 
-					goto err_exit;
+					exit_status = 1;
+					goto my_exit;
 				}
 				/* Save the current file pointer in
 				pos variable. */
 				if (0 != fgetpos(fil_in, &pos)) {
 					perror("fgetpos");
 
-					goto err_exit;
+					exit_status = 1;
+					goto my_exit;
 				}
 			} else {
 
@@ -1788,7 +1640,8 @@ int main(
 							"to seek to necessary "
 							"offset");
 
-						goto err_exit;
+						exit_status = 1;
+						goto my_exit;
 					}
 				}
 			}
@@ -1827,14 +1680,16 @@ int main(
 					page_size.physical());
 				perror(" ");
 
-				goto err_exit;
+				exit_status = 1;
+				goto my_exit;
 			}
 
 			if (bytes != page_size.physical()) {
 				fprintf(stderr, "Error: bytes read (%lu) "
 					"doesn't match page size (" ULINTPF ")\n",
 					bytes, page_size.physical());
-				goto err_exit;
+				exit_status = 1;
+				goto my_exit;
 			}
 
 			if (is_system_tablespace) {
@@ -1842,22 +1697,6 @@ int main(
 				skip_page = is_page_doublewritebuffer(buf);
 			} else {
 				skip_page = false;
-#ifdef MYSQL_COMPRESSION
-				if (!page_decompress(buf, tbuf, page_size)) {
-
-					fprintf(stderr,
-						"Page decompress failed");
-
-					goto err_exit;
-				}
-#endif
-			}
-
-			ulint page_type = mach_read_from_2(buf + FIL_PAGE_TYPE);
-
-			if (page_type == FIL_PAGE_PAGE_COMPRESSED ||
-			    page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
-				skip_page = true;
 			}
 
 			/* If no-check is enabled, skip the
@@ -1866,7 +1705,7 @@ int main(
 				/* Checksum verification */
 				if (!skip_page) {
 					is_corrupted = is_page_corrupted(
-						buf, page_size);
+						buf, page_size, is_encrypted, is_compressed);
 
 					if (is_corrupted) {
 						fprintf(stderr, "Fail: page "
@@ -1883,19 +1722,24 @@ int main(
 								"count::%" PRIuMAX "\n",
 								allow_mismatches);
 
-							goto err_exit;
+							exit_status = 1;
+							goto my_exit;
 						}
 					}
 				}
 			}
 
-			/* Rewrite checksum */
-			if (do_write
+			/* Rewrite checksum. Note that for encrypted and
+			page compressed tables this is not currently supported. */
+			if (do_write &&
+			    !is_encrypted &&
+			    !is_compressed
 			    && !write_file(filename, fil_in, buf,
-					   page_size.is_compressed(), &pos,
-					   static_cast<ulong>(page_size.physical()))) {
+				    page_size.logical() != 0, &pos,
+				    static_cast<ulong>(page_size.physical()))) {
 
-				goto err_exit;
+				exit_status = 1;
+				goto my_exit;
 			}
 
 			/* end if this was the last page we were supposed to check */
@@ -1903,8 +1747,12 @@ int main(
 				break;
 			}
 
+			if (per_page_details) {
+				printf("page %ld ", cur_page_num);
+			}
+
 			if (page_type_summary || page_type_dump) {
-				parse_page(buf, xdes , fil_page_type, page_size);
+				parse_page(buf, xdes, fil_page_type);
 			}
 
 			/* do counter increase and progress printing */
@@ -1948,30 +1796,10 @@ int main(
 		fclose(log_file);
 	}
 
-	free(buf);
-	free(xdes);
-	my_end(0);
-
-	DBUG_RETURN(0);
-
-err_exit:
+my_exit:
 	if (buf) {
 		free(buf);
 	}
-
-	if (xdes) {
-		free(xdes);
-	}
-
-	if (!read_from_stdin && fil_in) {
-		fclose(fil_in);
-	}
-
-	if (log_file) {
-		fclose(log_file);
-	}
-
-	my_end(1);
-
-	DBUG_RETURN(1);
+	my_end(exit_status);
+	exit(exit_status);
 }
diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc
index a1827e7b3b5..15c88aa723e 100644
--- a/storage/innobase/buf/buf0buf.cc
+++ b/storage/innobase/buf/buf0buf.cc
@@ -620,18 +620,15 @@ buf_page_is_checksum_valid_crc32(
 	const byte*			read_buf,
 	ulint				checksum_field1,
 	ulint				checksum_field2,
-#ifdef UNIV_INNOCHECKSUM
 	uintmax_t			page_no,
 	bool				is_log_enabled,
 	FILE*				log_file,
 	const srv_checksum_algorithm_t	curr_algo,
-#endif /* UNIV_INNOCHECKSUM */
 	bool				use_legacy_big_endian)
 {
 	const uint32_t	crc32 = buf_calc_page_crc32(read_buf,
 						    use_legacy_big_endian);
 
-#ifdef UNIV_INNOCHECKSUM
 	if (is_log_enabled
 	    && curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) {
 		fprintf(log_file, "page::%lu;"
@@ -640,7 +637,6 @@ buf_page_is_checksum_valid_crc32(
 			" checksum field2 =%lu\n", page_no,
 			crc32, checksum_field1, checksum_field2);
 	}
-#endif /* UNIV_INNOCHECKSUM */
 
 	if (checksum_field1 != checksum_field2) {
 		goto invalid;
@@ -668,6 +664,7 @@ buf_page_is_checksum_valid_crc32(
 @param[in]	read_buf	database page
 @param[in]	checksum_field1	new checksum field
 @param[in]	checksum_field2	old checksum field
+ at param[in]
 @param[in]	page_no		page number of given read_buf
 @param[in]	is_log_enabled	true if log option is enabled
 @param[in]	log_file	file pointer to log_file
@@ -678,14 +675,11 @@ bool
 buf_page_is_checksum_valid_innodb(
 	const byte*			read_buf,
 	ulint				checksum_field1,
-	ulint				checksum_field2
-#ifdef UNIV_INNOCHECKSUM
-	,uintmax_t			page_no,
+	ulint				checksum_field2,
+	uintmax_t			page_no,
 	bool				is_log_enabled,
 	FILE*				log_file,
-	const srv_checksum_algorithm_t	curr_algo
-#endif /* UNIV_INNOCHECKSUM */
-	)
+	const srv_checksum_algorithm_t	curr_algo)
 {
 	/* There are 2 valid formulas for
 	checksum_field2 (old checksum field) which algo=innodb could have
@@ -700,7 +694,7 @@ buf_page_is_checksum_valid_innodb(
 	ulint	old_checksum = buf_calc_page_old_checksum(read_buf);
 	ulint	new_checksum = buf_calc_page_new_checksum(read_buf);
 
-#ifdef UNIV_INNOCHECKSUM
+
 	if (is_log_enabled
 	    && curr_algo == SRV_CHECKSUM_ALGORITHM_INNODB) {
 		fprintf(log_file, "page::%lu;"
@@ -728,7 +722,6 @@ buf_page_is_checksum_valid_innodb(
 			page_no, new_checksum,
 			checksum_field1);
 	}
-#endif /* UNIV_INNOCHECKSUM */
 
 	if (checksum_field2 != mach_read_from_4(read_buf + FIL_PAGE_LSN)
 	    && checksum_field2 != old_checksum) {
@@ -775,14 +768,11 @@ bool
 buf_page_is_checksum_valid_none(
 	const byte*			read_buf,
 	ulint				checksum_field1,
-	ulint				checksum_field2
-#ifdef	UNIV_INNOCHECKSUM
-	,uintmax_t			page_no,
+	ulint				checksum_field2,
+	uintmax_t			page_no,
 	bool				is_log_enabled,
 	FILE*				log_file,
-	const srv_checksum_algorithm_t	curr_algo
-#endif	/* UNIV_INNOCHECKSUM */
-	)
+	const srv_checksum_algorithm_t	curr_algo)
 {
 #ifndef DBUG_OFF
 	if (checksum_field1 != checksum_field2
@@ -797,7 +787,6 @@ buf_page_is_checksum_valid_none(
 	}
 #endif
 
-#ifdef UNIV_INNOCHECKSUM
 	if (is_log_enabled
 	    && curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_NONE) {
 		fprintf(log_file,
@@ -807,8 +796,6 @@ buf_page_is_checksum_valid_none(
 			page_no, BUF_NO_CHECKSUM_MAGIC,
 			checksum_field1, checksum_field2);
 	}
-#endif /* UNIV_INNOCHECKSUM */
-
 
 	return(checksum_field1 == checksum_field2
 	       && checksum_field1 == BUF_NO_CHECKSUM_MAGIC);
@@ -820,33 +807,32 @@ the LSN
 @param[in]	read_buf	database page
 @param[in]	page_size	page size
 @param[in]	skip_checksum	if true, skip checksum
+ at param[in]	innochecksum	true if called from innochecksum tool
 @param[in]	page_no		page number of given read_buf
 @param[in]	strict_check	true if strict-check option is enabled
 @param[in]	is_log_enabled	true if log option is enabled
 @param[in]	log_file	file pointer to log_file
- at return TRUE if corrupted */
-ibool
+ at return true if corrupted */
+bool
 buf_page_is_corrupted(
 	bool			check_lsn,
 	const byte*		read_buf,
 	const page_size_t&	page_size,
-	bool			skip_checksum
-#ifdef UNIV_INNOCHECKSUM
-	,uintmax_t		page_no,
+	bool			skip_checksum,
+	/* Following parameters are used in innochecksum or similar tool */
+	bool			innochecksum,
+	uintmax_t		page_no,
 	bool			strict_check,
 	bool			is_log_enabled,
-	FILE*			log_file
-#endif /* UNIV_INNOCHECKSUM */
-)
+	FILE*			log_file)
 {
 	ulint		checksum_field1;
 	ulint		checksum_field2;
 	bool		no_checksum = false;
 
-#ifndef UNIV_INNOCHECKSUM
 	ulint 		space_id = mach_read_from_4(
 		read_buf + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
-	ulint page_type = mach_read_from_4(
+	ulint page_type = mach_read_from_2(
 		read_buf + FIL_PAGE_TYPE);
 	no_checksum = (page_type == FIL_PAGE_PAGE_COMPRESSED ||
 		page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED);
@@ -863,15 +849,9 @@ buf_page_is_corrupted(
 
 	/* Return early if there is no checksum or END_LSN */
 	if (no_checksum) {
-		return (FALSE);
-	}
-#else
-	if (mach_read_from_4(read_buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION) != 0
-	    || mach_read_from_2(read_buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
-		no_checksum= true;
+		return (false);
 	}
 
-#endif
 	DBUG_EXECUTE_IF("buf_page_import_corrupt_failure", return(TRUE); );
 
 	if (!no_checksum && !page_size.is_compressed()
@@ -882,18 +862,17 @@ buf_page_is_corrupted(
 		/* Stored log sequence numbers at the start and the end
 		of page do not match */
 
-#ifndef UNIV_INNOCHECKSUM
-		ib::info() << "Log sequence number at the start "
+		if (!innochecksum) {
+			ib::info() << "Log sequence number at the start "
 			   << mach_read_from_4(read_buf + FIL_PAGE_LSN + 4)
 			   << " and the end "
 			   << mach_read_from_4(read_buf + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM + 4)
 			   << " do not match";
-#endif
-		return(TRUE);
+		}
+		return(true);
 	}
 
-#ifndef UNIV_INNOCHECKSUM
-	if (check_lsn && recv_lsn_checks_on) {
+	if (check_lsn && recv_lsn_checks_on && !innochecksum) {
 		lsn_t		current_lsn;
 		const lsn_t	page_lsn
 			= mach_read_from_8(read_buf + FIL_PAGE_LSN);
@@ -922,25 +901,21 @@ buf_page_is_corrupted(
 
 		}
 	}
-#endif /* !UNIV_INNOCHECKSUM */
 
 	/* Check whether the checksum fields have correct values */
 
 	if (srv_checksum_algorithm == SRV_CHECKSUM_ALGORITHM_NONE
 	    || skip_checksum) {
-		return(FALSE);
+		return(false);
 	}
 
 	if (page_size.is_compressed()) {
-#ifdef UNIV_INNOCHECKSUM
 		return(!page_zip_verify_checksum(read_buf,
 						 page_size.physical(),
-						 page_no, strict_check,
+						 innochecksum,
+						 page_no,
+						 strict_check,
 						 is_log_enabled, log_file));
-#else
-		return(!page_zip_verify_checksum(read_buf,
-						 page_size.physical()));
-#endif /* UNIV_INNOCHECKSUM */
 	}
 
 	checksum_field1 = mach_read_from_4(
@@ -973,33 +948,29 @@ buf_page_is_corrupted(
 			     || i >= FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID)
 			    && read_buf[i] != 0) {
 
-#ifndef UNIV_INNOCHECKSUM
-				ib::info() << "Checksum fields zero but page is not empty.";
-#endif
+				if (!innochecksum) {
+					ib::info() << "Checksum fields zero "
+						   << "but page is not empty.";
+				}
 
 				break;
 			}
 		}
-#ifdef UNIV_INNOCHECKSUM
-		if (i >= page_size.logical()) {
-			if (is_log_enabled) {
-				fprintf(log_file, "Page::%lu"
-					" is empty and uncorrupted\n",
-					page_no);
-			}
-			return(FALSE);
+
+		if (i >= page_size.logical() && is_log_enabled) {
+			fprintf(log_file, "Page::%lu"
+				" is empty and uncorrupted\n",
+				page_no);
 		}
-#else
+
 		return(i < page_size.logical());
-#endif /* UNIV_INNOCHECKSUM */
 	}
 
-#ifndef UNIV_INNOCHECKSUM
+
 	const page_id_t	page_id(mach_read_from_4(
 					read_buf + FIL_PAGE_SPACE_ID),
 				mach_read_from_4(
 					read_buf + FIL_PAGE_OFFSET));
-#endif /* UNIV_INNOCHECKSUM */
 
 	const srv_checksum_algorithm_t	curr_algo =
 		static_cast<srv_checksum_algorithm_t>(srv_checksum_algorithm);
@@ -1012,29 +983,23 @@ buf_page_is_corrupted(
 
 		if (buf_page_is_checksum_valid_crc32(read_buf,
 			checksum_field1, checksum_field2,
-#ifdef UNIV_INNOCHECKSUM
 			page_no, is_log_enabled, log_file, curr_algo,
-#endif /* UNIV_INNOCHECKSUM */
 			false)) {
 			return(FALSE);
 		}
 
 		if (buf_page_is_checksum_valid_none(read_buf,
-			checksum_field1, checksum_field2
-#ifdef UNIV_INNOCHECKSUM
-			, page_no, is_log_enabled, log_file, curr_algo)) {
-#else /* UNIV_INNOCHECKSUM */
-		)) {
-			if (curr_algo
+			checksum_field1, checksum_field2,
+			page_no, is_log_enabled, log_file, curr_algo)) {
+
+			if (!innochecksum && curr_algo
 			    == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) {
 				page_warn_strict_checksum(
 					curr_algo,
 					SRV_CHECKSUM_ALGORITHM_NONE,
 					page_id);
 			}
-#endif /* UNIV_INNOCHECKSUM */
 
-#ifdef UNIV_INNOCHECKSUM
 			if (is_log_enabled) {
 
 				fprintf(log_file, "page::%lu;"
@@ -1050,8 +1015,8 @@ buf_page_is_corrupted(
 					buf_calc_page_crc32(read_buf),
 					checksum_field1);
 			}
-#endif /* UNIV_INNOCHECKSUM */
-			return(FALSE);
+
+			return(false);
 		}
 
 		/* We need to check whether the stored checksum matches legacy
@@ -1062,82 +1027,69 @@ buf_page_is_corrupted(
 		if (legacy_big_endian_checksum) {
 			if (buf_page_is_checksum_valid_crc32(read_buf,
 				checksum_field1, checksum_field2,
-#ifdef UNIV_INNOCHECKSUM
 				page_no, is_log_enabled, log_file, curr_algo,
-#endif /* UNIV_INNOCHECKSUM */
 				true)) {
 
-				return(FALSE);
+				return(false);
 			}
 			legacy_checksum_checked = true;
 		}
 
 		if (buf_page_is_checksum_valid_innodb(read_buf,
-			checksum_field1, checksum_field2
-#ifdef UNIV_INNOCHECKSUM
-			, page_no, is_log_enabled, log_file, curr_algo)) {
-#else /* UNIV_INNOCHECKSUM */
-		)) {
-			if (curr_algo
+				checksum_field1, checksum_field2,
+				page_no, is_log_enabled, log_file, curr_algo)) {
+
+			if (!innochecksum && curr_algo
 			    == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) {
 				page_warn_strict_checksum(
 					curr_algo,
 					SRV_CHECKSUM_ALGORITHM_INNODB,
 					page_id);
 			}
-#endif /* UNIV_INNOCHECKSUM */
-			return(FALSE);
+
+			return(false);
 		}
 
 		/* If legacy checksum is not checked, do it now. */
 		if (!legacy_checksum_checked && buf_page_is_checksum_valid_crc32(
 			read_buf, checksum_field1, checksum_field2,
-#ifdef UNIV_INNOCHECKSUM
 			page_no, is_log_enabled, log_file, curr_algo,
-#endif /* UNIV_INNOCHECKSUM */
 			true)) {
 
 				legacy_big_endian_checksum = true;
-				return(FALSE);
+				return(false);
 		}
 
-#ifdef UNIV_INNOCHECKSUM
 		if (is_log_enabled) {
 			fprintf(log_file, "Fail; page %lu"
 				" invalid (fails crc32 checksum)\n",
 				page_no);
 		}
-#endif /* UNIV_INNOCHECKSUM */
-		return(TRUE);
+
+		return(true);
 
 	case SRV_CHECKSUM_ALGORITHM_INNODB:
 	case SRV_CHECKSUM_ALGORITHM_STRICT_INNODB:
 
 		if (buf_page_is_checksum_valid_innodb(read_buf,
-			checksum_field1, checksum_field2
-#ifdef UNIV_INNOCHECKSUM
-			, page_no, is_log_enabled, log_file, curr_algo
-#endif /* UNIV_INNOCHECKSUM */
+			checksum_field1, checksum_field2,
+			page_no, is_log_enabled, log_file, curr_algo
 		)) {
-			return(FALSE);
+			return(false);
 		}
 
 		if (buf_page_is_checksum_valid_none(read_buf,
-			checksum_field1, checksum_field2
-#ifdef UNIV_INNOCHECKSUM
-			, page_no, is_log_enabled, log_file, curr_algo)) {
-#else	/* UNIV_INNOCHECKSUM */
-		)) {
-			if (curr_algo
+				checksum_field1, checksum_field2,
+				page_no, is_log_enabled, log_file, curr_algo)) {
+
+			if (!innochecksum && curr_algo
 			    == SRV_CHECKSUM_ALGORITHM_STRICT_INNODB) {
 				page_warn_strict_checksum(
 					curr_algo,
 					SRV_CHECKSUM_ALGORITHM_NONE,
 					page_id);
 			}
-#endif /* UNIV_INNOCHECKSUM */
 
-#ifdef UNIV_INNOCHECKSUM
 			if (is_log_enabled) {
 				fprintf(log_file, "page::%lu;"
 					" old style: calculated = %lu;"
@@ -1152,98 +1104,84 @@ buf_page_is_corrupted(
 					buf_calc_page_crc32(read_buf),
 					checksum_field1);
 			}
-#endif /* UNIV_INNOCHECKSUM */
-			return(FALSE);
+
+			return(false);
 		}
 
-#ifdef UNIV_INNOCHECKSUM
-		if (buf_page_is_checksum_valid_crc32(read_buf,
-			checksum_field1, checksum_field2,
-			page_no, is_log_enabled, log_file, curr_algo, false)
-		    || buf_page_is_checksum_valid_crc32(read_buf,
-			checksum_field1, checksum_field2,
-			page_no, is_log_enabled, log_file, curr_algo, true)) {
-#else /* UNIV_INNOCHECKSUM */
+
 		if (buf_page_is_checksum_valid_crc32(read_buf,
-			checksum_field1, checksum_field2, false)
+				checksum_field1, checksum_field2,
+				page_no, is_log_enabled, log_file, curr_algo, false)
 		    || buf_page_is_checksum_valid_crc32(read_buf,
-			checksum_field1, checksum_field2, true)) {
+			    checksum_field1, checksum_field2,
+			    page_no, is_log_enabled, log_file, curr_algo, true)) {
 
-			if (curr_algo
+			if (!innochecksum && curr_algo
 			    == SRV_CHECKSUM_ALGORITHM_STRICT_INNODB) {
 				page_warn_strict_checksum(
 					curr_algo,
 					SRV_CHECKSUM_ALGORITHM_CRC32,
 					page_id);
 			}
-#endif /* UNIV_INNOCHECKSUM */
 
-			return(FALSE);
+			return(false);
 		}
 
-#ifdef UNIV_INNOCHECKSUM
 		if (is_log_enabled) {
 			fprintf(log_file, "Fail; page %lu"
 				" invalid (fails innodb checksum)\n",
 				page_no);
 		}
-#endif /* UNIV_INNOCHECKSUM */
-		return(TRUE);
+
+		return(true);
 
 	case SRV_CHECKSUM_ALGORITHM_STRICT_NONE:
 
 		if (buf_page_is_checksum_valid_none(read_buf,
-			checksum_field1, checksum_field2
-#ifdef UNIV_INNOCHECKSUM
-			, page_no, is_log_enabled, log_file, curr_algo
-#endif /* UNIV_INNOCHECKSUM */
+				checksum_field1, checksum_field2,
+				page_no, is_log_enabled, log_file, curr_algo
 		)) {
 			return(false);
 		}
 
-#ifdef UNIV_INNOCHECKSUM
 		if (buf_page_is_checksum_valid_crc32(read_buf,
 			checksum_field1, checksum_field2,
 			page_no, is_log_enabled, log_file, curr_algo, false)
 		    || buf_page_is_checksum_valid_crc32(read_buf,
-			checksum_field1, checksum_field2,
-			page_no, is_log_enabled, log_file, curr_algo, true)) {
-#else /* UNIV_INNOCHECKSUM */
-		if (buf_page_is_checksum_valid_crc32(read_buf,
-			checksum_field1, checksum_field2, false)
-		    || buf_page_is_checksum_valid_crc32(read_buf,
-			checksum_field1, checksum_field2, true)) {
+			    checksum_field1, checksum_field2,
+			    page_no, is_log_enabled, log_file, curr_algo, true)) {
 
-			page_warn_strict_checksum(
-				curr_algo,
-				SRV_CHECKSUM_ALGORITHM_CRC32,
-				page_id);
-#endif /* UNIV_INNOCHECKSUM */
-			return(FALSE);
+			if (!innochecksum) {
+				page_warn_strict_checksum(
+					curr_algo,
+					SRV_CHECKSUM_ALGORITHM_CRC32,
+					page_id);
+			}
+
+			return(false);
 		}
 
 		if (buf_page_is_checksum_valid_innodb(read_buf,
-			checksum_field1, checksum_field2
-#ifdef UNIV_INNOCHECKSUM
-			, page_no, is_log_enabled, log_file, curr_algo)) {
-#else /* UNIV_INNOCHECKSUM */
-		)) {
-			page_warn_strict_checksum(
-				curr_algo,
-				SRV_CHECKSUM_ALGORITHM_INNODB,
-				page_id);
-#endif /* UNIV_INNOCHECKSUM */
-			return(FALSE);
+				checksum_field1, checksum_field2,
+				page_no, is_log_enabled, log_file, curr_algo)) {
+
+			if (!innochecksum) {
+				page_warn_strict_checksum(
+					curr_algo,
+					SRV_CHECKSUM_ALGORITHM_INNODB,
+					page_id);
+			}
+
+			return(false);
 		}
 
-#ifdef UNIV_INNOCHECKSUM
 		if (is_log_enabled) {
 			fprintf(log_file, "Fail; page %lu"
 				" invalid (fails none checksum)\n",
 				page_no);
 		}
-#endif /* UNIV_INNOCHECKSUM */
-		return(TRUE);
+
+		return(true);
 
 	case SRV_CHECKSUM_ALGORITHM_NONE:
 		/* should have returned FALSE earlier */
@@ -1253,7 +1191,7 @@ buf_page_is_corrupted(
 	}
 
 	ut_error;
-	return(FALSE);
+	return(false);
 }
 
 #ifndef UNIV_INNOCHECKSUM
diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h
index ea0dd48cdbd..b12fb996284 100644
--- a/storage/innobase/include/buf0buf.h
+++ b/storage/innobase/include/buf0buf.h
@@ -791,19 +791,20 @@ the LSN
 @param[in]	is_log_enabled	true if log option is enabled
 @param[in]	log_file	file pointer to log_file
 @return TRUE if corrupted */
-ibool
+bool
 buf_page_is_corrupted(
 	bool			check_lsn,
 	const byte*		read_buf,
 	const page_size_t&	page_size,
-	bool			skip_checksum
-#ifdef UNIV_INNOCHECKSUM
-	,uintmax_t		page_no,
-	bool			strict_check,
-	bool			is_log_enabled,
-	FILE*			log_file
-#endif /* UNIV_INNOCHECKSUM */
-) MY_ATTRIBUTE((warn_unused_result));
+	bool			skip_checksum,
+	/* Following parameters are used in innochecksum or similar tool */
+	bool			innochecksum = false,
+	uintmax_t		page_no = 0,
+	bool			strict_check = false,
+	bool			is_log_enabled = false,
+	FILE*			log_file = NULL)
+	MY_ATTRIBUTE((warn_unused_result));
+
 #ifndef UNIV_INNOCHECKSUM
 /**********************************************************************//**
 Gets the space id, page offset, and byte offset within page of a
diff --git a/storage/innobase/include/page0zip.h b/storage/innobase/include/page0zip.h
index f4da2b55385..58303b858bb 100644
--- a/storage/innobase/include/page0zip.h
+++ b/storage/innobase/include/page0zip.h
@@ -506,25 +506,25 @@ page_zip_calc_checksum(
 
 /**********************************************************************//**
 Verify a compressed page's checksum.
+ at param[in]	data		compressed page
+ at param[in]	size		size of compressed page
+ at param[in]	innochecksum	true if innochecksum or similar tool
+ at param[in]	cur_page_no	current read page number
+ at param[in]	strict_check	true if strict check is enabled
+ at param[in]	is_log_enabled	true if log output should be produced
+ at param[in]	log_file	log file
 @return TRUE if the stored checksum is valid according to the value of
 innodb_checksum_algorithm */
-ibool
+bool
 page_zip_verify_checksum(
-/*=====================*/
-	const void*	data,	/*!< in: compressed page */
-	ulint		size	/*!< in: size of compressed page */
-#ifdef UNIV_INNOCHECKSUM
-	/* these variables are used only for innochecksum tool. */
-	,uintmax_t	page_no,	/*!< in: page number of
-					given read_buf */
-	bool		strict_check,	/*!< in: true if strict-check
-					option is enable */
-	bool		is_log_enabled, /*!< in: true if log option is
-					enable */
-	FILE*		log_file	/*!< in: file pointer to
-					log_file */
-#endif /* UNIV_INNOCHECKSUM */
-);
+	const void*	data,
+	ulint		size,
+	/* these variables are used only for innochecksum or similar tool. */
+	bool		innochecksum = false,
+	uintmax_t	cur_page_no = 0,
+	bool		strict_check = false,
+	bool		is_log_enabled = false,
+	FILE*		log_file = NULL);
 
 #ifndef UNIV_INNOCHECKSUM
 /**********************************************************************//**
diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc
index c0746bd9d5f..b52b6706290 100644
--- a/storage/innobase/page/page0zip.cc
+++ b/storage/innobase/page/page0zip.cc
@@ -4970,25 +4970,25 @@ page_zip_calc_checksum(
 
 /**********************************************************************//**
 Verify a compressed page's checksum.
+ at param[in]	data		compressed page
+ at param[in]	size		size of compressed page
+ at param[in]	innochecksum	true if innochecksum or similar tool
+ at param[in]	cur_page_no	current read page number
+ at param[in]	strict_check	true if strict check is enabled
+ at param[in]	is_log_enabled	true if log output should be produced
+ at param[in]	log_file	log file
 @return TRUE if the stored checksum is valid according to the value of
 innodb_checksum_algorithm */
-ibool
+bool
 page_zip_verify_checksum(
-/*=====================*/
-	const void*	data,		/*!< in: compressed page */
-	ulint		size		/*!< in: size of compressed page */
-#ifdef UNIV_INNOCHECKSUM
-	/* these variables are used only for innochecksum tool. */
-	,uintmax_t	page_no,	/*!< in: page number of
-					given read_buf */
-	bool		strict_check,	/*!< in: true if strict-check
-					option is enable */
-	bool		is_log_enabled,	/*!< in: true if log option is
-					enabled */
-	FILE*		log_file	/*!< in: file pointer to
-					log_file */
-#endif /* UNIV_INNOCHECKSUM */
-)
+	const void*	data,
+	ulint		size,
+	/* these variables are used only for innochecksum or similar tool. */
+	bool		innochecksum,
+	uintmax_t	cur_page_no,
+	bool		strict_check,
+	bool		is_log_enabled,
+	FILE*		log_file)
 {
 	const unsigned char*	p = static_cast<const unsigned char*>(data)
 		+ FIL_PAGE_SPACE_OR_CHKSUM;
@@ -4996,19 +4996,6 @@ page_zip_verify_checksum(
 	const uint32_t		stored = static_cast<uint32_t>(
 		mach_read_from_4(p));
 
-#ifdef UNIV_INNOCHECKSUM
-	p = static_cast<const unsigned char*>(data) + FIL_PAGE_TYPE;
-	bool no_checksum = (mach_read_from_2(p) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED);
-	p = static_cast<const unsigned char*>(data) + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION;
-	bool encrypted = (mach_read_from_4(p) != 0);
-	p = static_cast<const unsigned char*>(data) + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION + 4;
-	const uint32_t checksum = static_cast<uint32_t>(mach_read_from_4(p));
-
-	if (no_checksum) {
-		return (TRUE);
-	}
-#endif
-
 #if FIL_PAGE_LSN % 8
 #error "FIL_PAGE_LSN must be 64 bit aligned"
 #endif
@@ -5019,39 +5006,27 @@ page_zip_verify_checksum(
 		data)
 		+ FIL_PAGE_LSN) == 0) {
 		/* make sure that the page is really empty */
-#ifdef UNIV_INNOCHECKSUM
+
 		ulint i;
 		for (i = 0; i < size; i++) {
 			if (*((const char*) data + i) != 0)
 				break;
 		}
-		if (i >= size) {
-			if (is_log_enabled) {
-				fprintf(log_file, "Page::%lu is empty and"
-					" uncorrupted\n", page_no);
-			}
-
-			return(TRUE);
-		}
-#else
-		for (ulint i = 0; i < size; i++) {
-			if (*((const char*) data + i) != 0) {
-				return(FALSE);
-			}
+		if (i >= size && is_log_enabled) {
+			fprintf(log_file, "Page::%lu is empty and"
+				" uncorrupted\n", cur_page_no);
 		}
-		/* Empty page */
-		return(TRUE);
-#endif /* UNIV_INNOCHECKSUM */
+
+		return(i >= size);
 	}
 
 	const srv_checksum_algorithm_t	curr_algo =
 		static_cast<srv_checksum_algorithm_t>(srv_checksum_algorithm);
 
 	if (curr_algo == SRV_CHECKSUM_ALGORITHM_NONE) {
-		return(TRUE);
+		return(true);
 	}
 
-#ifndef	UNIV_INNOCHECKSUM
 	ulint		page_no = mach_read_from_4(static_cast<
 						   const unsigned char*>
 						   (data) + FIL_PAGE_OFFSET);
@@ -5059,15 +5034,13 @@ page_zip_verify_checksum(
 						    const unsigned char*>
 						    (data) + FIL_PAGE_SPACE_ID);
 	const page_id_t	page_id(space_id, page_no);
-#endif	/* UNIV_INNOCHECKSUM */
 
 	const uint32_t	calc = page_zip_calc_checksum(data, size, curr_algo);
 
-#ifdef UNIV_INNOCHECKSUM
 	if (is_log_enabled) {
 		fprintf(log_file, "page::%lu;"
 			" %s checksum: calculated = %u;"
-			" recorded = %u\n", page_no,
+			" recorded = %u\n", cur_page_no,
 			buf_checksum_algorithm_name(
 				static_cast<srv_checksum_algorithm_t>(
 				srv_checksum_algorithm)),
@@ -5082,20 +5055,15 @@ page_zip_verify_checksum(
 		if (is_log_enabled) {
 			fprintf(log_file, "page::%lu: crc32 checksum:"
 				" calculated = %u; recorded = %u\n",
-				page_no, crc32, stored);
+				cur_page_no, crc32, stored);
 			fprintf(log_file, "page::%lu: none checksum:"
 				" calculated = %lu; recorded = %u\n",
-				page_no, BUF_NO_CHECKSUM_MAGIC, stored);
+				cur_page_no, BUF_NO_CHECKSUM_MAGIC, stored);
 		}
 	}
-#endif /* UNIV_INNOCHECKSUM */
 
-	if (stored == calc
-#ifdef UNIV_INNOCHECKSUM
-	    || ( encrypted == true && stored == checksum)
-#endif
-	) {
-		return(TRUE);
+	if (stored == calc) {
+		return(true);
 	}
 
 	bool	legacy_checksum_checked = false;
@@ -5105,17 +5073,15 @@ page_zip_verify_checksum(
 	case SRV_CHECKSUM_ALGORITHM_CRC32: {
 
 		if (stored == BUF_NO_CHECKSUM_MAGIC) {
-#ifndef	UNIV_INNOCHECKSUM
-			if (curr_algo
+			if (!innochecksum && curr_algo
 			    == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) {
 				page_warn_strict_checksum(
 					curr_algo,
 					SRV_CHECKSUM_ALGORITHM_NONE,
 					page_id);
 			}
-#endif	/* UNIV_INNOCHECKSUM */
 
-			return(TRUE);
+			return(true);
 		}
 
 		/* We need to check whether the stored checksum matches legacy
@@ -5126,13 +5092,8 @@ page_zip_verify_checksum(
 		if (legacy_big_endian_checksum) {
 			const uint32_t calculated =
 				page_zip_calc_checksum(data, size, curr_algo, true);
-			if (stored == calculated
-#ifdef UNIV_INNOCHECKSUM
-			    || ( encrypted == true && calculated == checksum)
-#endif
-			) {
-
-				return(TRUE);
+			if (stored == calculated) {
+				return(true);
 			}
 			legacy_checksum_checked = true;
 		}
@@ -5140,23 +5101,17 @@ page_zip_verify_checksum(
 		uint32_t calculated =
 				page_zip_calc_checksum(data, size, SRV_CHECKSUM_ALGORITHM_INNODB);
 
-		if (stored == calculated
-#ifdef UNIV_INNOCHECKSUM
-		    || ( encrypted == true && stored == checksum)
-#endif
-		) {
+		if (stored == calculated) {
 
-#ifndef	UNIV_INNOCHECKSUM
-			if (curr_algo
+			if (!innochecksum && curr_algo
 			    == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) {
 				page_warn_strict_checksum(
 					curr_algo,
 					SRV_CHECKSUM_ALGORITHM_INNODB,
 					page_id);
 			}
-#endif	/* UNIV_INNOCHECKSUM */
 
-			return(TRUE);
+			return(true);
 		}
 
 		calculated = page_zip_calc_checksum(
@@ -5164,13 +5119,9 @@ page_zip_verify_checksum(
 
 		/* If legacy checksum is not checked, do it now. */
 		if ((legacy_checksum_checked
-		     && stored == calculated)
-#ifdef UNIV_INNOCHECKSUM
-		    || ( encrypted == true && calculated == checksum)
-#endif
-		) {
+		     && stored == calculated)) {
 			legacy_big_endian_checksum = true;
-			return(TRUE);
+			return(true);
 		}
 
 		break;
@@ -5178,22 +5129,16 @@ page_zip_verify_checksum(
 	case SRV_CHECKSUM_ALGORITHM_STRICT_INNODB:
 	case SRV_CHECKSUM_ALGORITHM_INNODB: {
 
-		if (stored == BUF_NO_CHECKSUM_MAGIC
-#ifdef UNIV_INNOCHECKSUM
-		    || ( encrypted == true && checksum == BUF_NO_CHECKSUM_MAGIC)
-#endif
-		) {
-#ifndef	UNIV_INNOCHECKSUM
-			if (curr_algo
+		if (stored == BUF_NO_CHECKSUM_MAGIC) {
+			if (!innochecksum && curr_algo
 			    == SRV_CHECKSUM_ALGORITHM_STRICT_INNODB) {
 				page_warn_strict_checksum(
 					curr_algo,
 					SRV_CHECKSUM_ALGORITHM_NONE,
 					page_id);
 			}
-#endif	/* UNIV_INNOCHECKSUM */
 
-			return(TRUE);
+			return(true);
 		}
 
 		const uint32_t calculated = page_zip_calc_checksum(
@@ -5201,25 +5146,17 @@ page_zip_verify_checksum(
 		uint32_t calculated1;
 
 		if (stored == calculated
-#ifdef UNIV_INNOCHECKSUM
-		    || ( encrypted == true && checksum == calculated)
-#endif
-		    || stored == (calculated1 = 
+		    || stored == (calculated1 =
 					page_zip_calc_checksum(data, size, SRV_CHECKSUM_ALGORITHM_CRC32, true))
-#ifdef UNIV_INNOCHECKSUM
-		    || ( encrypted == true && checksum == calculated1)
-#endif
 		) {
-#ifndef	UNIV_INNOCHECKSUM
-			if (curr_algo
+			if (!innochecksum && curr_algo
 			    == SRV_CHECKSUM_ALGORITHM_STRICT_INNODB) {
 				page_warn_strict_checksum(
 					curr_algo,
 					SRV_CHECKSUM_ALGORITHM_CRC32,
 					page_id);
 			}
-#endif	/* UNIV_INNOCHECKSUM */
-			return(TRUE);
+			return(true);
 		}
 
 		break;
@@ -5232,37 +5169,28 @@ page_zip_verify_checksum(
 			data, size, SRV_CHECKSUM_ALGORITHM_CRC32, true);
 
 		if (stored == calculated
-		    || stored == calculated1
-#ifdef UNIV_INNOCHECKSUM
-		    || ( encrypted == true && checksum == calculated)
-		    || ( encrypted == true && checksum == calculated1)
-#endif
-		) {
-#ifndef	UNIV_INNOCHECKSUM
-			page_warn_strict_checksum(
-				curr_algo,
-				SRV_CHECKSUM_ALGORITHM_CRC32,
-				page_id);
-#endif	/* UNIV_INNOCHECKSUM */
-			return(TRUE);
+		    || stored == calculated1) {
+			if (!innochecksum) {
+				page_warn_strict_checksum(
+					curr_algo,
+					SRV_CHECKSUM_ALGORITHM_CRC32,
+					page_id);
+			}
+			return(true);
 		}
 
 		calculated = page_zip_calc_checksum(
 			data, size, SRV_CHECKSUM_ALGORITHM_INNODB);
 
-		if (stored == calculated
-#ifdef UNIV_INNOCHECKSUM
-		    || ( encrypted == true && checksum == calculated)
-#endif
-		) {
+		if (stored == calculated) {
 
-#ifndef	UNIV_INNOCHECKSUM
-			page_warn_strict_checksum(
-				curr_algo,
-				SRV_CHECKSUM_ALGORITHM_INNODB,
-				page_id);
-#endif	/* UNIV_INNOCHECKSUM */
-			return(TRUE);
+			if (!innochecksum) {
+				page_warn_strict_checksum(
+					curr_algo,
+					SRV_CHECKSUM_ALGORITHM_INNODB,
+					page_id);
+				return(true);
+			}
 		}
 
 		break;
@@ -5273,5 +5201,5 @@ page_zip_verify_checksum(
 	is added and not handled here */
 	}
 
-	return(FALSE);
+	return(false);
 }
diff --git a/storage/xtradb/buf/buf0buf.cc b/storage/xtradb/buf/buf0buf.cc
index 6d5776dc726..b069cbaf8ce 100644
--- a/storage/xtradb/buf/buf0buf.cc
+++ b/storage/xtradb/buf/buf0buf.cc
@@ -707,7 +707,7 @@ buf_page_is_corrupted(
 	ulint		checksum_field2;
 	ulint 		space_id = mach_read_from_4(
 		read_buf + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
-	ulint page_type = mach_read_from_4(
+	ulint page_type = mach_read_from_2(
 		read_buf + FIL_PAGE_TYPE);
 	bool no_checksum = (page_type == FIL_PAGE_PAGE_COMPRESSED ||
 		page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED);


More information about the commits mailing list