int pageSize;
int usableSize;
ISqlJetMemoryPointer page1 = pPage1.aData;
rc = SqlJetErrorCode.NOTADB;
if (SqlJetUtility.memcmp(page1, zMagicHeader, 16) != 0) {
throw new SqlJetException(rc);
}
if (SqlJetUtility.getUnsignedByte(page1, 18) > 1) {
pBt.readOnly = true;
}
if (SqlJetUtility.getUnsignedByte(page1, 19) > 1) {
throw new SqlJetException(rc);
}
/*
* The maximum embedded fraction must be exactly 25%. And the
* minimum embedded fraction must be 12.5% for both leaf-data
* and non-leaf-data. The original design allowed these amounts
* to vary, but as of version 3.6.0, we require them to be
* fixed.
*/
if (SqlJetUtility.memcmp(page1, 21, PAGE1_21, 0, 3) != 0) {
throw new SqlJetException(rc);
}
pageSize = SqlJetUtility.get2byte(page1, 16);
if (((pageSize - 1) & pageSize) != 0 || pageSize < ISqlJetLimits.SQLJET_MIN_PAGE_SIZE
|| (ISqlJetLimits.SQLJET_MAX_PAGE_SIZE < 32768)) {
throw new SqlJetException(rc);
}
assert ((pageSize & 7) == 0);
usableSize = pageSize - SqlJetUtility.getUnsignedByte(page1, 20);
if (pageSize != pBt.pageSize) {
/*
* After reading the first page of the database assuming a
* page size of BtShared.pageSize, we have discovered that
* the page-size is actually pageSize. Unlock the database,
* leave pBt->pPage1 at zero and return SQLITE_OK. The
* caller will call this function again with the correct
* page-size.
*/
SqlJetMemPage.releasePage(pPage1);
pBt.usableSize = usableSize;
pBt.pageSize = pageSize;
freeTempSpace(pBt);
pBt.pageSize = pBt.pPager.setPageSize(pBt.pageSize);
return;
}
if (usableSize < 500) {
throw new SqlJetException(rc);
}
pBt.pageSize = pageSize;
pBt.usableSize = usableSize;
pBt.autoVacuum = (SqlJetUtility.get4byte(page1, 36 + 4 * 4) > 0);
pBt.incrVacuum = (SqlJetUtility.get4byte(page1, 36 + 7 * 4) > 0);