1 /* Copyright (c) 2003, 2005-2007 MySQL AB 2 Use is subject to license terms 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; version 2 of the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ 16 17 #ifndef BACKUP_FORMAT_HPP 18 #define BACKUP_FORMAT_HPP 19 20 #include <ndb_types.h> 21 22 static const char BACKUP_MAGIC[] = { 'N', 'D', 'B', 'B', 'C', 'K', 'U', 'P' }; 23 24 struct BackupFormat { 25 26 /** 27 * Section types in file 28 */ 29 enum SectionType { 30 FILE_HEADER = 1, 31 FRAGMENT_HEADER = 2, 32 FRAGMENT_FOOTER = 3, 33 TABLE_LIST = 4, 34 TABLE_DESCRIPTION = 5, 35 GCP_ENTRY = 6, 36 FRAGMENT_INFO = 7, 37 EMPTY_ENTRY = 8 38 }; 39 40 struct FileHeader { 41 char Magic[8]; 42 Uint32 NdbVersion; 43 44 Uint32 SectionType; 45 Uint32 SectionLength; 46 Uint32 FileType; 47 Uint32 BackupId; 48 Uint32 BackupKey_0; 49 Uint32 BackupKey_1; 50 Uint32 ByteOrder; 51 }; 52 53 /** 54 * File types 55 */ 56 enum FileType { 57 CTL_FILE = 1, 58 LOG_FILE = 2, 59 DATA_FILE = 3, 60 LCP_FILE = 4 61 }; 62 63 /** 64 * Data file formats 65 */ 66 struct DataFile { 67 68 struct FragmentHeader { 69 Uint32 SectionType; 70 Uint32 SectionLength; 71 Uint32 TableId; 72 Uint32 FragmentNo; 73 Uint32 ChecksumType; 74 }; 75 76 struct VariableData { 77 Uint32 Sz; 78 Uint32 Id; 79 Uint32 Data[1]; 80 }; 81 82 struct Record { 83 Uint32 Length; 84 Uint32 NullBitmask[1]; 85 Uint32 DataFixedKeys[1]; 86 Uint32 DataFixedAttributes[1]; 87 VariableData DataVariableAttributes[1]; 88 }; 89 90 struct FragmentFooter { 91 Uint32 SectionType; 92 Uint32 SectionLength; 93 Uint32 TableId; 94 Uint32 FragmentNo; 95 Uint32 NoOfRecords; 96 Uint32 Checksum; 97 }; 98 99 /* optional padding for O_DIRECT */ 100 struct EmptyEntry { 101 Uint32 SectionType; 102 Uint32 SectionLength; 103 /* not used data */ 104 }; 105 }; 106 107 /** 108 * CTL file formats 109 */ 110 struct CtlFile { 111 112 /** 113 * Table list 114 */ 115 struct TableList { 116 Uint32 SectionType; 117 Uint32 SectionLength; 118 Uint32 TableIds[1]; // Length = SectionLength - 2 119 }; 120 121 /** 122 * Table description(s) 123 */ 124 struct TableDescription { 125 Uint32 SectionType; 126 Uint32 SectionLength; 127 Uint32 TableType; 128 Uint32 DictTabInfo[1]; // Length = SectionLength - 3 129 }; 130 131 /** 132 * GCP Entry 133 */ 134 struct GCPEntry { 135 Uint32 SectionType; 136 Uint32 SectionLength; 137 Uint32 StartGCP; 138 Uint32 StopGCP; 139 }; 140 141 /** 142 * Fragment Info 143 */ 144 struct FragmentInfo { 145 Uint32 SectionType; 146 Uint32 SectionLength; 147 Uint32 TableId; 148 Uint32 FragmentNo; 149 Uint32 NoOfRecordsLow; 150 Uint32 NoOfRecordsHigh; 151 Uint32 FilePosLow; 152 Uint32 FilePosHigh; 153 }; 154 }; 155 156 /** 157 * LOG file format 158 */ 159 struct LogFile { 160 161 /** 162 * Log Entry 163 */ 164 struct LogEntry { 165 Uint32 Length; 166 Uint32 TableId; 167 // If TriggerEvent & 0x10000 == true then GCI is right after data 168 Uint32 TriggerEvent; 169 Uint32 FragId; 170 Uint32 Data[1]; // Len = Length - 3 171 }; 172 173 /** 174 * Log Entry pre NDBD_FRAGID_VERSION 175 */ 176 struct LogEntry_no_fragid { 177 Uint32 Length; 178 Uint32 TableId; 179 // If TriggerEvent & 0x10000 == true then GCI is right after data 180 Uint32 TriggerEvent; 181 Uint32 Data[1]; // Len = Length - 2 182 }; 183 }; 184 185 /** 186 * LCP file format 187 */ 188 struct LcpFile { 189 CtlFile::TableList TableList; 190 CtlFile::TableDescription TableDescription; 191 DataFile::FragmentHeader FragmentHeader; 192 DataFile::Record Record; 193 DataFile::FragmentFooter FragmentFooter; 194 }; 195 }; 196 197 #endif 198