#include <ndb_global.h>#include <ndb_version.h>#include <NdbMain.h>#include <NdbOut.hpp>#include <SchemaFile.hpp>#include <kernel_types.h>Include dependency graph for printSchemaFile.cpp:

Go to the source code of this file.
Functions | |
| static void | usage () |
| static void | fill (const char *buf, int mod) |
| static const char * | version (Uint32 v) |
| static int | print_head (const char *filename, const SchemaFile *sf) |
| Uint32 | table_version_minor (Uint32 ver) |
| static int | print_old (const char *filename, const SchemaFile *sf, Uint32 sz) |
| static int | print (const char *filename, const SchemaFile *xsf, Uint32 sz) |
| NDB_COMMAND (printSchemafile,"printSchemafile","printSchemafile","Prints a schemafile", 16384) | |
Variables | |
| static const char * | progname = 0 |
| static bool | allflag = false |
| static bool | checkonly = false |
| static bool | equalcontents = false |
| static bool | okquiet = false |
| static void fill | ( | const char * | buf, | |
| int | mod | |||
| ) | [static] |
| NDB_COMMAND | ( | printSchemafile | , | |
| "printSchemafile" | , | |||
| "printSchemafile" | , | |||
| "Prints a schemafile" | , | |||
| 16384 | ||||
| ) |
Definition at line 187 of file printSchemaFile.cpp.
References allflag, buf, checkonly, equalcontents, errno, exitcode, f, filename, memcmp(), NDB_SF_VERSION_5_0_6, ndbout(), SchemaFile::NdbVersion, okquiet, print(), print_old(), progname, strchr(), usage(), and version().
00189 { 00190 progname = argv[0]; 00191 int exitcode = 0; 00192 00193 while (argc > 1 && argv[1][0] == '-') { 00194 if (strchr(argv[1], 'a') != 0) 00195 allflag = true; 00196 if (strchr(argv[1], 'c') != 0) 00197 checkonly = true; 00198 if (strchr(argv[1], 'e') != 0) 00199 equalcontents = true; 00200 if (strchr(argv[1], 'q') != 0) 00201 okquiet = true; 00202 if (strchr(argv[1], 'h') != 0 || strchr(argv[1], '?') != 0) { 00203 usage(); 00204 return 0; 00205 } 00206 argc--, argv++; 00207 } 00208 00209 const char * prevfilename = 0; 00210 Uint32 * prevbuf = 0; 00211 Uint32 prevbytes = 0; 00212 00213 while (argc > 1) { 00214 const char * filename = argv[1]; 00215 argc--, argv++; 00216 00217 struct stat sbuf; 00218 const int res = stat(filename, &sbuf); 00219 if (res != 0) { 00220 ndbout << filename << ": not found errno=" << errno << endl; 00221 exitcode = 1; 00222 continue; 00223 } 00224 const Uint32 bytes = sbuf.st_size; 00225 00226 Uint32 * buf = new Uint32[bytes/4+1]; 00227 00228 FILE * f = fopen(filename, "rb"); 00229 if (f == 0) { 00230 ndbout << filename << ": open failed errno=" << errno << endl; 00231 delete [] buf; 00232 exitcode = 1; 00233 continue; 00234 } 00235 Uint32 sz = fread(buf, 1, bytes, f); 00236 fclose(f); 00237 if (sz != bytes) { 00238 ndbout << filename << ": read failed errno=" << errno << endl; 00239 delete [] buf; 00240 exitcode = 1; 00241 continue; 00242 } 00243 00244 if (sz < 32) { 00245 ndbout << filename << ": too short (no header)" << endl; 00246 delete [] buf; 00247 exitcode = 1; 00248 continue; 00249 } 00250 00251 SchemaFile* sf = (SchemaFile *)&buf[0]; 00252 int ret; 00253 if (sf->NdbVersion < NDB_SF_VERSION_5_0_6) 00254 ret = print_old(filename, sf, sz); 00255 else 00256 ret = print(filename, sf, sz); 00257 00258 if (ret != 0) { 00259 ndbout << filename << ": check failed" 00260 << " version=" << version(sf->NdbVersion) << endl; 00261 exitcode = 1; 00262 } else if (! okquiet) { 00263 ndbout << filename << ": ok" 00264 << " version=" << version(sf->NdbVersion) << endl; 00265 } 00266 00267 if (equalcontents && prevfilename != 0) { 00268 if (prevbytes != bytes || memcmp(prevbuf, buf, bytes) != 0) { 00269 ndbout << filename << ": differs from " << prevfilename << endl; 00270 exitcode = 1; 00271 } 00272 } 00273 00274 prevfilename = filename; 00275 delete [] prevbuf; 00276 prevbuf = buf; 00277 prevbytes = bytes; 00278 } 00279 00280 delete [] prevbuf; 00281 return exitcode; 00282 }
Here is the call graph for this function:

