Lines Matching defs:pPg

49390     PgHdr *pPg;
49400 pPg = (PgHdr*)pLower->pExtra;
49401 printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
49405 if( pPg->pPage==0 ){
49422 ** assert( sqlite3PcachePageSanity(pPg) );
49425 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
49427 assert( pPg!=0 );
49428 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
49429 pCache = pPg->pCache;
49431 if( pPg->flags & PGHDR_CLEAN ){
49432 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
49433 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
49434 assert( pCache->pDirtyTail!=pPg );
49437 if( pPg->flags & PGHDR_WRITEABLE ){
49438 assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
49726 PgHdr *pPg;
49739 for(pPg=pCache->pSynced;
49740 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
49741 pPg=pPg->pDirtyPrev
49743 pCache->pSynced = pPg;
49744 if( !pPg ){
49745 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
49747 if( pPg ){
49752 pPg->pgno, pgno,
49756 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
49757 rc = pCache->xStress(pCache->pStress, pPg);
50625 void *pPg;
50644 pPg = pcache1Alloc(pCache->szPage);
50646 if( !pPg || !p ){
50647 pcache1Free(pPg);
50649 pPg = 0;
50652 pPg = pcache1Alloc(pCache->szAlloc);
50658 if( pPg==0 ) return 0;
50660 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
50662 p->page.pBuf = pPg;
51280 sqlite3_pcache_page *pPg,
51284 PgHdr1 *pPage = (PgHdr1 *)pPg;
51315 sqlite3_pcache_page *pPg,
51320 PgHdr1 *pPage = (PgHdr1 *)pPg;
53205 ** Return true if it is necessary to write page *pPg into the sub-journal.
53213 static int subjRequiresPage(PgHdr *pPg){
53214 Pager *pPager = pPg->pPager;
53216 Pgno pgno = pPg->pgno;
53234 static int pageInJournal(Pager *pPager, PgHdr *pPg){
53235 return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno);
53408 static void checkPage(PgHdr *pPg){
53409 Pager *pPager = pPg->pPager;
53411 assert( (pPg->flags&PGHDR_DIRTY) || pPg->pageHash==pager_pagehash(pPg) );
54392 PgHdr *pPg; /* An existing page in the cache */
54498 pPg = 0;
54500 pPg = sqlite3PagerLookup(pPager, pgno);
54502 assert( pPg || !MEMDB );
54503 assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
54511 isSynced = (pPg==0 || 0==(pPg->flags & PGHDR_NEED_SYNC));
54518 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
54535 }else if( !isMainJrnl && pPg==0 ){
54555 rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
54559 sqlite3PcacheMakeDirty(pPg);
54561 if( pPg ){
54569 pData = pPg->pData;
54571 pPager->xReiniter(pPg);
54572 /* It used to be that sqlite3PcacheMakeClean(pPg) was called here. But
54576 pager_set_pagehash(pPg);
54583 sqlite3PcacheRelease(pPg);
55098 ** Read the content for page pPg out of the database file (or out of
55100 ** pPg->pData. A shared lock or greater must be held on the database
55109 static int readDbPage(PgHdr *pPg){
55110 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
55120 rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
55124 rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData);
55128 i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
55129 rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
55135 if( pPg->pgno==1 ){
55151 u8 *dbFileVers = &((u8*)pPg->pData)[24];
55157 IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno));
55159 PAGERID(pPager), pPg->pgno, pager_pagehash(pPg)));
55172 static void pager_write_changecounter(PgHdr *pPg){
55176 change_counter = sqlite3Get4byte((u8*)pPg->pPager->dbFileVers)+1;
55177 put32bits(((char*)pPg->pData)+24, change_counter);
55182 put32bits(((char*)pPg->pData)+92, change_counter);
55183 put32bits(((char*)pPg->pData)+96, SQLITE_VERSION_NUMBER);
55202 PgHdr *pPg;
55205 pPg = sqlite3PagerLookup(pPager, iPg);
55206 if( pPg ){
55207 if( sqlite3PcachePageRefcount(pPg)==1 ){
55208 sqlite3PcacheDrop(pPg);
55210 rc = readDbPage(pPg);
55212 pPager->xReiniter(pPg);
55214 sqlite3PagerUnrefNotNull(pPg);
56063 static void assertTruncateConstraintCb(PgHdr *pPg){
56064 assert( pPg->flags&PGHDR_DIRTY );
56065 assert( !subjRequiresPage(pPg) || pPg->pgno<=pPg->pPager->dbSize );
56179 ** Release a reference to page pPg. pPg must have been returned by an
56182 static void pagerReleaseMapPage(PgHdr *pPg){
56183 Pager *pPager = pPg->pPager;
56185 pPg->pDirty = pPager->pMmapFreelist;
56186 pPager->pMmapFreelist = pPg;
56189 sqlite3OsUnfetch(pPager->fd, (i64)(pPg->pgno-1)*pPager->pageSize, pPg->pData);
56302 ** Return the page number for page pPg.
56304 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage *pPg){
56305 return pPg->pgno;
56310 ** Increment the reference count for page pPg.
56312 SQLITE_PRIVATE void sqlite3PagerRef(DbPage *pPg){
56313 sqlite3PcacheRef(pPg);
56601 ** Append a record of the current state of page pPg to the sub-journal.
56603 ** If successful, set the bit corresponding to pPg->pgno in the bitvecs
56611 static int subjournalPage(PgHdr *pPg){
56613 Pager *pPager = pPg->pPager;
56621 || pageInJournal(pPager, pPg)
56622 || pPg->pgno>pPager->dbOrigSize
56629 void *pData = pPg->pData;
56633 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
56634 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
56643 rc = addToSavepointBitvecs(pPager, pPg->pgno);
56647 static int subjournalPageIfRequired(PgHdr *pPg){
56648 if( subjRequiresPage(pPg) ){
56649 return subjournalPage(pPg);
56664 ** The job of this function is to make pPg clean by writing its contents
56674 static int pagerStress(void *p, PgHdr *pPg){
56678 assert( pPg->pPager==pPager );
56679 assert( pPg->flags&PGHDR_DIRTY );
56703 || (pPg->flags & PGHDR_NEED_SYNC)!=0)
56709 pPg->pDirty = 0;
56712 rc = subjournalPageIfRequired(pPg);
56714 rc = pagerWalFrames(pPager, pPg, 0, 0);
56726 if( pPg->flags&PGHDR_NEED_SYNC
56734 assert( (pPg->flags&PGHDR_NEED_SYNC)==0 );
56735 rc = pager_write_pagelist(pPager, pPg);
56741 PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno));
56742 sqlite3PcacheMakeClean(pPg);
57620 PgHdr *pPg;
57632 pPg = 0;
57640 pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
57641 assert( pPg==(*ppPage) );
57642 assert( pPg->pgno==pgno );
57643 assert( pPg->pPager==pPager || pPg->pPager==0 );
57646 if( pPg->pPager && !noContent ){
57665 pPg->pPager = pPager;
57689 memset(pPg->pData, 0, pPager->pageSize);
57692 assert( pPg->pPager==pPager );
57694 rc = readDbPage(pPg);
57699 pager_set_pagehash(pPg);
57705 if( pPg ){
57706 sqlite3PcacheDrop(pPg);
57722 PgHdr *pPg = 0;
57761 pPg = sqlite3PagerLookup(pPager, pgno);
57763 if( pPg==0 ){
57764 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
57768 if( pPg ){
57770 *ppPage = pPg;
57843 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
57844 TESTONLY( Pager *pPager = pPg->pPager; )
57845 assert( pPg!=0 );
57846 if( pPg->flags & PGHDR_MMAP ){
57847 assert( pPg->pgno!=1 ); /* Page1 is never memory mapped */
57848 pagerReleaseMapPage(pPg);
57850 sqlite3PcacheRelease(pPg);
57855 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
57856 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
57858 SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *pPg){
57860 assert( pPg!=0 );
57861 assert( pPg->pgno==1 );
57862 assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */
57863 pPager = pPg->pPager;
57864 sqlite3PcacheRelease(pPg);
58046 ** Write page pPg onto the end of the rollback journal.
58048 static SQLITE_NOINLINE int pagerAddPageToRollbackJournal(PgHdr *pPg){
58049 Pager *pPager = pPg->pPager;
58058 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
58061 pData2 = pPg->pData;
58071 pPg->flags |= PGHDR_NEED_SYNC;
58073 rc = write32bits(pPager->jfd, iOff, pPg->pgno);
58080 IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno,
58084 PAGERID(pPager), pPg->pgno,
58085 ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
58090 rc = sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
58093 rc |= addToSavepointBitvecs(pPager, pPg->pgno);
58105 static int pager_write(PgHdr *pPg){
58106 Pager *pPager = pPg->pPager;
58120 CHECK_PAGE(pPg);
58139 sqlite3PcacheMakeDirty(pPg);
58147 && sqlite3BitvecTestNotNull(pPager->pInJournal, pPg->pgno)==0
58150 if( pPg->pgno<=pPager->dbOrigSize ){
58151 rc = pagerAddPageToRollbackJournal(pPg);
58157 pPg->flags |= PGHDR_NEED_SYNC;
58160 PAGERID(pPager), pPg->pgno,
58161 ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
58170 pPg->flags |= PGHDR_WRITEABLE;
58176 rc = subjournalPageIfRequired(pPg);
58180 if( pPager->dbSize<pPg->pgno ){
58181 pPager->dbSize = pPg->pgno;
58197 static SQLITE_NOINLINE int pagerWriteLargeSector(PgHdr *pPg){
58200 Pgno pg1; /* First page of the sector pPg is located on. */
58204 Pager *pPager = pPg->pPager; /* The pager that owns pPg */
58217 ** of the first page of the sector pPg is located on.
58219 pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
58222 if( pPg->pgno>nPageCount ){
58223 nPage = (pPg->pgno - pg1)+1;
58230 assert(pg1<=pPg->pgno);
58231 assert((pg1+nPage)>pPg->pgno);
58236 if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){
58291 SQLITE_PRIVATE int sqlite3PagerWrite(PgHdr *pPg){
58292 Pager *pPager = pPg->pPager;
58293 assert( (pPg->flags & PGHDR_MMAP)==0 );
58296 if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
58297 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
58303 return pagerWriteLargeSector(pPg);
58305 return pager_write(pPg);
58315 SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage *pPg){
58316 return pPg->flags & PGHDR_WRITEABLE;
58322 ** write the information on page pPg back to the disk, even though
58336 ** memory pressure forces page pPg out of the cache, the data does need
58340 SQLITE_PRIVATE void sqlite3PagerDontWrite(PgHdr *pPg){
58341 Pager *pPager = pPg->pPager;
58342 if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
58343 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
58344 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
58345 pPg->flags |= PGHDR_DONT_WRITE;
58346 pPg->flags &= ~PGHDR_WRITEABLE;
58347 testcase( pPg->flags & PGHDR_NEED_SYNC );
58348 pager_set_pagehash(pPg);
58615 PgHdr *pPg;
58623 && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
59180 ** Move the page pPg to location pgno in the file.
59187 ** References to the page pPg remain valid. Updating any
59188 ** meta-data associated with pPg (i.e. data stored in the nExtra bytes
59199 ** pPg refers to will not be written to again within this transaction.
59204 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
59206 Pgno needSyncPgno = 0; /* Old value of pPg->pgno, if sync is required */
59210 assert( pPg->nRef>0 );
59221 rc = sqlite3PagerWrite(pPg);
59239 ** subjournalPage() may need to allocate space to store pPg->pgno into
59243 if( (pPg->flags & PGHDR_DIRTY)!=0
59244 && SQLITE_OK!=(rc = subjournalPageIfRequired(pPg))
59250 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
59251 IOTRACE(("MOVE %p %d %d\n", pPager, pPg->pgno, pgno))
59253 /* If the journal needs to be sync()ed before page pPg->pgno can
59254 ** be written to, store pPg->pgno in local variable needSyncPgno.
59257 ** the journal needs to be sync()ed before database page pPg->pgno
59260 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
59261 needSyncPgno = pPg->pgno;
59263 pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize );
59264 assert( pPg->flags&PGHDR_DIRTY );
59272 pPg->flags &= ~PGHDR_NEED_SYNC;
59280 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
59290 origPgno = pPg->pgno;
59291 sqlite3PcacheMove(pPg, pgno);
59292 sqlite3PcacheMakeDirty(pPg);
59342 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){
59343 assert( pPg->pgno!=iNew );
59344 pPg->flags = flags;
59345 sqlite3PcacheMove(pPg, iNew);
59351 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
59352 assert( pPg->nRef>0 || pPg->pPager->memDb );
59353 return pPg->pData;
59360 SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *pPg){
59361 return pPg->pExtra;
66516 ** Search the free-list on page pPg for space to store a cell nByte bytes in
66522 ** This function may detect corruption within pPg. If corruption is
66529 static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
66530 const int hdr = pPg->hdrOffset; /* Offset to page header */
66531 u8 * const aData = pPg->aData; /* Page data */
66535 int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */
66558 *pRc = SQLITE_CORRUPT_PAGE(pPg);
66572 *pRc = SQLITE_CORRUPT_PAGE(pPg);
66579 *pRc = SQLITE_CORRUPT_PAGE(pPg);
71186 MemPage *pPg = 0;
71189 rc = btreeGetUnusedPage(pBt, pBt->nPage, &pPg, bNoContent);
71191 rc = sqlite3PagerWrite(pPg->pDbPage);
71192 releasePage(pPg);
71930 ** replaces the current contents of page pPg with the contents of the cell
71933 ** Some of the cells in apCell[] may currently be stored in pPg. This
71941 CellArray *pCArray, /* Content to be added to page pPg */
71944 MemPage *pPg /* The page to be reconstructed */
71946 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
71947 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
71948 const int usableSize = pPg->pBt->usableSize;
71953 u8 *pCellptr = pPg->aCellIdx;
71954 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
71986 assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
71987 testcase( sz!=pPg->xCellSize(pPg,pCell) )
71996 /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
71997 pPg->nCell = nCell;
71998 pPg->nOverflow = 0;
72001 put2byte(&aData[hdr+3], pPg->nCell);
72009 ** This function attempts to add the cells stored in the array to page pPg.
72015 ** (part of page pPg) to populate. After cell apCell[0] is written to the
72021 ** content area on page pPg. If the size of the content area is extended,
72032 MemPage *pPg, /* Page to add cells to */
72037 int nCell, /* Number of cells to add to pPg */
72041 u8 *aData = pPg->aData; /* Complete page */
72046 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
72055 if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
72091 ** that is currently stored within the body of pPg to the pPg free-list.
72097 MemPage *pPg, /* Page to edit */
72102 u8 * const aData = pPg->aData;
72103 u8 * const pEnd = &aData[pPg->pBt->usableSize];
72104 u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
72122 freeSpace(pPg, (u16)(pFree - aData), szFree);
72136 freeSpace(pPg, (u16)(pFree - aData), szFree);
72143 ** balanced. The current page, pPg, has pPg->nCell cells starting with
72147 ** This routine makes the necessary adjustments to pPg so that it contains
72150 ** The pPg->nFree field is invalid when this function returns. It is the
72154 MemPage *pPg, /* Edit this page */
72160 u8 * const aData = pPg->aData;
72161 const int hdr = pPg->hdrOffset;
72162 u8 *pBegin = &pPg->aCellIdx[nNew * 2];
72163 int nCell = pPg->nCell; /* Cells stored on pPg */
72167 int iOldEnd = iOld + pPg->nCell + pPg->nOverflow;
72171 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
72172 memcpy(pTmp, aData, pPg->pBt->usableSize);
72178 int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
72180 memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
72184 int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
72197 pCellptr = pPg->aCellIdx;
72200 pPg, pBegin, &pData, pCellptr,
72207 for(i=0; i<pPg->nOverflow; i++){
72208 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
72210 pCellptr = &pPg->aCellIdx[iCell * 2];
72217 pPg, pBegin, &pData, pCellptr,
72225 pCellptr = &pPg->aCellIdx[nCell*2];
72227 pPg, pBegin, &pData, pCellptr,
72231 pPg->nCell = nNew;
72232 pPg->nOverflow = 0;
72234 put2byte(&aData[hdr+3], pPg->nCell);
72240 int iOff = get2byteAligned(&pPg->aCellIdx[i*2]);
72241 if( SQLITE_WITHIN(pCell, aData, &aData[pPg->pBt->usableSize]) ){
72253 return rebuildPage(pCArray, iNew, nNew, pPg);
76192 DbPage *pPg;
76193 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
76195 rc = sqlite3PagerWrite(pPg);
76196 sqlite3PagerUnref(pPg);
204393 DbPage *pPg; /* Page content */
204608 sqlite3PagerUnref(p->pPg);
204683 u8 *aData = sqlite3PagerGetData(p->pPg);
204765 DbPage *pPg = 0;
204766 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg, 0);
204768 assert( pPg==0 );
204771 pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
204772 sqlite3PagerUnref(pPg);
204831 if( pCsr->aPage[0].pPg==0 ){
204843 rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg, 0);
204915 rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg, 0);