Lines Matching refs:pPage
17564 sqlite3_pcache_page *pPage; /* Pcache object page handle */ member
17634 SQLITE_PRIVATE PgHdr *sqlite3PcacheFetchFinish(PCache*, Pgno, sqlite3_pcache_page *pPage);
20674 void *pPage; /* Page cache memory */ member
30893 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512 in sqlite3MallocInit()
30895 sqlite3GlobalConfig.pPage = 0; in sqlite3MallocInit()
54342 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
54345 UNUSED_PARAMETER(pPage);
54633 DbPage *pPage = 0; local
54635 rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pPage, 0);
54637 memcpy(pTo, sqlite3PagerGetData(pPage), szPage);
54641 sqlite3PagerUnref(pPage);
55263 if( pLower && ((PgHdr*)pLower)->pPage==0 ){
55363 static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
55364 PCache *p = pPage->pCache;
55368 pPage->pgno));
55370 assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
55371 assert( pPage->pDirtyPrev || pPage==p->pDirty );
55374 if( p->pSynced==pPage ){
55375 p->pSynced = pPage->pDirtyPrev;
55378 if( pPage->pDirtyNext ){
55379 pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
55381 assert( pPage==p->pDirtyTail );
55382 p->pDirtyTail = pPage->pDirtyPrev;
55384 if( pPage->pDirtyPrev ){
55385 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
55391 assert( pPage==p->pDirty );
55392 p->pDirty = pPage->pDirtyNext;
55401 pPage->pDirtyPrev = 0;
55402 pPage->pDirtyNext = p->pDirty;
55403 if( pPage->pDirtyNext ){
55404 assert( pPage->pDirtyNext->pDirtyPrev==0 );
55405 pPage->pDirtyNext->pDirtyPrev = pPage;
55407 p->pDirtyTail = pPage;
55413 p->pDirty = pPage;
55421 && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
55423 p->pSynced = pPage;
55436 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
55672 sqlite3_pcache_page *pPage /* Page obtained by prior PcacheFetch() call */
55675 assert( pPage!=0 );
55676 pPgHdr = (PgHdr*)pPage->pExtra;
55677 assert( pPgHdr->pPage==0 );
55679 pPgHdr->pPage = pPage;
55680 pPgHdr->pData = pPage->pBuf;
55687 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
55699 sqlite3_pcache_page *pPage /* Page obtained by prior PcacheFetch() call */
55703 assert( pPage!=0 );
55704 pPgHdr = (PgHdr *)pPage->pExtra;
55706 if( !pPgHdr->pPage ){
55707 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
55754 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
55847 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
56661 PgHdr1 *pPage; local
56663 while( (pPage = pNext)!=0 ){
56664 unsigned int h = pPage->iKey % nNew;
56665 pNext = pPage->pNext;
56666 pPage->pNext = apNew[h];
56667 apNew[h] = pPage;
56683 static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){
56684 assert( pPage!=0 );
56685 assert( PAGE_IS_UNPINNED(pPage) );
56686 assert( pPage->pLruNext );
56687 assert( pPage->pLruPrev );
56688 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
56689 pPage->pLruPrev->pLruNext = pPage->pLruNext;
56690 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
56691 pPage->pLruNext = 0;
56694 assert( pPage->isAnchor==0 );
56695 assert( pPage->pCache->pGroup->lru.isAnchor==1 );
56696 pPage->pCache->nRecyclable--;
56697 return pPage;
56708 static void pcache1RemoveFromHash(PgHdr1 *pPage, int freeFlag){
56710 PCache1 *pCache = pPage->pCache;
56714 h = pPage->iKey % pCache->nHash;
56715 for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
56719 if( freeFlag ) pcache1FreePage(pPage);
56776 PgHdr1 *pPage; local
56779 while( (pPage = *pp)!=0 ){
56780 if( pPage->iKey>=iLimit ){
56782 *pp = pPage->pNext;
56783 if( PAGE_IS_UNPINNED(pPage) ) pcache1PinPage(pPage);
56784 pcache1FreePage(pPage);
56786 pp = &pPage->pNext;
56825 pcache1.separateCache = sqlite3GlobalConfig.pPage==0
56828 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
56839 && sqlite3GlobalConfig.pPage==0
56986 PgHdr1 *pPage = 0; local
57010 pPage = pGroup->lru.pLruPrev;
57011 assert( PAGE_IS_UNPINNED(pPage) );
57012 pcache1RemoveFromHash(pPage, 0);
57013 pcache1PinPage(pPage);
57014 pOther = pPage->pCache;
57016 pcache1FreePage(pPage);
57017 pPage = 0;
57026 if( !pPage ){
57027 pPage = pcache1AllocPage(pCache, createFlag==1);
57030 if( pPage ){
57033 pPage->iKey = iKey;
57034 pPage->pNext = pCache->apHash[h];
57035 pPage->pCache = pCache;
57036 pPage->pLruNext = 0;
57039 *(void **)pPage->page.pExtra = 0;
57040 pCache->apHash[h] = pPage;
57045 return pPage;
57113 PgHdr1 *pPage = 0; local
57116 pPage = pCache->apHash[iKey % pCache->nHash];
57117 while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; }
57123 if( pPage ){
57124 if( PAGE_IS_UNPINNED(pPage) ){
57125 return pcache1PinPage(pPage);
57127 return pPage;
57143 PgHdr1 *pPage; local
57146 pPage = pcache1FetchNoMutex(p, iKey, createFlag);
57147 assert( pPage==0 || pCache->iMaxKey>=iKey );
57149 return pPage;
57189 PgHdr1 *pPage = (PgHdr1 *)pPg; local
57192 assert( pPage->pCache==pCache );
57198 assert( pPage->pLruNext==0 );
57199 assert( PAGE_IS_PINNED(pPage) );
57202 pcache1RemoveFromHash(pPage, 1);
57206 pPage->pLruPrev = &pGroup->lru;
57207 (pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
57208 *ppFirst = pPage;
57225 PgHdr1 *pPage = (PgHdr1 *)pPg; local
57228 assert( pPage->iKey==iOld );
57229 assert( pPage->pCache==pCache );
57234 assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
57237 while( (*pp)!=pPage ){
57240 *pp = pPage->pNext;
57244 pPage->iKey = iNew;
57245 pPage->pNext = pCache->apHash[hNew];
57246 pCache->apHash[hNew] = pPage;
57345 if( sqlite3GlobalConfig.pPage==0 ){
59303 static u32 pager_pagehash(PgHdr *pPage){
59304 return pager_datahash(pPage->pPager->pageSize, (unsigned char *)pPage->pData);
59306 static void pager_set_pagehash(PgHdr *pPage){
59307 pPage->pageHash = pager_pagehash(pPage);
62140 assert( p->pPage==0 );
63800 sqlite3_pcache_page *pPage; local
63804 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
63805 assert( pPage==0 || pPager->hasHeldSharedLock );
63806 if( pPage==0 ) return 0;
63807 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
64218 PgHdr *pPage; local
64221 rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
64223 rc = pager_write(pPage);
64224 if( pPage->flags&PGHDR_NEED_SYNC ){
64227 sqlite3PagerUnrefNotNull(pPage);
64230 }else if( (pPage = sqlite3PagerLookup(pPager, pg))!=0 ){
64231 if( pPage->flags&PGHDR_NEED_SYNC ){
64234 sqlite3PagerUnrefNotNull(pPage);
64247 PgHdr *pPage = sqlite3PagerLookup(pPager, pg1+ii); local
64248 if( pPage ){
64249 pPage->flags |= PGHDR_NEED_SYNC;
64250 sqlite3PagerUnrefNotNull(pPage);
64886 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *pPage){
64887 return sqlite3PcachePageRefcount(pPage);
69819 PgHdr *pPage, /* The page of the frame to be written */
69826 pData = pPage->pData;
69827 walEncodeFrame(p->pWal, pPage->pgno, nTruncate, pData, aFrame);
71070 MemPage *pPage; /* Current page */ member
72083 static void releasePage(MemPage *pPage); /* Forward reference */
72084 static void releasePageOne(MemPage *pPage); /* Forward reference */
72085 static void releasePageNotNull(MemPage *pPage); /* Forward reference */
72248 releasePageNotNull(pCur->pPage);
72731 MemPage *pPage, /* Page containing the cell */
72748 minLocal = pPage->minLocal;
72749 maxLocal = pPage->maxLocal;
72750 surplus = minLocal + (pInfo->nPayload - minLocal)%(pPage->pBt->usableSize-4);
72765 static int btreePayloadToLocal(MemPage *pPage, i64 nPayload){
72767 maxLocal = pPage->maxLocal;
72774 minLocal = pPage->minLocal;
72775 surplus = (int)(minLocal +(nPayload - minLocal)%(pPage->pBt->usableSize-4));
72795 MemPage *pPage, /* Page containing the cell */
72799 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
72800 assert( pPage->leaf==0 );
72801 assert( pPage->childPtrSize==4 );
72803 UNUSED_PARAMETER(pPage);
72812 MemPage *pPage, /* Page containing the cell */
72820 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
72821 assert( pPage->leaf==0 || pPage->leaf==1 );
72822 assert( pPage->intKeyLeaf );
72823 assert( pPage->childPtrSize==0 );
72884 testcase( nPayload==pPage->maxLocal );
72885 testcase( nPayload==(u32)pPage->maxLocal+1 );
72887 assert( pPage->maxLocal <= BT_MAX_LOCAL );
72888 if( nPayload<=pPage->maxLocal ){
72896 btreeParseCellAdjustSizeForOverflow(pPage, pCell, pInfo);
72900 MemPage *pPage, /* Page containing the cell */
72907 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
72908 assert( pPage->leaf==0 || pPage->leaf==1 );
72909 assert( pPage->intKeyLeaf==0 );
72910 pIter = pCell + pPage->childPtrSize;
72923 testcase( nPayload==pPage->maxLocal );
72924 testcase( nPayload==(u32)pPage->maxLocal+1 );
72926 assert( pPage->maxLocal <= BT_MAX_LOCAL );
72927 if( nPayload<=pPage->maxLocal ){
72935 btreeParseCellAdjustSizeForOverflow(pPage, pCell, pInfo);
72939 MemPage *pPage, /* Page containing the cell */
72943 pPage->xParseCell(pPage, findCell(pPage, iCell), pInfo);
72960 static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
72971 pPage->xParseCell(pPage, pCell, &debuginfo);
72974 assert( pPage->childPtrSize==4 );
72984 testcase( nSize==pPage->maxLocal );
72985 testcase( nSize==(u32)pPage->maxLocal+1 );
72986 if( nSize<=pPage->maxLocal ){
72990 int minLocal = pPage->minLocal;
72991 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
72992 testcase( nSize==pPage->maxLocal );
72993 testcase( nSize==(u32)pPage->maxLocal+1 );
72994 if( nSize>pPage->maxLocal ){
73002 static u16 cellSizePtrIdxLeaf(MemPage *pPage, u8 *pCell){
73013 pPage->xParseCell(pPage, pCell, &debuginfo);
73016 assert( pPage->childPtrSize==0 );
73026 testcase( nSize==pPage->maxLocal );
73027 testcase( nSize==(u32)pPage->maxLocal+1 );
73028 if( nSize<=pPage->maxLocal ){
73032 int minLocal = pPage->minLocal;
73033 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
73034 testcase( nSize==pPage->maxLocal );
73035 testcase( nSize==(u32)pPage->maxLocal+1 );
73036 if( nSize>pPage->maxLocal ){
73044 static u16 cellSizePtrNoPayload(MemPage *pPage, u8 *pCell){
73054 pPage->xParseCell(pPage, pCell, &debuginfo);
73056 UNUSED_PARAMETER(pPage);
73059 assert( pPage->childPtrSize==4 );
73065 static u16 cellSizePtrTableLeaf(MemPage *pPage, u8 *pCell){
73076 pPage->xParseCell(pPage, pCell, &debuginfo);
73099 testcase( nSize==pPage->maxLocal );
73100 testcase( nSize==(u32)pPage->maxLocal+1 );
73101 if( nSize<=pPage->maxLocal ){
73105 int minLocal = pPage->minLocal;
73106 nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
73107 testcase( nSize==pPage->maxLocal );
73108 testcase( nSize==(u32)pPage->maxLocal+1 );
73109 if( nSize>pPage->maxLocal ){
73122 static u16 cellSize(MemPage *pPage, int iCell){
73123 return pPage->xCellSize(pPage, findCell(pPage, iCell));
73134 static void ptrmapPutOvflPtr(MemPage *pPage, MemPage *pSrc, u8 *pCell,int *pRC){
73138 pPage->xParseCell(pPage, pCell, &info);
73142 testcase( pSrc!=pPage );
73147 ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, pRC);
73165 static int defragmentPage(MemPage *pPage, int nMaxFrag){
73181 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
73182 assert( pPage->pBt!=0 );
73183 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
73184 assert( pPage->nOverflow==0 );
73185 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73186 data = pPage->aData;
73187 hdr = pPage->hdrOffset;
73188 cellOffset = pPage->cellOffset;
73189 nCell = pPage->nCell;
73192 usableSize = pPage->pBt->usableSize;
73201 if( iFree>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
73204 if( iFree2>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
73212 return SQLITE_CORRUPT_PAGE(pPage);
73215 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
73217 if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
73221 return SQLITE_CORRUPT_PAGE(pPage);
73241 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
73254 return SQLITE_CORRUPT_PAGE(pPage);
73257 size = pPage->xCellSize(pPage, &src[pc]);
73260 return SQLITE_CORRUPT_PAGE(pPage);
73272 assert( pPage->nFree>=0 );
73273 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
73274 return SQLITE_CORRUPT_PAGE(pPage);
73281 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
73371 static SQLITE_INLINE int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
73372 const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
73373 u8 * const data = pPage->aData; /* Local cache of pPage->aData */
73379 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
73380 assert( pPage->pBt );
73381 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73383 assert( pPage->nFree>=nByte );
73384 assert( pPage->nOverflow==0 );
73385 assert( nByte < (int)(pPage->pBt->usableSize-8) );
73387 assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
73388 gap = pPage->cellOffset + 2*pPage->nCell;
73398 if( top==0 && pPage->pBt->usableSize==65536 ){
73401 return SQLITE_CORRUPT_PAGE(pPage);
73403 }else if( top>(int)pPage->pBt->usableSize ){
73404 return SQLITE_CORRUPT_PAGE(pPage);
73415 u8 *pSpace = pageFindSlot(pPage, nByte, &rc);
73418 assert( pSpace+nByte<=data+pPage->pBt->usableSize );
73421 return SQLITE_CORRUPT_PAGE(pPage);
73435 assert( pPage->nCell>0 || CORRUPT_DB );
73436 assert( pPage->nFree>=0 );
73437 rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
73452 assert( top+nByte <= (int)pPage->pBt->usableSize );
73470 static int freeSpace(MemPage *pPage, int iStart, int iSize){
73478 unsigned char *data = pPage->aData; /* Page content */
73481 assert( pPage->pBt!=0 );
73482 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
73483 assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
73484 assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
73485 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73487 assert( CORRUPT_DB || iStart<=pPage->pBt->usableSize-4 );
73492 hdr = pPage->hdrOffset;
73500 return SQLITE_CORRUPT_PAGE(pPage);
73504 if( iFreeBlk>(int)pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
73505 return SQLITE_CORRUPT_PAGE(pPage);
73517 if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
73519 if( iEnd > (int)pPage->pBt->usableSize ){
73520 return SQLITE_CORRUPT_PAGE(pPage);
73533 if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PAGE(pPage);
73539 if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage);
73544 if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){
73553 if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage);
73554 if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage);
73564 pPage->nFree += iOrigSize;
73580 static int decodeFlags(MemPage *pPage, int flagByte){
73583 assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
73584 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73585 pBt = pPage->pBt;
73586 pPage->max1bytePayload = pBt->max1bytePayload;
73588 pPage->childPtrSize = 0;
73589 pPage->leaf = 1;
73591 pPage->intKeyLeaf = 1;
73592 pPage->xCellSize = cellSizePtrTableLeaf;
73593 pPage->xParseCell = btreeParseCellPtr;
73594 pPage->intKey = 1;
73595 pPage->maxLocal = pBt->maxLeaf;
73596 pPage->minLocal = pBt->minLeaf;
73598 pPage->intKey = 0;
73599 pPage->intKeyLeaf = 0;
73600 pPage->xCellSize = cellSizePtrIdxLeaf;
73601 pPage->xParseCell = btreeParseCellPtrIndex;
73602 pPage->maxLocal = pBt->maxLocal;
73603 pPage->minLocal = pBt->minLocal;
73605 pPage->intKey = 0;
73606 pPage->intKeyLeaf = 0;
73607 pPage->xCellSize = cellSizePtrIdxLeaf;
73608 pPage->xParseCell = btreeParseCellPtrIndex;
73609 return SQLITE_CORRUPT_PAGE(pPage);
73612 pPage->childPtrSize = 4;
73613 pPage->leaf = 0;
73615 pPage->intKey = 0;
73616 pPage->intKeyLeaf = 0;
73617 pPage->xCellSize = cellSizePtr;
73618 pPage->xParseCell = btreeParseCellPtrIndex;
73619 pPage->maxLocal = pBt->maxLocal;
73620 pPage->minLocal = pBt->minLocal;
73622 pPage->intKeyLeaf = 0;
73623 pPage->xCellSize = cellSizePtrNoPayload;
73624 pPage->xParseCell = btreeParseCellPtrNoPayload;
73625 pPage->intKey = 1;
73626 pPage->maxLocal = pBt->maxLeaf;
73627 pPage->minLocal = pBt->minLeaf;
73629 pPage->intKey = 0;
73630 pPage->intKeyLeaf = 0;
73631 pPage->xCellSize = cellSizePtr;
73632 pPage->xParseCell = btreeParseCellPtrIndex;
73633 return SQLITE_CORRUPT_PAGE(pPage);
73643 static int btreeComputeFreeSpace(MemPage *pPage){
73653 assert( pPage->pBt!=0 );
73654 assert( pPage->pBt->db!=0 );
73655 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73656 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
73657 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
73658 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
73659 assert( pPage->isInit==1 );
73660 assert( pPage->nFree<0 );
73662 usableSize = pPage->pBt->usableSize;
73663 hdr = pPage->hdrOffset;
73664 data = pPage->aData;
73669 iCellFirst = hdr + 8 + pPage->childPtrSize + 2*pPage->nCell;
73684 return SQLITE_CORRUPT_PAGE(pPage);
73689 return SQLITE_CORRUPT_PAGE(pPage);
73699 return SQLITE_CORRUPT_PAGE(pPage);
73703 return SQLITE_CORRUPT_PAGE(pPage);
73715 return SQLITE_CORRUPT_PAGE(pPage);
73717 pPage->nFree = (u16)(nFree - iCellFirst);
73725 static SQLITE_NOINLINE int btreeCellSizeCheck(MemPage *pPage){
73735 iCellFirst = pPage->cellOffset + 2*pPage->nCell;
73736 usableSize = pPage->pBt->usableSize;
73738 data = pPage->aData;
73739 cellOffset = pPage->cellOffset;
73740 if( !pPage->leaf ) iCellLast--;
73741 for(i=0; i<pPage->nCell; i++){
73746 return SQLITE_CORRUPT_PAGE(pPage);
73748 sz = pPage->xCellSize(pPage, &data[pc]);
73751 return SQLITE_CORRUPT_PAGE(pPage);
73766 static int btreeInitPage(MemPage *pPage){
73770 assert( pPage->pBt!=0 );
73771 assert( pPage->pBt->db!=0 );
73772 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73773 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
73774 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
73775 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
73776 assert( pPage->isInit==0 );
73778 pBt = pPage->pBt;
73779 data = pPage->aData + pPage->hdrOffset;
73782 if( decodeFlags(pPage, data[0]) ){
73783 return SQLITE_CORRUPT_PAGE(pPage);
73786 pPage->maskPage = (u16)(pBt->pageSize - 1);
73787 pPage->nOverflow = 0;
73788 pPage->cellOffset = (u16)(pPage->hdrOffset + 8 + pPage->childPtrSize);
73789 pPage->aCellIdx = data + pPage->childPtrSize + 8;
73790 pPage->aDataEnd = pPage->aData + pBt->pageSize;
73791 pPage->aDataOfst = pPage->aData + pPage->childPtrSize;
73794 pPage->nCell = get2byte(&data[3]);
73795 if( pPage->nCell>MX_CELL(pBt) ){
73797 return SQLITE_CORRUPT_PAGE(pPage);
73799 testcase( pPage->nCell==MX_CELL(pBt) );
73804 assert( pPage->nCell>0
73807 pPage->nFree = -1; /* Indicate that this value is yet uncomputed */
73808 pPage->isInit = 1;
73810 return btreeCellSizeCheck(pPage);
73819 static void zeroPage(MemPage *pPage, int flags){
73820 unsigned char *data = pPage->aData;
73821 BtShared *pBt = pPage->pBt;
73822 int hdr = pPage->hdrOffset;
73825 assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB );
73826 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
73827 assert( sqlite3PagerGetData(pPage->pDbPage) == data );
73828 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
73838 pPage->nFree = (u16)(pBt->usableSize - first);
73839 decodeFlags(pPage, flags);
73840 pPage->cellOffset = (u16)first;
73841 pPage->aDataEnd = &data[pBt->pageSize];
73842 pPage->aCellIdx = &data[first];
73843 pPage->aDataOfst = &data[pPage->childPtrSize];
73844 pPage->nOverflow = 0;
73846 pPage->maskPage = (u16)(pBt->pageSize - 1);
73847 pPage->nCell = 0;
73848 pPage->isInit = 1;
73857 MemPage *pPage = (MemPage*)sqlite3PagerGetExtra(pDbPage); local
73858 if( pgno!=pPage->pgno ){
73859 pPage->aData = sqlite3PagerGetData(pDbPage);
73860 pPage->pDbPage = pDbPage;
73861 pPage->pBt = pBt;
73862 pPage->pgno = pgno;
73863 pPage->hdrOffset = pgno==1 ? 100 : 0;
73865 assert( pPage->aData==sqlite3PagerGetData(pDbPage) );
73866 return pPage;
73935 MemPage *pPage; local
73947 pPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
73948 if( pPage->isInit==0 ){
73950 rc = btreeInitPage(pPage);
73952 releasePage(pPage);
73957 assert( pPage->pgno==pgno || CORRUPT_DB );
73958 assert( pPage->aData==sqlite3PagerGetData(pDbPage) );
73959 *ppPage = pPage;
73969 static void releasePageNotNull(MemPage *pPage){
73970 assert( pPage->aData );
73971 assert( pPage->pBt );
73972 assert( pPage->pDbPage!=0 );
73973 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
73974 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
73975 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73976 sqlite3PagerUnrefNotNull(pPage->pDbPage);
73978 static void releasePage(MemPage *pPage){
73979 if( pPage ) releasePageNotNull(pPage);
73981 static void releasePageOne(MemPage *pPage){
73982 assert( pPage!=0 );
73983 assert( pPage->aData );
73984 assert( pPage->pBt );
73985 assert( pPage->pDbPage!=0 );
73986 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
73987 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
73988 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
73989 sqlite3PagerUnrefPageOne(pPage->pDbPage);
74031 MemPage *pPage; local
74032 pPage = (MemPage *)sqlite3PagerGetExtra(pData);
74034 if( pPage->isInit ){
74035 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
74036 pPage->isInit = 0;
74044 btreeInitPage(pPage);
75354 static int setChildPtrmaps(MemPage *pPage){
75358 BtShared *pBt = pPage->pBt;
75359 Pgno pgno = pPage->pgno;
75361 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
75362 rc = pPage->isInit ? SQLITE_OK : btreeInitPage(pPage);
75364 nCell = pPage->nCell;
75367 u8 *pCell = findCell(pPage, i);
75369 ptrmapPutOvflPtr(pPage, pPage, pCell, &rc);
75371 if( !pPage->leaf ){
75377 if( !pPage->leaf ){
75378 Pgno childPgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
75399 static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){
75400 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
75401 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
75404 if( get4byte(pPage->aData)!=iFrom ){
75405 return SQLITE_CORRUPT_PAGE(pPage);
75407 put4byte(pPage->aData, iTo);
75413 rc = pPage->isInit ? SQLITE_OK : btreeInitPage(pPage);
75415 nCell = pPage->nCell;
75418 u8 *pCell = findCell(pPage, i);
75421 pPage->xParseCell(pPage, pCell, &info);
75423 if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){
75424 return SQLITE_CORRUPT_PAGE(pPage);
75432 if( pCell+4 > pPage->aData+pPage->pBt->usableSize ){
75433 return SQLITE_CORRUPT_PAGE(pPage);
75444 get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
75445 return SQLITE_CORRUPT_PAGE(pPage);
75447 put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
76404 btreeParseCell(pCur->pPage, pCur->ix, &info);
76413 btreeParseCell(pCur->pPage,pCur->ix,&pCur->info);
76468 return (i64)pCur->pBt->pageSize*((i64)pCur->pPage->pgno - 1) +
76469 (i64)(pCur->info.pPayload - pCur->pPage->aData);
76533 MemPage *pPage = 0; local
76567 rc = btreeGetPage(pBt, ovfl, &pPage, (ppPage==0) ? PAGER_GET_READONLY : 0);
76568 assert( rc==SQLITE_OK || pPage==0 );
76570 next = get4byte(pPage->aData);
76576 *ppPage = pPage;
76578 releasePage(pPage);
76654 MemPage *pPage = pCur->pPage; /* Btree page of current entry */ local
76660 assert( pPage );
76663 if( pCur->ix>=pPage->nCell ){
76664 return SQLITE_CORRUPT_PAGE(pPage);
76672 assert( aPayload > pPage->aData );
76673 if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){
76679 return SQLITE_CORRUPT_PAGE(pPage);
76688 rc = copyPayload(&aPayload[offset], pBuf, a, eOp, pPage->pDbPage);
76834 return SQLITE_CORRUPT_PAGE(pPage);
76859 assert( pCur->iPage>=0 && pCur->pPage );
76917 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
76921 assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
76923 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
76924 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
76926 if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
76930 amt = MAX(0, (int)(pCur->pPage->aDataEnd - pCur->info.pPayload));
76977 pCur->apPage[pCur->iPage] = pCur->pPage;
76980 rc = getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur->curPagerFlags);
76981 assert( pCur->pPage!=0 || rc!=SQLITE_OK );
76983 && (pCur->pPage->nCell<1 || pCur->pPage->intKey!=pCur->curIntKey)
76985 releasePage(pCur->pPage);
76989 pCur->pPage = pCur->apPage[--pCur->iPage];
77029 assert( pCur->pPage );
77033 pCur->pPage->pgno
77039 pLeaf = pCur->pPage;
77040 pCur->pPage = pCur->apPage[--pCur->iPage];
77078 releasePageNotNull(pCur->pPage);
77082 pRoot = pCur->pPage = pCur->apPage[0];
77097 rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
77104 pCur->curIntKey = pCur->pPage->intKey;
77106 pRoot = pCur->pPage;
77121 return SQLITE_CORRUPT_PAGE(pCur->pPage);
77154 MemPage *pPage; local
77158 while( rc==SQLITE_OK && !(pPage = pCur->pPage)->leaf ){
77159 assert( pCur->ix<pPage->nCell );
77160 pgno = get4byte(findCell(pPage, pCur->ix));
77179 MemPage *pPage = 0; local
77183 while( !(pPage = pCur->pPage)->leaf ){
77184 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
77185 pCur->ix = pPage->nCell;
77189 pCur->ix = pPage->nCell-1;
77206 assert( pCur->pPage->nCell>0 );
77210 assert( pCur->pgnoRoot==0 || (pCur->pPage!=0 && pCur->pPage->nCell==0) );
77230 return pCur->ix==pCur->pPage->nCell-1 && pCur->pPage->leaf!=0;
77250 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77345 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77351 assert( pCur->pPage );
77352 assert( pCur->pPage->isInit );
77354 assert( pCur->pPage->nCell > 0 );
77361 MemPage *pPage = pCur->pPage; local
77370 assert( pPage->nCell>0 );
77371 assert( pPage->intKey );
77373 upr = pPage->nCell-1;
77378 pCell = findCellPastPtr(pPage, idx);
77379 if( pPage->intKeyLeaf ){
77381 if( pCell>=pPage->aDataEnd ){
77382 return SQLITE_CORRUPT_PAGE(pPage);
77396 if( !pPage->leaf ){
77410 assert( lwr==upr+1 || !pPage->leaf );
77411 assert( pPage->isInit );
77412 if( pPage->leaf ){
77413 assert( pCur->ix<pCur->pPage->nCell );
77420 if( lwr>=pPage->nCell ){
77421 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
77423 chldPg = get4byte(findCell(pPage, lwr));
77457 MemPage *pPage = pCur->pPage; local
77460 u8 *pCell = findCellPastPtr(pPage, idx);
77463 if( nCell<=pPage->max1bytePayload ){
77467 testcase( pCell+nCell+1==pPage->aDataEnd );
77470 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
77474 testcase( pCell+nCell+2==pPage->aDataEnd );
77492 MemPage *pPage = pCur->apPage[i]; local
77493 if( pCur->aiIdx[i]<pPage->nCell ) return 0;
77561 && pCur->pPage->leaf
77565 if( pCur->ix==pCur->pPage->nCell-1
77577 if( !pCur->pPage->isInit ){
77588 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
77596 assert( pCur->pPage );
77597 assert( pCur->pPage->isInit );
77599 assert( pCur->pPage->nCell > 0 );
77605 MemPage *pPage = pCur->pPage; local
77614 assert( pPage->nCell>0 );
77615 assert( pPage->intKey==0 );
77617 upr = pPage->nCell-1;
77621 pCell = findCellPastPtr(pPage, idx);
77632 if( nCell<=pPage->max1bytePayload ){
77636 testcase( pCell+nCell+1==pPage->aDataEnd );
77639 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
77643 testcase( pCell+nCell+2==pPage->aDataEnd );
77656 u8 * const pCellBody = pCell - pPage->childPtrSize;
77658 pPage->xParseCell(pPage, pCellBody, &pCur->info);
77665 rc = SQLITE_CORRUPT_PAGE(pPage);
77704 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
77705 assert( pPage->isInit );
77706 if( pPage->leaf ){
77707 assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
77713 if( lwr>=pPage->nCell ){
77714 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
77716 chldPg = get4byte(findCell(pPage, lwr));
77731 pCur->apPage[pCur->iPage] = pCur->pPage;
77734 rc = getAndInitPage(pCur->pBt, chldPg, &pCur->pPage, pCur->curPagerFlags);
77736 && (pCur->pPage->nCell<1 || pCur->pPage->intKey!=pCur->curIntKey)
77738 releasePage(pCur->pPage);
77742 pCur->pPage = pCur->apPage[--pCur->iPage];
77786 if( NEVER(pCur->pPage->leaf==0) ) return -1;
77788 n = pCur->pPage->nCell;
77818 MemPage *pPage; local
77836 pPage = pCur->pPage;
77838 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
77839 if( !pPage->isInit ){
77843 if( idx>=pPage->nCell ){
77844 if( !pPage->leaf ){
77845 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
77855 pPage = pCur->pPage;
77856 }while( pCur->ix>=pPage->nCell );
77857 if( pPage->intKey ){
77863 if( pPage->leaf ){
77870 MemPage *pPage; local
77877 pPage = pCur->pPage;
77878 if( (++pCur->ix)>=pPage->nCell ){
77882 if( pPage->leaf ){
77911 MemPage *pPage; local
77930 pPage = pCur->pPage;
77931 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
77932 if( !pPage->isInit ){
77935 if( !pPage->leaf ){
77937 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
77952 pPage = pCur->pPage;
77953 if( pPage->intKey && !pPage->leaf ){
77969 || pCur->pPage->leaf==0
78325 MemPage *pPage; /* Page being freed. May be NULL. */ local
78337 pPage = pMemPage;
78338 sqlite3PagerRef(pPage->pDbPage);
78340 pPage = btreePageLookup(pBt, iPage);
78353 if( (!pPage && ((rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0) )
78354 || ((rc = sqlite3PagerWrite(pPage->pDbPage))!=0)
78358 memset(pPage->aData, 0, pPage->pBt->pageSize);
78419 if( pPage && (pBt->btsFlags & BTS_SECURE_DELETE)==0 ){
78420 sqlite3PagerDontWrite(pPage->pDbPage);
78424 TRACE(("FREE-PAGE: %u leaf on trunk page %u\n",pPage->pgno,pTrunk->pgno));
78435 if( pPage==0 && SQLITE_OK!=(rc = btreeGetPage(pBt, iPage, &pPage, 0)) ){
78438 rc = sqlite3PagerWrite(pPage->pDbPage);
78442 put4byte(pPage->aData, iTrunk);
78443 put4byte(&pPage->aData[4], 0);
78445 TRACE(("FREE-PAGE: %u new trunk page replacing %u\n", pPage->pgno, iTrunk));
78448 if( pPage ){
78449 pPage->isInit = 0;
78451 releasePage(pPage);
78455 static void freePage(MemPage *pPage, int *pRC){
78457 *pRC = freePage2(pPage->pBt, pPage, pPage->pgno);
78465 MemPage *pPage, /* The page that contains the Cell */
78475 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
78477 testcase( pCell + pInfo->nSize == pPage->aDataEnd );
78478 testcase( pCell + (pInfo->nSize-1) == pPage->aDataEnd );
78479 if( pCell + pInfo->nSize > pPage->aDataEnd ){
78481 return SQLITE_CORRUPT_PAGE(pPage);
78484 pBt = pPage->pBt;
78538 #define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \ argument
78539 pPage->xParseCell(pPage, pCell, &sInfo); \
78541 rc = clearCellOverflow(pPage, pCell, &sInfo); \
78560 MemPage *pPage, /* The page that contains the cell */
78576 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
78580 assert( pCell<pPage->aData || pCell>=&pPage->aData[pPage->pBt->pageSize]
78581 || sqlite3PagerIswriteable(pPage->pDbPage) );
78584 nHeader = pPage->childPtrSize;
78585 if( pPage->intKey ){
78589 assert( pPage->intKeyLeaf ); /* fillInCell() only called for leaves */
78601 if( nPayload<=pPage->maxLocal ){
78622 mn = pPage->minLocal;
78623 n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
78624 testcase( n==pPage->maxLocal );
78625 testcase( n==pPage->maxLocal+1 );
78626 if( n > pPage->maxLocal ) n = mn;
78632 pBt = pPage->pBt;
78649 pPage->xParseCell(pPage, pCell, &info);
78668 assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
78669 || sqlite3PagerIswriteable(pPage->pDbPage) );
78728 assert( pPrior<pPage->aData || pPrior>=&pPage->aData[pBt->pageSize]
78729 || sqlite3PagerIswriteable(pPage->pDbPage) );
78752 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
78761 assert( idx<pPage->nCell );
78762 assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
78763 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
78764 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
78765 assert( pPage->nFree>=0 );
78766 data = pPage->aData;
78767 ptr = &pPage->aCellIdx[2*idx];
78768 assert( pPage->pBt->usableSize > (u32)(ptr-data) );
78770 hdr = pPage->hdrOffset;
78772 testcase( pc+sz==pPage->pBt->usableSize );
78773 if( pc+sz > pPage->pBt->usableSize ){
78777 rc = freeSpace(pPage, pc, sz);
78782 pPage->nCell--;
78783 if( pPage->nCell==0 ){
78786 put2byte(&data[hdr+5], pPage->pBt->usableSize);
78787 pPage->nFree = pPage->pBt->usableSize - pPage->hdrOffset
78788 - pPage->childPtrSize - 8;
78790 memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
78791 put2byte(&data[hdr+3], pPage->nCell);
78792 pPage->nFree += 2;
78817 MemPage *pPage, /* Page into which we are copying */
78829 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
78830 assert( MX_CELL(pPage->pBt)<=10921 );
78831 assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
78832 assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) );
78833 assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) );
78834 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
78835 assert( sz==pPage->xCellSize(pPage, pCell) || CORRUPT_DB );
78836 assert( pPage->nFree>=0 );
78838 if( pPage->nOverflow || sz+2>pPage->nFree ){
78844 j = pPage->nOverflow++;
78848 assert( j < ArraySize(pPage->apOvfl)-1 );
78849 pPage->apOvfl[j] = pCell;
78850 pPage->aiOvfl[j] = (u16)i;
78857 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
78858 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
78860 int rc = sqlite3PagerWrite(pPage->pDbPage);
78864 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
78865 data = pPage->aData;
78866 assert( &data[pPage->cellOffset]==pPage->aCellIdx );
78867 rc = allocateSpace(pPage, sz, &idx);
78872 assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB );
78873 assert( idx+sz <= (int)pPage->pBt->usableSize );
78874 pPage->nFree -= (u16)(2 + sz);
78882 pIns = pPage->aCellIdx + i*2;
78883 memmove(pIns+2, pIns, 2*(pPage->nCell - i));
78885 pPage->nCell++;
78887 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
78888 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
78890 if( pPage->pBt->autoVacuum ){
78895 ptrmapPutOvflPtr(pPage, pPage, pCell, &rc2);
78914 MemPage *pPage, /* Page into which we are copying */
78924 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
78925 assert( MX_CELL(pPage->pBt)<=10921 );
78926 assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
78927 assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) );
78928 assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) );
78929 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
78930 assert( sz==pPage->xCellSize(pPage, pCell) || CORRUPT_DB );
78931 assert( pPage->nFree>=0 );
78932 assert( pPage->nOverflow==0 );
78933 if( sz+2>pPage->nFree ){
78934 j = pPage->nOverflow++;
78938 assert( j < ArraySize(pPage->apOvfl)-1 );
78939 pPage->apOvfl[j] = pCell;
78940 pPage->aiOvfl[j] = (u16)i;
78947 assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
78948 assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */
78950 int rc = sqlite3PagerWrite(pPage->pDbPage);
78954 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
78955 data = pPage->aData;
78956 assert( &data[pPage->cellOffset]==pPage->aCellIdx );
78957 rc = allocateSpace(pPage, sz, &idx);
78962 assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB );
78963 assert( idx+sz <= (int)pPage->pBt->usableSize );
78964 pPage->nFree -= (u16)(2 + sz);
78966 pIns = pPage->aCellIdx + i*2;
78967 memmove(pIns+2, pIns, 2*(pPage->nCell - i));
78969 pPage->nCell++;
78971 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
78972 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
78974 if( pPage->pBt->autoVacuum ){
78979 ptrmapPutOvflPtr(pPage, pPage, pCell, &rc2);
79492 static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace){
79493 BtShared *const pBt = pPage->pBt; /* B-Tree Database */
79498 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
79500 assert( pPage->nOverflow==1 );
79502 if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; /* dbfuzz001.test */
79503 assert( pPage->nFree>=0 );
79515 u8 *pCell = pPage->apOvfl[0];
79516 u16 szCell = pPage->xCellSize(pPage, pCell);
79521 assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
79524 b.pRef = pPage;
79527 b.apEnd[0] = pPage->aDataEnd;
79566 pCell = findCell(pPage, pPage->nCell-1);
79575 0, pPage->pgno);
79600 MemPage *pPage = apPage[i]; local
79601 BtShared *pBt = pPage->pBt;
79602 assert( pPage->isInit );
79604 for(j=0; j<pPage->nCell; j++){
79608 z = findCell(pPage, j);
79609 pPage->xParseCell(pPage, z, &info);
79613 assert( n==pPage->pgno && e==PTRMAP_OVERFLOW1 );
79615 if( !pPage->leaf ){
79618 assert( n==pPage->pgno && e==PTRMAP_BTREE );
79621 if( !pPage->leaf ){
79622 Pgno child = get4byte(&pPage->aData[pPage->hdrOffset+8]);
79624 assert( n==pPage->pgno && e==PTRMAP_BTREE );
80592 && pOther->pPage==pCur->pPage
80594 return SQLITE_CORRUPT_PAGE(pCur->pPage);
80620 MemPage *pPage = pCur->pPage; local
80622 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
80623 if( pPage->nOverflow==0 && pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
80630 if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
80638 rc = balance_deeper(pPage, &pCur->apPage[1]);
80643 pCur->apPage[0] = pPage;
80644 pCur->pPage = pCur->apPage[1];
80645 assert( pCur->pPage->nOverflow );
80650 }else if( sqlite3PagerPageRefcount(pPage->pDbPage)>1 ){
80654 rc = SQLITE_CORRUPT_PAGE(pPage);
80665 if( pPage->intKeyLeaf
80666 && pPage->nOverflow==1
80667 && pPage->aiOvfl[0]==pPage->nCell
80686 rc = balance_quick(pParent, pPage, aBalanceQuickSpace);
80725 pPage->nOverflow = 0;
80728 releasePage(pPage);
80731 pCur->pPage = pCur->apPage[pCur->iPage];
80745 MemPage *pPage, /* MemPage on which writing will occur */
80757 int rc = sqlite3PagerWrite(pPage->pDbPage);
80765 int rc = btreeOverwriteContent(pPage, pDest+nData, pX, iOffset+nData,
80771 int rc = sqlite3PagerWrite(pPage->pDbPage);
80795 MemPage *pPage = pCur->pPage; /* Page being written */ local
80803 rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
80812 pBt = pPage->pBt;
80815 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
80817 if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){
80818 rc = SQLITE_CORRUPT_PAGE(pPage);
80821 ovflPgno = get4byte(pPage->aData);
80825 rc = btreeOverwriteContent(pPage, pPage->aData+4, pX,
80828 sqlite3PagerUnref(pPage->pDbPage);
80841 MemPage *pPage = pCur->pPage; /* Page being written */ local
80843 if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
80844 || pCur->info.pPayload < pPage->aData + pPage->cellOffset
80846 return SQLITE_CORRUPT_PAGE(pPage);
80850 return btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
80899 MemPage *pPage; local
81044 pPage = pCur->pPage;
81045 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
81046 assert( pPage->leaf || !pPage->intKey );
81047 if( pPage->nFree<0 ){
81050 rc = SQLITE_CORRUPT_PAGE(pPage);
81052 rc = btreeComputeFreeSpace(pPage);
81058 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
81060 assert( pPage->isInit || CORRUPT_DB );
81071 if( ISAUTOVACUUM(p->pBt) && szNew>pPage->maxLocal ){
81073 pPage->xParseCell(pPage, newCell, &info);
81076 ptrmapPut(p->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, &rc);
81081 rc = fillInCell(pPage, newCell, pX, &szNew);
81084 assert( szNew==pPage->xCellSize(pPage, newCell) );
81091 if( idx>=pPage->nCell ){
81092 return SQLITE_CORRUPT_PAGE(pPage);
81094 rc = sqlite3PagerWrite(pPage->pDbPage);
81098 oldCell = findCell(pPage, idx);
81099 if( !pPage->leaf ){
81102 BTREE_CLEAR_CELL(rc, pPage, oldCell, info);
81106 && (!ISAUTOVACUUM(p->pBt) || szNew<pPage->minLocal)
81118 if( oldCell < pPage->aData+pPage->hdrOffset+10 ){
81119 return SQLITE_CORRUPT_PAGE(pPage);
81121 if( oldCell+szNew > pPage->aDataEnd ){
81122 return SQLITE_CORRUPT_PAGE(pPage);
81127 dropCell(pPage, idx, info.nSize, &rc);
81129 }else if( loc<0 && pPage->nCell>0 ){
81130 assert( pPage->leaf );
81134 assert( pPage->leaf );
81136 rc = insertCellFast(pPage, idx, newCell, szNew);
81137 assert( pPage->nOverflow==0 || rc==SQLITE_OK );
81138 assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
81160 if( pPage->nOverflow ){
81169 pCur->pPage->nOverflow = 0;
81186 assert( pCur->iPage<0 || pCur->pPage->nOverflow==0 );
81223 if( aIn+nIn>pSrc->pPage->aDataEnd ){
81224 return SQLITE_CORRUPT_PAGE(pSrc->pPage);
81227 if( nIn==nRem && nIn<pDest->pPage->maxLocal ){
81240 nOut = btreePayloadToLocal(pDest->pPage, pSrc->info.nPayload);
81248 if( aIn+nIn+4>pSrc->pPage->aDataEnd ){
81249 return SQLITE_CORRUPT_PAGE(pSrc->pPage);
81325 MemPage *pPage; /* Page to delete cell from */ local
81352 pPage = pCur->pPage;
81353 if( pPage->nCell<=iCellIdx ){
81354 return SQLITE_CORRUPT_PAGE(pPage);
81356 pCell = findCell(pPage, iCellIdx);
81357 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
81358 return SQLITE_CORRUPT_PAGE(pPage);
81360 if( pCell<&pPage->aCellIdx[pPage->nCell] ){
81361 return SQLITE_CORRUPT_PAGE(pPage);
81382 if( !pPage->leaf
81383 || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2) >
81385 || pPage->nCell==1 /* See dbfuzz001.test for a test case */
81403 if( !pPage->leaf ){
81425 rc = sqlite3PagerWrite(pPage->pDbPage);
81427 BTREE_CLEAR_CELL(rc, pPage, pCell, info);
81428 dropCell(pPage, iCellIdx, info.nSize, &rc);
81436 if( !pPage->leaf ){
81437 MemPage *pLeaf = pCur->pPage;
81449 n = pCur->pPage->pgno;
81459 rc = insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n);
81480 assert( pCur->pPage->nOverflow==0 );
81481 assert( pCur->pPage->nFree>=0 );
81482 if( pCur->pPage->nFree*3<=(int)pCur->pBt->usableSize*2 ){
81490 releasePageNotNull(pCur->pPage);
81495 pCur->pPage = pCur->apPage[pCur->iPage];
81502 assert( pPage==pCur->pPage || CORRUPT_DB );
81503 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
81505 if( iCellIdx>=pPage->nCell ){
81507 pCur->ix = pPage->nCell-1;
81697 MemPage *pPage; local
81708 rc = getAndInitPage(pBt, pgno, &pPage, 0);
81711 && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
81713 rc = SQLITE_CORRUPT_PAGE(pPage);
81716 hdr = pPage->hdrOffset;
81717 for(i=0; i<pPage->nCell; i++){
81718 pCell = findCell(pPage, i);
81719 if( !pPage->leaf ){
81723 BTREE_CLEAR_CELL(rc, pPage, pCell, info);
81726 if( !pPage->leaf ){
81727 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
81729 if( pPage->intKey ) pnChange = 0;
81732 testcase( !pPage->intKey );
81733 *pnChange += pPage->nCell;
81736 freePage(pPage, &rc);
81737 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
81738 zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
81742 releasePage(pPage);
81810 MemPage *pPage = 0; local
81822 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
81824 releasePage(pPage);
81831 freePage(pPage, &rc);
81832 releasePage(pPage);
81842 freePage(pPage, &rc);
81843 releasePage(pPage);
81853 releasePage(pPage);
81887 freePage(pPage, &rc);
81888 releasePage(pPage);
81999 MemPage *pPage; /* Current page of the b-tree */ local
82005 pPage = pCur->pPage;
82006 if( pPage->leaf || !pPage->intKey ){
82007 nEntry += pPage->nCell;
82020 if( pPage->leaf ){
82028 }while ( pCur->ix>=pCur->pPage->nCell );
82031 pPage = pCur->pPage;
82038 if( iIdx==pPage->nCell ){
82039 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
82041 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
82341 MemPage *pPage = 0; /* The page being analyzed */ local
82377 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
82386 savedIsInit = pPage->isInit;
82387 pPage->isInit = 0;
82388 if( (rc = btreeInitPage(pPage))!=0 ){
82394 if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
82399 data = pPage->aData;
82400 hdr = pPage->hdrOffset;
82410 assert( pPage->nCell==nCell );
82411 if( pPage->leaf || pPage->intKey==0 ){
82417 cellStart = hdr + 12 - 4*pPage->leaf;
82418 assert( pPage->aCellIdx==&data[cellStart] );
82421 if( !pPage->leaf ){
82456 pPage->xParseCell(pPage, pCell, &info);
82464 if( pPage->intKey ){
82487 if( !pPage->leaf ){
82515 if( !pPage->leaf ){
82521 size = pPage->xCellSize(pPage, &data[pc]);
82589 if( !doCoverageCheck ) pPage->isInit = savedIsInit;
82590 releasePage(pPage);
82964 assert( pCsr->pPage->intKey );
182901 sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
183129 sqlite3GlobalConfig.pPage = va_arg(ap, void*);
248586 Fts5PageWriter *pPage = &pWriter->writer;
248589 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
248592 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
248593 fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
248597 assert( pPage->pgidx.n==0 );
248601 fts5BufferAppendBlob(&p->rc, &pPage->buf, pPage->pgidx.n, pPage->pgidx.p);
248605 iRowid = FTS5_SEGMENT_ROWID(pWriter->iSegid, pPage->pgno);
248606 fts5DataWrite(p, iRowid, pPage->buf.p, pPage->buf.n);
248609 fts5BufferZero(&pPage->buf);
248610 fts5BufferZero(&pPage->pgidx);
248611 fts5BufferAppendBlob(&p->rc, &pPage->buf, 4, zero);
248612 pPage->iPrevPgidx = 0;
248613 pPage->pgno++;
248636 Fts5PageWriter *pPage = &pWriter->writer;
248638 int nMin = MIN(pPage->term.n, nTerm);
248641 assert( pPage->buf.n>=4 );
248642 assert( pPage->buf.n>4 || pWriter->bFirstTermInPage );
248645 if( (pPage->buf.n + pPgidx->n + nTerm + 2)>=p->pConfig->pgsz ){
248646 if( pPage->buf.n>4 ){
248650 fts5BufferGrow(&p->rc, &pPage->buf, nTerm+FTS5_DATA_PADDING);
248655 &pPgidx->p[pPgidx->n], pPage->buf.n - pPage->iPrevPgidx
248657 pPage->iPrevPgidx = pPage->buf.n;
248659 fts5PutU16(&pPgidx->p[pPgidx->n], pPage->buf.n);
248665 if( pPage->pgno!=1 ){
248680 if( pPage->term.n ){
248681 n = 1 + fts5PrefixCompress(nMin, pPage->term.p, pTerm);
248685 pPage = &pWriter->writer;
248688 nPrefix = fts5PrefixCompress(nMin, pPage->term.p, pTerm);
248689 fts5BufferAppendVarint(&p->rc, &pPage->buf, nPrefix);
248694 fts5BufferAppendVarint(&p->rc, &pPage->buf, nTerm - nPrefix);
248695 fts5BufferAppendBlob(&p->rc, &pPage->buf, nTerm - nPrefix, &pTerm[nPrefix]);
248698 fts5BufferSet(&p->rc, &pPage->term, nTerm, pTerm);
248705 pWriter->aDlidx[0].pgno = pPage->pgno;
248717 Fts5PageWriter *pPage = &pWriter->writer;
248719 if( (pPage->buf.n + pPage->pgidx.n)>=p->pConfig->pgsz ){
248727 fts5PutU16(pPage->buf.p, (u16)pPage->buf.n);
248733 fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid);
248736 fts5BufferAppendVarint(&p->rc, &pPage->buf,
248752 Fts5PageWriter *pPage = &pWriter->writer;
248758 && (pPage->buf.n + pPage->pgidx.n + n)>=p->pConfig->pgsz
248760 int nReq = p->pConfig->pgsz - pPage->buf.n - pPage->pgidx.n;
248766 fts5BufferAppendBlob(&p->rc, &pPage->buf, nCopy, a);
248772 fts5BufferAppendBlob(&p->rc, &pPage->buf, n, a);