| static int print | ( | const char * | filename, | |
| const SchemaFile * | xsf, | |||
| Uint32 | sz | |||
| ) | [static] |
Definition at line 125 of file printSchemaFile.cpp.
References assert, checkonly, SchemaFile::FileSize, SchemaFile::Magic, memcmp(), n, NDB_SF_PAGE_SIZE, ndbout(), and print_head().
00126 { 00127 int retcode = 0; 00128 00129 if (print_head(filename, xsf) != 0) 00130 retcode = 1; 00131 00132 assert(sizeof(SchemaFile) == NDB_SF_PAGE_SIZE); 00133 if (xsf->FileSize != sz || xsf->FileSize % NDB_SF_PAGE_SIZE != 0) { 00134 ndbout << filename << ": invalid FileSize " << xsf->FileSize << endl; 00135 retcode = 1; 00136 } 00137 Uint32 noOfPages = xsf->FileSize / NDB_SF_PAGE_SIZE; 00138 for (Uint32 n = 0; n < noOfPages; n++) { 00139 if (! checkonly) { 00140 ndbout << "----- Page: " << n << " (" << noOfPages << ") -----" << endl; 00141 } 00142 const SchemaFile * sf = &xsf[n]; 00143 if (memcmp(sf->Magic, xsf->Magic, sizeof(sf->Magic)) != 0) { 00144 ndbout << filename << ": page " << n << " invalid magic" << endl; 00145 retcode = 1; 00146 } 00147 if (sf->FileSize != xsf->FileSize) { 00148 ndbout << filename << ": page " << n << " FileSize changed to " << sf->FileSize << "!=" << xsf->FileSize << endl; 00149 retcode = 1; 00150 } 00151 Uint32 cs = 0; 00152 for (Uint32 j = 0; j < NDB_SF_PAGE_SIZE_IN_WORDS; j++) 00153 cs ^= ((const Uint32*)sf)[j]; 00154 if (cs != 0) { 00155 ndbout << filename << ": page " << n << " invalid CheckSum" << endl; 00156 retcode = 1; 00157 } 00158 if (sf->NoOfTableEntries != NDB_SF_PAGE_ENTRIES) { 00159 ndbout << filename << ": page " << n << " invalid NoOfTableEntries " << sf->NoOfTableEntries << endl; 00160 retcode = 1; 00161 } 00162 for (Uint32 i = 0; i < NDB_SF_PAGE_ENTRIES; i++) { 00163 SchemaFile::TableEntry te = sf->TableEntries[i]; 00164 Uint32 j = n * NDB_SF_PAGE_ENTRIES + i; 00165 if (allflag || 00166 (te.m_tableState != SchemaFile::INIT && 00167 te.m_tableState != SchemaFile::DROP_TABLE_COMMITTED)) { 00168 if (! checkonly) 00169 ndbout << "Table " << j << ":" 00170 << " State = " << te.m_tableState 00171 << " version = " << table_version_major(te.m_tableVersion) 00172 << "(" << table_version_minor(te.m_tableVersion) << ")" 00173 << " type = " << te.m_tableType 00174 << " noOfWords = " << te.m_info_words 00175 << " gcp: " << te.m_gcp << endl; 00176 } 00177 if (te.m_unused[0] != 0 || te.m_unused[1] != 0 || te.m_unused[2] != 0) { 00178 ndbout << filename << ": entry " << j << " garbage in m_unused[3]" << endl; 00179 retcode = 1; 00180 } 00181 } 00182 } 00183 00184 return retcode; 00185 }
Here is the call graph for this function:

