mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 23:23:04 +01:00
Backported CORE-5796: gstat may produce faulty report about presence of some none-encrypted pages in database
This commit is contained in:
parent
7e42941523
commit
b5ad1ec5cf
@ -184,6 +184,7 @@ static bool analyze_data_page(dba_rel*, const data_page*, bool);
|
||||
static ULONG analyze_fragments(dba_rel*, const rhdf*);
|
||||
static ULONG analyze_versions(dba_rel*, const rhdf*);
|
||||
static void analyze_index(const dba_rel*, dba_idx*);
|
||||
static ULONG lastUsedPage(ULONG);
|
||||
|
||||
#if (defined WIN_NT)
|
||||
static void db_error(SLONG);
|
||||
@ -716,7 +717,8 @@ int gstat(Firebird::UtilSvc* uSvc)
|
||||
};
|
||||
Statist data, index, blob, other;
|
||||
|
||||
for (page = 0; true; ++page)
|
||||
ULONG last = lastUsedPage(header->hdr_page_size);
|
||||
for (page = 0; page <= last; ++page)
|
||||
{
|
||||
const pag* p = db_read(page, true);
|
||||
if (!p)
|
||||
@ -1212,6 +1214,59 @@ int gstat(Firebird::UtilSvc* uSvc)
|
||||
}
|
||||
|
||||
|
||||
static ULONG lastUsedPage(ULONG pageSize)
|
||||
{
|
||||
const ULONG pipFirst = FIRST_PIP_PAGE;
|
||||
ULONG pipLast = pipFirst;
|
||||
ULONG pagesPerPIP = Ods::pagesPerPIP(pageSize);
|
||||
ULONG bytesBitPIP = Ods::bytesBitPIP(pageSize);
|
||||
page_inv_page* pip;
|
||||
|
||||
while (true)
|
||||
{
|
||||
const pag* page = db_read(pipLast, true);
|
||||
if (page->pag_type != pag_pages)
|
||||
{
|
||||
tdba* tddba = tdba::getSpecific();
|
||||
tddba->uSvc->printf(true, "Expected page inventory page %" ULONGFORMAT, pipLast);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pip = (page_inv_page*) page;
|
||||
if (pip->pip_used != pagesPerPIP)
|
||||
break;
|
||||
|
||||
UCHAR lastByte = pip->pip_bits[bytesBitPIP - 1];
|
||||
if (lastByte & 0x80)
|
||||
break;
|
||||
|
||||
if (pipLast == pipFirst)
|
||||
pipLast = pagesPerPIP - 1;
|
||||
else
|
||||
pipLast += pagesPerPIP;
|
||||
}
|
||||
|
||||
int last_bit = pip->pip_used;
|
||||
int byte_num = last_bit / 8;
|
||||
UCHAR mask = 1 << (last_bit % 8);
|
||||
while (last_bit >= 0 && (pip->pip_bits[byte_num] & mask))
|
||||
{
|
||||
if (mask == 1)
|
||||
{
|
||||
mask = 0x80;
|
||||
byte_num--;
|
||||
//fb_assert(byte_num > -1); ???
|
||||
}
|
||||
else
|
||||
mask >>= 1;
|
||||
|
||||
last_bit--;
|
||||
}
|
||||
|
||||
return last_bit + (pipLast == pipFirst ? 0 : pipLast);
|
||||
}
|
||||
|
||||
|
||||
static char* alloc(size_t size)
|
||||
{
|
||||
/**************************************
|
||||
|
Loading…
Reference in New Issue
Block a user