#include <ndb_global.h>#include <NdbTCP.h>#include <NdbOut.hpp>#include "BackupFormat.hpp"#include <AttributeHeader.hpp>#include <SimpleProperties.hpp>#include <ndb_version.h>Include dependency graph for read.cpp:

Go to the source code of this file.
| #define RETURN_FALSE | ( | ) | { ndbout_c("false: %d", __LINE__); abort(); return false; } |
Definition at line 212 of file read.cpp.
Referenced by readFragFooter(), readFragHeader(), readGCPEntry(), readHeader(), readLogEntry(), readRecord(), readTableDesc(), and readTableList().
| int main | ( | int | argc, | |
| const char * | argv[] | |||
| ) |
Definition at line 50 of file read.cpp.
References BackupFormat::CTL_FILE, data, BackupFormat::DATA_FILE, exit, f, BackupFormat::FileHeader::FileType, AttributeHeader::getAttributeId(), AttributeHeader::getDataSize(), BackupFormat::LCP_FILE, BackupFormat::LOG_FILE, logEntryNo, ndb_init(), ndbout(), ndbout_c(), pos(), readFragFooter(), readFragHeader(), readGCPEntry(), readHeader(), readLogEntry(), readRecord(), readTableDesc(), readTableList(), and BackupFormat::CtlFile::TableList::SectionLength.
00050 { 00051 00052 ndb_init(); 00053 if(argc <= 1){ 00054 printf("Usage: %s <filename>", argv[0]); 00055 exit(1); 00056 } 00057 FILE * f = fopen(argv[1], "rb"); 00058 if(!f){ 00059 ndbout << "No such file!" << endl; 00060 exit(1); 00061 } 00062 00063 BackupFormat::FileHeader fileHeader; 00064 if(!readHeader(f, &fileHeader)){ 00065 ndbout << "Invalid file!" << endl; 00066 exit(1); 00067 } 00068 ndbout << fileHeader << endl; 00069 00070 switch(fileHeader.FileType){ 00071 case BackupFormat::DATA_FILE: 00072 while(!feof(f)){ 00073 BackupFormat::DataFile::FragmentHeader fragHeader; 00074 if(!readFragHeader(f, &fragHeader)) 00075 break; 00076 ndbout << fragHeader << endl; 00077 00078 Uint32 len, * data; 00079 while((len = readRecord(f, &data)) > 0){ 00080 #if 0 00081 ndbout << "-> " << hex; 00082 for(Uint32 i = 0; i<len; i++){ 00083 ndbout << data[i] << " "; 00084 } 00085 ndbout << endl; 00086 #endif 00087 } 00088 00089 BackupFormat::DataFile::FragmentFooter fragFooter; 00090 if(!readFragFooter(f, &fragFooter)) 00091 break; 00092 ndbout << fragFooter << endl; 00093 } 00094 break; 00095 case BackupFormat::CTL_FILE:{ 00096 BackupFormat::CtlFile::TableList * tabList; 00097 if(!readTableList(f, &tabList)){ 00098 ndbout << "Invalid file! No table list" << endl; 00099 break; 00100 } 00101 ndbout << (* tabList) << endl; 00102 00103 const Uint32 noOfTables = tabList->SectionLength - 2; 00104 for(Uint32 i = 0; i<noOfTables; i++){ 00105 BackupFormat::CtlFile::TableDescription * tabDesc; 00106 if(!readTableDesc(f, &tabDesc)){ 00107 ndbout << "Invalid file missing table description" << endl; 00108 break; 00109 } 00110 ndbout << (* tabDesc) << endl; 00111 } 00112 00113 BackupFormat::CtlFile::GCPEntry * gcpE; 00114 if(!readGCPEntry(f, &gcpE)){ 00115 ndbout << "Invalid file! GCP ENtry" << endl; 00116 break; 00117 } 00118 ndbout << (* gcpE) << endl; 00119 00120 break; 00121 } 00122 case BackupFormat::LOG_FILE:{ 00123 logEntryNo = 0; 00124 00125 typedef BackupFormat::LogFile::LogEntry LogEntry; 00126 00127 Uint32 len, * data; 00128 while((len = readLogEntry(f, &data)) > 0){ 00129 LogEntry * logEntry = (LogEntry *) data; 00133 Uint32 event = ntohl(logEntry->TriggerEvent); 00134 bool gcp = (event & 0x10000) != 0; 00135 event &= 0xFFFF; 00136 if(gcp) 00137 len --; 00138 00139 ndbout << "LogEntry Table: " << (Uint32)ntohl(logEntry->TableId) 00140 << " Event: " << event 00141 << " Length: " << (len - 2); 00142 00143 const Uint32 dataLen = len - 2; 00144 #if 0 00145 Uint32 pos = 0; 00146 while(pos < dataLen){ 00147 AttributeHeader * ah = (AttributeHeader*)&logEntry->Data[pos]; 00148 ndbout_c(" Attribut: %d Size: %d", 00149 ah->getAttributeId(), 00150 ah->getDataSize()); 00151 pos += ah->getDataSize() + 1; 00152 } 00153 #endif 00154 if(gcp) 00155 ndbout << " GCP: " << (Uint32)ntohl(logEntry->Data[dataLen]); 00156 ndbout << endl; 00157 } 00158 break; 00159 } 00160 case BackupFormat::LCP_FILE: 00161 { 00162 BackupFormat::CtlFile::TableList * tabList; 00163 if(!readTableList(f, &tabList)){ 00164 ndbout << "Invalid file! No table list" << endl; 00165 break; 00166 } 00167 ndbout << (* tabList) << endl; 00168 00169 const Uint32 noOfTables = tabList->SectionLength - 2; 00170 for(Uint32 i = 0; i<noOfTables; i++){ 00171 BackupFormat::CtlFile::TableDescription * tabDesc; 00172 if(!readTableDesc(f, &tabDesc)){ 00173 ndbout << "Invalid file missing table description" << endl; 00174 break; 00175 } 00176 ndbout << (* tabDesc) << endl; 00177 } 00178 00179 while(!feof(f)){ 00180 BackupFormat::DataFile::FragmentHeader fragHeader; 00181 if(!readFragHeader(f, &fragHeader)) 00182 break; 00183 ndbout << fragHeader << endl; 00184 00185 Uint32 len, * data; 00186 while((len = readRecord(f, &data)) > 0){ 00187 #if 0 00188 ndbout << "-> " << hex; 00189 for(Uint32 i = 0; i<len; i++){ 00190 ndbout << data[i] << " "; 00191 } 00192 ndbout << endl; 00193 #endif 00194 } 00195 00196 BackupFormat::DataFile::FragmentFooter fragFooter; 00197 if(!readFragFooter(f, &fragFooter)) 00198 break; 00199 ndbout << fragFooter << endl; 00200 } 00201 break; 00202 } 00203 default: 00204 ndbout << "Unsupported file type for printer: " 00205 << fileHeader.FileType << endl; 00206 break; 00207 } 00208 fclose(f); 00209 return 0; 00210 }
Here is the call graph for this function:

| NdbOut & operator<< | ( | NdbOut & | , | |
| const BackupFormat::CtlFile::GCPEntry & | ||||
| ) |
Definition at line 514 of file read.cpp.
References BackupFormat::CtlFile::GCPEntry::SectionLength, BackupFormat::CtlFile::GCPEntry::SectionType, BackupFormat::CtlFile::GCPEntry::StartGCP, and BackupFormat::CtlFile::GCPEntry::StopGCP.
00514 { 00515 ndbout << "-- GCP Entry:" << endl; 00516 ndbout << "SectionType: " << hf.SectionType << endl; 00517 ndbout << "SectionLength: " << hf.SectionLength << endl; 00518 ndbout << "Start GCP: " << hf.StartGCP << endl; 00519 ndbout << "Stop GCP: " << hf.StopGCP << endl; 00520 00521 return ndbout; 00522 }
| NdbOut & operator<< | ( | NdbOut & | , | |
| const BackupFormat::CtlFile::TableDescription & | ||||
| ) |
Definition at line 477 of file read.cpp.
References buf, BackupFormat::CtlFile::TableDescription::DictTabInfo, SimpleProperties::Reader::first(), SimpleProperties::Reader::getKey(), SimpleProperties::Reader::getString(), SimpleProperties::Reader::getUint32(), SimpleProperties::Reader::getValueLen(), SimpleProperties::Reader::getValueType(), SimpleProperties::Reader::next(), BackupFormat::CtlFile::TableDescription::SectionLength, BackupFormat::CtlFile::TableDescription::SectionType, SimpleProperties::StringValue, SimpleProperties::Uint32Value, and SimpleProperties::Reader::valid().
00477 { 00478 ndbout << "-- Table Description:" << endl; 00479 ndbout << "SectionType: " << hf.SectionType << endl; 00480 ndbout << "SectionLength: " << hf.SectionLength << endl; 00481 00482 SimplePropertiesLinearReader it(&hf.DictTabInfo[0], hf.SectionLength - 2); 00483 char buf[1024]; 00484 for(it.first(); it.valid(); it.next()){ 00485 switch(it.getValueType()){ 00486 case SimpleProperties::Uint32Value: 00487 ndbout << "Key: " << it.getKey() 00488 << " value(" << it.getValueLen() << ") : " 00489 << it.getUint32() << endl; 00490 break; 00491 case SimpleProperties::StringValue: 00492 if(it.getValueLen() < sizeof(buf)){ 00493 it.getString(buf); 00494 ndbout << "Key: " << it.getKey() 00495 << " value(" << it.getValueLen() << ") : " 00496 << "\"" << buf << "\"" << endl; 00497 } else { 00498 ndbout << "Key: " << it.getKey() 00499 << " value(" << it.getValueLen() << ") : " 00500 << "\"" << "<TOO LONG>" << "\"" << endl; 00501 00502 } 00503 break; 00504 default: 00505 ndbout << "Unknown type for key: " << it.getKey() 00506 << " type: " << it.getValueType() << endl; 00507 } 00508 } 00509 00510 return ndbout; 00511 }
Here is the call graph for this function:

| NdbOut & operator<< | ( | NdbOut & | , | |
| const BackupFormat::CtlFile::TableList & | ||||
| ) |
Definition at line 464 of file read.cpp.
References BackupFormat::CtlFile::TableList::SectionLength, BackupFormat::CtlFile::TableList::SectionType, and BackupFormat::CtlFile::TableList::TableIds.
00464 { 00465 ndbout << "-- Table List:" << endl; 00466 ndbout << "SectionType: " << hf.SectionType << endl; 00467 ndbout << "SectionLength: " << hf.SectionLength << endl; 00468 for(Uint32 i = 0; i < hf.SectionLength - 2; i++){ 00469 ndbout << hf.TableIds[i] << " "; 00470 if((i + 1) % 16 == 0) 00471 ndbout << endl; 00472 } 00473 return ndbout; 00474 }
| NdbOut & operator<< | ( | NdbOut & | , | |
| const BackupFormat::DataFile::FragmentFooter & | ||||
| ) |
Definition at line 376 of file read.cpp.
References BackupFormat::DataFile::FragmentFooter::Checksum, BackupFormat::DataFile::FragmentFooter::FragmentNo, BackupFormat::DataFile::FragmentFooter::NoOfRecords, BackupFormat::DataFile::FragmentFooter::SectionLength, BackupFormat::DataFile::FragmentFooter::SectionType, and BackupFormat::DataFile::FragmentFooter::TableId.
00377 { 00378 00379 ndbout << "-- Fragment footer:" << endl; 00380 ndbout << "SectionType: " << hf.SectionType << endl; 00381 ndbout << "SectionLength: " << hf.SectionLength << endl; 00382 ndbout << "TableId: " << hf.TableId << endl; 00383 ndbout << "FragmentNo: " << hf.FragmentNo << endl; 00384 ndbout << "NoOfRecords: " << hf.NoOfRecords << endl; 00385 ndbout << "Checksum: " << hf.Checksum << endl; 00386 00387 return ndbout; 00388 }
| NdbOut & operator<< | ( | NdbOut & | , | |
| const BackupFormat::DataFile::FragmentHeader & | ||||
| ) |
Definition at line 364 of file read.cpp.
References BackupFormat::DataFile::FragmentHeader::ChecksumType, BackupFormat::DataFile::FragmentHeader::FragmentNo, BackupFormat::DataFile::FragmentHeader::SectionLength, BackupFormat::DataFile::FragmentHeader::SectionType, and BackupFormat::DataFile::FragmentHeader::TableId.
00365 { 00366 00367 ndbout << "-- Fragment header:" << endl; 00368 ndbout << "SectionType: " << hf.SectionType << endl; 00369 ndbout << "SectionLength: " << hf.SectionLength << endl; 00370 ndbout << "TableId: " << hf.TableId << endl; 00371 ndbout << "FragmentNo: " << hf.FragmentNo << endl; 00372 ndbout << "ChecksumType: " << hf.ChecksumType << endl; 00373 00374 return ndbout; 00375 }
| NdbOut & operator<< | ( | NdbOut & | , | |
| const BackupFormat::FileHeader & | ||||
| ) |
Definition at line 345 of file read.cpp.
References BackupFormat::FileHeader::BackupId, BackupFormat::FileHeader::BackupKey_0, BackupFormat::FileHeader::BackupKey_1, buf, BackupFormat::FileHeader::ByteOrder, BackupFormat::FileHeader::FileType, BackupFormat::FileHeader::Magic, memcpy, BackupFormat::FileHeader::NdbVersion, BackupFormat::FileHeader::SectionLength, and BackupFormat::FileHeader::SectionType.
00345 { 00346 00347 char buf[9]; 00348 memcpy(buf, hf.Magic, sizeof(hf.Magic)); 00349 buf[8] = 0; 00350 00351 ndbout << "-- FileHeader:" << endl; 00352 ndbout << "Magic: " << buf << endl; 00353 ndbout << "NdbVersion: " << hf.NdbVersion << endl; 00354 ndbout << "SectionType: " << hf.SectionType << endl; 00355 ndbout << "SectionLength: " << hf.SectionLength << endl; 00356 ndbout << "FileType: " << hf.FileType << endl; 00357 ndbout << "BackupId: " << hf.BackupId << endl; 00358 ndbout << "BackupKey: [ " << hex << hf.BackupKey_0 00359 << " "<< hf.BackupKey_1 << " ]" << endl; 00360 ndbout << "ByteOrder: " << hex << hf.ByteOrder << endl; 00361 return ndbout; 00362 }
| bool readFragFooter | ( | FILE * | , | |
| BackupFormat::DataFile::FragmentFooter * | ||||
| ) |
Definition at line 277 of file read.cpp.
References BackupFormat::FRAGMENT_FOOTER, and RETURN_FALSE.
Referenced by main().
00277 { 00278 if(fread(dst, 1, sizeof(* dst), f) != sizeof(* dst)) 00279 RETURN_FALSE(); 00280 00281 dst->SectionType = ntohl(dst->SectionType); 00282 dst->SectionLength = ntohl(dst->SectionLength); 00283 dst->TableId = ntohl(dst->TableId); 00284 dst->FragmentNo = ntohl(dst->FragmentNo); 00285 dst->NoOfRecords = ntohl(dst->NoOfRecords); 00286 dst->Checksum = ntohl(dst->Checksum); 00287 00288 if(dst->SectionLength != (sizeof(* dst) >> 2)) 00289 RETURN_FALSE(); 00290 00291 if(dst->SectionType != BackupFormat::FRAGMENT_FOOTER) 00292 RETURN_FALSE(); 00293 return true; 00294 }
Here is the caller graph for this function:

| bool readFragHeader | ( | FILE * | , | |
| BackupFormat::DataFile::FragmentHeader * | ||||
| ) |
Definition at line 255 of file read.cpp.
References BackupFormat::FRAGMENT_HEADER, recNo, and RETURN_FALSE.
Referenced by main().
00255 { 00256 if(fread(dst, 1, sizeof(* dst), f) != sizeof(* dst)) 00257 return false; 00258 00259 dst->SectionType = ntohl(dst->SectionType); 00260 dst->SectionLength = ntohl(dst->SectionLength); 00261 dst->TableId = ntohl(dst->TableId); 00262 dst->FragmentNo = ntohl(dst->FragmentNo); 00263 dst->ChecksumType = ntohl(dst->ChecksumType); 00264 00265 if(dst->SectionLength != (sizeof(* dst) >> 2)) 00266 RETURN_FALSE(); 00267 00268 if(dst->SectionType != BackupFormat::FRAGMENT_HEADER) 00269 RETURN_FALSE(); 00270 00271 recNo = 0; 00272 00273 return true; 00274 }
Here is the caller graph for this function:

| bool readGCPEntry | ( | FILE * | , | |
| BackupFormat::CtlFile::GCPEntry ** | ||||
| ) |
Definition at line 441 of file read.cpp.
References buf, BackupFormat::GCP_ENTRY, and RETURN_FALSE.
Referenced by main().
00441 { 00442 BackupFormat::CtlFile::GCPEntry * dst = 00443 (BackupFormat::CtlFile::GCPEntry *)&buf[0]; 00444 00445 if(fread(dst, 4, 4, f) != 4) 00446 RETURN_FALSE(); 00447 00448 dst->SectionType = ntohl(dst->SectionType); 00449 dst->SectionLength = ntohl(dst->SectionLength); 00450 00451 if(dst->SectionType != BackupFormat::GCP_ENTRY) 00452 RETURN_FALSE(); 00453 00454 dst->StartGCP = ntohl(dst->StartGCP); 00455 dst->StopGCP = ntohl(dst->StopGCP); 00456 00457 * ret = dst; 00458 00459 return true; 00460 }
Here is the caller graph for this function:

| bool readHeader | ( | FILE * | , | |
| BackupFormat::FileHeader * | ||||
| ) |
Definition at line 217 of file read.cpp.
References BACKUP_MAGIC, BackupFormat::FileHeader::BackupId, BackupFormat::FileHeader::BackupKey_0, BackupFormat::FileHeader::BackupKey_1, BackupFormat::FileHeader::ByteOrder, endian, BackupFormat::FILE_HEADER, BackupFormat::FileHeader::FileType, BackupFormat::FileHeader::Magic, memcmp(), NDB_VERSION, BackupFormat::FileHeader::NdbVersion, RETURN_FALSE, BackupFormat::FileHeader::SectionLength, and BackupFormat::FileHeader::SectionType.
Referenced by main().
00217 { 00218 if(fread(dst, 4, 3, f) != 3) 00219 RETURN_FALSE(); 00220 00221 if(memcmp(dst->Magic, BACKUP_MAGIC, sizeof(BACKUP_MAGIC)) != 0) 00222 RETURN_FALSE(); 00223 00224 dst->NdbVersion = ntohl(dst->NdbVersion); 00225 if(dst->NdbVersion != NDB_VERSION) 00226 RETURN_FALSE(); 00227 00228 if(fread(&dst->SectionType, 4, 2, f) != 2) 00229 RETURN_FALSE(); 00230 dst->SectionType = ntohl(dst->SectionType); 00231 dst->SectionLength = ntohl(dst->SectionLength); 00232 00233 if(dst->SectionType != BackupFormat::FILE_HEADER) 00234 RETURN_FALSE(); 00235 00236 if(dst->SectionLength != ((sizeof(BackupFormat::FileHeader) - 12) >> 2)) 00237 RETURN_FALSE(); 00238 00239 if(fread(&dst->FileType, 4, dst->SectionLength - 2, f) != 00240 (dst->SectionLength - 2)) 00241 RETURN_FALSE(); 00242 00243 dst->FileType = ntohl(dst->FileType); 00244 dst->BackupId = ntohl(dst->BackupId); 00245 dst->BackupKey_0 = ntohl(dst->BackupKey_0); 00246 dst->BackupKey_1 = ntohl(dst->BackupKey_1); 00247 00248 if(dst->ByteOrder != 0x12345678) 00249 endian = true; 00250 00251 return true; 00252 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 323 of file read.cpp.
References buf, logEntryNo, and RETURN_FALSE.
Referenced by main().
00323 { 00324 Uint32 len; 00325 if(fread(&len, 1, 4, f) != 4) 00326 RETURN_FALSE(); 00327 00328 len = ntohl(len); 00329 00330 if(fread(&buf[1], 4, len, f) != len) 00331 return -1; 00332 00333 buf[0] = len; 00334 00335 if(len > 0) 00336 logEntryNo++; 00337 00338 * dst = &buf[0]; 00339 00340 return len; 00341 }
Here is the caller graph for this function:

Definition at line 299 of file read.cpp.
References buf, ndbout_c(), recNo, and RETURN_FALSE.
Referenced by main().
00299 { 00300 Uint32 len; 00301 if(fread(&len, 1, 4, f) != 4) 00302 RETURN_FALSE(); 00303 00304 len = ntohl(len); 00305 00306 if(fread(buf, 4, len, f) != len) 00307 { 00308 return -1; 00309 } 00310 00311 if(len > 0) 00312 recNo++; 00313 else 00314 ndbout_c("Found %d records", recNo); 00315 00316 * dst = &buf[0]; 00317 00318 00319 return len; 00320 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool readTableDesc | ( | FILE * | , | |
| BackupFormat::CtlFile::TableDescription ** | ||||
| ) |
Definition at line 418 of file read.cpp.
References buf, RETURN_FALSE, and BackupFormat::TABLE_DESCRIPTION.
Referenced by main().
00418 { 00419 BackupFormat::CtlFile::TableDescription * dst = 00420 (BackupFormat::CtlFile::TableDescription *)&buf[0]; 00421 00422 if(fread(dst, 4, 2, f) != 2) 00423 RETURN_FALSE(); 00424 00425 dst->SectionType = ntohl(dst->SectionType); 00426 dst->SectionLength = ntohl(dst->SectionLength); 00427 00428 if(dst->SectionType != BackupFormat::TABLE_DESCRIPTION) 00429 RETURN_FALSE(); 00430 00431 const Uint32 len = dst->SectionLength - 2; 00432 if(fread(&dst->DictTabInfo[0], 4, len, f) != len) 00433 RETURN_FALSE(); 00434 00435 * ret = dst; 00436 00437 return true; 00438 }
Here is the caller graph for this function:

| bool readTableList | ( | FILE * | , | |
| BackupFormat::CtlFile::TableList ** | ||||
| ) |
Definition at line 391 of file read.cpp.
References buf, RETURN_FALSE, and BackupFormat::TABLE_LIST.
Referenced by main().
00391 { 00392 BackupFormat::CtlFile::TableList * dst = 00393 (BackupFormat::CtlFile::TableList *)&buf[0]; 00394 00395 if(fread(dst, 4, 2, f) != 2) 00396 RETURN_FALSE(); 00397 00398 dst->SectionType = ntohl(dst->SectionType); 00399 dst->SectionLength = ntohl(dst->SectionLength); 00400 00401 if(dst->SectionType != BackupFormat::TABLE_LIST) 00402 RETURN_FALSE(); 00403 00404 const Uint32 len = dst->SectionLength - 2; 00405 if(fread(&dst->TableIds[0], 4, len, f) != len) 00406 RETURN_FALSE(); 00407 00408 for(Uint32 i = 0; i<len; i++){ 00409 dst->TableIds[i] = ntohl(dst->TableIds[i]); 00410 } 00411 00412 * ret = dst; 00413 00414 return true; 00415 }
Here is the caller graph for this function:

Definition at line 214 of file read.cpp.
Referenced by crc32(), MgmApiSession::get_nodeid(), and readHeader().
Uint32 logEntryNo [static] |
1.4.7
