| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 2015, 2017, MariaDB Corporation. |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify it under |
| 6 | the terms of the GNU General Public License as published by the Free Software |
| 7 | Foundation; version 2 of the License. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License along with |
| 14 | this program; if not, write to the Free Software Foundation, Inc., |
| 15 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 16 | |
| 17 | *****************************************************************************/ |
| 18 | |
| 19 | /**************************************************//** |
| 20 | @file include/fil0fil.ic |
| 21 | The low-level file system support functions |
| 22 | |
| 23 | Created 31/03/2015 Jan Lindström |
| 24 | *******************************************************/ |
| 25 | |
| 26 | #ifndef fil0fil_ic |
| 27 | #define fil0fil_ic |
| 28 | |
| 29 | /*******************************************************************//** |
| 30 | Return page type name */ |
| 31 | UNIV_INLINE |
| 32 | const char* |
| 33 | fil_get_page_type_name( |
| 34 | /*===================*/ |
| 35 | ulint page_type) /*!< in: FIL_PAGE_TYPE */ |
| 36 | { |
| 37 | switch(page_type) { |
| 38 | case FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED: |
| 39 | return "PAGE_COMPRESSED_ENRYPTED" ; |
| 40 | case FIL_PAGE_PAGE_COMPRESSED: |
| 41 | return "PAGE_COMPRESSED" ; |
| 42 | case FIL_PAGE_TYPE_INSTANT: |
| 43 | case FIL_PAGE_INDEX: |
| 44 | return "INDEX" ; |
| 45 | case FIL_PAGE_RTREE: |
| 46 | return "RTREE" ; |
| 47 | case FIL_PAGE_UNDO_LOG: |
| 48 | return "UNDO LOG" ; |
| 49 | case FIL_PAGE_INODE: |
| 50 | return "INODE" ; |
| 51 | case FIL_PAGE_IBUF_FREE_LIST: |
| 52 | return "IBUF_FREE_LIST" ; |
| 53 | case FIL_PAGE_TYPE_ALLOCATED: |
| 54 | return "ALLOCATED" ; |
| 55 | case FIL_PAGE_IBUF_BITMAP: |
| 56 | return "IBUF_BITMAP" ; |
| 57 | case FIL_PAGE_TYPE_SYS: |
| 58 | return "SYS" ; |
| 59 | case FIL_PAGE_TYPE_TRX_SYS: |
| 60 | return "TRX_SYS" ; |
| 61 | case FIL_PAGE_TYPE_FSP_HDR: |
| 62 | return "FSP_HDR" ; |
| 63 | case FIL_PAGE_TYPE_XDES: |
| 64 | return "XDES" ; |
| 65 | case FIL_PAGE_TYPE_BLOB: |
| 66 | return "BLOB" ; |
| 67 | case FIL_PAGE_TYPE_ZBLOB: |
| 68 | return "ZBLOB" ; |
| 69 | case FIL_PAGE_TYPE_ZBLOB2: |
| 70 | return "ZBLOB2" ; |
| 71 | case FIL_PAGE_TYPE_UNKNOWN: |
| 72 | return "OLD UNKOWN PAGE TYPE" ; |
| 73 | default: |
| 74 | return "PAGE TYPE CORRUPTED" ; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /****************************************************************//** |
| 79 | Validate page type. |
| 80 | @return true if valid, false if not */ |
| 81 | UNIV_INLINE |
| 82 | bool |
| 83 | fil_page_type_validate( |
| 84 | const byte* page) /*!< in: page */ |
| 85 | { |
| 86 | #ifdef UNIV_DEBUG |
| 87 | ulint page_type = mach_read_from_2(page + FIL_PAGE_TYPE); |
| 88 | |
| 89 | /* Validate page type */ |
| 90 | if (!((page_type == FIL_PAGE_PAGE_COMPRESSED || |
| 91 | page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED || |
| 92 | page_type == FIL_PAGE_INDEX || |
| 93 | page_type == FIL_PAGE_TYPE_INSTANT || |
| 94 | page_type == FIL_PAGE_RTREE || |
| 95 | page_type == FIL_PAGE_UNDO_LOG || |
| 96 | page_type == FIL_PAGE_INODE || |
| 97 | page_type == FIL_PAGE_IBUF_FREE_LIST || |
| 98 | page_type == FIL_PAGE_TYPE_ALLOCATED || |
| 99 | page_type == FIL_PAGE_IBUF_BITMAP || |
| 100 | page_type == FIL_PAGE_TYPE_SYS || |
| 101 | page_type == FIL_PAGE_TYPE_TRX_SYS || |
| 102 | page_type == FIL_PAGE_TYPE_FSP_HDR || |
| 103 | page_type == FIL_PAGE_TYPE_XDES || |
| 104 | page_type == FIL_PAGE_TYPE_BLOB || |
| 105 | page_type == FIL_PAGE_TYPE_ZBLOB || |
| 106 | page_type == FIL_PAGE_TYPE_ZBLOB2 || |
| 107 | page_type == FIL_PAGE_TYPE_UNKNOWN))) { |
| 108 | |
| 109 | ulint space = mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID); |
| 110 | ulint offset = mach_read_from_4(page + FIL_PAGE_OFFSET); |
| 111 | fil_system_enter(); |
| 112 | fil_space_t* rspace = fil_space_get_by_id(space); |
| 113 | fil_system_exit(); |
| 114 | |
| 115 | /* Dump out the page info */ |
| 116 | ib::fatal() << "Page " << space << ":" << offset |
| 117 | << " name " << (rspace ? rspace->name : "???" ) |
| 118 | << " page_type " << page_type |
| 119 | << " key_version " |
| 120 | << mach_read_from_4(page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION) |
| 121 | << " lsn " << mach_read_from_8(page + FIL_PAGE_LSN) |
| 122 | << " compressed_len " << mach_read_from_2(page + FIL_PAGE_DATA); |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | #endif /* UNIV_DEBUG */ |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | #endif /* fil0fil_ic */ |
| 131 | |