| static int print_head | ( | const char * | filename, | |
| const SchemaFile * | sf | |||
| ) | [static] |
Definition at line 64 of file printSchemaFile.cpp.
References SchemaFile::ByteOrder, checkonly, SchemaFile::FileSize, SchemaFile::Magic, memcmp(), ndbout(), ndbout_c(), SchemaFile::NdbVersion, and version().
Referenced by print(), and print_old().
00065 { 00066 int retcode = 0; 00067 00068 if (! checkonly) { 00069 ndbout << "----- Schemafile: " << filename << " -----" << endl; 00070 ndbout_c("Magic: %.*s ByteOrder: %.8x NdbVersion: %s FileSize: %d", 00071 sizeof(sf->Magic), 00072 sf->Magic, 00073 sf->ByteOrder, 00074 version(sf->NdbVersion), 00075 sf->FileSize); 00076 } 00077 00078 if (memcmp(sf->Magic, "NDBSCHMA", sizeof(sf->Magic) != 0)) { 00079 ndbout << filename << ": invalid header magic" << endl; 00080 retcode = 1; 00081 } 00082 00083 if ((sf->NdbVersion >> 16) < 4 || (sf->NdbVersion >> 16) > 9) { 00084 ndbout << filename << ": impossible version " << hex << sf->NdbVersion << endl; 00085 retcode = 1; 00086 } 00087 00088 return retcode; 00089 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int print_old | ( | const char * | filename, | |
| const SchemaFile * | sf, | |||
| Uint32 | sz | |||
| ) | [static] |
Definition at line 99 of file printSchemaFile.cpp.
References allflag, checkonly, SchemaFile::DROP_TABLE_COMMITTED, SchemaFile::INIT, ndbout(), SchemaFile::NoOfTableEntries, print_head(), table_version_major(), table_version_minor(), and SchemaFile::TableEntries_old.
Referenced by NDB_COMMAND().
00100 { 00101 int retcode = 0; 00102 00103 if (print_head(filename, sf) != 0) 00104 retcode = 1; 00105 00106 for (Uint32 i = 0; i < sf->NoOfTableEntries; i++) { 00107 SchemaFile::TableEntry_old te = sf->TableEntries_old[i]; 00108 if (allflag || 00109 (te.m_tableState != SchemaFile::INIT && 00110 te.m_tableState != SchemaFile::DROP_TABLE_COMMITTED)) { 00111 if (! checkonly) 00112 ndbout << "Table " << i << ":" 00113 << " State = " << te.m_tableState 00114 << " version = " << table_version_major(te.m_tableVersion) 00115 << "(" << table_version_minor(te.m_tableVersion) << ")" 00116 << " type = " << te.m_tableType 00117 << " noOfPages = " << te.m_noOfPages 00118 << " gcp: " << te.m_gcp << endl; 00119 } 00120 } 00121 return retcode; 00122 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 93 of file printSchemaFile.cpp.
Referenced by print_old().
Here is the caller graph for this function:

| static void usage | ( | void | ) | [static] |
Definition at line 33 of file printSchemaFile.cpp.
References ndbout(), and progname.
00034 { 00035 ndbout 00036 << "Usage: " << progname << " [-aceq]" << " file ..." << endl 00037 << "-a print also unused slots" << endl 00038 << "-c check only (return status 1 on error)" << endl 00039 << "-e check also that the files have identical contents" << endl 00040 << "-q no output if file is ok" << endl 00041 << "Example: " << progname << " -ceq ndb_*_fs/D[12]/DBDICT/P0.SchemaLog" << endl; 00042 }
Here is the call graph for this function:

| static const char* version | ( | Uint32 | v | ) | [static] |
Definition at line 56 of file printSchemaFile.cpp.
References buf.
00057 { 00058 static char buf[40]; 00059 sprintf(buf, "%d.%d.%d", v >> 16, (v >> 8) & 0xFF, v & 0xFF); 00060 return buf; 00061 }
Definition at line 28 of file printSchemaFile.cpp.
Referenced by NDB_COMMAND(), print(), print_head(), and print_old().
bool equalcontents = false [static] |
const char* progname = 0 [static] |
Definition at line 26 of file printSchemaFile.cpp.
1.4.7

