/* Copyright (C) 2000-2005 MySQL AB & Innobase Oy 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* InnoDB offline file checksum utility. 85% of the code in this file was taken wholesale fron the InnoDB codebase. The final 15% was originally written by Mark Smith of Danga Interactive, Inc. Published with a permission. */ /* needed to have access to 64 bit file functions */ #ifndef _LARGEFILE_SOURCE #define _LARGEFILE_SOURCE #endif #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE #endif #ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 500 /* needed to include getopt.h on some platforms. */ #endif #include #include #include #include #include #include #include #include /* all of these ripped from InnoDB code from MySQL 4.0.22 */ #define UT_HASH_RANDOM_MASK 1463735687 #define UT_HASH_RANDOM_MASK2 1653893711 #define FIL_PAGE_LSN 16 #define FIL_PAGE_FILE_FLUSH_LSN 26 #define FIL_PAGE_OFFSET 4 #define FIL_PAGE_DATA 38 #define FIL_PAGE_END_LSN_OLD_CHKSUM 8 #define FIL_PAGE_SPACE_OR_CHKSUM 0 #ifndef univ_i #define UNIV_PAGE_SIZE 16384 #endif /* command line argument to do page checks (that's it) */ /* another argument to specify page ranges... seek to right spot and go from there */ #ifndef univ_i typedef unsigned long int ulint; typedef unsigned char uchar; #endif /* innodb function in name; modified slightly to not have the ASM version (lots of #ifs that didn't apply) */ #ifndef univ_i ulint mach_read_from_4(uchar *b) { return( ((ulint)(b[0]) << 24) + ((ulint)(b[1]) << 16) + ((ulint)(b[2]) << 8) + (ulint)(b[3]) ); } ulint ut_fold_ulint_pair( /*===============*/ /* out: folded value */ ulint n1, /* in: ulint */ ulint n2) /* in: ulint */ { return(((((n1 ^ n2 ^ UT_HASH_RANDOM_MASK2) << 8) + n1) ^ UT_HASH_RANDOM_MASK) + n2); } ulint ut_fold_binary( /*===========*/ /* out: folded value */ uchar* str, /* in: string of bytes */ ulint len) /* in: length */ { ulint i; ulint fold= 0; for (i= 0; i < len; i++) { fold= ut_fold_ulint_pair(fold, (ulint)(*str)); str++; } return(fold); } #endif ulint buf_calc_page_new_checksum( /*=======================*/ /* out: checksum */ uchar* page) /* in: buffer page */ { ulint checksum; /* Since the fields FIL_PAGE_FILE_FLUSH_LSN and ..._ARCH_LOG_NO are written outside the buffer pool to the first pages of data files, we have to skip them in the page checksum calculation. We must also skip the field FIL_PAGE_SPACE_OR_CHKSUM where the checksum is stored, and also the last 8 bytes of page because there we store the old formula checksum. */ checksum= ut_fold_binary(page + FIL_PAGE_OFFSET, FIL_PAGE_FILE_FLUSH_LSN - FIL_PAGE_OFFSET) + ut_fold_binary(page + FIL_PAGE_DATA, UNIV_PAGE_SIZE - FIL_PAGE_DATA - FIL_PAGE_END_LSN_OLD_CHKSUM); checksum= checksum & 0xFFFFFFFF; return(checksum); } ulint buf_calc_page_old_checksum( /*=======================*/ /* out: checksum */ uchar* page) /* in: buffer page */ { ulint checksum; checksum= ut_fold_binary(page, FIL_PAGE_FILE_FLUSH_LSN); checksum= checksum & 0xFFFFFFFF; return(checksum); }