| 1 |
/* |
| 2 |
* PROGRAM: JRD Access Method |
| 3 |
* MODULE: ppg.cpp |
| 4 |
* DESCRIPTION: Database page print module |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Interbase Public |
| 7 |
* License Version 1.0 (the "License"); you may not use this file |
| 8 |
* except in compliance with the License. You may obtain a copy |
| 9 |
* of the License at http://www.Inprise.com/IPL.html |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an |
| 12 |
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express |
| 13 |
* or implied. See the License for the specific language governing |
| 14 |
* rights and limitations under the License. |
| 15 |
* |
| 16 |
* The Original Code was created by Inprise Corporation |
| 17 |
* and its predecessors. Portions created by Inprise Corporation are |
| 18 |
* Copyright (C) Inprise Corporation. |
| 19 |
* |
| 20 |
* All Rights Reserved. |
| 21 |
* Contributor(s): ______________________________________. |
| 22 |
* |
| 23 |
* 2001.08.07 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" |
| 24 |
* conditionals, second attempt |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "firebird.h" |
| 28 |
#include <stdio.h> |
| 29 |
#include <string.h> |
| 30 |
#include "../common/classes/timestamp.h" |
| 31 |
#include "../jrd/ibase.h" |
| 32 |
#include "../jrd/ods.h" |
| 33 |
#include "../jrd/ods_proto.h" |
| 34 |
#include "../common/os/guid.h" |
| 35 |
#include "../yvalve/gds_proto.h" |
| 36 |
#include "../common/classes/DbImplementation.h" |
| 37 |
|
| 38 |
#include "../utilities/gstat/ppg_proto.h" |
| 39 |
|
| 40 |
// gstat directly reads database files, therefore |
| 41 |
using namespace Ods; |
| 42 |
using Firebird::Guid; |
| 43 |
|
| 44 |
void PPG_print_header(const header_page* header, ULONG page, |
| 45 |
bool nocreation, Firebird::UtilSvc* uSvc) |
| 46 |
{ |
| 47 |
/************************************** |
| 48 |
* |
| 49 |
* P P G _ p r i n t _ h e a d e r |
| 50 |
* |
| 51 |
************************************** |
| 52 |
* |
| 53 |
* Functional description |
| 54 |
* Print database header page. |
| 55 |
* |
| 56 |
**************************************/ |
| 57 |
if (page == HEADER_PAGE) |
| 58 |
uSvc->printf(false, "Database header page information:\n"); |
| 59 |
else |
| 60 |
uSvc->printf(false, "Database overflow header page information:\n"); |
| 61 |
|
| 62 |
if (page == HEADER_PAGE) |
| 63 |
{ |
| 64 |
uSvc->printf(false, "\tFlags\t\t\t%d\n", header->hdr_header.pag_flags); |
| 65 |
//uSvc->printf("\tChecksum\t\t%d\n", header->hdr_header.pag_checksum); |
| 66 |
uSvc->printf(false, "\tGeneration\t\t%" ULONGFORMAT"\n", header->hdr_header.pag_generation); |
| 67 |
uSvc->printf(false, "\tSystem Change Number\t%" ULONGFORMAT"\n", header->hdr_header.pag_scn); |
| 68 |
uSvc->printf(false, "\tPage size\t\t%d\n", header->hdr_page_size); |
| 69 |
uSvc->printf(false, "\tODS version\t\t%d.%d\n", |
| 70 |
header->hdr_ods_version & ~ODS_FIREBIRD_FLAG, header->hdr_ods_minor); |
| 71 |
uSvc->printf(false, "\tOldest transaction\t%" SQUADFORMAT"\n", Ods::getOIT(header)); |
| 72 |
uSvc->printf(false, "\tOldest active\t\t%" SQUADFORMAT"\n", Ods::getOAT(header)); |
| 73 |
uSvc->printf(false, "\tOldest snapshot\t\t%" SQUADFORMAT"\n", Ods::getOST(header)); |
| 74 |
uSvc->printf(false, "\tNext transaction\t%" SQUADFORMAT"\n", Ods::getNT(header)); |
| 75 |
uSvc->printf(false, "\tSequence number\t\t%d\n", header->hdr_sequence); |
| 76 |
|
| 77 |
const AttNumber att_id = |
| 78 |
(AttNumber) header->hdr_att_high << BITS_PER_LONG | header->hdr_attachment_id; |
| 79 |
uSvc->printf(false, "\tNext attachment ID\t%" SQUADFORMAT"\n", att_id); |
| 80 |
|
| 81 |
Firebird::DbImplementation imp(header); |
| 82 |
uSvc->printf(false, "\tImplementation\t\tHW=%s %s-endian OS=%s CC=%s\n", |
| 83 |
imp.cpu(), imp.endianess(), imp.os(), imp.cc()); |
| 84 |
uSvc->printf(false, "\tShadow count\t\t%" SLONGFORMAT"\n", header->hdr_shadow_count); |
| 85 |
uSvc->printf(false, "\tPage buffers\t\t%" ULONGFORMAT"\n", header->hdr_page_buffers); |
| 86 |
} |
| 87 |
|
| 88 |
uSvc->printf(false, "\tNext header page\t%" ULONGFORMAT"\n", header->hdr_next_page); |
| 89 |
#ifdef DEV_BUILD |
| 90 |
uSvc->printf(false, "\tClumplet End\t\t%d\n", header->hdr_end); |
| 91 |
#endif |
| 92 |
|
| 93 |
if (page == HEADER_PAGE) |
| 94 |
{ |
| 95 |
|
| 96 |
// If the database dialect is not set to 3, then we need to |
| 97 |
// assume it was set to 1. The reason for this is that a dialect |
| 98 |
// 1 database has no dialect information written to the header. |
| 99 |
if (header->hdr_flags & hdr_SQL_dialect_3) |
| 100 |
uSvc->printf(false, "\tDatabase dialect\t3\n"); |
| 101 |
else |
| 102 |
uSvc->printf(false, "\tDatabase dialect\t1\n"); |
| 103 |
|
| 104 |
if (!nocreation) |
| 105 |
{ |
| 106 |
struct tm time; |
| 107 |
isc_decode_timestamp(reinterpret_cast<const ISC_TIMESTAMP*>(header->hdr_creation_date), |
| 108 |
&time); |
| 109 |
uSvc->printf(false, "\tCreation date\t\t%s %d, %d %d:%02d:%02d\n", |
| 110 |
FB_SHORT_MONTHS[time.tm_mon], time.tm_mday, time.tm_year + 1900, |
| 111 |
time.tm_hour, time.tm_min, time.tm_sec); |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
ULONG flags; |
| 116 |
if ((page == HEADER_PAGE) && (flags = header->hdr_flags)) |
| 117 |
{ |
| 118 |
int flag_count = 0; |
| 119 |
|
| 120 |
uSvc->printf(false, "\tAttributes\t\t"); |
| 121 |
if (flags & hdr_force_write) |
| 122 |
{ |
| 123 |
uSvc->printf(false, "force write"); |
| 124 |
flag_count++; |
| 125 |
} |
| 126 |
if (flags & hdr_no_reserve) |
| 127 |
{ |
| 128 |
if (flag_count++) |
| 129 |
uSvc->printf(false, ", "); |
| 130 |
uSvc->printf(false, "no reserve"); |
| 131 |
} |
| 132 |
/* |
| 133 |
if (flags & hdr_disable_cache) |
| 134 |
{ |
| 135 |
if (flag_count++) |
| 136 |
uSvc->printf(false, ", "); |
| 137 |
uSvc->printf(false, "shared cache disabled"); |
| 138 |
} |
| 139 |
*/ |
| 140 |
if (flags & hdr_active_shadow) |
| 141 |
{ |
| 142 |
if (flag_count++) |
| 143 |
uSvc->printf(false, ", "); |
| 144 |
uSvc->printf(false, "active shadow"); |
| 145 |
} |
| 146 |
|
| 147 |
if (flags & hdr_encrypted) |
| 148 |
{ |
| 149 |
if (flag_count++) |
| 150 |
uSvc->printf(false, ", "); |
| 151 |
uSvc->printf(false, "encrypted"); |
| 152 |
} |
| 153 |
|
| 154 |
if (flags & hdr_crypt_process) |
| 155 |
{ |
| 156 |
if (flag_count++) |
| 157 |
uSvc->printf(false, ", "); |
| 158 |
uSvc->printf(false, "crypt process"); |
| 159 |
} |
| 160 |
|
| 161 |
if (flags & (hdr_encrypted | hdr_crypt_process)) |
| 162 |
{ |
| 163 |
if (flag_count++) |
| 164 |
uSvc->printf(false, ", "); |
| 165 |
uSvc->printf(false, "plugin %s", header->hdr_crypt_plugin); |
| 166 |
} |
| 167 |
|
| 168 |
if (flags & hdr_shutdown_mask) |
| 169 |
{ |
| 170 |
if (flag_count++) |
| 171 |
uSvc->printf(false, ", "); |
| 172 |
switch (flags & hdr_shutdown_mask) |
| 173 |
{ |
| 174 |
case hdr_shutdown_multi: |
| 175 |
uSvc->printf(false, "multi-user maintenance"); |
| 176 |
break; |
| 177 |
case hdr_shutdown_single: |
| 178 |
uSvc->printf(false, "single-user maintenance"); |
| 179 |
break; |
| 180 |
case hdr_shutdown_full: |
| 181 |
uSvc->printf(false, "full shutdown"); |
| 182 |
break; |
| 183 |
default: |
| 184 |
uSvc->printf(false, "wrong shutdown state %d", flags & hdr_shutdown_mask); |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
if (flags & hdr_read_only) |
| 189 |
{ |
| 190 |
if (flag_count++) |
| 191 |
uSvc->printf(false, ", "); |
| 192 |
uSvc->printf(false, "read only"); |
| 193 |
} |
| 194 |
if (flags & hdr_backup_mask) |
| 195 |
{ |
| 196 |
if (flag_count++) |
| 197 |
uSvc->printf(false, ", "); |
| 198 |
switch (flags & hdr_backup_mask) |
| 199 |
{ |
| 200 |
case Ods::hdr_nbak_stalled: |
| 201 |
uSvc->printf(false, "backup lock"); |
| 202 |
break; |
| 203 |
case Ods::hdr_nbak_merge: |
| 204 |
uSvc->printf(false, "backup merge"); |
| 205 |
break; |
| 206 |
default: |
| 207 |
uSvc->printf(false, "wrong backup state %d", flags & hdr_backup_mask); |
| 208 |
} |
| 209 |
} |
| 210 |
uSvc->printf(false, "\n"); |
| 211 |
} |
| 212 |
|
| 213 |
uSvc->printf(false, "\n Variable header data:\n"); |
| 214 |
|
| 215 |
TEXT temp[257]; |
| 216 |
|
| 217 |
const UCHAR* p = header->hdr_data; |
| 218 |
for (const UCHAR* const end = p + header->hdr_page_size; p < end && *p != HDR_end; p += 2 + p[1]) |
| 219 |
{ |
| 220 |
SLONG number; |
| 221 |
|
| 222 |
switch (*p) |
| 223 |
{ |
| 224 |
case HDR_root_file_name: |
| 225 |
memcpy(temp, p + 2, p[1]); |
| 226 |
temp[p[1]] = '\0'; |
| 227 |
uSvc->printf(false, "\tRoot file name:\t\t%s\n", temp); |
| 228 |
break; |
| 229 |
|
| 230 |
case HDR_file: |
| 231 |
memcpy(temp, p + 2, p[1]); |
| 232 |
temp[p[1]] = '\0'; |
| 233 |
uSvc->printf(false, "\tContinuation file:\t\t%s\n", temp); |
| 234 |
break; |
| 235 |
|
| 236 |
case HDR_last_page: |
| 237 |
memcpy(&number, p + 2, sizeof(number)); |
| 238 |
uSvc->printf(false, "\tLast logical page:\t\t%ld\n", number); |
| 239 |
break; |
| 240 |
|
| 241 |
case HDR_sweep_interval: |
| 242 |
memcpy(&number, p + 2, sizeof(number)); |
| 243 |
uSvc->printf(false, "\tSweep interval:\t\t%ld\n", number); |
| 244 |
break; |
| 245 |
|
| 246 |
case HDR_difference_file: |
| 247 |
memcpy(temp, p + 2, p[1]); |
| 248 |
temp[p[1]] = '\0'; |
| 249 |
uSvc->printf(false, "\tBackup difference file:\t%s\n", temp); |
| 250 |
break; |
| 251 |
|
| 252 |
case HDR_backup_guid: |
| 253 |
{ |
| 254 |
char buff[Firebird::GUID_BUFF_SIZE]; |
| 255 |
Firebird::GuidToString(buff, reinterpret_cast<const Guid*>(p + 2)); |
| 256 |
uSvc->printf(false, "\tDatabase backup GUID:\t%s\n", buff); |
| 257 |
break; |
| 258 |
} |
| 259 |
|
| 260 |
case HDR_crypt_key: |
| 261 |
uSvc->printf(false, "\tEncryption key name:\t%*.*s\n", p[1], p[1], p + 2); |
| 262 |
break; |
| 263 |
|
| 264 |
case HDR_crypt_hash: |
| 265 |
uSvc->printf(false, "\tKey hash:\t%*.*s\n", p[1], p[1], p + 2); |
| 266 |
break; |
| 267 |
|
| 268 |
case HDR_crypt_checksum: |
| 269 |
uSvc->printf(false, "\tCrypt checksum:\t%*.*s\n", p[1], p[1], p + 2); |
| 270 |
break; |
| 271 |
|
| 272 |
default: |
| 273 |
if (*p > HDR_max) |
| 274 |
uSvc->printf(false, "\tUnrecognized option %d, length %d\n", p[0], p[1]); |
| 275 |
else |
| 276 |
uSvc->printf(false, "\tEncoded option %d, length %d\n", p[0], p[1]); |
| 277 |
break; |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
uSvc->printf(false, "\t*END*\n"); |
| 282 |
} |