Lines Matching refs:pPg
40715 PgHdr *pPg;
40724 for(pPg=pCache->pSynced;
40725 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
40726 pPg=pPg->pDirtyPrev
40728 pCache->pSynced = pPg;
40729 if( !pPg ){
40730 for(pPg=pCache->pDirtyTail; pPg && pPg->nRef; pPg=pPg->pDirtyPrev);
40732 if( pPg ){
40737 pPg->pgno, pgno,
40741 rc = pCache->xStress(pCache->pStress, pPg);
41518 void *pPg;
41536 pPg = pcache1Alloc(pCache->szPage);
41538 if( !pPg || !p ){
41539 pcache1Free(pPg);
41541 pPg = 0;
41544 pPg = pcache1Alloc(pCache->szAlloc);
41545 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
41551 if( pPg==0 ) return 0;
41552 p->page.pBuf = pPg;
42152 sqlite3_pcache_page *pPg,
42156 PgHdr1 *pPage = (PgHdr1 *)pPg;
42188 sqlite3_pcache_page *pPg,
42193 PgHdr1 *pPage = (PgHdr1 *)pPg;
44027 ** Return true if it is necessary to write page *pPg into the sub-journal.
44035 static int subjRequiresPage(PgHdr *pPg){
44036 Pager *pPager = pPg->pPager;
44038 Pgno pgno = pPg->pgno;
44053 static int pageInJournal(Pager *pPager, PgHdr *pPg){
44054 return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno);
44211 static void checkPage(PgHdr *pPg){
44212 Pager *pPager = pPg->pPager;
44214 assert( (pPg->flags&PGHDR_DIRTY) || pPg->pageHash==pager_pagehash(pPg) );
45186 PgHdr *pPg; /* An existing page in the cache */
45293 pPg = 0;
45295 pPg = sqlite3PagerLookup(pPager, pgno);
45297 assert( pPg || !MEMDB );
45298 assert( pPager->eState!=PAGER_OPEN || pPg==0 );
45306 isSynced = (pPg==0 || 0==(pPg->flags & PGHDR_NEED_SYNC));
45313 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
45324 }else if( !isMainJrnl && pPg==0 ){
45344 rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1);
45348 pPg->flags &= ~PGHDR_NEED_READ;
45349 sqlite3PcacheMakeDirty(pPg);
45351 if( pPg ){
45359 pData = pPg->pData;
45361 pPager->xReiniter(pPg);
45383 sqlite3PcacheMakeClean(pPg);
45385 pager_set_pagehash(pPg);
45394 CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM);
45395 sqlite3PcacheRelease(pPg);
45894 ** Read the content for page pPg out of the database file and into
45895 ** pPg->pData. A shared lock or greater must be held on the database
45904 static int readDbPage(PgHdr *pPg, u32 iFrame){
45905 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
45906 Pgno pgno = pPg->pgno; /* Page number to read */
45916 rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
45921 rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
45943 u8 *dbFileVers = &((u8*)pPg->pData)[24];
45947 CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM);
45953 PAGERID(pPager), pgno, pager_pagehash(pPg)));
45966 static void pager_write_changecounter(PgHdr *pPg){
45970 change_counter = sqlite3Get4byte((u8*)pPg->pPager->dbFileVers)+1;
45971 put32bits(((char*)pPg->pData)+24, change_counter);
45976 put32bits(((char*)pPg->pData)+92, change_counter);
45977 put32bits(((char*)pPg->pData)+96, SQLITE_VERSION_NUMBER);
45996 PgHdr *pPg;
45999 pPg = sqlite3PagerLookup(pPager, iPg);
46000 if( pPg ){
46001 if( sqlite3PcachePageRefcount(pPg)==1 ){
46002 sqlite3PcacheDrop(pPg);
46005 rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
46007 rc = readDbPage(pPg, iFrame);
46010 pPager->xReiniter(pPg);
46012 sqlite3PagerUnrefNotNull(pPg);
46840 static void assertTruncateConstraintCb(PgHdr *pPg){
46841 assert( pPg->flags&PGHDR_DIRTY );
46842 assert( !subjRequiresPage(pPg) || pPg->pgno<=pPg->pPager->dbSize );
46953 ** Release a reference to page pPg. pPg must have been returned by an
46956 static void pagerReleaseMapPage(PgHdr *pPg){
46957 Pager *pPager = pPg->pPager;
46959 pPg->pDirty = pPager->pMmapFreelist;
46960 pPager->pMmapFreelist = pPg;
46963 sqlite3OsUnfetch(pPager->fd, (i64)(pPg->pgno-1)*pPager->pageSize, pPg->pData);
47048 ** Return the page number for page pPg.
47050 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage *pPg){
47051 return pPg->pgno;
47056 ** Increment the reference count for page pPg.
47058 SQLITE_PRIVATE void sqlite3PagerRef(DbPage *pPg){
47059 sqlite3PcacheRef(pPg);
47344 ** Append a record of the current state of page pPg to the sub-journal.
47346 ** If successful, set the bit corresponding to pPg->pgno in the bitvecs
47354 static int subjournalPage(PgHdr *pPg){
47356 Pager *pPager = pPg->pPager;
47364 || pageInJournal(pPager, pPg)
47365 || pPg->pgno>pPager->dbOrigSize
47372 void *pData = pPg->pData;
47376 CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
47377 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
47378 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
47387 rc = addToSavepointBitvecs(pPager, pPg->pgno);
47391 static int subjournalPageIfRequired(PgHdr *pPg){
47392 if( subjRequiresPage(pPg) ){
47393 return subjournalPage(pPg);
47408 ** The job of this function is to make pPg clean by writing its contents
47418 static int pagerStress(void *p, PgHdr *pPg){
47422 assert( pPg->pPager==pPager );
47423 assert( pPg->flags&PGHDR_DIRTY );
47447 || (pPg->flags & PGHDR_NEED_SYNC)!=0)
47452 pPg->pDirty = 0;
47455 rc = subjournalPageIfRequired(pPg);
47457 rc = pagerWalFrames(pPager, pPg, 0, 0);
47462 if( pPg->flags&PGHDR_NEED_SYNC
47470 assert( (pPg->flags&PGHDR_NEED_SYNC)==0 );
47471 rc = pager_write_pagelist(pPager, pPg);
47477 PAGERTRACE(("STRESS %d page %d\n", PAGERID(pPager), pPg->pgno));
47478 sqlite3PcacheMakeClean(pPg);
48271 PgHdr *pPg = 0;
48318 pPg = sqlite3PagerLookup(pPager, pgno);
48320 if( pPg==0 ){
48321 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
48325 if( pPg ){
48327 *ppPage = pPg;
48343 pPg = *ppPage = 0;
48348 pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
48349 assert( pPg!=0 );
48356 ** Set pPg to 0 and jump to the exception handler. */
48357 pPg = 0;
48360 assert( pPg==(*ppPage) );
48361 assert( pPg->pgno==pgno );
48362 assert( pPg->pPager==pPager || pPg->pPager==0 );
48364 if( pPg->pPager && !noContent ){
48375 pPg->pPager = pPager;
48405 memset(pPg->pData, 0, pPager->pageSize);
48412 assert( pPg->pPager==pPager );
48414 rc = readDbPage(pPg, iFrame);
48419 pager_set_pagehash(pPg);
48426 if( pPg ){
48427 sqlite3PcacheDrop(pPg);
48465 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
48467 assert( pPg!=0 );
48468 pPager = pPg->pPager;
48469 if( pPg->flags & PGHDR_MMAP ){
48470 pagerReleaseMapPage(pPg);
48472 sqlite3PcacheRelease(pPg);
48476 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
48477 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
48658 ** Write page pPg onto the end of the rollback journal.
48660 static SQLITE_NOINLINE int pagerAddPageToRollbackJournal(PgHdr *pPg){
48661 Pager *pPager = pPg->pPager;
48670 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
48673 CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
48683 pPg->flags |= PGHDR_NEED_SYNC;
48685 rc = write32bits(pPager->jfd, iOff, pPg->pgno);
48692 IOTRACE(("JOUT %p %d %lld %d\n", pPager, pPg->pgno,
48696 PAGERID(pPager), pPg->pgno,
48697 ((pPg->flags&PGHDR_NEED_SYNC)?1:0), pager_pagehash(pPg)));
48702 rc = sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
48705 rc |= addToSavepointBitvecs(pPager, pPg->pgno);
48717 static int pager_write(PgHdr *pPg){
48718 Pager *pPager = pPg->pPager;
48732 CHECK_PAGE(pPg);
48751 sqlite3PcacheMakeDirty(pPg);
48759 && sqlite3BitvecTestNotNull(pPager->pInJournal, pPg->pgno)==0
48762 if( pPg->pgno<=pPager->dbOrigSize ){
48763 rc = pagerAddPageToRollbackJournal(pPg);
48769 pPg->flags |= PGHDR_NEED_SYNC;
48772 PAGERID(pPager), pPg->pgno,
48773 ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
48782 pPg->flags |= PGHDR_WRITEABLE;
48788 rc = subjournalPageIfRequired(pPg);
48792 if( pPager->dbSize<pPg->pgno ){
48793 pPager->dbSize = pPg->pgno;
48809 static SQLITE_NOINLINE int pagerWriteLargeSector(PgHdr *pPg){
48812 Pgno pg1; /* First page of the sector pPg is located on. */
48816 Pager *pPager = pPg->pPager; /* The pager that owns pPg */
48829 ** of the first page of the sector pPg is located on.
48831 pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
48834 if( pPg->pgno>nPageCount ){
48835 nPage = (pPg->pgno - pg1)+1;
48842 assert(pg1<=pPg->pgno);
48843 assert((pg1+nPage)>pPg->pgno);
48848 if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){
48903 SQLITE_PRIVATE int sqlite3PagerWrite(PgHdr *pPg){
48904 Pager *pPager = pPg->pPager;
48905 assert( (pPg->flags & PGHDR_MMAP)==0 );
48909 if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
48910 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
48913 return pagerWriteLargeSector(pPg);
48915 return pager_write(pPg);
48925 SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage *pPg){
48926 return pPg->flags & PGHDR_WRITEABLE;
48932 ** write the information on page pPg back to the disk, even though
48944 SQLITE_PRIVATE void sqlite3PagerDontWrite(PgHdr *pPg){
48945 Pager *pPager = pPg->pPager;
48946 if( (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
48947 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
48948 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
48949 pPg->flags |= PGHDR_DONT_WRITE;
48950 pPg->flags &= ~PGHDR_WRITEABLE;
48951 pager_set_pagehash(pPg);
49198 PgHdr *pPg;
49206 && (0==(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
49715 SQLITE_PRIVATE void *sqlite3PagerCodec(PgHdr *pPg){
49717 CODEC2(pPg->pPager, pPg->pData, pPg->pgno, 6, return 0, aData);
49731 ** Move the page pPg to location pgno in the file.
49738 ** References to the page pPg remain valid. Updating any
49739 ** meta-data associated with pPg (i.e. data stored in the nExtra bytes
49750 ** pPg refers to will not be written to again within this transaction.
49755 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
49757 Pgno needSyncPgno = 0; /* Old value of pPg->pgno, if sync is required */
49761 assert( pPg->nRef>0 );
49771 rc = sqlite3PagerWrite(pPg);
49789 ** subjournalPage() may need to allocate space to store pPg->pgno into
49793 if( (pPg->flags & PGHDR_DIRTY)!=0
49794 && SQLITE_OK!=(rc = subjournalPageIfRequired(pPg))
49800 PAGERID(pPager), pPg->pgno, (pPg->flags&PGHDR_NEED_SYNC)?1:0, pgno));
49801 IOTRACE(("MOVE %p %d %d\n", pPager, pPg->pgno, pgno))
49803 /* If the journal needs to be sync()ed before page pPg->pgno can
49804 ** be written to, store pPg->pgno in local variable needSyncPgno.
49807 ** the journal needs to be sync()ed before database page pPg->pgno
49810 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
49811 needSyncPgno = pPg->pgno;
49813 pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize );
49814 assert( pPg->flags&PGHDR_DIRTY );
49822 pPg->flags &= ~PGHDR_NEED_SYNC;
49826 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
49836 origPgno = pPg->pgno;
49837 sqlite3PcacheMove(pPg, pgno);
49838 sqlite3PcacheMakeDirty(pPg);
49889 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){
49890 assert( pPg->pgno!=iNew );
49891 pPg->flags = flags;
49892 sqlite3PcacheMove(pPg, iNew);
49898 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
49899 assert( pPg->nRef>0 || pPg->pPager->memDb );
49900 return pPg->pData;
49907 SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *pPg){
49908 return pPg->pExtra;
55891 ** Search the free-list on page pPg for space to store a cell nByte bytes in
55897 ** This function may detect corruption within pPg. If corruption is
55904 static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
55905 const int hdr = pPg->hdrOffset;
55906 u8 * const aData = pPg->aData;
55910 int usableSize = pPg->pBt->usableSize;
55928 if( pc < pPg->cellOffset+2*pPg->nCell || size+pc > usableSize ){
60255 MemPage *pPg = 0;
60258 rc = btreeGetUnusedPage(pBt, pBt->nPage, &pPg, bNoContent);
60260 rc = sqlite3PagerWrite(pPg->pDbPage);
60261 releasePage(pPg);
60903 ** replaces the current contents of page pPg with the contents of the cell
60906 ** Some of the cells in apCell[] may currently be stored in pPg. This
60914 MemPage *pPg, /* Edit this page */
60919 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
60920 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
60921 const int usableSize = pPg->pBt->usableSize;
60924 u8 *pCellptr = pPg->aCellIdx;
60925 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
60942 assert( szCell[i]==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
60943 testcase( szCell[i]!=pPg->xCellSize(pPg,pCell) );
60946 /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
60947 pPg->nCell = nCell;
60948 pPg->nOverflow = 0;
60951 put2byte(&aData[hdr+3], pPg->nCell);
60960 ** add the cells stored in the array to page pPg. If it cannot (because
60966 ** (part of page pPg) to populate. After cell apCell[0] is written to the
60972 ** content area on page pPg. If the size of the content area is extended,
60983 MemPage *pPg, /* Page to add cells to */
60988 int nCell, /* Number of cells to add to pPg */
60992 u8 *aData = pPg->aData;
60995 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
61000 if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
61023 ** within the body of pPg to the pPg free-list. The cell-pointers and other
61029 MemPage *pPg, /* Page to edit */
61034 u8 * const aData = pPg->aData;
61035 u8 * const pEnd = &aData[pPg->pBt->usableSize];
61036 u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
61054 freeSpace(pPg, (u16)(pFree - aData), szFree);
61068 freeSpace(pPg, (u16)(pFree - aData), szFree);
61075 ** pages being balanced. The current page, pPg, has pPg->nCell cells starting
61079 ** This routine makes the necessary adjustments to pPg so that it contains
61082 ** The pPg->nFree field is invalid when this function returns. It is the
61086 MemPage *pPg, /* Edit this page */
61092 u8 * const aData = pPg->aData;
61093 const int hdr = pPg->hdrOffset;
61094 u8 *pBegin = &pPg->aCellIdx[nNew * 2];
61095 int nCell = pPg->nCell; /* Cells stored on pPg */
61099 int iOldEnd = iOld + pPg->nCell + pPg->nOverflow;
61103 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
61104 memcpy(pTmp, aData, pPg->pBt->usableSize);
61109 int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
61110 memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
61114 nCell -= pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
61124 pCellptr = pPg->aCellIdx;
61127 pPg, pBegin, &pData, pCellptr,
61134 for(i=0; i<pPg->nOverflow; i++){
61135 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
61137 pCellptr = &pPg->aCellIdx[iCell * 2];
61141 pPg, pBegin, &pData, pCellptr,
61148 pCellptr = &pPg->aCellIdx[nCell*2];
61150 pPg, pBegin, &pData, pCellptr,
61154 pPg->nCell = nNew;
61155 pPg->nOverflow = 0;
61157 put2byte(&aData[hdr+3], pPg->nCell);
61163 int iOff = get2byteAligned(&pPg->aCellIdx[i*2]);
61164 if( pCell>=aData && pCell<&aData[pPg->pBt->usableSize] ){
61176 return rebuildPage(pPg, nNew, &pCArray->apCell[iNew], &pCArray->szCell[iNew]);
64681 DbPage *pPg;
64682 rc = sqlite3PagerGet(pDestPager, iPg, &pPg);
64684 rc = sqlite3PagerWrite(pPg);
64685 sqlite3PagerUnref(pPg);
162941 DbPage *pPg;
163113 sqlite3PagerUnref(p->pPg);
163171 u8 *aData = sqlite3PagerGetData(p->pPg);
163238 DbPage *pPg = 0;
163239 rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg);
163241 assert( pPg==0 );
163244 pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg));
163245 sqlite3PagerUnref(pPg);
163297 if( pCsr->aPage[0].pPg==0 ){
163307 rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg);
163367 rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg);