/ Check-in [7dc76588]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Modify the interface to the pager sub-system in preparation for performing IO in blocks based on sector-size, not database page-size. (CVS 3705)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7dc7658887046f066b564a5994578074a99756ba
User & Date: danielk1977 2007-03-19 17:44:27
Context
2007-03-20
23:52
Refactor PLWriter in preparation for buffered-document change. Currently, PLWriter (Position List Writer) creates a locally-owned DataBuffer to write into. This is necessary to support doclist collection during tokenization, where there is no obvious buffer to write output to, but is not necessary for the other users of PLWriter. This change adds a DLCollector (Doc List Collector) structure to handle the tokenization case.

Also fix a potential memory leak in writeZeroSegment(). In case of error from leafWriterStep(), the DataBuffer dl was being leaked. (CVS 3706) check-in: 1b9918e2 user: shess tags: trunk

2007-03-19
17:44
Modify the interface to the pager sub-system in preparation for performing IO in blocks based on sector-size, not database page-size. (CVS 3705) check-in: 7dc76588 user: danielk1977 tags: trunk
15:04
Add some test cases simulating crashes with various storage medium sector sizes. (CVS 3704) check-in: c3c5f658 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.340 2007/03/19 11:54:10 drh Exp $
           12  +** $Id: btree.c,v 1.341 2007/03/19 17:44:27 danielk1977 Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** For a detailed discussion of BTrees, refer to
    16     16   **
    17     17   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
    18     18   **     "Sorting And Searching", pages 473-480. Addison-Wesley
    19     19   **     Publishing Company, Reading, Massachusetts.
................................................................................
   287    287     u16 nCell;           /* Number of cells on this page, local and ovfl */
   288    288     struct _OvflCell {   /* Cells that will not fit on aData[] */
   289    289       u8 *pCell;          /* Pointers to the body of the overflow cell */
   290    290       u16 idx;            /* Insert this cell before idx-th non-overflow cell */
   291    291     } aOvfl[5];
   292    292     BtShared *pBt;       /* Pointer back to BTree structure */
   293    293     u8 *aData;           /* Pointer back to the start of the page */
          294  +  DbPage *pDbPage;     /* Pager page handle */
   294    295     Pgno pgno;           /* Page number for this page */
   295    296     MemPage *pParent;    /* The parent of this page.  NULL for root */
   296    297   };
   297    298   
   298    299   /*
   299    300   ** The in-memory image of a disk page has the auxiliary information appended
   300    301   ** to the end.  EXTRA_SIZE is the number of bytes of space needed to hold
................................................................................
   811    812   ** Write an entry into the pointer map.
   812    813   **
   813    814   ** This routine updates the pointer map entry for page number 'key'
   814    815   ** so that it maps to type 'eType' and parent page number 'pgno'.
   815    816   ** An error code is returned if something goes wrong, otherwise SQLITE_OK.
   816    817   */
   817    818   static int ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent){
   818         -  u8 *pPtrmap;    /* The pointer map page */
   819         -  Pgno iPtrmap;   /* The pointer map page number */
   820         -  int offset;     /* Offset in pointer map page */
          819  +  DbPage *pDbPage;  /* The pointer map page */
          820  +  u8 *pPtrmap;      /* The pointer map data */
          821  +  Pgno iPtrmap;     /* The pointer map page number */
          822  +  int offset;       /* Offset in pointer map page */
   821    823     int rc;
   822    824   
   823    825     /* The master-journal page number must never be used as a pointer map page */
   824    826     assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
   825    827   
   826    828     assert( pBt->autoVacuum );
   827    829     if( key==0 ){
   828    830       return SQLITE_CORRUPT_BKPT;
   829    831     }
   830    832     iPtrmap = PTRMAP_PAGENO(pBt, key);
   831         -  rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap);
          833  +  rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage);
   832    834     if( rc!=SQLITE_OK ){
   833    835       return rc;
   834    836     }
   835    837     offset = PTRMAP_PTROFFSET(pBt, key);
          838  +  pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
   836    839   
   837    840     if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
   838    841       TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
   839         -    rc = sqlite3pager_write(pPtrmap);
          842  +    rc = sqlite3PagerWrite(pDbPage);
   840    843       if( rc==SQLITE_OK ){
   841    844         pPtrmap[offset] = eType;
   842    845         put4byte(&pPtrmap[offset+1], parent);
   843    846       }
   844    847     }
   845    848   
   846         -  sqlite3pager_unref(pPtrmap);
          849  +  sqlite3PagerUnref(pDbPage);
   847    850     return rc;
   848    851   }
   849    852   
   850    853   /*
   851    854   ** Read an entry from the pointer map.
   852    855   **
   853    856   ** This routine retrieves the pointer map entry for page 'key', writing
   854    857   ** the type and parent page number to *pEType and *pPgno respectively.
   855    858   ** An error code is returned if something goes wrong, otherwise SQLITE_OK.
   856    859   */
   857    860   static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){
          861  +  DbPage *pDbPage;   /* The pointer map page */
   858    862     int iPtrmap;       /* Pointer map page index */
   859    863     u8 *pPtrmap;       /* Pointer map page data */
   860    864     int offset;        /* Offset of entry in pointer map */
   861    865     int rc;
   862    866   
   863    867     iPtrmap = PTRMAP_PAGENO(pBt, key);
   864         -  rc = sqlite3pager_get(pBt->pPager, iPtrmap, (void **)&pPtrmap);
          868  +  rc = sqlite3PagerGet(pBt->pPager, iPtrmap, &pDbPage);
   865    869     if( rc!=0 ){
   866    870       return rc;
   867    871     }
          872  +  pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
   868    873   
   869    874     offset = PTRMAP_PTROFFSET(pBt, key);
   870    875     assert( pEType!=0 );
   871    876     *pEType = pPtrmap[offset];
   872    877     if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]);
   873    878   
   874         -  sqlite3pager_unref(pPtrmap);
          879  +  sqlite3PagerUnref(pDbPage);
   875    880     if( *pEType<1 || *pEType>5 ) return SQLITE_CORRUPT_BKPT;
   876    881     return SQLITE_OK;
   877    882   }
   878    883   
   879    884   #endif /* SQLITE_OMIT_AUTOVACUUM */
   880    885   
   881    886   /*
................................................................................
  1067   1072     int usableSize;            /* Number of usable bytes on a page */
  1068   1073     int cellOffset;            /* Offset to the cell pointer array */
  1069   1074     int brk;                   /* Offset to the cell content area */
  1070   1075     int nCell;                 /* Number of cells on the page */
  1071   1076     unsigned char *data;       /* The page data */
  1072   1077     unsigned char *temp;       /* Temp area for cell content */
  1073   1078   
  1074         -  assert( sqlite3pager_iswriteable(pPage->aData) );
         1079  +  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  1075   1080     assert( pPage->pBt!=0 );
  1076   1081     assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
  1077   1082     assert( pPage->nOverflow==0 );
  1078   1083     temp = sqliteMalloc( pPage->pBt->pageSize );
  1079   1084     if( temp==0 ) return SQLITE_NOMEM;
  1080   1085     data = pPage->aData;
  1081   1086     hdr = pPage->hdrOffset;
................................................................................
  1125   1130     int nFrag;
  1126   1131     int top;
  1127   1132     int nCell;
  1128   1133     int cellOffset;
  1129   1134     unsigned char *data;
  1130   1135     
  1131   1136     data = pPage->aData;
  1132         -  assert( sqlite3pager_iswriteable(data) );
         1137  +  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  1133   1138     assert( pPage->pBt );
  1134   1139     if( nByte<4 ) nByte = 4;
  1135   1140     if( pPage->nFree<nByte || pPage->nOverflow>0 ) return 0;
  1136   1141     pPage->nFree -= nByte;
  1137   1142     hdr = pPage->hdrOffset;
  1138   1143   
  1139   1144     nFrag = data[hdr+7];
................................................................................
  1182   1187   ** free blocks into a single big free block.
  1183   1188   */
  1184   1189   static void freeSpace(MemPage *pPage, int start, int size){
  1185   1190     int addr, pbegin, hdr;
  1186   1191     unsigned char *data = pPage->aData;
  1187   1192   
  1188   1193     assert( pPage->pBt!=0 );
  1189         -  assert( sqlite3pager_iswriteable(data) );
         1194  +  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  1190   1195     assert( start>=pPage->hdrOffset+6+(pPage->leaf?0:4) );
  1191   1196     assert( (start + size)<=pPage->pBt->usableSize );
  1192   1197     if( size<4 ) size = 4;
  1193   1198   
  1194   1199   #ifdef SQLITE_SECURE_DELETE
  1195   1200     /* Overwrite deleted information with zeros when the SECURE_DELETE 
  1196   1201     ** option is enabled at compile-time */
................................................................................
  1291   1296     int cellOffset;    /* Offset from start of page to first cell pointer */
  1292   1297     int nFree;         /* Number of unused bytes on the page */
  1293   1298     int top;           /* First byte of the cell content area */
  1294   1299   
  1295   1300     pBt = pPage->pBt;
  1296   1301     assert( pBt!=0 );
  1297   1302     assert( pParent==0 || pParent->pBt==pBt );
  1298         -  assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) );
         1303  +  assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
  1299   1304     assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] );
  1300   1305     if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){
  1301   1306       /* The parent page should never change unless the file is corrupt */
  1302   1307       return SQLITE_CORRUPT_BKPT;
  1303   1308     }
  1304   1309     if( pPage->isInit ) return SQLITE_OK;
  1305   1310     if( pPage->pParent==0 && pParent!=0 ){
  1306   1311       pPage->pParent = pParent;
  1307         -    sqlite3pager_ref(pParent->aData);
         1312  +    sqlite3PagerRef(pParent->pDbPage);
  1308   1313     }
  1309   1314     hdr = pPage->hdrOffset;
  1310   1315     data = pPage->aData;
  1311   1316     decodeFlags(pPage, data[hdr]);
  1312   1317     pPage->nOverflow = 0;
  1313   1318     pPage->idxShift = 0;
  1314   1319     usableSize = pBt->usableSize;
................................................................................
  1358   1363   */
  1359   1364   static void zeroPage(MemPage *pPage, int flags){
  1360   1365     unsigned char *data = pPage->aData;
  1361   1366     BtShared *pBt = pPage->pBt;
  1362   1367     int hdr = pPage->hdrOffset;
  1363   1368     int first;
  1364   1369   
  1365         -  assert( sqlite3pager_pagenumber(data)==pPage->pgno );
         1370  +  assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
  1366   1371     assert( &data[pBt->pageSize] == (unsigned char*)pPage );
  1367         -  assert( sqlite3pager_iswriteable(data) );
         1372  +  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  1368   1373     memset(&data[hdr], 0, pBt->usableSize - hdr);
  1369   1374     data[hdr] = flags;
  1370   1375     first = hdr + 8 + 4*((flags&PTF_LEAF)==0);
  1371   1376     memset(&data[hdr+1], 0, 4);
  1372   1377     data[hdr+7] = 0;
  1373   1378     put2byte(&data[hdr+5], pBt->usableSize);
  1374   1379     pPage->nFree = pBt->usableSize - first;
................................................................................
  1383   1388   
  1384   1389   /*
  1385   1390   ** Get a page from the pager.  Initialize the MemPage.pBt and
  1386   1391   ** MemPage.aData elements if needed.
  1387   1392   */
  1388   1393   static int getPage(BtShared *pBt, Pgno pgno, MemPage **ppPage, int clrFlag){
  1389   1394     int rc;
  1390         -  unsigned char *aData;
  1391   1395     MemPage *pPage;
  1392         -  rc = sqlite3pager_acquire(pBt->pPager, pgno, (void**)&aData, clrFlag);
         1396  +  DbPage *pDbPage;
         1397  +
         1398  +  rc = sqlite3PagerAcquire(pBt->pPager, pgno, (DbPage**)&pDbPage, clrFlag);
  1393   1399     if( rc ) return rc;
  1394         -  pPage = (MemPage*)&aData[pBt->pageSize];
  1395         -  pPage->aData = aData;
         1400  +  pPage = (MemPage *)sqlite3PagerGetExtra(pDbPage);
         1401  +  pPage->aData = sqlite3PagerGetData(pDbPage);
         1402  +  pPage->pDbPage = pDbPage;
  1396   1403     pPage->pBt = pBt;
  1397   1404     pPage->pgno = pgno;
  1398   1405     pPage->hdrOffset = pPage->pgno==1 ? 100 : 0;
  1399   1406     *ppPage = pPage;
  1400   1407     if( clrFlag ){
  1401         -    sqlite3pager_dont_rollback(aData);
         1408  +    sqlite3PagerDontRollback(pPage->pDbPage);
  1402   1409     }
  1403   1410     return SQLITE_OK;
  1404   1411   }
  1405   1412   
  1406   1413   /*
  1407   1414   ** Get a page from the pager and initialize it.  This routine
  1408   1415   ** is just a convenience wrapper around separate calls to
................................................................................
  1430   1437   ** call to getPage.
  1431   1438   */
  1432   1439   static void releasePage(MemPage *pPage){
  1433   1440     if( pPage ){
  1434   1441       assert( pPage->aData );
  1435   1442       assert( pPage->pBt );
  1436   1443       assert( &pPage->aData[pPage->pBt->pageSize]==(unsigned char*)pPage );
  1437         -    sqlite3pager_unref(pPage->aData);
         1444  +    sqlite3PagerUnref(pPage->pDbPage);
  1438   1445     }
  1439   1446   }
  1440   1447   
  1441   1448   /*
  1442   1449   ** This routine is called when the reference count for a page
  1443   1450   ** reaches zero.  We need to unref the pParent pointer when that
  1444   1451   ** happens.
  1445   1452   */
  1446         -static void pageDestructor(void *pData, int pageSize){
         1453  +static void pageDestructor(DbPage *pData, int pageSize){
  1447   1454     MemPage *pPage;
  1448   1455     assert( (pageSize & 7)==0 );
  1449         -  pPage = (MemPage*)&((char*)pData)[pageSize];
         1456  +  pPage = (MemPage *)sqlite3PagerGetExtra(pData);
  1450   1457     if( pPage->pParent ){
  1451   1458       MemPage *pParent = pPage->pParent;
  1452   1459       pPage->pParent = 0;
  1453   1460       releasePage(pParent);
  1454   1461     }
  1455   1462     pPage->isInit = 0;
  1456   1463   }
................................................................................
  1459   1466   ** During a rollback, when the pager reloads information into the cache
  1460   1467   ** so that the cache is restored to its original state at the start of
  1461   1468   ** the transaction, for each page restored this routine is called.
  1462   1469   **
  1463   1470   ** This routine needs to reset the extra data section at the end of the
  1464   1471   ** page to agree with the restored data.
  1465   1472   */
  1466         -static void pageReinit(void *pData, int pageSize){
         1473  +static void pageReinit(DbPage *pData, int pageSize){
  1467   1474     MemPage *pPage;
  1468   1475     assert( (pageSize & 7)==0 );
  1469         -  pPage = (MemPage*)&((char*)pData)[pageSize];
         1476  +  pPage = (MemPage *)sqlite3PagerGetExtra(pData);
  1470   1477     if( pPage->isInit ){
  1471   1478       pPage->isInit = 0;
  1472   1479       initPage(pPage, pPage->pParent);
  1473   1480     }
  1474   1481   }
  1475   1482   
  1476   1483   /*
................................................................................
  1522   1529       char *zFullPathname = sqlite3OsFullPathname(zFilename);
  1523   1530       if( !zFullPathname ){
  1524   1531         sqliteFree(p);
  1525   1532         return SQLITE_NOMEM;
  1526   1533       }
  1527   1534       for(pBt=pTsdro->pBtree; pBt; pBt=pBt->pNext){
  1528   1535         assert( pBt->nRef>0 );
  1529         -      if( 0==strcmp(zFullPathname, sqlite3pager_filename(pBt->pPager)) ){
         1536  +      if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager)) ){
  1530   1537           p->pBt = pBt;
  1531   1538           *ppBtree = p;
  1532   1539           pBt->nRef++;
  1533   1540           sqliteFree(zFullPathname);
  1534   1541           return SQLITE_OK;
  1535   1542         }
  1536   1543       }
................................................................................
  1551   1558   
  1552   1559     pBt = sqliteMalloc( sizeof(*pBt) );
  1553   1560     if( pBt==0 ){
  1554   1561       *ppBtree = 0;
  1555   1562       sqliteFree(p);
  1556   1563       return SQLITE_NOMEM;
  1557   1564     }
  1558         -  rc = sqlite3pager_open(&pBt->pPager, zFilename, EXTRA_SIZE, flags);
         1565  +  rc = sqlite3PagerOpen(&pBt->pPager, zFilename, EXTRA_SIZE, flags);
  1559   1566     if( rc==SQLITE_OK ){
  1560         -    rc = sqlite3pager_read_fileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
         1567  +    rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
  1561   1568     }
  1562   1569     if( rc!=SQLITE_OK ){
  1563   1570       if( pBt->pPager ){
  1564         -      sqlite3pager_close(pBt->pPager);
         1571  +      sqlite3PagerClose(pBt->pPager);
  1565   1572       }
  1566   1573       sqliteFree(pBt);
  1567   1574       sqliteFree(p);
  1568   1575       *ppBtree = 0;
  1569   1576       return rc;
  1570   1577     }
  1571   1578     p->pBt = pBt;
  1572   1579   
  1573         -  sqlite3pager_set_destructor(pBt->pPager, pageDestructor);
  1574         -  sqlite3pager_set_reiniter(pBt->pPager, pageReinit);
         1580  +  sqlite3PagerSetDestructor(pBt->pPager, pageDestructor);
         1581  +  sqlite3PagerSetReiniter(pBt->pPager, pageReinit);
  1575   1582     pBt->pCursor = 0;
  1576   1583     pBt->pPage1 = 0;
  1577         -  pBt->readOnly = sqlite3pager_isreadonly(pBt->pPager);
         1584  +  pBt->readOnly = sqlite3PagerIsreadonly(pBt->pPager);
  1578   1585     pBt->pageSize = get2byte(&zDbHeader[16]);
  1579   1586     if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
  1580   1587          || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
  1581   1588       pBt->pageSize = SQLITE_DEFAULT_PAGE_SIZE;
  1582   1589       pBt->maxEmbedFrac = 64;   /* 25% */
  1583   1590       pBt->minEmbedFrac = 32;   /* 12.5% */
  1584   1591       pBt->minLeafFrac = 32;    /* 12.5% */
................................................................................
  1602   1609       pBt->pageSizeFixed = 1;
  1603   1610   #ifndef SQLITE_OMIT_AUTOVACUUM
  1604   1611       pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
  1605   1612   #endif
  1606   1613     }
  1607   1614     pBt->usableSize = pBt->pageSize - nReserve;
  1608   1615     assert( (pBt->pageSize & 7)==0 );  /* 8-byte alignment of pageSize */
  1609         -  sqlite3pager_set_pagesize(pBt->pPager, pBt->pageSize);
         1616  +  sqlite3PagerSetPagesize(pBt->pPager, pBt->pageSize);
  1610   1617   
  1611   1618   #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
  1612   1619     /* Add the new btree to the linked list starting at ThreadData.pBtree.
  1613   1620     ** There is no chance that a malloc() may fail inside of the 
  1614   1621     ** sqlite3ThreadData() call, as the ThreadData structure must have already
  1615   1622     ** been allocated for pTsdro->useSharedData to be non-zero.
  1616   1623     */
................................................................................
  1679   1686         pPrev->pNext = pBt->pNext;
  1680   1687       }
  1681   1688     }
  1682   1689   #endif
  1683   1690   
  1684   1691     /* Close the pager and free the shared-btree structure */
  1685   1692     assert( !pBt->pCursor );
  1686         -  sqlite3pager_close(pBt->pPager);
         1693  +  sqlite3PagerClose(pBt->pPager);
  1687   1694     if( pBt->xFreeSchema && pBt->pSchema ){
  1688   1695       pBt->xFreeSchema(pBt->pSchema);
  1689   1696     }
  1690   1697     sqliteFree(pBt->pSchema);
  1691   1698     sqliteFree(pBt);
  1692   1699     return SQLITE_OK;
  1693   1700   }
................................................................................
  1694   1701   
  1695   1702   /*
  1696   1703   ** Change the busy handler callback function.
  1697   1704   */
  1698   1705   int sqlite3BtreeSetBusyHandler(Btree *p, BusyHandler *pHandler){
  1699   1706     BtShared *pBt = p->pBt;
  1700   1707     pBt->pBusyHandler = pHandler;
  1701         -  sqlite3pager_set_busyhandler(pBt->pPager, pHandler);
         1708  +  sqlite3PagerSetBusyhandler(pBt->pPager, pHandler);
  1702   1709     return SQLITE_OK;
  1703   1710   }
  1704   1711   
  1705   1712   /*
  1706   1713   ** Change the limit on the number of pages allowed in the cache.
  1707   1714   **
  1708   1715   ** The maximum number of cache pages is set to the absolute
................................................................................
  1715   1722   ** an abrupt power failure when synchronous is off, the database
  1716   1723   ** could be left in an inconsistent and unrecoverable state.
  1717   1724   ** Synchronous is on by default so database corruption is not
  1718   1725   ** normally a worry.
  1719   1726   */
  1720   1727   int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){
  1721   1728     BtShared *pBt = p->pBt;
  1722         -  sqlite3pager_set_cachesize(pBt->pPager, mxPage);
         1729  +  sqlite3PagerSetCachesize(pBt->pPager, mxPage);
  1723   1730     return SQLITE_OK;
  1724   1731   }
  1725   1732   
  1726   1733   /*
  1727   1734   ** Change the way data is synced to disk in order to increase or decrease
  1728   1735   ** how well the database resists damage due to OS crashes and power
  1729   1736   ** failures.  Level 1 is the same as asynchronous (no syncs() occur and
................................................................................
  1730   1737   ** there is a high probability of damage)  Level 2 is the default.  There
  1731   1738   ** is a very low but non-zero probability of damage.  Level 3 reduces the
  1732   1739   ** probability of damage to near zero but with a write performance reduction.
  1733   1740   */
  1734   1741   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
  1735   1742   int sqlite3BtreeSetSafetyLevel(Btree *p, int level, int fullSync){
  1736   1743     BtShared *pBt = p->pBt;
  1737         -  sqlite3pager_set_safety_level(pBt->pPager, level, fullSync);
         1744  +  sqlite3PagerSetSafetyLevel(pBt->pPager, level, fullSync);
  1738   1745     return SQLITE_OK;
  1739   1746   }
  1740   1747   #endif
  1741   1748   
  1742   1749   /*
  1743   1750   ** Return TRUE if the given btree is set to safety level 1.  In other
  1744   1751   ** words, return TRUE if no sync() occurs on the disk files.
  1745   1752   */
  1746   1753   int sqlite3BtreeSyncDisabled(Btree *p){
  1747   1754     BtShared *pBt = p->pBt;
  1748   1755     assert( pBt && pBt->pPager );
  1749         -  return sqlite3pager_nosync(pBt->pPager);
         1756  +  return sqlite3PagerNosync(pBt->pPager);
  1750   1757   }
  1751   1758   
  1752   1759   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM)
  1753   1760   /*
  1754   1761   ** Change the default pages size and the number of reserved bytes per page.
  1755   1762   **
  1756   1763   ** The page size must be a power of 2 between 512 and 65536.  If the page
................................................................................
  1773   1780     if( nReserve<0 ){
  1774   1781       nReserve = pBt->pageSize - pBt->usableSize;
  1775   1782     }
  1776   1783     if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
  1777   1784           ((pageSize-1)&pageSize)==0 ){
  1778   1785       assert( (pageSize & 7)==0 );
  1779   1786       assert( !pBt->pPage1 && !pBt->pCursor );
  1780         -    pBt->pageSize = sqlite3pager_set_pagesize(pBt->pPager, pageSize);
         1787  +    pBt->pageSize = sqlite3PagerSetPagesize(pBt->pPager, pageSize);
  1781   1788     }
  1782   1789     pBt->usableSize = pBt->pageSize - nReserve;
  1783   1790     return SQLITE_OK;
  1784   1791   }
  1785   1792   
  1786   1793   /*
  1787   1794   ** Return the currently defined page size
................................................................................
  1844   1851     if( rc!=SQLITE_OK ) return rc;
  1845   1852     
  1846   1853   
  1847   1854     /* Do some checking to help insure the file we opened really is
  1848   1855     ** a valid database file. 
  1849   1856     */
  1850   1857     rc = SQLITE_NOTADB;
  1851         -  if( sqlite3pager_pagecount(pBt->pPager)>0 ){
         1858  +  if( sqlite3PagerPagecount(pBt->pPager)>0 ){
  1852   1859       u8 *page1 = pPage1->aData;
  1853   1860       if( memcmp(page1, zMagicHeader, 16)!=0 ){
  1854   1861         goto page1_init_failed;
  1855   1862       }
  1856   1863       if( page1[18]>1 || page1[19]>1 ){
  1857   1864         goto page1_init_failed;
  1858   1865       }
................................................................................
  1933   1940   **
  1934   1941   ** If there are any outstanding cursors, this routine is a no-op.
  1935   1942   **
  1936   1943   ** If there is a transaction in progress, this routine is a no-op.
  1937   1944   */
  1938   1945   static void unlockBtreeIfUnused(BtShared *pBt){
  1939   1946     if( pBt->inTransaction==TRANS_NONE && pBt->pCursor==0 && pBt->pPage1!=0 ){
  1940         -    if( sqlite3pager_refcount(pBt->pPager)>=1 ){
         1947  +    if( sqlite3PagerRefcount(pBt->pPager)>=1 ){
  1941   1948         if( pBt->pPage1->aData==0 ){
  1942   1949           MemPage *pPage = pBt->pPage1;
  1943   1950           pPage->aData = &((u8*)pPage)[-pBt->pageSize];
  1944   1951           pPage->pBt = pBt;
  1945   1952           pPage->pgno = 1;
  1946   1953         }
  1947   1954         releasePage(pBt->pPage1);
................................................................................
  1955   1962   ** Create a new database by initializing the first page of the
  1956   1963   ** file.
  1957   1964   */
  1958   1965   static int newDatabase(BtShared *pBt){
  1959   1966     MemPage *pP1;
  1960   1967     unsigned char *data;
  1961   1968     int rc;
  1962         -  if( sqlite3pager_pagecount(pBt->pPager)>0 ) return SQLITE_OK;
         1969  +  if( sqlite3PagerPagecount(pBt->pPager)>0 ) return SQLITE_OK;
  1963   1970     pP1 = pBt->pPage1;
  1964   1971     assert( pP1!=0 );
  1965   1972     data = pP1->aData;
  1966         -  rc = sqlite3pager_write(data);
         1973  +  rc = sqlite3PagerWrite(pP1->pDbPage);
  1967   1974     if( rc ) return rc;
  1968   1975     memcpy(data, zMagicHeader, sizeof(zMagicHeader));
  1969   1976     assert( sizeof(zMagicHeader)==16 );
  1970   1977     put2byte(&data[16], pBt->pageSize);
  1971   1978     data[18] = 1;
  1972   1979     data[19] = 1;
  1973   1980     data[20] = pBt->pageSize - pBt->usableSize;
................................................................................
  2049   2056   
  2050   2057     do {
  2051   2058       if( pBt->pPage1==0 ){
  2052   2059         rc = lockBtree(pBt);
  2053   2060       }
  2054   2061     
  2055   2062       if( rc==SQLITE_OK && wrflag ){
  2056         -      rc = sqlite3pager_begin(pBt->pPage1->aData, wrflag>1);
         2063  +      rc = sqlite3PagerBegin(pBt->pPage1->pDbPage, wrflag>1);
  2057   2064         if( rc==SQLITE_OK ){
  2058   2065           rc = newDatabase(pBt);
  2059   2066         }
  2060   2067       }
  2061   2068     
  2062   2069       if( rc==SQLITE_OK ){
  2063   2070         if( wrflag ) pBt->inStmt = 0;
................................................................................
  2205   2212   
  2206   2213     assert( eType==PTRMAP_OVERFLOW2 || eType==PTRMAP_OVERFLOW1 || 
  2207   2214         eType==PTRMAP_BTREE || eType==PTRMAP_ROOTPAGE );
  2208   2215   
  2209   2216     /* Move page iDbPage from it's current location to page number iFreePage */
  2210   2217     TRACE(("AUTOVACUUM: Moving %d to free page %d (ptr page %d type %d)\n", 
  2211   2218         iDbPage, iFreePage, iPtrPage, eType));
  2212         -  rc = sqlite3pager_movepage(pPager, pDbPage->aData, iFreePage);
         2219  +  rc = sqlite3PagerMovepage(pPager, pDbPage->pDbPage, iFreePage);
  2213   2220     if( rc!=SQLITE_OK ){
  2214   2221       return rc;
  2215   2222     }
  2216   2223     pDbPage->pgno = iFreePage;
  2217   2224   
  2218   2225     /* If pDbPage was a btree-page, then it may have child pages and/or cells
  2219   2226     ** that point to overflow pages. The pointer map entries for all these
................................................................................
  2243   2250     ** iPtrPage.
  2244   2251     */
  2245   2252     if( eType!=PTRMAP_ROOTPAGE ){
  2246   2253       rc = getPage(pBt, iPtrPage, &pPtrPage, 0);
  2247   2254       if( rc!=SQLITE_OK ){
  2248   2255         return rc;
  2249   2256       }
  2250         -    rc = sqlite3pager_write(pPtrPage->aData);
         2257  +    rc = sqlite3PagerWrite(pPtrPage->pDbPage);
  2251   2258       if( rc!=SQLITE_OK ){
  2252   2259         releasePage(pPtrPage);
  2253   2260         return rc;
  2254   2261       }
  2255   2262       rc = modifyPagePointer(pPtrPage, iDbPage, iFreePage, eType);
  2256   2263       releasePage(pPtrPage);
  2257   2264       if( rc==SQLITE_OK ){
................................................................................
  2261   2268     return rc;
  2262   2269   }
  2263   2270   
  2264   2271   /* Forward declaration required by autoVacuumCommit(). */
  2265   2272   static int allocatePage(BtShared *, MemPage **, Pgno *, Pgno, u8);
  2266   2273   
  2267   2274   /*
  2268         -** This routine is called prior to sqlite3pager_commit when a transaction
         2275  +** This routine is called prior to sqlite3PagerCommit when a transaction
  2269   2276   ** is commited for an auto-vacuum database.
  2270   2277   */
  2271   2278   static int autoVacuumCommit(BtShared *pBt, Pgno *nTrunc){
  2272   2279     Pager *pPager = pBt->pPager;
  2273   2280     Pgno nFreeList;            /* Number of pages remaining on the free-list. */
  2274   2281     int nPtrMap;               /* Number of pointer-map pages deallocated */
  2275   2282     Pgno origSize;             /* Pages in the database file */
................................................................................
  2280   2287     Pgno iDbPage;              /* The database page to move */
  2281   2288     MemPage *pDbMemPage = 0;   /* "" */
  2282   2289     Pgno iPtrPage;             /* The page that contains a pointer to iDbPage */
  2283   2290     Pgno iFreePage;            /* The free-list page to move iDbPage to */
  2284   2291     MemPage *pFreeMemPage = 0; /* "" */
  2285   2292   
  2286   2293   #ifndef NDEBUG
  2287         -  int nRef = sqlite3pager_refcount(pPager);
         2294  +  int nRef = sqlite3PagerRefcount(pPager);
  2288   2295   #endif
  2289   2296   
  2290   2297     assert( pBt->autoVacuum );
  2291         -  if( PTRMAP_ISPAGE(pBt, sqlite3pager_pagecount(pPager)) ){
         2298  +  if( PTRMAP_ISPAGE(pBt, sqlite3PagerPagecount(pPager)) ){
  2292   2299       return SQLITE_CORRUPT_BKPT;
  2293   2300     }
  2294   2301   
  2295   2302     /* Figure out how many free-pages are in the database. If there are no
  2296   2303     ** free pages, then auto-vacuum is a no-op.
  2297   2304     */
  2298   2305     nFreeList = get4byte(&pBt->pPage1->aData[36]);
................................................................................
  2306   2313     ** truncation (variable finSize).
  2307   2314     **
  2308   2315     ** The final size is the original size, less the number of free pages
  2309   2316     ** in the database, less any pointer-map pages that will no longer
  2310   2317     ** be required, less 1 if the pending-byte page was part of the database
  2311   2318     ** but is not after the truncation.
  2312   2319     **/
  2313         -  origSize = sqlite3pager_pagecount(pPager);
         2320  +  origSize = sqlite3PagerPagecount(pPager);
  2314   2321     if( origSize==PENDING_BYTE_PAGE(pBt) ){
  2315   2322       origSize--;
  2316   2323     }
  2317   2324     nPtrMap = (nFreeList-origSize+PTRMAP_PAGENO(pBt, origSize)+pgsz/5)/(pgsz/5);
  2318   2325     finSize = origSize - nFreeList - nPtrMap;
  2319   2326     if( origSize>PENDING_BYTE_PAGE(pBt) && finSize<=PENDING_BYTE_PAGE(pBt) ){
  2320   2327       finSize--;
................................................................................
  2380   2387       if( rc!=SQLITE_OK ) goto autovacuum_out;
  2381   2388     }
  2382   2389   
  2383   2390     /* The entire free-list has been swapped to the end of the file. So
  2384   2391     ** truncate the database file to finSize pages and consider the
  2385   2392     ** free-list empty.
  2386   2393     */
  2387         -  rc = sqlite3pager_write(pBt->pPage1->aData);
         2394  +  rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
  2388   2395     if( rc!=SQLITE_OK ) goto autovacuum_out;
  2389   2396     put4byte(&pBt->pPage1->aData[32], 0);
  2390   2397     put4byte(&pBt->pPage1->aData[36], 0);
  2391   2398     *nTrunc = finSize;
  2392   2399     assert( finSize!=PENDING_BYTE_PAGE(pBt) );
  2393   2400   
  2394   2401   autovacuum_out:
  2395         -  assert( nRef==sqlite3pager_refcount(pPager) );
         2402  +  assert( nRef==sqlite3PagerRefcount(pPager) );
  2396   2403     if( rc!=SQLITE_OK ){
  2397         -    sqlite3pager_rollback(pPager);
         2404  +    sqlite3PagerRollback(pPager);
  2398   2405     }
  2399   2406     return rc;
  2400   2407   }
  2401   2408   #endif
  2402   2409   
  2403   2410   /*
  2404   2411   ** Commit the transaction currently in progress.
................................................................................
  2414   2421     /* If the handle has a write-transaction open, commit the shared-btrees 
  2415   2422     ** transaction and set the shared state to TRANS_READ.
  2416   2423     */
  2417   2424     if( p->inTrans==TRANS_WRITE ){
  2418   2425       int rc;
  2419   2426       assert( pBt->inTransaction==TRANS_WRITE );
  2420   2427       assert( pBt->nTransaction>0 );
  2421         -    rc = sqlite3pager_commit(pBt->pPager);
         2428  +    rc = sqlite3PagerCommit(pBt->pPager);
  2422   2429       if( rc!=SQLITE_OK ){
  2423   2430         return rc;
  2424   2431       }
  2425   2432       pBt->inTransaction = TRANS_READ;
  2426   2433       pBt->inStmt = 0;
  2427   2434     }
  2428   2435     unlockAllTables(p);
................................................................................
  2519   2526     btreeIntegrity(p);
  2520   2527     unlockAllTables(p);
  2521   2528   
  2522   2529     if( p->inTrans==TRANS_WRITE ){
  2523   2530       int rc2;
  2524   2531   
  2525   2532       assert( TRANS_WRITE==pBt->inTransaction );
  2526         -    rc2 = sqlite3pager_rollback(pBt->pPager);
         2533  +    rc2 = sqlite3PagerRollback(pBt->pPager);
  2527   2534       if( rc2!=SQLITE_OK ){
  2528   2535         rc = rc2;
  2529   2536       }
  2530   2537   
  2531   2538       /* The rollback may have destroyed the pPage1->aData value.  So
  2532   2539       ** call getPage() on page 1 again to make sure pPage1->aData is
  2533   2540       ** set correctly. */
................................................................................
  2572   2579   int sqlite3BtreeBeginStmt(Btree *p){
  2573   2580     int rc;
  2574   2581     BtShared *pBt = p->pBt;
  2575   2582     if( (p->inTrans!=TRANS_WRITE) || pBt->inStmt ){
  2576   2583       return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
  2577   2584     }
  2578   2585     assert( pBt->inTransaction==TRANS_WRITE );
  2579         -  rc = pBt->readOnly ? SQLITE_OK : sqlite3pager_stmt_begin(pBt->pPager);
         2586  +  rc = pBt->readOnly ? SQLITE_OK : sqlite3PagerStmtBegin(pBt->pPager);
  2580   2587     pBt->inStmt = 1;
  2581   2588     return rc;
  2582   2589   }
  2583   2590   
  2584   2591   
  2585   2592   /*
  2586   2593   ** Commit the statment subtransaction currently in progress.  If no
  2587   2594   ** subtransaction is active, this is a no-op.
  2588   2595   */
  2589   2596   int sqlite3BtreeCommitStmt(Btree *p){
  2590   2597     int rc;
  2591   2598     BtShared *pBt = p->pBt;
  2592   2599     if( pBt->inStmt && !pBt->readOnly ){
  2593         -    rc = sqlite3pager_stmt_commit(pBt->pPager);
         2600  +    rc = sqlite3PagerStmtCommit(pBt->pPager);
  2594   2601     }else{
  2595   2602       rc = SQLITE_OK;
  2596   2603     }
  2597   2604     pBt->inStmt = 0;
  2598   2605     return rc;
  2599   2606   }
  2600   2607   
................................................................................
  2607   2614   ** will result in an error.
  2608   2615   */
  2609   2616   int sqlite3BtreeRollbackStmt(Btree *p){
  2610   2617     int rc = SQLITE_OK;
  2611   2618     BtShared *pBt = p->pBt;
  2612   2619     sqlite3MallocDisallow();
  2613   2620     if( pBt->inStmt && !pBt->readOnly ){
  2614         -    rc = sqlite3pager_stmt_rollback(pBt->pPager);
         2621  +    rc = sqlite3PagerStmtRollback(pBt->pPager);
  2615   2622       assert( countWriteCursors(pBt)==0 );
  2616   2623       pBt->inStmt = 0;
  2617   2624     }
  2618   2625     sqlite3MallocAllow();
  2619   2626     return rc;
  2620   2627   }
  2621   2628   
................................................................................
  2699   2706     }
  2700   2707     pCur = sqliteMalloc( sizeof(*pCur) );
  2701   2708     if( pCur==0 ){
  2702   2709       rc = SQLITE_NOMEM;
  2703   2710       goto create_cursor_exception;
  2704   2711     }
  2705   2712     pCur->pgnoRoot = (Pgno)iTable;
  2706         -  if( iTable==1 && sqlite3pager_pagecount(pBt->pPager)==0 ){
         2713  +  if( iTable==1 && sqlite3PagerPagecount(pBt->pPager)==0 ){
  2707   2714       rc = SQLITE_EMPTY;
  2708   2715       goto create_cursor_exception;
  2709   2716     }
  2710   2717     rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->pPage, 0);
  2711   2718     if( rc!=SQLITE_OK ){
  2712   2719       goto create_cursor_exception;
  2713   2720     }
................................................................................
  2778   2785   ** The temporary cursor is not on the cursor list for the Btree.
  2779   2786   */
  2780   2787   static void getTempCursor(BtCursor *pCur, BtCursor *pTempCur){
  2781   2788     memcpy(pTempCur, pCur, sizeof(*pCur));
  2782   2789     pTempCur->pNext = 0;
  2783   2790     pTempCur->pPrev = 0;
  2784   2791     if( pTempCur->pPage ){
  2785         -    sqlite3pager_ref(pTempCur->pPage->aData);
         2792  +    sqlite3PagerRef(pTempCur->pPage->pDbPage);
  2786   2793     }
  2787   2794   }
  2788   2795   
  2789   2796   /*
  2790   2797   ** Delete a temporary cursor such as was made by the CreateTemporaryCursor()
  2791   2798   ** function above.
  2792   2799   */
  2793   2800   static void releaseTempCursor(BtCursor *pCur){
  2794   2801     if( pCur->pPage ){
  2795         -    sqlite3pager_unref(pCur->pPage->aData);
         2802  +    sqlite3PagerUnref(pCur->pPage->pDbPage);
  2796   2803     }
  2797   2804   }
  2798   2805   
  2799   2806   /*
  2800   2807   ** Make sure the BtCursor.info field of the given cursor is valid.
  2801   2808   ** If it is not already valid, call parseCell() to fill it in.
  2802   2809   **
................................................................................
  2918   2925     }else{
  2919   2926       offset -= pCur->info.nLocal;
  2920   2927     }
  2921   2928     ovflSize = pBt->usableSize - 4;
  2922   2929     if( amt>0 ){
  2923   2930       nextPage = get4byte(&aPayload[pCur->info.nLocal]);
  2924   2931       while( amt>0 && nextPage ){
  2925         -      rc = sqlite3pager_get(pBt->pPager, nextPage, (void**)&aPayload);
         2932  +      DbPage *pDbPage;
         2933  +      rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage);
  2926   2934         if( rc!=0 ){
  2927   2935           return rc;
  2928   2936         }
         2937  +      aPayload = sqlite3PagerGetData(pDbPage);
  2929   2938         nextPage = get4byte(aPayload);
  2930   2939         if( offset<ovflSize ){
  2931   2940           int a = amt;
  2932   2941           if( a + offset > ovflSize ){
  2933   2942             a = ovflSize - offset;
  2934   2943           }
  2935   2944           memcpy(pBuf, &aPayload[offset+4], a);
  2936   2945           offset = 0;
  2937   2946           amt -= a;
  2938   2947           pBuf += a;
  2939   2948         }else{
  2940   2949           offset -= ovflSize;
  2941   2950         }
  2942         -      sqlite3pager_unref(aPayload);
         2951  +      sqlite3PagerUnref(pDbPage);
  2943   2952       }
  2944   2953     }
  2945   2954   
  2946   2955     if( amt>0 ){
  2947   2956       return SQLITE_CORRUPT_BKPT;
  2948   2957     }
  2949   2958     return SQLITE_OK;
................................................................................
  3132   3141     assert( pCur->eState==CURSOR_VALID );
  3133   3142     pPage = pCur->pPage;
  3134   3143     assert( pPage!=0 );
  3135   3144     assert( !isRootPage(pPage) );
  3136   3145     pParent = pPage->pParent;
  3137   3146     assert( pParent!=0 );
  3138   3147     idxParent = pPage->idxParent;
  3139         -  sqlite3pager_ref(pParent->aData);
         3148  +  sqlite3PagerRef(pParent->pDbPage);
  3140   3149     releasePage(pPage);
  3141   3150     pCur->pPage = pParent;
  3142   3151     pCur->info.nSize = 0;
  3143   3152     assert( pParent->idxShift==0 );
  3144   3153     pCur->idx = idxParent;
  3145   3154   }
  3146   3155   
................................................................................
  3536   3545     *pRes = 0;
  3537   3546     return rc;
  3538   3547   }
  3539   3548   
  3540   3549   /*
  3541   3550   ** Allocate a new page from the database file.
  3542   3551   **
  3543         -** The new page is marked as dirty.  (In other words, sqlite3pager_write()
         3552  +** The new page is marked as dirty.  (In other words, sqlite3PagerWrite()
  3544   3553   ** has already been called on the new page.)  The new page has also
  3545   3554   ** been referenced and the calling routine is responsible for calling
  3546         -** sqlite3pager_unref() on the new page when it is done.
         3555  +** sqlite3PagerUnref() on the new page when it is done.
  3547   3556   **
  3548   3557   ** SQLITE_OK is returned on success.  Any other return value indicates
  3549   3558   ** an error.  *ppPage and *pPgno are undefined in the event of an error.
  3550         -** Do not invoke sqlite3pager_unref() on *ppPage if an error is returned.
         3559  +** Do not invoke sqlite3PagerUnref() on *ppPage if an error is returned.
  3551   3560   **
  3552   3561   ** If the "nearby" parameter is not 0, then a (feeble) effort is made to 
  3553   3562   ** locate a page close to the page number "nearby".  This can be used in an
  3554   3563   ** attempt to keep related pages close to each other in the database file,
  3555   3564   ** which in turn can make database access faster.
  3556   3565   **
  3557   3566   ** If the "exact" parameter is not 0, and the page-number nearby exists 
................................................................................
  3596   3605         *pPgno = nearby;
  3597   3606       }
  3598   3607   #endif
  3599   3608   
  3600   3609       /* Decrement the free-list count by 1. Set iTrunk to the index of the
  3601   3610       ** first free-list trunk page. iPrevTrunk is initially 1.
  3602   3611       */
  3603         -    rc = sqlite3pager_write(pPage1->aData);
         3612  +    rc = sqlite3PagerWrite(pPage1->pDbPage);
  3604   3613       if( rc ) return rc;
  3605   3614       put4byte(&pPage1->aData[36], n-1);
  3606   3615   
  3607   3616       /* The code within this loop is run only once if the 'searchList' variable
  3608   3617       ** is not true. Otherwise, it runs once for each trunk-page on the
  3609   3618       ** free-list until the page 'nearby' is located.
  3610   3619       */
................................................................................
  3623   3632   
  3624   3633         k = get4byte(&pTrunk->aData[4]);
  3625   3634         if( k==0 && !searchList ){
  3626   3635           /* The trunk has no leaves and the list is not being searched. 
  3627   3636           ** So extract the trunk page itself and use it as the newly 
  3628   3637           ** allocated page */
  3629   3638           assert( pPrevTrunk==0 );
  3630         -        rc = sqlite3pager_write(pTrunk->aData);
         3639  +        rc = sqlite3PagerWrite(pTrunk->pDbPage);
  3631   3640           if( rc ){
  3632   3641             goto end_allocate_page;
  3633   3642           }
  3634   3643           *pPgno = iTrunk;
  3635   3644           memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
  3636   3645           *ppPage = pTrunk;
  3637   3646           pTrunk = 0;
................................................................................
  3644   3653         }else if( searchList && nearby==iTrunk ){
  3645   3654           /* The list is being searched and this trunk page is the page
  3646   3655           ** to allocate, regardless of whether it has leaves.
  3647   3656           */
  3648   3657           assert( *pPgno==iTrunk );
  3649   3658           *ppPage = pTrunk;
  3650   3659           searchList = 0;
  3651         -        rc = sqlite3pager_write(pTrunk->aData);
         3660  +        rc = sqlite3PagerWrite(pTrunk->pDbPage);
  3652   3661           if( rc ){
  3653   3662             goto end_allocate_page;
  3654   3663           }
  3655   3664           if( k==0 ){
  3656   3665             if( !pPrevTrunk ){
  3657   3666               memcpy(&pPage1->aData[32], &pTrunk->aData[0], 4);
  3658   3667             }else{
................................................................................
  3665   3674             */
  3666   3675             MemPage *pNewTrunk;
  3667   3676             Pgno iNewTrunk = get4byte(&pTrunk->aData[8]);
  3668   3677             rc = getPage(pBt, iNewTrunk, &pNewTrunk, 0);
  3669   3678             if( rc!=SQLITE_OK ){
  3670   3679               goto end_allocate_page;
  3671   3680             }
  3672         -          rc = sqlite3pager_write(pNewTrunk->aData);
         3681  +          rc = sqlite3PagerWrite(pNewTrunk->pDbPage);
  3673   3682             if( rc!=SQLITE_OK ){
  3674   3683               releasePage(pNewTrunk);
  3675   3684               goto end_allocate_page;
  3676   3685             }
  3677   3686             memcpy(&pNewTrunk->aData[0], &pTrunk->aData[0], 4);
  3678   3687             put4byte(&pNewTrunk->aData[4], k-1);
  3679   3688             memcpy(&pNewTrunk->aData[8], &pTrunk->aData[12], (k-1)*4);
  3680   3689             releasePage(pNewTrunk);
  3681   3690             if( !pPrevTrunk ){
  3682   3691               put4byte(&pPage1->aData[32], iNewTrunk);
  3683   3692             }else{
  3684         -            rc = sqlite3pager_write(pPrevTrunk->aData);
         3693  +            rc = sqlite3PagerWrite(pPrevTrunk->pDbPage);
  3685   3694               if( rc ){
  3686   3695                 goto end_allocate_page;
  3687   3696               }
  3688   3697               put4byte(&pPrevTrunk->aData[0], iNewTrunk);
  3689   3698             }
  3690   3699           }
  3691   3700           pTrunk = 0;
................................................................................
  3692   3701           TRACE(("ALLOCATE: %d trunk - %d free pages left\n", *pPgno, n-1));
  3693   3702   #endif
  3694   3703         }else{
  3695   3704           /* Extract a leaf from the trunk */
  3696   3705           int closest;
  3697   3706           Pgno iPage;
  3698   3707           unsigned char *aData = pTrunk->aData;
  3699         -        rc = sqlite3pager_write(aData);
         3708  +        rc = sqlite3PagerWrite(pTrunk->pDbPage);
  3700   3709           if( rc ){
  3701   3710             goto end_allocate_page;
  3702   3711           }
  3703   3712           if( nearby>0 ){
  3704   3713             int i, dist;
  3705   3714             closest = 0;
  3706   3715             dist = get4byte(&aData[8]) - nearby;
................................................................................
  3716   3725           }else{
  3717   3726             closest = 0;
  3718   3727           }
  3719   3728   
  3720   3729           iPage = get4byte(&aData[8+closest*4]);
  3721   3730           if( !searchList || iPage==nearby ){
  3722   3731             *pPgno = iPage;
  3723         -          if( *pPgno>sqlite3pager_pagecount(pBt->pPager) ){
         3732  +          if( *pPgno>sqlite3PagerPagecount(pBt->pPager) ){
  3724   3733               /* Free page off the end of the file */
  3725   3734               return SQLITE_CORRUPT_BKPT;
  3726   3735             }
  3727   3736             TRACE(("ALLOCATE: %d was leaf %d of %d on trunk %d"
  3728   3737                    ": %d more free pages\n",
  3729   3738                    *pPgno, closest+1, k, pTrunk->pgno, n-1));
  3730   3739             if( closest<k-1 ){
  3731   3740               memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
  3732   3741             }
  3733   3742             put4byte(&aData[4], k-1);
  3734   3743             rc = getPage(pBt, *pPgno, ppPage, 1);
  3735   3744             if( rc==SQLITE_OK ){
  3736         -            rc = sqlite3pager_write((*ppPage)->aData);
         3745  +            rc = sqlite3PagerWrite((*ppPage)->pDbPage);
  3737   3746               if( rc!=SQLITE_OK ){
  3738   3747                 releasePage(*ppPage);
  3739   3748               }
  3740   3749             }
  3741   3750             searchList = 0;
  3742   3751           }
  3743   3752         }
  3744   3753         releasePage(pPrevTrunk);
  3745   3754         pPrevTrunk = 0;
  3746   3755       }while( searchList );
  3747   3756     }else{
  3748   3757       /* There are no pages on the freelist, so create a new page at the
  3749   3758       ** end of the file */
  3750         -    *pPgno = sqlite3pager_pagecount(pBt->pPager) + 1;
         3759  +    *pPgno = sqlite3PagerPagecount(pBt->pPager) + 1;
  3751   3760   
  3752   3761   #ifndef SQLITE_OMIT_AUTOVACUUM
  3753   3762       if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
  3754   3763         /* If *pPgno refers to a pointer-map page, allocate two new pages
  3755   3764         ** at the end of the file instead of one. The first allocated page
  3756   3765         ** becomes a new pointer-map page, the second is used by the caller.
  3757   3766         */
................................................................................
  3760   3769         (*pPgno)++;
  3761   3770       }
  3762   3771   #endif
  3763   3772   
  3764   3773       assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
  3765   3774       rc = getPage(pBt, *pPgno, ppPage, 0);
  3766   3775       if( rc ) return rc;
  3767         -    rc = sqlite3pager_write((*ppPage)->aData);
         3776  +    rc = sqlite3PagerWrite((*ppPage)->pDbPage);
  3768   3777       if( rc!=SQLITE_OK ){
  3769   3778         releasePage(*ppPage);
  3770   3779       }
  3771   3780       TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
  3772   3781     }
  3773   3782   
  3774   3783     assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
................................................................................
  3778   3787     releasePage(pPrevTrunk);
  3779   3788     return rc;
  3780   3789   }
  3781   3790   
  3782   3791   /*
  3783   3792   ** Add a page of the database file to the freelist.
  3784   3793   **
  3785         -** sqlite3pager_unref() is NOT called for pPage.
         3794  +** sqlite3PagerUnref() is NOT called for pPage.
  3786   3795   */
  3787   3796   static int freePage(MemPage *pPage){
  3788   3797     BtShared *pBt = pPage->pBt;
  3789   3798     MemPage *pPage1 = pBt->pPage1;
  3790   3799     int rc, n, k;
  3791   3800   
  3792   3801     /* Prepare the page for freeing */
  3793   3802     assert( pPage->pgno>1 );
  3794   3803     pPage->isInit = 0;
  3795   3804     releasePage(pPage->pParent);
  3796   3805     pPage->pParent = 0;
  3797   3806   
  3798   3807     /* Increment the free page count on pPage1 */
  3799         -  rc = sqlite3pager_write(pPage1->aData);
         3808  +  rc = sqlite3PagerWrite(pPage1->pDbPage);
  3800   3809     if( rc ) return rc;
  3801   3810     n = get4byte(&pPage1->aData[36]);
  3802   3811     put4byte(&pPage1->aData[36], n+1);
  3803   3812   
  3804   3813   #ifdef SQLITE_SECURE_DELETE
  3805   3814     /* If the SQLITE_SECURE_DELETE compile-time option is enabled, then
  3806   3815     ** always fully overwrite deleted information with zeros.
  3807   3816     */
  3808         -  rc = sqlite3pager_write(pPage->aData);
         3817  +  rc = sqlite3PagerWrite(pPage->pDbPage);
  3809   3818     if( rc ) return rc;
  3810   3819     memset(pPage->aData, 0, pPage->pBt->pageSize);
  3811   3820   #endif
  3812   3821   
  3813   3822   #ifndef SQLITE_OMIT_AUTOVACUUM
  3814   3823     /* If the database supports auto-vacuum, write an entry in the pointer-map
  3815   3824     ** to indicate that the page is free.
................................................................................
  3818   3827       rc = ptrmapPut(pBt, pPage->pgno, PTRMAP_FREEPAGE, 0);
  3819   3828       if( rc ) return rc;
  3820   3829     }
  3821   3830   #endif
  3822   3831   
  3823   3832     if( n==0 ){
  3824   3833       /* This is the first free page */
  3825         -    rc = sqlite3pager_write(pPage->aData);
         3834  +    rc = sqlite3PagerWrite(pPage->pDbPage);
  3826   3835       if( rc ) return rc;
  3827   3836       memset(pPage->aData, 0, 8);
  3828   3837       put4byte(&pPage1->aData[32], pPage->pgno);
  3829   3838       TRACE(("FREE-PAGE: %d first\n", pPage->pgno));
  3830   3839     }else{
  3831   3840       /* Other free pages already exist.  Retrive the first trunk page
  3832   3841       ** of the freelist and find out how many leaves it has. */
................................................................................
  3833   3842       MemPage *pTrunk;
  3834   3843       rc = getPage(pBt, get4byte(&pPage1->aData[32]), &pTrunk, 0);
  3835   3844       if( rc ) return rc;
  3836   3845       k = get4byte(&pTrunk->aData[4]);
  3837   3846       if( k>=pBt->usableSize/4 - 8 ){
  3838   3847         /* The trunk is full.  Turn the page being freed into a new
  3839   3848         ** trunk page with no leaves. */
  3840         -      rc = sqlite3pager_write(pPage->aData);
         3849  +      rc = sqlite3PagerWrite(pPage->pDbPage);
  3841   3850         if( rc ) return rc;
  3842   3851         put4byte(pPage->aData, pTrunk->pgno);
  3843   3852         put4byte(&pPage->aData[4], 0);
  3844   3853         put4byte(&pPage1->aData[32], pPage->pgno);
  3845   3854         TRACE(("FREE-PAGE: %d new trunk page replacing %d\n",
  3846   3855                 pPage->pgno, pTrunk->pgno));
  3847   3856       }else{
  3848   3857         /* Add the newly freed page as a leaf on the current trunk */
  3849         -      rc = sqlite3pager_write(pTrunk->aData);
         3858  +      rc = sqlite3PagerWrite(pTrunk->pDbPage);
  3850   3859         if( rc ) return rc;
  3851   3860         put4byte(&pTrunk->aData[4], k+1);
  3852   3861         put4byte(&pTrunk->aData[8+k*4], pPage->pgno);
  3853   3862   #ifndef SQLITE_SECURE_DELETE
  3854         -      sqlite3pager_dont_write(pBt->pPager, pPage->pgno);
         3863  +      sqlite3PagerDontWrite(pBt->pPager, pPage->pgno);
  3855   3864   #endif
  3856   3865         TRACE(("FREE-PAGE: %d leaf on trunk page %d\n",pPage->pgno,pTrunk->pgno));
  3857   3866       }
  3858   3867       releasePage(pTrunk);
  3859   3868     }
  3860   3869     return rc;
  3861   3870   }
................................................................................
  3877   3886     }
  3878   3887     ovflPgno = get4byte(&pCell[info.iOverflow]);
  3879   3888     ovflPageSize = pBt->usableSize - 4;
  3880   3889     nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
  3881   3890     assert( ovflPgno==0 || nOvfl>0 );
  3882   3891     while( nOvfl-- ){
  3883   3892       MemPage *pOvfl;
  3884         -    if( ovflPgno==0 || ovflPgno>sqlite3pager_pagecount(pBt->pPager) ){
         3893  +    if( ovflPgno==0 || ovflPgno>sqlite3PagerPagecount(pBt->pPager) ){
  3885   3894         return SQLITE_CORRUPT_BKPT;
  3886   3895       }
  3887   3896       rc = getPage(pBt, ovflPgno, &pOvfl, 0);
  3888   3897       if( rc ) return rc;
  3889   3898       if( nOvfl ){
  3890   3899         ovflPgno = get4byte(pOvfl->aData);
  3891   3900       }
  3892   3901       rc = freePage(pOvfl);
  3893         -    sqlite3pager_unref(pOvfl->aData);
         3902  +    sqlite3PagerUnref(pOvfl->pDbPage);
  3894   3903       if( rc ) return rc;
  3895   3904     }
  3896   3905     return SQLITE_OK;
  3897   3906   }
  3898   3907   
  3899   3908   /*
  3900   3909   ** Create the byte sequence used to represent a cell on page pPage
................................................................................
  4010   4019   /*
  4011   4020   ** Change the MemPage.pParent pointer on the page whose number is
  4012   4021   ** given in the second argument so that MemPage.pParent holds the
  4013   4022   ** pointer in the third argument.
  4014   4023   */
  4015   4024   static int reparentPage(BtShared *pBt, Pgno pgno, MemPage *pNewParent, int idx){
  4016   4025     MemPage *pThis;
  4017         -  unsigned char *aData;
         4026  +  DbPage *pDbPage;
  4018   4027   
  4019   4028     assert( pNewParent!=0 );
  4020   4029     if( pgno==0 ) return SQLITE_OK;
  4021   4030     assert( pBt->pPager!=0 );
  4022         -  aData = sqlite3pager_lookup(pBt->pPager, pgno);
  4023         -  if( aData ){
  4024         -    pThis = (MemPage*)&aData[pBt->pageSize];
         4031  +  pDbPage = sqlite3PagerLookup(pBt->pPager, pgno);
         4032  +  if( pDbPage ){
         4033  +    pThis = (MemPage *)sqlite3PagerGetExtra(pDbPage);
  4025   4034       if( pThis->isInit ){
  4026         -      assert( pThis->aData==aData );
         4035  +      assert( pThis->aData==(sqlite3PagerGetData(pDbPage)) );
  4027   4036         if( pThis->pParent!=pNewParent ){
  4028         -        if( pThis->pParent ) sqlite3pager_unref(pThis->pParent->aData);
         4037  +        if( pThis->pParent ) sqlite3PagerUnref(pThis->pParent->pDbPage);
  4029   4038           pThis->pParent = pNewParent;
  4030         -        sqlite3pager_ref(pNewParent->aData);
         4039  +        sqlite3PagerRef(pNewParent->pDbPage);
  4031   4040         }
  4032   4041         pThis->idxParent = idx;
  4033   4042       }
  4034         -    sqlite3pager_unref(aData);
         4043  +    sqlite3PagerUnref(pDbPage);
  4035   4044     }
  4036   4045   
  4037   4046   #ifndef SQLITE_OMIT_AUTOVACUUM
  4038   4047     if( pBt->autoVacuum ){
  4039   4048       return ptrmapPut(pBt, pgno, PTRMAP_BTREE, pNewParent->pgno);
  4040   4049     }
  4041   4050   #endif
................................................................................
  4088   4097     int i;          /* Loop counter */
  4089   4098     int pc;         /* Offset to cell content of cell being deleted */
  4090   4099     u8 *data;       /* pPage->aData */
  4091   4100     u8 *ptr;        /* Used to move bytes around within data[] */
  4092   4101   
  4093   4102     assert( idx>=0 && idx<pPage->nCell );
  4094   4103     assert( sz==cellSize(pPage, idx) );
  4095         -  assert( sqlite3pager_iswriteable(pPage->aData) );
         4104  +  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  4096   4105     data = pPage->aData;
  4097   4106     ptr = &data[pPage->cellOffset + 2*idx];
  4098   4107     pc = get2byte(ptr);
  4099   4108     assert( pc>10 && pc+sz<=pPage->pBt->usableSize );
  4100   4109     freeSpace(pPage, pc, sz);
  4101   4110     for(i=idx+1; i<pPage->nCell; i++, ptr+=2){
  4102   4111       ptr[0] = ptr[2];
................................................................................
  4141   4150     int hdr;          /* Offset into data[] of the page header */
  4142   4151     int cellOffset;   /* Address of first cell pointer in data[] */
  4143   4152     u8 *data;         /* The content of the whole page */
  4144   4153     u8 *ptr;          /* Used for moving information around in data[] */
  4145   4154   
  4146   4155     assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
  4147   4156     assert( sz==cellSizePtr(pPage, pCell) );
  4148         -  assert( sqlite3pager_iswriteable(pPage->aData) );
         4157  +  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  4149   4158     if( pPage->nOverflow || sz+2>pPage->nFree ){
  4150   4159       if( pTemp ){
  4151   4160         memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
  4152   4161         pCell = pTemp;
  4153   4162       }
  4154   4163       j = pPage->nOverflow++;
  4155   4164       assert( j<sizeof(pPage->aOvfl)/sizeof(pPage->aOvfl[0]) );
................................................................................
  4305   4314     szCell = cellSizePtr(pPage, pCell);
  4306   4315     zeroPage(pNew, pPage->aData[0]);
  4307   4316     assemblePage(pNew, 1, &pCell, &szCell);
  4308   4317     pPage->nOverflow = 0;
  4309   4318   
  4310   4319     /* Set the parent of the newly allocated page to pParent. */
  4311   4320     pNew->pParent = pParent;
  4312         -  sqlite3pager_ref(pParent->aData);
         4321  +  sqlite3PagerRef(pParent->pDbPage);
  4313   4322   
  4314   4323     /* pPage is currently the right-child of pParent. Change this
  4315   4324     ** so that the right-child is the new page allocated above and
  4316   4325     ** pPage is the next-to-right child. 
  4317   4326     */
  4318   4327     assert( pPage->nCell>0 );
  4319   4328     parseCellPtr(pPage, findCell(pPage, pPage->nCell-1), &info);
................................................................................
  4430   4439     u8 *aFrom = 0;
  4431   4440   #endif
  4432   4441   
  4433   4442     /* 
  4434   4443     ** Find the parent page.
  4435   4444     */
  4436   4445     assert( pPage->isInit );
  4437         -  assert( sqlite3pager_iswriteable(pPage->aData) );
         4446  +  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  4438   4447     pBt = pPage->pBt;
  4439   4448     pParent = pPage->pParent;
  4440   4449     assert( pParent );
  4441         -  if( SQLITE_OK!=(rc = sqlite3pager_write(pParent->aData)) ){
         4450  +  if( SQLITE_OK!=(rc = sqlite3PagerWrite(pParent->pDbPage)) ){
  4442   4451       return rc;
  4443   4452     }
  4444   4453     TRACE(("BALANCE: begin page %d child of %d\n", pPage->pgno, pParent->pgno));
  4445   4454   
  4446   4455   #ifndef SQLITE_OMIT_QUICKBALANCE
  4447   4456     /*
  4448   4457     ** A special case:  If a new entry has just been inserted into a
................................................................................
  4472   4481     ** Find the cell in the parent page whose left child points back
  4473   4482     ** to pPage.  The "idx" variable is the index of that cell.  If pPage
  4474   4483     ** is the rightmost child of pParent then set idx to pParent->nCell 
  4475   4484     */
  4476   4485     if( pParent->idxShift ){
  4477   4486       Pgno pgno;
  4478   4487       pgno = pPage->pgno;
  4479         -    assert( pgno==sqlite3pager_pagenumber(pPage->aData) );
         4488  +    assert( pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
  4480   4489       for(idx=0; idx<pParent->nCell; idx++){
  4481   4490         if( get4byte(findCell(pParent, idx))==pgno ){
  4482   4491           break;
  4483   4492         }
  4484   4493       }
  4485   4494       assert( idx<pParent->nCell
  4486   4495                || get4byte(&pParent->aData[pParent->hdrOffset+8])==pgno );
................................................................................
  4489   4498     }
  4490   4499   
  4491   4500     /*
  4492   4501     ** Initialize variables so that it will be safe to jump
  4493   4502     ** directly to balance_cleanup at any moment.
  4494   4503     */
  4495   4504     nOld = nNew = 0;
  4496         -  sqlite3pager_ref(pParent->aData);
         4505  +  sqlite3PagerRef(pParent->pDbPage);
  4497   4506   
  4498   4507     /*
  4499   4508     ** Find sibling pages to pPage and the cells in pParent that divide
  4500   4509     ** the siblings.  An attempt is made to find NN siblings on either
  4501   4510     ** side of pPage.  More siblings are taken from one side, however, if
  4502   4511     ** pPage there are fewer than NN siblings on the other side.  If pParent
  4503   4512     ** has NB or fewer children then all children of pParent are taken.
................................................................................
  4733   4742     pageFlags = pPage->aData[0];
  4734   4743     for(i=0; i<k; i++){
  4735   4744       MemPage *pNew;
  4736   4745       if( i<nOld ){
  4737   4746         pNew = apNew[i] = apOld[i];
  4738   4747         pgnoNew[i] = pgnoOld[i];
  4739   4748         apOld[i] = 0;
  4740         -      rc = sqlite3pager_write(pNew->aData);
         4749  +      rc = sqlite3PagerWrite(pNew->pDbPage);
  4741   4750         if( rc ) goto balance_cleanup;
  4742   4751       }else{
  4743   4752         assert( i>0 );
  4744   4753         rc = allocatePage(pBt, &pNew, &pgnoNew[i], pgnoNew[i-1], 0);
  4745   4754         if( rc ) goto balance_cleanup;
  4746   4755         apNew[i] = pNew;
  4747   4756       }
................................................................................
  4976   4985       ** information currently contained in the child.  If this is the 
  4977   4986       ** case, then do not do the transfer.  Leave page 1 empty except
  4978   4987       ** for the right-pointer to the child page.  The child page becomes
  4979   4988       ** the virtual root of the tree.
  4980   4989       */
  4981   4990       pgnoChild = get4byte(&pPage->aData[pPage->hdrOffset+8]);
  4982   4991       assert( pgnoChild>0 );
  4983         -    assert( pgnoChild<=sqlite3pager_pagecount(pPage->pBt->pPager) );
         4992  +    assert( pgnoChild<=sqlite3PagerPagecount(pPage->pBt->pPager) );
  4984   4993       rc = getPage(pPage->pBt, pgnoChild, &pChild, 0);
  4985   4994       if( rc ) goto end_shallow_balance;
  4986   4995       if( pPage->pgno==1 ){
  4987   4996         rc = initPage(pChild, pPage);
  4988   4997         if( rc ) goto end_shallow_balance;
  4989   4998         assert( pChild->nOverflow==0 );
  4990   4999         if( pChild->nFree>=100 ){
................................................................................
  5060   5069     int brk;            /* Offset to content of first cell in parent */
  5061   5070   
  5062   5071     assert( pPage->pParent==0 );
  5063   5072     assert( pPage->nOverflow>0 );
  5064   5073     pBt = pPage->pBt;
  5065   5074     rc = allocatePage(pBt, &pChild, &pgnoChild, pPage->pgno, 0);
  5066   5075     if( rc ) return rc;
  5067         -  assert( sqlite3pager_iswriteable(pChild->aData) );
         5076  +  assert( sqlite3PagerIswriteable(pChild->pDbPage) );
  5068   5077     usableSize = pBt->usableSize;
  5069   5078     data = pPage->aData;
  5070   5079     hdr = pPage->hdrOffset;
  5071   5080     brk = get2byte(&data[hdr+5]);
  5072   5081     cdata = pChild->aData;
  5073   5082     memcpy(cdata, &data[hdr], pPage->cellOffset+2*pPage->nCell-hdr);
  5074   5083     memcpy(&cdata[brk], &data[brk], usableSize-brk);
................................................................................
  5209   5218     pPage = pCur->pPage;
  5210   5219     assert( pPage->intKey || nKey>=0 );
  5211   5220     assert( pPage->leaf || !pPage->leafData );
  5212   5221     TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
  5213   5222             pCur->pgnoRoot, nKey, nData, pPage->pgno,
  5214   5223             loc==0 ? "overwrite" : "new entry"));
  5215   5224     assert( pPage->isInit );
  5216         -  rc = sqlite3pager_write(pPage->aData);
         5225  +  rc = sqlite3PagerWrite(pPage->pDbPage);
  5217   5226     if( rc ) return rc;
  5218   5227     newCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
  5219   5228     if( newCell==0 ) return SQLITE_NOMEM;
  5220   5229     rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, &szNew);
  5221   5230     if( rc ) goto end_insert;
  5222   5231     assert( szNew==cellSizePtr(pPage, newCell) );
  5223   5232     assert( szNew<=MX_CELL_SIZE(pBt) );
................................................................................
  5277   5286     }
  5278   5287     if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur) ){
  5279   5288       return SQLITE_LOCKED; /* The table pCur points to has a read lock */
  5280   5289     }
  5281   5290   
  5282   5291     /* Restore the current cursor position (a no-op if the cursor is not in 
  5283   5292     ** CURSOR_REQUIRESEEK state) and save the positions of any other cursors 
  5284         -  ** open on the same table. Then call sqlite3pager_write() on the page
         5293  +  ** open on the same table. Then call sqlite3PagerWrite() on the page
  5285   5294     ** that the entry will be deleted from.
  5286   5295     */
  5287   5296     if( 
  5288   5297       (rc = restoreOrClearCursorPosition(pCur, 1))!=0 ||
  5289   5298       (rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur))!=0 ||
  5290         -    (rc = sqlite3pager_write(pPage->aData))!=0
         5299  +    (rc = sqlite3PagerWrite(pPage->pDbPage))!=0
  5291   5300     ){
  5292   5301       return rc;
  5293   5302     }
  5294   5303   
  5295   5304     /* Locate the cell within it's page and leave pCell pointing to the
  5296   5305     ** data. The clearCell() call frees any overflow pages associated with the
  5297   5306     ** cell. The cell itself is still intact.
................................................................................
  5323   5332       rc = sqlite3BtreeNext(&leafCur, &notUsed);
  5324   5333       if( rc!=SQLITE_OK ){
  5325   5334         if( rc!=SQLITE_NOMEM ){
  5326   5335           rc = SQLITE_CORRUPT_BKPT; 
  5327   5336         }
  5328   5337       }
  5329   5338       if( rc==SQLITE_OK ){
  5330         -      rc = sqlite3pager_write(leafCur.pPage->aData);
         5339  +      rc = sqlite3PagerWrite(leafCur.pPage->pDbPage);
  5331   5340       }
  5332   5341       if( rc==SQLITE_OK ){
  5333   5342         TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n",
  5334   5343            pCur->pgnoRoot, pPage->pgno, leafCur.pPage->pgno));
  5335   5344         dropCell(pPage, pCur->idx, cellSizePtr(pPage, pCell));
  5336   5345         pNext = findCell(leafCur.pPage, leafCur.idx);
  5337   5346         szNext = cellSizePtr(leafCur.pPage, pNext);
................................................................................
  5443   5452         rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
  5444   5453         if( rc!=SQLITE_OK || eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
  5445   5454           releasePage(pRoot);
  5446   5455           return rc;
  5447   5456         }
  5448   5457         assert( eType!=PTRMAP_ROOTPAGE );
  5449   5458         assert( eType!=PTRMAP_FREEPAGE );
  5450         -      rc = sqlite3pager_write(pRoot->aData);
         5459  +      rc = sqlite3PagerWrite(pRoot->pDbPage);
  5451   5460         if( rc!=SQLITE_OK ){
  5452   5461           releasePage(pRoot);
  5453   5462           return rc;
  5454   5463         }
  5455   5464         rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove);
  5456   5465         releasePage(pRoot);
  5457   5466         if( rc!=SQLITE_OK ){
  5458   5467           return rc;
  5459   5468         }
  5460   5469         rc = getPage(pBt, pgnoRoot, &pRoot, 0);
  5461   5470         if( rc!=SQLITE_OK ){
  5462   5471           return rc;
  5463   5472         }
  5464         -      rc = sqlite3pager_write(pRoot->aData);
         5473  +      rc = sqlite3PagerWrite(pRoot->pDbPage);
  5465   5474         if( rc!=SQLITE_OK ){
  5466   5475           releasePage(pRoot);
  5467   5476           return rc;
  5468   5477         }
  5469   5478       }else{
  5470   5479         pRoot = pPageMove;
  5471   5480       } 
................................................................................
  5483   5492       }
  5484   5493   
  5485   5494     }else{
  5486   5495       rc = allocatePage(pBt, &pRoot, &pgnoRoot, 1, 0);
  5487   5496       if( rc ) return rc;
  5488   5497     }
  5489   5498   #endif
  5490         -  assert( sqlite3pager_iswriteable(pRoot->aData) );
         5499  +  assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
  5491   5500     zeroPage(pRoot, flags | PTF_LEAF);
  5492         -  sqlite3pager_unref(pRoot->aData);
         5501  +  sqlite3PagerUnref(pRoot->pDbPage);
  5493   5502     *piTable = (int)pgnoRoot;
  5494   5503     return SQLITE_OK;
  5495   5504   }
  5496   5505   
  5497   5506   /*
  5498   5507   ** Erase the given database page and all its children.  Return
  5499   5508   ** the page to the freelist.
................................................................................
  5505   5514     int freePageFlag      /* Deallocate page if true */
  5506   5515   ){
  5507   5516     MemPage *pPage = 0;
  5508   5517     int rc;
  5509   5518     unsigned char *pCell;
  5510   5519     int i;
  5511   5520   
  5512         -  if( pgno>sqlite3pager_pagecount(pBt->pPager) ){
         5521  +  if( pgno>sqlite3PagerPagecount(pBt->pPager) ){
  5513   5522       return SQLITE_CORRUPT_BKPT;
  5514   5523     }
  5515   5524   
  5516   5525     rc = getAndInitPage(pBt, pgno, &pPage, pParent);
  5517   5526     if( rc ) goto cleardatabasepage_out;
  5518   5527     for(i=0; i<pPage->nCell; i++){
  5519   5528       pCell = findCell(pPage, i);
................................................................................
  5526   5535     }
  5527   5536     if( !pPage->leaf ){
  5528   5537       rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), pPage->pParent, 1);
  5529   5538       if( rc ) goto cleardatabasepage_out;
  5530   5539     }
  5531   5540     if( freePageFlag ){
  5532   5541       rc = freePage(pPage);
  5533         -  }else if( (rc = sqlite3pager_write(pPage->aData))==0 ){
         5542  +  }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
  5534   5543       zeroPage(pPage, pPage->aData[0] | PTF_LEAF);
  5535   5544     }
  5536   5545   
  5537   5546   cleardatabasepage_out:
  5538   5547     releasePage(pPage);
  5539   5548     return rc;
  5540   5549   }
................................................................................
  5702   5711   ** is read-only, the others are read/write.
  5703   5712   ** 
  5704   5713   ** The schema layer numbers meta values differently.  At the schema
  5705   5714   ** layer (and the SetCookie and ReadCookie opcodes) the number of
  5706   5715   ** free pages is not visible.  So Cookie[0] is the same as Meta[1].
  5707   5716   */
  5708   5717   int sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
         5718  +  DbPage *pDbPage;
  5709   5719     int rc;
  5710   5720     unsigned char *pP1;
  5711   5721     BtShared *pBt = p->pBt;
  5712   5722   
  5713   5723     /* Reading a meta-data value requires a read-lock on page 1 (and hence
  5714   5724     ** the sqlite_master table. We grab this lock regardless of whether or
  5715   5725     ** not the SQLITE_ReadUncommitted flag is set (the table rooted at page
................................................................................
  5717   5727     */
  5718   5728     rc = queryTableLock(p, 1, READ_LOCK);
  5719   5729     if( rc!=SQLITE_OK ){
  5720   5730       return rc;
  5721   5731     }
  5722   5732   
  5723   5733     assert( idx>=0 && idx<=15 );
  5724         -  rc = sqlite3pager_get(pBt->pPager, 1, (void**)&pP1);
         5734  +  rc = sqlite3PagerGet(pBt->pPager, 1, &pDbPage);
  5725   5735     if( rc ) return rc;
         5736  +  pP1 = (unsigned char *)sqlite3PagerGetData(pDbPage);
  5726   5737     *pMeta = get4byte(&pP1[36 + idx*4]);
  5727         -  sqlite3pager_unref(pP1);
         5738  +  sqlite3PagerUnref(pDbPage);
  5728   5739   
  5729   5740     /* If autovacuumed is disabled in this build but we are trying to 
  5730   5741     ** access an autovacuumed database, then make the database readonly. 
  5731   5742     */
  5732   5743   #ifdef SQLITE_OMIT_AUTOVACUUM
  5733   5744     if( idx==4 && *pMeta>0 ) pBt->readOnly = 1;
  5734   5745   #endif
................................................................................
  5748   5759     int rc;
  5749   5760     assert( idx>=1 && idx<=15 );
  5750   5761     if( p->inTrans!=TRANS_WRITE ){
  5751   5762       return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
  5752   5763     }
  5753   5764     assert( pBt->pPage1!=0 );
  5754   5765     pP1 = pBt->pPage1->aData;
  5755         -  rc = sqlite3pager_write(pP1);
         5766  +  rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
  5756   5767     if( rc ) return rc;
  5757   5768     put4byte(&pP1[36 + idx*4], iMeta);
  5758   5769     return SQLITE_OK;
  5759   5770   }
  5760   5771   
  5761   5772   /*
  5762   5773   ** Return the flag byte at the beginning of the page that the cursor
................................................................................
  5863   5874         unsigned char *pCell = findCell(pPage, i);
  5864   5875         btreePageDump(pBt, get4byte(pCell), 1, pPage);
  5865   5876         idx = get2byte(pCell);
  5866   5877       }
  5867   5878       btreePageDump(pBt, get4byte(&data[hdr+8]), 1, pPage);
  5868   5879     }
  5869   5880     pPage->isInit = isInit;
  5870         -  sqlite3pager_unref(data);
         5881  +  sqlite3PagerUnref(pPage->pDbPage);
  5871   5882     fflush(stdout);
  5872   5883     return SQLITE_OK;
  5873   5884   }
  5874   5885   int sqlite3BtreePageDump(Btree *p, int pgno, int recursive){
  5875   5886     return btreePageDump(p->pBt, pgno, recursive, 0);
  5876   5887   }
  5877   5888   #endif
................................................................................
  5907   5918   
  5908   5919     assert( pPage->isInit );
  5909   5920     getTempCursor(pCur, &tmpCur);
  5910   5921     while( upCnt-- ){
  5911   5922       moveToParent(&tmpCur);
  5912   5923     }
  5913   5924     pPage = tmpCur.pPage;
  5914         -  aResult[0] = sqlite3pager_pagenumber(pPage->aData);
         5925  +  aResult[0] = sqlite3PagerPagenumber(pPage->pDbPage);
  5915   5926     assert( aResult[0]==pPage->pgno );
  5916   5927     aResult[1] = tmpCur.idx;
  5917   5928     aResult[2] = pPage->nCell;
  5918   5929     if( tmpCur.idx>=0 && tmpCur.idx<pPage->nCell ){
  5919   5930       getCellInfo(&tmpCur);
  5920   5931       aResult[3] = tmpCur.info.nSize;
  5921   5932       aResult[6] = tmpCur.info.nData;
................................................................................
  6068   6079     int N,                /* Expected number of pages in the list */
  6069   6080     char *zContext        /* Context for error messages */
  6070   6081   ){
  6071   6082     int i;
  6072   6083     int expected = N;
  6073   6084     int iFirst = iPage;
  6074   6085     while( N-- > 0 && pCheck->mxErr ){
  6075         -    unsigned char *pOvfl;
         6086  +    DbPage *pOvflPage;
         6087  +    unsigned char *pOvflData;
  6076   6088       if( iPage<1 ){
  6077   6089         checkAppendMsg(pCheck, zContext,
  6078   6090            "%d of %d pages missing from overflow list starting at %d",
  6079   6091             N+1, expected, iFirst);
  6080   6092         break;
  6081   6093       }
  6082   6094       if( checkRef(pCheck, iPage, zContext) ) break;
  6083         -    if( sqlite3pager_get(pCheck->pPager, (Pgno)iPage, (void**)&pOvfl) ){
         6095  +    if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage) ){
  6084   6096         checkAppendMsg(pCheck, zContext, "failed to get page %d", iPage);
  6085   6097         break;
  6086   6098       }
         6099  +    pOvflData = (unsigned char *)sqlite3PagerGetData(pOvflPage);
  6087   6100       if( isFreeList ){
  6088         -      int n = get4byte(&pOvfl[4]);
         6101  +      int n = get4byte(&pOvflData[4]);
  6089   6102   #ifndef SQLITE_OMIT_AUTOVACUUM
  6090   6103         if( pCheck->pBt->autoVacuum ){
  6091   6104           checkPtrmap(pCheck, iPage, PTRMAP_FREEPAGE, 0, zContext);
  6092   6105         }
  6093   6106   #endif
  6094   6107         if( n>pCheck->pBt->usableSize/4-8 ){
  6095   6108           checkAppendMsg(pCheck, zContext,
  6096   6109              "freelist leaf count too big on page %d", iPage);
  6097   6110           N--;
  6098   6111         }else{
  6099   6112           for(i=0; i<n; i++){
  6100         -          Pgno iFreePage = get4byte(&pOvfl[8+i*4]);
         6113  +          Pgno iFreePage = get4byte(&pOvflData[8+i*4]);
  6101   6114   #ifndef SQLITE_OMIT_AUTOVACUUM
  6102   6115             if( pCheck->pBt->autoVacuum ){
  6103   6116               checkPtrmap(pCheck, iFreePage, PTRMAP_FREEPAGE, 0, zContext);
  6104   6117             }
  6105   6118   #endif
  6106   6119             checkRef(pCheck, iFreePage, zContext);
  6107   6120           }
................................................................................
  6111   6124   #ifndef SQLITE_OMIT_AUTOVACUUM
  6112   6125       else{
  6113   6126         /* If this database supports auto-vacuum and iPage is not the last
  6114   6127         ** page in this overflow list, check that the pointer-map entry for
  6115   6128         ** the following page matches iPage.
  6116   6129         */
  6117   6130         if( pCheck->pBt->autoVacuum && N>0 ){
  6118         -        i = get4byte(pOvfl);
         6131  +        i = get4byte(pOvflData);
  6119   6132           checkPtrmap(pCheck, i, PTRMAP_OVERFLOW2, iPage, zContext);
  6120   6133         }
  6121   6134       }
  6122   6135   #endif
  6123         -    iPage = get4byte(pOvfl);
  6124         -    sqlite3pager_unref(pOvfl);
         6136  +    iPage = get4byte(pOvflData);
         6137  +    sqlite3PagerUnref(pOvflPage);
  6125   6138     }
  6126   6139   }
  6127   6140   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
  6128   6141   
  6129   6142   #ifndef SQLITE_OMIT_INTEGRITY_CHECK
  6130   6143   /*
  6131   6144   ** Do various sanity checks on a single page of a tree.  Return
................................................................................
  6307   6320     int *pnErr    /* Write number of errors seen to this variable */
  6308   6321   ){
  6309   6322     int i;
  6310   6323     int nRef;
  6311   6324     IntegrityCk sCheck;
  6312   6325     BtShared *pBt = p->pBt;
  6313   6326   
  6314         -  nRef = sqlite3pager_refcount(pBt->pPager);
         6327  +  nRef = sqlite3PagerRefcount(pBt->pPager);
  6315   6328     if( lockBtreeWithRetry(p)!=SQLITE_OK ){
  6316   6329       return sqliteStrDup("Unable to acquire a read lock on the database");
  6317   6330     }
  6318   6331     sCheck.pBt = pBt;
  6319   6332     sCheck.pPager = pBt->pPager;
  6320         -  sCheck.nPage = sqlite3pager_pagecount(sCheck.pPager);
         6333  +  sCheck.nPage = sqlite3PagerPagecount(sCheck.pPager);
  6321   6334     sCheck.mxErr = mxErr;
  6322   6335     sCheck.nErr = 0;
  6323   6336     *pnErr = 0;
  6324   6337     if( sCheck.nPage==0 ){
  6325   6338       unlockBtreeIfUnused(pBt);
  6326   6339       return 0;
  6327   6340     }
................................................................................
  6377   6390       }
  6378   6391   #endif
  6379   6392     }
  6380   6393   
  6381   6394     /* Make sure this analysis did not leave any unref() pages
  6382   6395     */
  6383   6396     unlockBtreeIfUnused(pBt);
  6384         -  if( nRef != sqlite3pager_refcount(pBt->pPager) ){
         6397  +  if( nRef != sqlite3PagerRefcount(pBt->pPager) ){
  6385   6398       checkAppendMsg(&sCheck, 0, 
  6386   6399         "Outstanding page count goes from %d to %d during this analysis",
  6387         -      nRef, sqlite3pager_refcount(pBt->pPager)
         6400  +      nRef, sqlite3PagerRefcount(pBt->pPager)
  6388   6401       );
  6389   6402     }
  6390   6403   
  6391   6404     /* Clean  up and report errors.
  6392   6405     */
  6393   6406     sqliteFree(sCheck.anRef);
  6394   6407     *pnErr = sCheck.nErr;
................................................................................
  6397   6410   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
  6398   6411   
  6399   6412   /*
  6400   6413   ** Return the full pathname of the underlying database file.
  6401   6414   */
  6402   6415   const char *sqlite3BtreeGetFilename(Btree *p){
  6403   6416     assert( p->pBt->pPager!=0 );
  6404         -  return sqlite3pager_filename(p->pBt->pPager);
         6417  +  return sqlite3PagerFilename(p->pBt->pPager);
  6405   6418   }
  6406   6419   
  6407   6420   /*
  6408   6421   ** Return the pathname of the directory that contains the database file.
  6409   6422   */
  6410   6423   const char *sqlite3BtreeGetDirname(Btree *p){
  6411   6424     assert( p->pBt->pPager!=0 );
  6412         -  return sqlite3pager_dirname(p->pBt->pPager);
         6425  +  return sqlite3PagerDirname(p->pBt->pPager);
  6413   6426   }
  6414   6427   
  6415   6428   /*
  6416   6429   ** Return the pathname of the journal file for this database. The return
  6417   6430   ** value of this routine is the same regardless of whether the journal file
  6418   6431   ** has been created or not.
  6419   6432   */
  6420   6433   const char *sqlite3BtreeGetJournalname(Btree *p){
  6421   6434     assert( p->pBt->pPager!=0 );
  6422         -  return sqlite3pager_journalname(p->pBt->pPager);
         6435  +  return sqlite3PagerJournalname(p->pBt->pPager);
  6423   6436   }
  6424   6437   
  6425   6438   #ifndef SQLITE_OMIT_VACUUM
  6426   6439   /*
  6427   6440   ** Copy the complete content of pBtFrom into pBtTo.  A transaction
  6428   6441   ** must be active for both files.
  6429   6442   **
................................................................................
  6437   6450     BtShared *pBtTo = pTo->pBt;
  6438   6451     BtShared *pBtFrom = pFrom->pBt;
  6439   6452   
  6440   6453     if( pTo->inTrans!=TRANS_WRITE || pFrom->inTrans!=TRANS_WRITE ){
  6441   6454       return SQLITE_ERROR;
  6442   6455     }
  6443   6456     if( pBtTo->pCursor ) return SQLITE_BUSY;
  6444         -  nToPage = sqlite3pager_pagecount(pBtTo->pPager);
  6445         -  nPage = sqlite3pager_pagecount(pBtFrom->pPager);
         6457  +  nToPage = sqlite3PagerPagecount(pBtTo->pPager);
         6458  +  nPage = sqlite3PagerPagecount(pBtFrom->pPager);
  6446   6459     iSkip = PENDING_BYTE_PAGE(pBtTo);
  6447   6460     for(i=1; rc==SQLITE_OK && i<=nPage; i++){
  6448         -    void *pPage;
         6461  +    DbPage *pDbPage;
  6449   6462       if( i==iSkip ) continue;
  6450         -    rc = sqlite3pager_get(pBtFrom->pPager, i, &pPage);
         6463  +    rc = sqlite3PagerGet(pBtFrom->pPager, i, &pDbPage);
  6451   6464       if( rc ) break;
  6452         -    rc = sqlite3pager_overwrite(pBtTo->pPager, i, pPage);
  6453         -    sqlite3pager_unref(pPage);
         6465  +    rc = sqlite3PagerOverwrite(pBtTo->pPager, i, sqlite3PagerGetData(pDbPage));
         6466  +    sqlite3PagerUnref(pDbPage);
  6454   6467     }
  6455   6468     for(i=nPage+1; rc==SQLITE_OK && i<=nToPage; i++){
  6456         -    void *pPage;
         6469  +    DbPage *pDbPage;
  6457   6470       if( i==iSkip ) continue;
  6458         -    rc = sqlite3pager_get(pBtTo->pPager, i, &pPage);
         6471  +    rc = sqlite3PagerGet(pBtTo->pPager, i, &pDbPage);
  6459   6472       if( rc ) break;
  6460         -    rc = sqlite3pager_write(pPage);
  6461         -    sqlite3pager_unref(pPage);
  6462         -    sqlite3pager_dont_write(pBtTo->pPager, i);
         6473  +    rc = sqlite3PagerWrite(pDbPage);
         6474  +    sqlite3PagerUnref(pDbPage);
         6475  +    sqlite3PagerDontWrite(pBtTo->pPager, i);
  6463   6476     }
  6464   6477     if( !rc && nPage<nToPage ){
  6465         -    rc = sqlite3pager_truncate(pBtTo->pPager, nPage);
         6478  +    rc = sqlite3PagerTruncate(pBtTo->pPager, nPage);
  6466   6479     }
  6467   6480     if( rc ){
  6468   6481       sqlite3BtreeRollback(pTo);
  6469   6482     }
  6470   6483     return rc;  
  6471   6484   }
  6472   6485   #endif /* SQLITE_OMIT_VACUUM */
................................................................................
  6515   6528       if( pBt->autoVacuum ){
  6516   6529         rc = autoVacuumCommit(pBt, &nTrunc); 
  6517   6530         if( rc!=SQLITE_OK ){
  6518   6531           return rc;
  6519   6532         }
  6520   6533       }
  6521   6534   #endif
  6522         -    rc = sqlite3pager_sync(pBt->pPager, zMaster, nTrunc);
         6535  +    rc = sqlite3PagerSync(pBt->pPager, zMaster, nTrunc);
  6523   6536     }
  6524   6537     return rc;
  6525   6538   }
  6526   6539   
  6527   6540   /*
  6528   6541   ** This function returns a pointer to a blob of memory associated with
  6529   6542   ** a single shared-btree. The memory is used by client code for it's own
................................................................................
  6590   6603   ){
  6591   6604   #ifndef SQLITE_OMIT_SHARED_CACHE
  6592   6605     const ThreadData *pTd = sqlite3ThreadDataReadOnly();
  6593   6606     if( pTd->useSharedData ){
  6594   6607       BtShared *pBt;
  6595   6608       Tcl_Obj *pRet = Tcl_NewObj();
  6596   6609       for(pBt=pTd->pBtree; pBt; pBt=pBt->pNext){
  6597         -      const char *zFile = sqlite3pager_filename(pBt->pPager);
         6610  +      const char *zFile = sqlite3PagerFilename(pBt->pPager);
  6598   6611         Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
  6599   6612         Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
  6600   6613       }
  6601   6614       Tcl_SetObjResult(interp, pRet);
  6602   6615     }
  6603   6616   #endif
  6604   6617     return TCL_OK;
  6605   6618   }
  6606   6619   #endif

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.291 2007/03/19 13:53:38 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.292 2007/03/19 17:44:27 danielk1977 Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
    86     86   **                       after all dirty pages have been written to the
    87     87   **                       database file and the file has been synced to
    88     88   **                       disk. All that remains to do is to remove the
    89     89   **                       journal file and the transaction will be
    90     90   **                       committed.
    91     91   **
    92     92   ** The page cache comes up in PAGER_UNLOCK.  The first time a
    93         -** sqlite3pager_get() occurs, the state transitions to PAGER_SHARED.
           93  +** sqlite3PagerGet() occurs, the state transitions to PAGER_SHARED.
    94     94   ** After all pages have been released using sqlite_page_unref(),
    95     95   ** the state transitions back to PAGER_UNLOCK.  The first time
    96         -** that sqlite3pager_write() is called, the state transitions to
           96  +** that sqlite3PagerWrite() is called, the state transitions to
    97     97   ** PAGER_RESERVED.  (Note that sqlite_page_write() can only be
    98     98   ** called on an outstanding page which means that the pager must
    99     99   ** be in PAGER_SHARED before it transitions to PAGER_RESERVED.)
   100    100   ** The transition to PAGER_EXCLUSIVE occurs when before any changes
   101         -** are made to the database file.  After an sqlite3pager_rollback()
          101  +** are made to the database file.  After an sqlite3PagerRollback()
   102    102   ** or sqlite_pager_commit(), the state goes back to PAGER_SHARED.
   103    103   */
   104    104   #define PAGER_UNLOCK      0
   105    105   #define PAGER_SHARED      1   /* same as SHARED_LOCK */
   106    106   #define PAGER_RESERVED    2   /* same as RESERVED_LOCK */
   107    107   #define PAGER_EXCLUSIVE   4   /* same as EXCLUSIVE_LOCK */
   108    108   #define PAGER_SYNCED      5
................................................................................
   131    131   #define FORCE_ALIGNMENT(X)   (((X)+7)&~7)
   132    132   
   133    133   /*
   134    134   ** Each in-memory image of a page begins with the following header.
   135    135   ** This header is only visible to this pager module.  The client
   136    136   ** code that calls pager sees only the data that follows the header.
   137    137   **
   138         -** Client code should call sqlite3pager_write() on a page prior to making
   139         -** any modifications to that page.  The first time sqlite3pager_write()
          138  +** Client code should call sqlite3PagerWrite() on a page prior to making
          139  +** any modifications to that page.  The first time sqlite3PagerWrite()
   140    140   ** is called, the original page contents are written into the rollback
   141    141   ** journal and PgHdr.inJournal and PgHdr.needSync are set.  Later, once
   142    142   ** the journal page has made it onto the disk surface, PgHdr.needSync
   143    143   ** is cleared.  The modified page cannot be written back into the original
   144    144   ** database file until the journal pages has been synced to disk and the
   145    145   ** PgHdr.needSync has been cleared.
   146    146   **
   147         -** The PgHdr.dirty flag is set when sqlite3pager_write() is called and
          147  +** The PgHdr.dirty flag is set when sqlite3PagerWrite() is called and
   148    148   ** is cleared again when the page content is written back to the original
   149    149   ** database file.
   150    150   */
   151    151   typedef struct PgHdr PgHdr;
   152    152   struct PgHdr {
   153    153     Pager *pPager;                 /* The pager to which this page belongs */
   154    154     Pgno pgno;                     /* The page number for this page */
................................................................................
   213    213   ** A open page cache is an instance of the following structure.
   214    214   **
   215    215   ** Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, SQLITE_PROTOCOL
   216    216   ** or SQLITE_FULL. Once one of the first three errors occurs, it persists
   217    217   ** and is returned as the result of every major pager API call.  The
   218    218   ** SQLITE_FULL return code is slightly different. It persists only until the
   219    219   ** next successful rollback is performed on the pager cache. Also,
   220         -** SQLITE_FULL does not affect the sqlite3pager_get() and sqlite3pager_lookup()
          220  +** SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup()
   221    221   ** APIs, they may still be used successfully.
   222    222   */
   223    223   struct Pager {
   224    224     u8 journalOpen;             /* True if journal file descriptors is valid */
   225    225     u8 journalStarted;          /* True if header of journal is synced */
   226    226     u8 useJournal;              /* Use a rollback journal on this file */
   227    227     u8 noReadlock;              /* Do not bother to obtain readlocks */
................................................................................
   271    271     i64 stmtCksum;              /* cksumInit when statement was started */
   272    272     i64 stmtJSize;              /* Size of journal at stmt_begin() */
   273    273     int sectorSize;             /* Assumed sector size during rollback */
   274    274   #ifdef SQLITE_TEST
   275    275     int nHit, nMiss, nOvfl;     /* Cache hits, missing, and LRU overflows */
   276    276     int nRead,nWrite;           /* Database pages read/written */
   277    277   #endif
   278         -  void (*xDestructor)(void*,int); /* Call this routine when freeing pages */
   279         -  void (*xReiniter)(void*,int);   /* Call this routine when reloading pages */
          278  +  void (*xDestructor)(DbPage*,int); /* Call this routine when freeing pages */
          279  +  void (*xReiniter)(DbPage*,int);   /* Call this routine when reloading pages */
   280    280     void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
   281    281     void *pCodecArg;            /* First argument to xCodec() */
   282    282     int nHash;                  /* Size of the pager hash table */
   283    283     PgHdr **aHash;              /* Hash table to map page number to PgHdr */
   284    284   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   285    285     Pager *pNext;               /* Linked list of pagers in this thread */
   286    286   #endif
................................................................................
   797    797   }
   798    798   
   799    799   /*
   800    800   ** Add or remove a page from the list of all pages that are in the
   801    801   ** statement journal.
   802    802   **
   803    803   ** The Pager keeps a separate list of pages that are currently in
   804         -** the statement journal.  This helps the sqlite3pager_stmt_commit()
          804  +** the statement journal.  This helps the sqlite3PagerStmtCommit()
   805    805   ** routine run MUCH faster for the common case where there are many
   806    806   ** pages in memory but only a few are in the statement journal.
   807    807   */
   808    808   static void page_add_to_stmt_list(PgHdr *pPg){
   809    809     Pager *pPager = pPg->pPager;
   810    810     if( pPg->inStmt ) return;
   811    811     assert( pPg->pPrevStmt==0 && pPg->pNextStmt==0 );
................................................................................
   886    886     pPager->pLast = 0;
   887    887     pPager->pAll = 0;
   888    888     pPager->nHash = 0;
   889    889     sqliteFree(pPager->aHash);
   890    890     pPager->nPage = 0;
   891    891     pPager->aHash = 0;
   892    892     if( pPager->state>=PAGER_RESERVED ){
   893         -    sqlite3pager_rollback(pPager);
          893  +    sqlite3PagerRollback(pPager);
   894    894     }
   895    895     pager_unlock(pPager);
   896    896     pPager->nRef = 0;
   897    897     assert( pPager->errCode || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
   898    898   }
   899    899   
   900    900   /*
................................................................................
   910    910   static int pager_unwritelock(Pager *pPager){
   911    911     PgHdr *pPg;
   912    912     int rc;
   913    913     assert( !MEMDB );
   914    914     if( pPager->state<PAGER_RESERVED ){
   915    915       return SQLITE_OK;
   916    916     }
   917         -  sqlite3pager_stmt_commit(pPager);
          917  +  sqlite3PagerStmtCommit(pPager);
   918    918     if( pPager->stmtOpen ){
   919    919       sqlite3OsClose(&pPager->stfd);
   920    920       pPager->stmtOpen = 0;
   921    921     }
   922    922     if( pPager->journalOpen ){
   923    923       sqlite3OsClose(&pPager->jfd);
   924    924       pPager->journalOpen = 0;
................................................................................
  1065   1065       }
  1066   1066     }
  1067   1067     if( pPg ){
  1068   1068       /* No page should ever be explicitly rolled back that is in use, except
  1069   1069       ** for page 1 which is held in use in order to keep the lock on the
  1070   1070       ** database active. However such a page may be rolled back as a result
  1071   1071       ** of an internal error resulting in an automatic call to
  1072         -    ** sqlite3pager_rollback().
         1072  +    ** sqlite3PagerRollback().
  1073   1073       */
  1074   1074       void *pData;
  1075   1075       /* assert( pPg->nRef==0 || pPg->pgno==1 ); */
  1076   1076       pData = PGHDR_TO_DATA(pPg);
  1077   1077       memcpy(pData, aData, pPager->pageSize);
  1078   1078       if( pPager->xDestructor ){  /*** FIX ME:  Should this be xReinit? ***/
  1079         -      pPager->xDestructor(pData, pPager->pageSize);
         1079  +      pPager->xDestructor(pPg, pPager->pageSize);
  1080   1080       }
  1081   1081   #ifdef SQLITE_CHECK_PAGES
  1082   1082       pPg->pageHash = pager_pagehash(pPg);
  1083   1083   #endif
  1084   1084       CODEC1(pPager, pData, pPg->pgno, 3);
  1085   1085     }
  1086   1086     return rc;
................................................................................
  1197   1197         CODEC1(pPager, zBuf, pPg->pgno, 2);
  1198   1198       }else{
  1199   1199         memset(zBuf, 0, pPager->pageSize);
  1200   1200       }
  1201   1201       if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), pPager->pageSize) ){
  1202   1202         memcpy(PGHDR_TO_DATA(pPg), zBuf, pPager->pageSize);
  1203   1203         if( pPager->xReiniter ){
  1204         -        pPager->xReiniter(PGHDR_TO_DATA(pPg), pPager->pageSize);
         1204  +        pPager->xReiniter(pPg, pPager->pageSize);
  1205   1205         }else{
  1206   1206           memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra);
  1207   1207         }
  1208   1208       }
  1209   1209       pPg->needSync = 0;
  1210   1210       pPg->dirty = 0;
  1211   1211   #ifdef SQLITE_CHECK_PAGES
................................................................................
  1509   1509     }
  1510   1510     return rc;
  1511   1511   }
  1512   1512   
  1513   1513   /*
  1514   1514   ** Change the maximum number of in-memory pages that are allowed.
  1515   1515   */
  1516         -void sqlite3pager_set_cachesize(Pager *pPager, int mxPage){
         1516  +void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
  1517   1517     if( mxPage>10 ){
  1518   1518       pPager->mxPage = mxPage;
  1519   1519     }else{
  1520   1520       pPager->mxPage = 10;
  1521   1521     }
  1522   1522   }
  1523   1523   
................................................................................
  1544   1544   **              assurance that the journal will not be corrupted to the
  1545   1545   **              point of causing damage to the database during rollback.
  1546   1546   **
  1547   1547   ** Numeric values associated with these states are OFF==1, NORMAL=2,
  1548   1548   ** and FULL=3.
  1549   1549   */
  1550   1550   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
  1551         -void sqlite3pager_set_safety_level(Pager *pPager, int level, int full_fsync){
         1551  +void sqlite3PagerSetSafetyLevel(Pager *pPager, int level, int full_fsync){
  1552   1552     pPager->noSync =  level==1 || pPager->tempFile;
  1553   1553     pPager->fullSync = level==3 && !pPager->tempFile;
  1554   1554     pPager->full_fsync = full_fsync;
  1555   1555     if( pPager->noSync ) pPager->needSync = 0;
  1556   1556   }
  1557   1557   #endif
  1558   1558   
................................................................................
  1570   1570   **
  1571   1571   ** Write the file descriptor into *fd.  Return SQLITE_OK on success or some
  1572   1572   ** other error code if we fail.
  1573   1573   **
  1574   1574   ** The OS will automatically delete the temporary file when it is
  1575   1575   ** closed.
  1576   1576   */
  1577         -static int sqlite3pager_opentemp(OsFile **pFd){
         1577  +static int sqlite3PagerOpentemp(OsFile **pFd){
  1578   1578     int cnt = 8;
  1579   1579     int rc;
  1580   1580     char zFile[SQLITE_TEMPNAME_SIZE];
  1581   1581   
  1582   1582   #ifdef SQLITE_TEST
  1583   1583     sqlite3_opentemp_count++;  /* Used for testing and analysis only */
  1584   1584   #endif
................................................................................
  1589   1589     }while( cnt>0 && rc!=SQLITE_OK && rc!=SQLITE_NOMEM );
  1590   1590     return rc;
  1591   1591   }
  1592   1592   
  1593   1593   /*
  1594   1594   ** Create a new page cache and put a pointer to the page cache in *ppPager.
  1595   1595   ** The file to be cached need not exist.  The file is not locked until
  1596         -** the first call to sqlite3pager_get() and is only held open until the
  1597         -** last page is released using sqlite3pager_unref().
         1596  +** the first call to sqlite3PagerGet() and is only held open until the
         1597  +** last page is released using sqlite3PagerUnref().
  1598   1598   **
  1599   1599   ** If zFilename is NULL then a randomly-named temporary file is created
  1600   1600   ** and used as the file to be cached.  The file will be deleted
  1601   1601   ** automatically when it is closed.
  1602   1602   **
  1603   1603   ** If zFilename is ":memory:" then all information is held in cache.
  1604   1604   ** It is never written to disk.  This can be used to implement an
  1605   1605   ** in-memory database.
  1606   1606   */
  1607         -int sqlite3pager_open(
         1607  +int sqlite3PagerOpen(
  1608   1608     Pager **ppPager,         /* Return the Pager structure here */
  1609   1609     const char *zFilename,   /* Name of the database file to open */
  1610   1610     int nExtra,              /* Extra bytes append to each in-memory page */
  1611   1611     int flags                /* flags controlling this file */
  1612   1612   ){
  1613   1613     Pager *pPager = 0;
  1614   1614     char *zFullPathname = 0;
................................................................................
  1657   1657       {
  1658   1658         zFullPathname = sqlite3OsFullPathname(zFilename);
  1659   1659         if( zFullPathname ){
  1660   1660           rc = sqlite3OsOpenReadWrite(zFullPathname, &fd, &readOnly);
  1661   1661         }
  1662   1662       }
  1663   1663     }else{
  1664         -    rc = sqlite3pager_opentemp(&fd);
         1664  +    rc = sqlite3PagerOpentemp(&fd);
  1665   1665       sqlite3OsTempFileName(zTemp);
  1666   1666       zFilename = zTemp;
  1667   1667       zFullPathname = sqlite3OsFullPathname(zFilename);
  1668   1668       if( rc==SQLITE_OK ){
  1669   1669         tempFile = 1;
  1670   1670       }
  1671   1671     }
................................................................................
  1748   1748   #endif
  1749   1749     return SQLITE_OK;
  1750   1750   }
  1751   1751   
  1752   1752   /*
  1753   1753   ** Set the busy handler function.
  1754   1754   */
  1755         -void sqlite3pager_set_busyhandler(Pager *pPager, BusyHandler *pBusyHandler){
         1755  +void sqlite3PagerSetBusyhandler(Pager *pPager, BusyHandler *pBusyHandler){
  1756   1756     pPager->pBusyHandler = pBusyHandler;
  1757   1757   }
  1758   1758   
  1759   1759   /*
  1760   1760   ** Set the destructor for this pager.  If not NULL, the destructor is called
  1761   1761   ** when the reference count on each page reaches zero.  The destructor can
  1762   1762   ** be used to clean up information in the extra segment appended to each page.
  1763   1763   **
  1764         -** The destructor is not called as a result sqlite3pager_close().  
  1765         -** Destructors are only called by sqlite3pager_unref().
         1764  +** The destructor is not called as a result sqlite3PagerClose().  
         1765  +** Destructors are only called by sqlite3PagerUnref().
  1766   1766   */
  1767         -void sqlite3pager_set_destructor(Pager *pPager, void (*xDesc)(void*,int)){
         1767  +void sqlite3PagerSetDestructor(Pager *pPager, void (*xDesc)(DbPage*,int)){
  1768   1768     pPager->xDestructor = xDesc;
  1769   1769   }
  1770   1770   
  1771   1771   /*
  1772   1772   ** Set the reinitializer for this pager.  If not NULL, the reinitializer
  1773   1773   ** is called when the content of a page in cache is restored to its original
  1774   1774   ** value as a result of a rollback.  The callback gives higher-level code
  1775   1775   ** an opportunity to restore the EXTRA section to agree with the restored
  1776   1776   ** page data.
  1777   1777   */
  1778         -void sqlite3pager_set_reiniter(Pager *pPager, void (*xReinit)(void*,int)){
         1778  +void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*,int)){
  1779   1779     pPager->xReiniter = xReinit;
  1780   1780   }
  1781   1781   
  1782   1782   /*
  1783   1783   ** Set the page size.  Return the new size.  If the suggest new page
  1784   1784   ** size is inappropriate, then an alternative page size is selected
  1785   1785   ** and returned.
  1786   1786   */
  1787         -int sqlite3pager_set_pagesize(Pager *pPager, int pageSize){
         1787  +int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){
  1788   1788     assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE );
  1789   1789     if( !pPager->memDb ){
  1790   1790       pPager->pageSize = pageSize;
  1791   1791       sqlite3ReallocOrFree((void **)&pPager->pTmpSpace, pageSize);
  1792   1792     }
  1793   1793     return pPager->pageSize;
  1794   1794   }
................................................................................
  1827   1827   **
  1828   1828   ** No error checking is done. The rational for this is that this function 
  1829   1829   ** may be called even if the file does not exist or contain a header. In 
  1830   1830   ** these cases sqlite3OsRead() will return an error, to which the correct 
  1831   1831   ** response is to zero the memory at pDest and continue.  A real IO error 
  1832   1832   ** will presumably recur and be picked up later (Todo: Think about this).
  1833   1833   */
  1834         -int sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
         1834  +int sqlite3PagerReadFileheader(Pager *pPager, int N, unsigned char *pDest){
  1835   1835     int rc = SQLITE_OK;
  1836   1836     memset(pDest, 0, N);
  1837   1837     if( MEMDB==0 ){
  1838   1838       disable_simulated_io_errors();
  1839   1839       sqlite3OsSeek(pPager->fd, 0);
  1840   1840       enable_simulated_io_errors();
  1841   1841       IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
................................................................................
  1852   1852   ** pPager. 
  1853   1853   **
  1854   1854   ** If the PENDING_BYTE lies on the page directly after the end of the
  1855   1855   ** file, then consider this page part of the file too. For example, if
  1856   1856   ** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the
  1857   1857   ** file is 4096 bytes, 5 is returned instead of 4.
  1858   1858   */
  1859         -int sqlite3pager_pagecount(Pager *pPager){
         1859  +int sqlite3PagerPagecount(Pager *pPager){
  1860   1860     i64 n;
  1861   1861     int rc;
  1862   1862     assert( pPager!=0 );
  1863   1863     if( pPager->errCode ){
  1864   1864       return 0;
  1865   1865     }
  1866   1866     if( pPager->dbSize>=0 ){
................................................................................
  1904   1904   ** Forward declaration
  1905   1905   */
  1906   1906   static int syncJournal(Pager*);
  1907   1907   
  1908   1908   /*
  1909   1909   ** Unlink pPg from it's hash chain. Also set the page number to 0 to indicate
  1910   1910   ** that the page is not part of any hash chain. This is required because the
  1911         -** sqlite3pager_movepage() routine can leave a page in the 
         1911  +** sqlite3PagerMovepage() routine can leave a page in the 
  1912   1912   ** pNextFree/pPrevFree list that is not a part of any hash-chain.
  1913   1913   */
  1914   1914   static void unlinkHashChain(Pager *pPager, PgHdr *pPg){
  1915   1915     if( pPg->pgno==0 ){
  1916   1916       assert( pPg->pNextHash==0 && pPg->pPrevHash==0 );
  1917   1917       return;
  1918   1918     }
................................................................................
  2029   2029     }
  2030   2030     return rc;
  2031   2031   }
  2032   2032   
  2033   2033   /*
  2034   2034   ** Truncate the file to the number of pages specified.
  2035   2035   */
  2036         -int sqlite3pager_truncate(Pager *pPager, Pgno nPage){
         2036  +int sqlite3PagerTruncate(Pager *pPager, Pgno nPage){
  2037   2037     int rc;
  2038   2038     assert( pPager->state>=PAGER_SHARED || MEMDB );
  2039         -  sqlite3pager_pagecount(pPager);
         2039  +  sqlite3PagerPagecount(pPager);
  2040   2040     if( pPager->errCode ){
  2041   2041       rc = pPager->errCode;
  2042   2042       return rc;
  2043   2043     }
  2044   2044     if( nPage>=(unsigned)pPager->dbSize ){
  2045   2045       return SQLITE_OK;
  2046   2046     }
................................................................................
  2077   2077   ** result in a coredump.
  2078   2078   **
  2079   2079   ** This function always succeeds. If a transaction is active an attempt
  2080   2080   ** is made to roll it back. If an error occurs during the rollback 
  2081   2081   ** a hot journal may be left in the filesystem but no error is returned
  2082   2082   ** to the caller.
  2083   2083   */
  2084         -int sqlite3pager_close(Pager *pPager){
         2084  +int sqlite3PagerClose(Pager *pPager){
  2085   2085   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  2086   2086     /* A malloc() cannot fail in sqlite3ThreadData() as one or more calls to 
  2087   2087     ** malloc() must have already been made by this thread before it gets
  2088   2088     ** to this point. This means the ThreadData must have been allocated already
  2089   2089     ** so that ThreadData.nAlloc can be set.
  2090   2090     */
  2091   2091     ThreadData *pTsd = sqlite3ThreadData();
................................................................................
  2131   2131     sqliteFree(pPager);
  2132   2132     return SQLITE_OK;
  2133   2133   }
  2134   2134   
  2135   2135   /*
  2136   2136   ** Return the page number for the given page data.
  2137   2137   */
  2138         -Pgno sqlite3pager_pagenumber(void *pData){
  2139         -  PgHdr *p = DATA_TO_PGHDR(pData);
         2138  +Pgno sqlite3PagerPagenumber(DbPage *p){
  2140   2139     return p->pgno;
  2141   2140   }
  2142   2141   
  2143   2142   /*
  2144   2143   ** The page_ref() function increments the reference count for a page.
  2145   2144   ** If the page is currently on the freelist (the reference count is zero) then
  2146   2145   ** remove it from the freelist.
................................................................................
  2185   2184   # define page_ref(P)   ((P)->nRef==0?_page_ref(P):(void)(P)->nRef++)
  2186   2185   #endif
  2187   2186   
  2188   2187   /*
  2189   2188   ** Increment the reference count for a page.  The input pointer is
  2190   2189   ** a reference to the page data.
  2191   2190   */
  2192         -int sqlite3pager_ref(void *pData){
  2193         -  PgHdr *pPg = DATA_TO_PGHDR(pData);
         2191  +int sqlite3PagerRef(DbPage *pPg){
  2194   2192     page_ref(pPg);
  2195   2193     return SQLITE_OK;
  2196   2194   }
  2197   2195   
  2198   2196   /*
  2199   2197   ** Sync the journal.  In other words, make sure all the pages that have
  2200   2198   ** been written to the journal have actually reached the surface of the
................................................................................
  2390   2388   
  2391   2389     pList = sort_pagelist(pList);
  2392   2390     while( pList ){
  2393   2391       assert( pList->dirty );
  2394   2392       rc = sqlite3OsSeek(pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize);
  2395   2393       if( rc ) return rc;
  2396   2394       /* If there are dirty pages in the page cache with page numbers greater
  2397         -    ** than Pager.dbSize, this means sqlite3pager_truncate() was called to
         2395  +    ** than Pager.dbSize, this means sqlite3PagerTruncate() was called to
  2398   2396       ** make the file smaller (presumably by auto-vacuum code). Do not write
  2399   2397       ** any such pages to the file.
  2400   2398       */
  2401   2399       if( pList->pgno<=pPager->dbSize ){
  2402   2400         char *pData = CODEC2(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6);
  2403   2401         TRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno);
  2404   2402         IOTRACE(("PGOUT %p %d\n", pPager, pList->pgno))
................................................................................
  2437   2435   ** exists, that is probably an old journal left over from a prior
  2438   2436   ** database with the same name.  Just delete the journal.
  2439   2437   */
  2440   2438   static int hasHotJournal(Pager *pPager){
  2441   2439     if( !pPager->useJournal ) return 0;
  2442   2440     if( !sqlite3OsFileExists(pPager->zJournal) ) return 0;
  2443   2441     if( sqlite3OsCheckReservedLock(pPager->fd) ) return 0;
  2444         -  if( sqlite3pager_pagecount(pPager)==0 ){
         2442  +  if( sqlite3PagerPagecount(pPager)==0 ){
  2445   2443       sqlite3OsDelete(pPager->zJournal);
  2446   2444       return 0;
  2447   2445     }else{
  2448   2446       return 1;
  2449   2447     }
  2450   2448   }
  2451   2449   
................................................................................
  2541   2539   **
  2542   2540   ** nReq is the number of bytes of memory required. Once this much has
  2543   2541   ** been released, the function returns. A negative value for nReq means
  2544   2542   ** free as much memory as possible. The return value is the total number 
  2545   2543   ** of bytes of memory released.
  2546   2544   */
  2547   2545   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  2548         -int sqlite3pager_release_memory(int nReq){
         2546  +int sqlite3PagerReleaseMemory(int nReq){
  2549   2547     const ThreadData *pTsdro = sqlite3ThreadDataReadOnly();
  2550   2548     Pager *p;
  2551   2549     int nReleased = 0;
  2552   2550     int i;
  2553   2551   
  2554   2552     /* If the the global mutex is held, this subroutine becomes a
  2555   2553     ** o-op; zero bytes of memory are freed.  This is because
................................................................................
  2628   2626   ** read occurs and the memory image of the page is initialized to
  2629   2627   ** all zeros.  The extra data appended to a page is always initialized
  2630   2628   ** to zeros the first time a page is loaded into memory.
  2631   2629   **
  2632   2630   ** The acquisition might fail for several reasons.  In all cases,
  2633   2631   ** an appropriate error code is returned and *ppPage is set to NULL.
  2634   2632   **
  2635         -** See also sqlite3pager_lookup().  Both this routine and _lookup() attempt
         2633  +** See also sqlite3PagerLookup().  Both this routine and _lookup() attempt
  2636   2634   ** to find a page in the in-memory cache first.  If the page is not already
  2637   2635   ** in memory, this routine goes to disk to read it in whereas _lookup()
  2638   2636   ** just returns 0.  This routine acquires a read-lock the first time it
  2639   2637   ** has to go to disk, and could also playback an old journal if necessary.
  2640   2638   ** Since _lookup() never goes to disk, it never has to deal with locks
  2641   2639   ** or journal files.
  2642   2640   **
  2643   2641   ** If clrFlag is false, the page contents are actually read from disk.
  2644   2642   ** If clfFlag is true, it means the page is about to be erased and
  2645   2643   ** rewritten without first being read so there is no point it doing
  2646   2644   ** the disk I/O.
  2647   2645   */
  2648         -int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag){
         2646  +int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag){
  2649   2647     PgHdr *pPg;
  2650   2648     int rc;
  2651   2649   
  2652   2650     /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
  2653   2651     ** number greater than this, or zero, is requested.
  2654   2652     */
  2655   2653     if( pgno>PAGER_MAX_PGNO || pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
................................................................................
  2793   2791       REFINFO(pPg);
  2794   2792   
  2795   2793       pPager->nRef++;
  2796   2794       if( pPager->nExtra>0 ){
  2797   2795         memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra);
  2798   2796       }
  2799   2797       if( pPager->errCode ){
  2800         -      sqlite3pager_unref(PGHDR_TO_DATA(pPg));
         2798  +      sqlite3PagerUnref(pPg);
  2801   2799         rc = pPager->errCode;
  2802   2800         return rc;
  2803   2801       }
  2804   2802   
  2805   2803       /* Populate the page with data, either by reading from the database
  2806   2804       ** file, or by setting the entire page to zero.
  2807   2805       */
  2808         -    if( sqlite3pager_pagecount(pPager)<(int)pgno || MEMDB
         2806  +    if( sqlite3PagerPagecount(pPager)<(int)pgno || MEMDB
  2809   2807            || (clrFlag && !pPager->alwaysRollback) 
  2810   2808       ){
  2811   2809         memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
  2812   2810       }else{
  2813   2811         assert( MEMDB==0 );
  2814   2812         rc = sqlite3OsSeek(pPager->fd, (pgno-1)*(i64)pPager->pageSize);
  2815   2813         if( rc==SQLITE_OK ){
................................................................................
  2817   2815                                 pPager->pageSize);
  2818   2816         }
  2819   2817         IOTRACE(("PGIN %p %d\n", pPager, pgno))
  2820   2818         TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
  2821   2819         CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
  2822   2820         if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
  2823   2821           pPg->pgno = 0;
  2824         -        sqlite3pager_unref(PGHDR_TO_DATA(pPg));
         2822  +        sqlite3PagerUnref(pPg);
  2825   2823           return rc;
  2826   2824         }else{
  2827   2825           TEST_INCR(pPager->nRead);
  2828   2826         }
  2829   2827       }
  2830   2828   
  2831   2829       /* Link the page into the page hash table */
................................................................................
  2842   2840       pPg->pageHash = pager_pagehash(pPg);
  2843   2841   #endif
  2844   2842     }else{
  2845   2843       /* The requested page is in the page cache. */
  2846   2844       TEST_INCR(pPager->nHit);
  2847   2845       page_ref(pPg);
  2848   2846     }
  2849         -  *ppPage = PGHDR_TO_DATA(pPg);
         2847  +  *ppPage = pPg;
  2850   2848     return SQLITE_OK;
  2851   2849   }
  2852   2850   
  2853   2851   /*
  2854   2852   ** Acquire a page if it is already in the in-memory cache.  Do
  2855   2853   ** not read the page from disk.  Return a pointer to the page,
  2856   2854   ** or 0 if the page is not in cache.
  2857   2855   **
  2858         -** See also sqlite3pager_get().  The difference between this routine
  2859         -** and sqlite3pager_get() is that _get() will go to the disk and read
         2856  +** See also sqlite3PagerGet().  The difference between this routine
         2857  +** and sqlite3PagerGet() is that _get() will go to the disk and read
  2860   2858   ** in the page if the page is not already in cache.  This routine
  2861   2859   ** returns NULL if the page is not in cache or if a disk I/O error 
  2862   2860   ** has ever happened.
  2863   2861   */
  2864         -void *sqlite3pager_lookup(Pager *pPager, Pgno pgno){
         2862  +DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
  2865   2863     PgHdr *pPg;
  2866   2864   
  2867   2865     assert( pPager!=0 );
  2868   2866     assert( pgno!=0 );
  2869   2867     if( pPager->errCode && pPager->errCode!=SQLITE_FULL ){
  2870   2868       return 0;
  2871   2869     }
  2872   2870     pPg = pager_lookup(pPager, pgno);
  2873   2871     if( pPg==0 ) return 0;
  2874   2872     page_ref(pPg);
  2875         -  return PGHDR_TO_DATA(pPg);
         2873  +  return pPg;
  2876   2874   }
  2877   2875   
  2878   2876   /*
  2879   2877   ** Release a page.
  2880   2878   **
  2881   2879   ** If the number of references to the page drop to zero, then the
  2882   2880   ** page is added to the LRU list.  When all references to all pages
  2883   2881   ** are released, a rollback occurs and the lock on the database is
  2884   2882   ** removed.
  2885   2883   */
  2886         -int sqlite3pager_unref(void *pData){
  2887         -  PgHdr *pPg;
         2884  +int sqlite3PagerUnref(DbPage *pPg){
  2888   2885   
  2889   2886     /* Decrement the reference count for this page
  2890   2887     */
  2891         -  pPg = DATA_TO_PGHDR(pData);
  2892   2888     assert( pPg->nRef>0 );
  2893   2889     pPg->nRef--;
  2894   2890     REFINFO(pPg);
  2895   2891   
  2896   2892     CHECK_PAGE(pPg);
  2897   2893   
  2898   2894     /* When the number of references to a page reach 0, call the
................................................................................
  2909   2905       }else{
  2910   2906         pPager->pFirst = pPg;
  2911   2907       }
  2912   2908       if( pPg->needSync==0 && pPager->pFirstSynced==0 ){
  2913   2909         pPager->pFirstSynced = pPg;
  2914   2910       }
  2915   2911       if( pPager->xDestructor ){
  2916         -      pPager->xDestructor(pData, pPager->pageSize);
         2912  +      pPager->xDestructor(pPg, pPager->pageSize);
  2917   2913       }
  2918   2914     
  2919   2915       /* When all pages reach the freelist, drop the read lock from
  2920   2916       ** the database file.
  2921   2917       */
  2922   2918       pPager->nRef--;
  2923   2919       assert( pPager->nRef>=0 );
................................................................................
  2938   2934   static int pager_open_journal(Pager *pPager){
  2939   2935     int rc;
  2940   2936     assert( !MEMDB );
  2941   2937     assert( pPager->state>=PAGER_RESERVED );
  2942   2938     assert( pPager->journalOpen==0 );
  2943   2939     assert( pPager->useJournal );
  2944   2940     assert( pPager->aInJournal==0 );
  2945         -  sqlite3pager_pagecount(pPager);
         2941  +  sqlite3PagerPagecount(pPager);
  2946   2942     pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 );
  2947   2943     if( pPager->aInJournal==0 ){
  2948   2944       rc = SQLITE_NOMEM;
  2949   2945       goto failed_to_open_journal;
  2950   2946     }
  2951   2947     rc = sqlite3OsOpenExclusive(pPager->zJournal, &pPager->jfd,
  2952   2948                                    pPager->tempFile);
................................................................................
  2969   2965       goto failed_to_open_journal;
  2970   2966     }
  2971   2967     pPager->origDbSize = pPager->dbSize;
  2972   2968   
  2973   2969     rc = writeJournalHdr(pPager);
  2974   2970   
  2975   2971     if( pPager->stmtAutoopen && rc==SQLITE_OK ){
  2976         -    rc = sqlite3pager_stmt_begin(pPager);
         2972  +    rc = sqlite3PagerStmtBegin(pPager);
  2977   2973     }
  2978   2974     if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){
  2979   2975       rc = pager_unwritelock(pPager);
  2980   2976       if( rc==SQLITE_OK ){
  2981   2977         rc = SQLITE_FULL;
  2982   2978       }
  2983   2979     }
................................................................................
  2999   2995     return rc;
  3000   2996   }
  3001   2997   
  3002   2998   /*
  3003   2999   ** Acquire a write-lock on the database.  The lock is removed when
  3004   3000   ** the any of the following happen:
  3005   3001   **
  3006         -**   *  sqlite3pager_commit() is called.
  3007         -**   *  sqlite3pager_rollback() is called.
  3008         -**   *  sqlite3pager_close() is called.
  3009         -**   *  sqlite3pager_unref() is called to on every outstanding page.
         3002  +**   *  sqlite3PagerCommit() is called.
         3003  +**   *  sqlite3PagerRollback() is called.
         3004  +**   *  sqlite3PagerClose() is called.
         3005  +**   *  sqlite3PagerUnref() is called to on every outstanding page.
  3010   3006   **
  3011   3007   ** The first parameter to this routine is a pointer to any open page of the
  3012   3008   ** database file.  Nothing changes about the page - it is used merely to
  3013   3009   ** acquire a pointer to the Pager structure and as proof that there is
  3014   3010   ** already a read-lock on the database.
  3015   3011   **
  3016   3012   ** The second parameter indicates how much space in bytes to reserve for a
................................................................................
  3022   3018   **
  3023   3019   ** If the database is already reserved for writing, this routine is a no-op.
  3024   3020   **
  3025   3021   ** If exFlag is true, go ahead and get an EXCLUSIVE lock on the file
  3026   3022   ** immediately instead of waiting until we try to flush the cache.  The
  3027   3023   ** exFlag is ignored if a transaction is already active.
  3028   3024   */
  3029         -int sqlite3pager_begin(void *pData, int exFlag){
  3030         -  PgHdr *pPg = DATA_TO_PGHDR(pData);
         3025  +int sqlite3PagerBegin(DbPage *pPg, int exFlag){
  3031   3026     Pager *pPager = pPg->pPager;
  3032   3027     int rc = SQLITE_OK;
  3033   3028     assert( pPg->nRef>0 );
  3034   3029     assert( pPager->state!=PAGER_UNLOCK );
  3035   3030     if( pPager->state==PAGER_SHARED ){
  3036   3031       assert( pPager->aInJournal==0 );
  3037   3032       if( MEMDB ){
................................................................................
  3104   3099   ** lock could not be acquired, this routine returns SQLITE_BUSY.  The
  3105   3100   ** calling routine must check for that return value and be careful not to
  3106   3101   ** change any page data until this routine returns SQLITE_OK.
  3107   3102   **
  3108   3103   ** If the journal file could not be written because the disk is full,
  3109   3104   ** then this routine returns SQLITE_FULL and does an immediate rollback.
  3110   3105   ** All subsequent write attempts also return SQLITE_FULL until there
  3111         -** is a call to sqlite3pager_commit() or sqlite3pager_rollback() to
         3106  +** is a call to sqlite3PagerCommit() or sqlite3PagerRollback() to
  3112   3107   ** reset.
  3113   3108   */
  3114         -static int pager_write(void *pData){
  3115         -  PgHdr *pPg = DATA_TO_PGHDR(pData);
         3109  +static int pager_write(PgHdr *pPg){
         3110  +  void *pData = PGHDR_TO_DATA(pPg);
  3116   3111     Pager *pPager = pPg->pPager;
  3117   3112     int rc = SQLITE_OK;
  3118   3113   
  3119   3114     /* Check for errors
  3120   3115     */
  3121   3116     if( pPager->errCode ){ 
  3122   3117       return pPager->errCode;
................................................................................
  3141   3136       ** written to the transaction journal or the ckeckpoint journal
  3142   3137       ** or both.
  3143   3138       **
  3144   3139       ** First check to see that the transaction journal exists and
  3145   3140       ** create it if it does not.
  3146   3141       */
  3147   3142       assert( pPager->state!=PAGER_UNLOCK );
  3148         -    rc = sqlite3pager_begin(pData, 0);
         3143  +    rc = sqlite3PagerBegin(pPg, 0);
  3149   3144       if( rc!=SQLITE_OK ){
  3150   3145         return rc;
  3151   3146       }
  3152   3147       assert( pPager->state>=PAGER_RESERVED );
  3153   3148       if( !pPager->journalOpen && pPager->useJournal ){
  3154   3149         rc = pager_open_journal(pPager);
  3155   3150         if( rc!=SQLITE_OK ) return rc;
................................................................................
  3271   3266   ** and write the page *pData to the journal.
  3272   3267   **
  3273   3268   ** The difference between this function and pager_write() is that this
  3274   3269   ** function also deals with the special case where 2 or more pages
  3275   3270   ** fit on a single disk sector. In this case all co-resident pages
  3276   3271   ** must have been written to the journal file before returning.
  3277   3272   */
  3278         -int sqlite3pager_write(void *pData){
         3273  +int sqlite3PagerWrite(DbPage *pDbPage){
  3279   3274     int rc = SQLITE_OK;
  3280   3275   
  3281         -  PgHdr *pPg = DATA_TO_PGHDR(pData);
         3276  +  PgHdr *pPg = pDbPage;
  3282   3277     Pager *pPager = pPg->pPager;
  3283   3278     Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
  3284   3279   
  3285   3280     if( !MEMDB && nPagePerSector>1 ){
  3286   3281       Pgno nPageCount;          /* Total number of pages in database file */
  3287   3282       Pgno pg1;                 /* First page of the sector pPg is located on. */
  3288   3283       int nPage;                /* Number of pages starting at pg1 to journal */
................................................................................
  3296   3291   
  3297   3292       /* This trick assumes that both the page-size and sector-size are
  3298   3293       ** an integer power of 2. It sets variable pg1 to the identifier
  3299   3294       ** of the first page of the sector pPg is located on.
  3300   3295       */
  3301   3296       pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
  3302   3297   
  3303         -    nPageCount = sqlite3pager_pagecount(pPager);
         3298  +    nPageCount = sqlite3PagerPagecount(pPager);
  3304   3299       if( pPg->pgno>nPageCount ){
  3305   3300         nPage = (pPg->pgno - pg1)+1;
  3306   3301       }else if( (pg1+nPagePerSector-1)>nPageCount ){
  3307   3302         nPage = nPageCount+1-pg1;
  3308   3303       }else{
  3309   3304         nPage = nPagePerSector;
  3310   3305       }
................................................................................
  3314   3309   
  3315   3310       for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){
  3316   3311         Pgno pg = pg1+ii;
  3317   3312         if( !pPager->aInJournal || pg==pPg->pgno || 
  3318   3313             pg>pPager->origDbSize || !(pPager->aInJournal[pg/8]&(1<<(pg&7)))
  3319   3314         ) {
  3320   3315           if( pg!=PAGER_MJ_PGNO(pPager) ){
  3321         -          void *pPage;
  3322         -          rc = sqlite3pager_get(pPager, pg, &pPage);
         3316  +          PgHdr *pPage;
         3317  +          rc = sqlite3PagerGet(pPager, pg, &pPage);
  3323   3318             if( rc==SQLITE_OK ){
  3324   3319               rc = pager_write(pPage);
  3325         -            sqlite3pager_unref(pPage);
         3320  +            sqlite3PagerUnref(pPage);
  3326   3321             }
  3327   3322           }
  3328   3323         }
  3329   3324       }
  3330   3325   
  3331   3326       assert( pPager->doNotSync==1 );
  3332   3327       pPager->doNotSync = 0;
  3333   3328     }else{
  3334         -    rc = pager_write(pData);
         3329  +    rc = pager_write(pDbPage);
  3335   3330     }
  3336   3331     return rc;
  3337   3332   }
  3338   3333   
  3339   3334   /*
  3340   3335   ** Return TRUE if the page given in the argument was previously passed
  3341         -** to sqlite3pager_write().  In other words, return TRUE if it is ok
         3336  +** to sqlite3PagerWrite().  In other words, return TRUE if it is ok
  3342   3337   ** to change the content of the page.
  3343   3338   */
  3344   3339   #ifndef NDEBUG
  3345         -int sqlite3pager_iswriteable(void *pData){
  3346         -  PgHdr *pPg = DATA_TO_PGHDR(pData);
         3340  +int sqlite3PagerIswriteable(DbPage *pPg){
  3347   3341     return pPg->dirty;
  3348   3342   }
  3349   3343   #endif
  3350   3344   
  3351   3345   #ifndef SQLITE_OMIT_VACUUM
  3352   3346   /*
  3353   3347   ** Replace the content of a single page with the information in the third
  3354   3348   ** argument.
  3355   3349   */
  3356         -int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void *pData){
  3357         -  void *pPage;
         3350  +int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void *pData){
         3351  +  PgHdr *pPg;
  3358   3352     int rc;
  3359   3353   
  3360         -  rc = sqlite3pager_get(pPager, pgno, &pPage);
         3354  +  rc = sqlite3PagerGet(pPager, pgno, &pPg);
  3361   3355     if( rc==SQLITE_OK ){
  3362         -    rc = sqlite3pager_write(pPage);
         3356  +    rc = sqlite3PagerWrite(pPg);
  3363   3357       if( rc==SQLITE_OK ){
  3364         -      memcpy(pPage, pData, pPager->pageSize);
         3358  +      memcpy(sqlite3PagerGetData(pPg), pData, pPager->pageSize);
  3365   3359       }
  3366         -    sqlite3pager_unref(pPage);
         3360  +    sqlite3PagerUnref(pPg);
  3367   3361     }
  3368   3362     return rc;
  3369   3363   }
  3370   3364   #endif
  3371   3365   
  3372   3366   /*
  3373   3367   ** A call to this routine tells the pager that it is not necessary to
................................................................................
  3375   3369   ** that page might be marked as dirty.
  3376   3370   **
  3377   3371   ** The overlying software layer calls this routine when all of the data
  3378   3372   ** on the given page is unused.  The pager marks the page as clean so
  3379   3373   ** that it does not get written to disk.
  3380   3374   **
  3381   3375   ** Tests show that this optimization, together with the
  3382         -** sqlite3pager_dont_rollback() below, more than double the speed
         3376  +** sqlite3PagerDontRollback() below, more than double the speed
  3383   3377   ** of large INSERT operations and quadruple the speed of large DELETEs.
  3384   3378   **
  3385   3379   ** When this routine is called, set the alwaysRollback flag to true.
  3386         -** Subsequent calls to sqlite3pager_dont_rollback() for the same page
         3380  +** Subsequent calls to sqlite3PagerDontRollback() for the same page
  3387   3381   ** will thereafter be ignored.  This is necessary to avoid a problem
  3388   3382   ** where a page with data is added to the freelist during one part of
  3389   3383   ** a transaction then removed from the freelist during a later part
  3390   3384   ** of the same transaction and reused for some other purpose.  When it
  3391   3385   ** is first added to the freelist, this routine is called.  When reused,
  3392   3386   ** the dont_rollback() routine is called.  But because the page contains
  3393   3387   ** critical data, we still need to be sure it gets rolled back in spite
  3394   3388   ** of the dont_rollback() call.
  3395   3389   */
  3396         -void sqlite3pager_dont_write(Pager *pPager, Pgno pgno){
         3390  +void sqlite3PagerDontWrite(Pager *pPager, Pgno pgno){
  3397   3391     PgHdr *pPg;
  3398   3392   
  3399   3393     if( MEMDB ) return;
  3400   3394   
  3401   3395     pPg = pager_lookup(pPager, pgno);
  3402   3396     assert( pPg!=0 );  /* We never call _dont_write unless the page is in mem */
  3403   3397     pPg->alwaysRollback = 1;
................................................................................
  3425   3419   
  3426   3420   /*
  3427   3421   ** A call to this routine tells the pager that if a rollback occurs,
  3428   3422   ** it is not necessary to restore the data on the given page.  This
  3429   3423   ** means that the pager does not have to record the given page in the
  3430   3424   ** rollback journal.
  3431   3425   */
  3432         -void sqlite3pager_dont_rollback(void *pData){
  3433         -  PgHdr *pPg = DATA_TO_PGHDR(pData);
         3426  +void sqlite3PagerDontRollback(DbPage *pPg){
  3434   3427     Pager *pPager = pPg->pPager;
  3435   3428   
  3436   3429     assert( pPager->state>=PAGER_RESERVED );
  3437   3430     if( pPager->journalOpen==0 ) return;
  3438   3431     if( pPg->alwaysRollback || pPager->alwaysRollback || MEMDB ) return;
  3439   3432     if( !pPg->inJournal && (int)pPg->pgno <= pPager->origDbSize ){
  3440   3433       assert( pPager->aInJournal!=0 );
................................................................................
  3459   3452   /*
  3460   3453   ** Commit all changes to the database and release the write lock.
  3461   3454   **
  3462   3455   ** If the commit fails for any reason, a rollback attempt is made
  3463   3456   ** and an error code is returned.  If the commit worked, SQLITE_OK
  3464   3457   ** is returned.
  3465   3458   */
  3466         -int sqlite3pager_commit(Pager *pPager){
         3459  +int sqlite3PagerCommit(Pager *pPager){
  3467   3460     int rc;
  3468   3461     PgHdr *pPg;
  3469   3462   
  3470   3463     if( pPager->errCode ){
  3471   3464       return pPager->errCode;
  3472   3465     }
  3473   3466     if( pPager->state<PAGER_RESERVED ){
................................................................................
  3502   3495       /* Exit early (without doing the time-consuming sqlite3OsSync() calls)
  3503   3496       ** if there have been no changes to the database file. */
  3504   3497       assert( pPager->needSync==0 );
  3505   3498       rc = pager_unwritelock(pPager);
  3506   3499       return rc;
  3507   3500     }
  3508   3501     assert( pPager->journalOpen );
  3509         -  rc = sqlite3pager_sync(pPager, 0, 0);
         3502  +  rc = sqlite3PagerSync(pPager, 0, 0);
  3510   3503     if( rc==SQLITE_OK ){
  3511   3504       rc = pager_unwritelock(pPager);
  3512   3505     }
  3513   3506     return rc;
  3514   3507   }
  3515   3508   
  3516   3509   /*
................................................................................
  3521   3514   ** This routine cannot fail unless some other process is not following
  3522   3515   ** the correct locking protocol (SQLITE_PROTOCOL) or unless some other
  3523   3516   ** process is writing trash into the journal file (SQLITE_CORRUPT) or
  3524   3517   ** unless a prior malloc() failed (SQLITE_NOMEM).  Appropriate error
  3525   3518   ** codes are returned for all these occasions.  Otherwise,
  3526   3519   ** SQLITE_OK is returned.
  3527   3520   */
  3528         -int sqlite3pager_rollback(Pager *pPager){
         3521  +int sqlite3PagerRollback(Pager *pPager){
  3529   3522     int rc;
  3530   3523     TRACE2("ROLLBACK %d\n", PAGERID(pPager));
  3531   3524     if( MEMDB ){
  3532   3525       PgHdr *p;
  3533   3526       for(p=pPager->pAll; p; p=p->pNextAll){
  3534   3527         PgHistory *pHist;
  3535   3528         assert( !p->alwaysRollback );
................................................................................
  3548   3541         }
  3549   3542         clearHistory(pHist);
  3550   3543         p->dirty = 0;
  3551   3544         p->inJournal = 0;
  3552   3545         p->inStmt = 0;
  3553   3546         p->pPrevStmt = p->pNextStmt = 0;
  3554   3547         if( pPager->xReiniter ){
  3555         -        pPager->xReiniter(PGHDR_TO_DATA(p), pPager->pageSize);
         3548  +        pPager->xReiniter(p, pPager->pageSize);
  3556   3549         }
  3557   3550       }
  3558   3551       pPager->pDirty = 0;
  3559   3552       pPager->pStmt = 0;
  3560   3553       pPager->dbSize = pPager->origDbSize;
  3561   3554       memoryTruncate(pPager);
  3562   3555       pPager->stmtInUse = 0;
................................................................................
  3594   3587     return pager_error(pPager, rc);
  3595   3588   }
  3596   3589   
  3597   3590   /*
  3598   3591   ** Return TRUE if the database file is opened read-only.  Return FALSE
  3599   3592   ** if the database is (in theory) writable.
  3600   3593   */
  3601         -int sqlite3pager_isreadonly(Pager *pPager){
         3594  +int sqlite3PagerIsreadonly(Pager *pPager){
  3602   3595     return pPager->readOnly;
  3603   3596   }
  3604   3597   
  3605   3598   /*
  3606   3599   ** Return the number of references to the pager.
  3607   3600   */
  3608         -int sqlite3pager_refcount(Pager *pPager){
         3601  +int sqlite3PagerRefcount(Pager *pPager){
  3609   3602     return pPager->nRef;
  3610   3603   }
  3611   3604   
  3612   3605   #ifdef SQLITE_TEST
  3613   3606   /*
  3614   3607   ** This routine is used for testing and analysis only.
  3615   3608   */
  3616         -int *sqlite3pager_stats(Pager *pPager){
         3609  +int *sqlite3PagerStats(Pager *pPager){
  3617   3610     static int a[11];
  3618   3611     a[0] = pPager->nRef;
  3619   3612     a[1] = pPager->nPage;
  3620   3613     a[2] = pPager->mxPage;
  3621   3614     a[3] = pPager->dbSize;
  3622   3615     a[4] = pPager->state;
  3623   3616     a[5] = pPager->errCode;
................................................................................
  3633   3626   /*
  3634   3627   ** Set the statement rollback point.
  3635   3628   **
  3636   3629   ** This routine should be called with the transaction journal already
  3637   3630   ** open.  A new statement journal is created that can be used to rollback
  3638   3631   ** changes of a single SQL command within a larger transaction.
  3639   3632   */
  3640         -int sqlite3pager_stmt_begin(Pager *pPager){
         3633  +int sqlite3PagerStmtBegin(Pager *pPager){
  3641   3634     int rc;
  3642   3635     assert( !pPager->stmtInUse );
  3643   3636     assert( pPager->state>=PAGER_SHARED );
  3644   3637     assert( pPager->dbSize>=0 );
  3645   3638     TRACE2("STMT-BEGIN %d\n", PAGERID(pPager));
  3646   3639     if( MEMDB ){
  3647   3640       pPager->stmtInUse = 1;
................................................................................
  3664   3657     assert( pPager->stmtJSize == pPager->journalOff );
  3665   3658   #endif
  3666   3659     pPager->stmtJSize = pPager->journalOff;
  3667   3660     pPager->stmtSize = pPager->dbSize;
  3668   3661     pPager->stmtHdrOff = 0;
  3669   3662     pPager->stmtCksum = pPager->cksumInit;
  3670   3663     if( !pPager->stmtOpen ){
  3671         -    rc = sqlite3pager_opentemp(&pPager->stfd);
         3664  +    rc = sqlite3PagerOpentemp(&pPager->stfd);
  3672   3665       if( rc ) goto stmt_begin_failed;
  3673   3666       pPager->stmtOpen = 1;
  3674   3667       pPager->stmtNRec = 0;
  3675   3668     }
  3676   3669     pPager->stmtInUse = 1;
  3677   3670     return SQLITE_OK;
  3678   3671    
................................................................................
  3683   3676     }
  3684   3677     return rc;
  3685   3678   }
  3686   3679   
  3687   3680   /*
  3688   3681   ** Commit a statement.
  3689   3682   */
  3690         -int sqlite3pager_stmt_commit(Pager *pPager){
         3683  +int sqlite3PagerStmtCommit(Pager *pPager){
  3691   3684     if( pPager->stmtInUse ){
  3692   3685       PgHdr *pPg, *pNext;
  3693   3686       TRACE2("STMT-COMMIT %d\n", PAGERID(pPager));
  3694   3687       if( !MEMDB ){
  3695   3688         sqlite3OsSeek(pPager->stfd, 0);
  3696   3689         /* sqlite3OsTruncate(pPager->stfd, 0); */
  3697   3690         sqliteFree( pPager->aInStmt );
................................................................................
  3715   3708     pPager->stmtAutoopen = 0;
  3716   3709     return SQLITE_OK;
  3717   3710   }
  3718   3711   
  3719   3712   /*
  3720   3713   ** Rollback a statement.
  3721   3714   */
  3722         -int sqlite3pager_stmt_rollback(Pager *pPager){
         3715  +int sqlite3PagerStmtRollback(Pager *pPager){
  3723   3716     int rc;
  3724   3717     if( pPager->stmtInUse ){
  3725   3718       TRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager));
  3726   3719       if( MEMDB ){
  3727   3720         PgHdr *pPg;
  3728   3721         for(pPg=pPager->pStmt; pPg; pPg=pPg->pNextStmt){
  3729   3722           PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
................................................................................
  3735   3728         }
  3736   3729         pPager->dbSize = pPager->stmtSize;
  3737   3730         memoryTruncate(pPager);
  3738   3731         rc = SQLITE_OK;
  3739   3732       }else{
  3740   3733         rc = pager_stmt_playback(pPager);
  3741   3734       }
  3742         -    sqlite3pager_stmt_commit(pPager);
         3735  +    sqlite3PagerStmtCommit(pPager);
  3743   3736     }else{
  3744   3737       rc = SQLITE_OK;
  3745   3738     }
  3746   3739     pPager->stmtAutoopen = 0;
  3747   3740     return rc;
  3748   3741   }
  3749   3742   
  3750   3743   /*
  3751   3744   ** Return the full pathname of the database file.
  3752   3745   */
  3753         -const char *sqlite3pager_filename(Pager *pPager){
         3746  +const char *sqlite3PagerFilename(Pager *pPager){
  3754   3747     return pPager->zFilename;
  3755   3748   }
  3756   3749   
  3757   3750   /*
  3758   3751   ** Return the directory of the database file.
  3759   3752   */
  3760         -const char *sqlite3pager_dirname(Pager *pPager){
         3753  +const char *sqlite3PagerDirname(Pager *pPager){
  3761   3754     return pPager->zDirectory;
  3762   3755   }
  3763   3756   
  3764   3757   /*
  3765   3758   ** Return the full pathname of the journal file.
  3766   3759   */
  3767         -const char *sqlite3pager_journalname(Pager *pPager){
         3760  +const char *sqlite3PagerJournalname(Pager *pPager){
  3768   3761     return pPager->zJournal;
  3769   3762   }
  3770   3763   
  3771   3764   /*
  3772   3765   ** Return true if fsync() calls are disabled for this pager.  Return FALSE
  3773   3766   ** if fsync()s are executed normally.
  3774   3767   */
  3775         -int sqlite3pager_nosync(Pager *pPager){
         3768  +int sqlite3PagerNosync(Pager *pPager){
  3776   3769     return pPager->noSync;
  3777   3770   }
  3778   3771   
  3779   3772   /*
  3780   3773   ** Set the codec for this pager
  3781   3774   */
  3782         -void sqlite3pager_set_codec(
         3775  +void sqlite3PagerSetCodec(
  3783   3776     Pager *pPager,
  3784   3777     void *(*xCodec)(void*,void*,Pgno,int),
  3785   3778     void *pCodecArg
  3786   3779   ){
  3787   3780     pPager->xCodec = xCodec;
  3788   3781     pPager->pCodecArg = pCodecArg;
  3789   3782   }
  3790   3783   
  3791   3784   /*
  3792   3785   ** This routine is called to increment the database file change-counter,
  3793   3786   ** stored at byte 24 of the pager file.
  3794   3787   */
  3795   3788   static int pager_incr_changecounter(Pager *pPager){
  3796         -  void *pPage;
  3797   3789     PgHdr *pPgHdr;
  3798   3790     u32 change_counter;
  3799   3791     int rc;
  3800   3792   
  3801   3793     /* Open page 1 of the file for writing. */
  3802         -  rc = sqlite3pager_get(pPager, 1, &pPage);
         3794  +  rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
  3803   3795     if( rc!=SQLITE_OK ) return rc;
  3804         -  rc = sqlite3pager_write(pPage);
         3796  +  rc = sqlite3PagerWrite(pPgHdr);
  3805   3797     if( rc!=SQLITE_OK ) return rc;
  3806   3798   
  3807   3799     /* Read the current value at byte 24. */
  3808         -  pPgHdr = DATA_TO_PGHDR(pPage);
  3809   3800     change_counter = retrieve32bits(pPgHdr, 24);
  3810   3801   
  3811   3802     /* Increment the value just read and write it back to byte 24. */
  3812   3803     change_counter++;
  3813   3804     put32bits(((char*)PGHDR_TO_DATA(pPgHdr))+24, change_counter);
  3814   3805   
  3815   3806     /* Release the page reference. */
  3816         -  sqlite3pager_unref(pPage);
         3807  +  sqlite3PagerUnref(pPgHdr);
  3817   3808     return SQLITE_OK;
  3818   3809   }
  3819   3810   
  3820   3811   /*
  3821   3812   ** Sync the database file for the pager pPager. zMaster points to the name
  3822   3813   ** of a master journal file that should be written into the individual
  3823   3814   ** journal file. zMaster may be NULL, which is interpreted as no master
................................................................................
  3825   3816   **
  3826   3817   ** This routine ensures that the journal is synced, all dirty pages written
  3827   3818   ** to the database file and the database file synced. The only thing that
  3828   3819   ** remains to commit the transaction is to delete the journal file (or
  3829   3820   ** master journal file if specified).
  3830   3821   **
  3831   3822   ** Note that if zMaster==NULL, this does not overwrite a previous value
  3832         -** passed to an sqlite3pager_sync() call.
         3823  +** passed to an sqlite3PagerSync() call.
  3833   3824   **
  3834   3825   ** If parameter nTrunc is non-zero, then the pager file is truncated to
  3835   3826   ** nTrunc pages (this is used by auto-vacuum databases).
  3836   3827   */
  3837         -int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){
         3828  +int sqlite3PagerSync(Pager *pPager, const char *zMaster, Pgno nTrunc){
  3838   3829     int rc = SQLITE_OK;
  3839   3830   
  3840   3831     TRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n", 
  3841   3832         pPager->zFilename, zMaster, nTrunc);
  3842   3833   
  3843   3834     /* If this is an in-memory db, or no pages have been written to, or this
  3844   3835     ** function has already been called, it is a no-op.
................................................................................
  3859   3850   #ifndef SQLITE_OMIT_AUTOVACUUM
  3860   3851         if( nTrunc!=0 ){
  3861   3852           /* If this transaction has made the database smaller, then all pages
  3862   3853           ** being discarded by the truncation must be written to the journal
  3863   3854           ** file.
  3864   3855           */
  3865   3856           Pgno i;
  3866         -        void *pPage;
  3867   3857           int iSkip = PAGER_MJ_PGNO(pPager);
  3868   3858           for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
  3869   3859             if( !(pPager->aInJournal[i/8] & (1<<(i&7))) && i!=iSkip ){
  3870         -            rc = sqlite3pager_get(pPager, i, &pPage);
         3860  +            rc = sqlite3PagerGet(pPager, i, &pPg);
  3871   3861               if( rc!=SQLITE_OK ) goto sync_exit;
  3872         -            rc = sqlite3pager_write(pPage);
  3873         -            sqlite3pager_unref(pPage);
         3862  +            rc = sqlite3PagerWrite(pPg);
         3863  +            sqlite3PagerUnref(pPg);
  3874   3864               if( rc!=SQLITE_OK ) goto sync_exit;
  3875   3865             }
  3876   3866           } 
  3877   3867         }
  3878   3868   #endif
  3879   3869         rc = writeMasterJournal(pPager, zMaster);
  3880   3870         if( rc!=SQLITE_OK ) goto sync_exit;
  3881   3871         rc = syncJournal(pPager);
  3882   3872         if( rc!=SQLITE_OK ) goto sync_exit;
  3883   3873       }
  3884   3874   
  3885   3875   #ifndef SQLITE_OMIT_AUTOVACUUM
  3886   3876       if( nTrunc!=0 ){
  3887         -      rc = sqlite3pager_truncate(pPager, nTrunc);
         3877  +      rc = sqlite3PagerTruncate(pPager, nTrunc);
  3888   3878         if( rc!=SQLITE_OK ) goto sync_exit;
  3889   3879       }
  3890   3880   #endif
  3891   3881   
  3892   3882       /* Write all dirty pages to the database file */
  3893   3883       pPg = pager_get_all_dirty_pages(pPager);
  3894   3884       rc = pager_write_pagelist(pPg);
................................................................................
  3898   3888       if( !pPager->noSync ){
  3899   3889         rc = sqlite3OsSync(pPager->fd, 0);
  3900   3890       }
  3901   3891       IOTRACE(("DBSYNC %p\n", pPager))
  3902   3892   
  3903   3893       pPager->state = PAGER_SYNCED;
  3904   3894     }else if( MEMDB && nTrunc!=0 ){
  3905         -    rc = sqlite3pager_truncate(pPager, nTrunc);
         3895  +    rc = sqlite3PagerTruncate(pPager, nTrunc);
  3906   3896     }
  3907   3897   
  3908   3898   sync_exit:
  3909   3899     return rc;
  3910   3900   }
  3911   3901   
  3912   3902   #ifndef SQLITE_OMIT_AUTOVACUUM
................................................................................
  3923   3913   ** allocated along with the page) is the responsibility of the caller.
  3924   3914   **
  3925   3915   ** A transaction must be active when this routine is called. It used to be
  3926   3916   ** required that a statement transaction was not active, but this restriction
  3927   3917   ** has been removed (CREATE INDEX needs to move a page when a statement
  3928   3918   ** transaction is active).
  3929   3919   */
  3930         -int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){
  3931         -  PgHdr *pPg = DATA_TO_PGHDR(pData);
         3920  +int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){
  3932   3921     PgHdr *pPgOld; 
  3933   3922     int h;
  3934   3923     Pgno needSyncPgno = 0;
  3935   3924   
  3936   3925     assert( pPg->nRef>0 );
  3937   3926   
  3938   3927     TRACE5("MOVE %d page %d (needSync=%d) moves to %d\n", 
................................................................................
  3985   3974     if( needSyncPgno ){
  3986   3975       /* If needSyncPgno is non-zero, then the journal file needs to be 
  3987   3976       ** sync()ed before any data is written to database file page needSyncPgno.
  3988   3977       ** Currently, no such page exists in the page-cache and the 
  3989   3978       ** Pager.aInJournal bit has been set. This needs to be remedied by loading
  3990   3979       ** the page into the pager-cache and setting the PgHdr.needSync flag.
  3991   3980       **
  3992         -    ** The sqlite3pager_get() call may cause the journal to sync. So make
         3981  +    ** The sqlite3PagerGet() call may cause the journal to sync. So make
  3993   3982       ** sure the Pager.needSync flag is set too.
  3994   3983       */
  3995   3984       int rc;
  3996         -    void *pNeedSync;
         3985  +    PgHdr *pPgHdr;
  3997   3986       assert( pPager->needSync );
  3998         -    rc = sqlite3pager_get(pPager, needSyncPgno, &pNeedSync);
         3987  +    rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr);
  3999   3988       if( rc!=SQLITE_OK ) return rc;
  4000   3989       pPager->needSync = 1;
  4001         -    DATA_TO_PGHDR(pNeedSync)->needSync = 1;
  4002         -    DATA_TO_PGHDR(pNeedSync)->inJournal = 1;
  4003         -    makeDirty(DATA_TO_PGHDR(pNeedSync));
  4004         -    sqlite3pager_unref(pNeedSync);
         3990  +    pPgHdr->needSync = 1;
         3991  +    pPgHdr->inJournal = 1;
         3992  +    makeDirty(pPgHdr);
         3993  +    sqlite3PagerUnref(pPgHdr);
  4005   3994     }
  4006   3995   
  4007   3996     return SQLITE_OK;
  4008   3997   }
  4009   3998   #endif
         3999  +
         4000  +/*
         4001  +** Return a pointer to the data for the specified page.
         4002  +*/
         4003  +void *sqlite3PagerGetData(DbPage *pPg){
         4004  +  return PGHDR_TO_DATA(pPg);
         4005  +}
         4006  +
         4007  +/*
         4008  +** Return a pointer to the Pager.nExtra bytes of "extra" space 
         4009  +** allocated along with the specified page.
         4010  +*/
         4011  +void *sqlite3PagerGetExtra(DbPage *pPg){
         4012  +  Pager *pPager = pPg->pPager;
         4013  +  return (pPager?PGHDR_TO_EXTRA(pPg, pPager):0);
         4014  +}
  4010   4015   
  4011   4016   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  4012   4017   /*
  4013   4018   ** Return the current state of the file lock for the given pager.
  4014   4019   ** The return value is one of NO_LOCK, SHARED_LOCK, RESERVED_LOCK,
  4015   4020   ** PENDING_LOCK, or EXCLUSIVE_LOCK.
  4016   4021   */
  4017         -int sqlite3pager_lockstate(Pager *pPager){
         4022  +int sqlite3PagerLockstate(Pager *pPager){
  4018   4023     return sqlite3OsLockState(pPager->fd);
  4019   4024   }
  4020   4025   #endif
  4021   4026   
  4022   4027   #ifdef SQLITE_DEBUG
  4023   4028   /*
  4024   4029   ** Print a listing of all referenced pages and their ref count.
  4025   4030   */
  4026         -void sqlite3pager_refdump(Pager *pPager){
         4031  +void sqlite3PagerRefdump(Pager *pPager){
  4027   4032     PgHdr *pPg;
  4028   4033     for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
  4029   4034       if( pPg->nRef<=0 ) continue;
  4030   4035       sqlite3DebugPrintf("PAGE %3d addr=%p nRef=%d\n", 
  4031   4036          pPg->pgno, PGHDR_TO_DATA(pPg), pPg->nRef);
  4032   4037     }
  4033   4038   }
  4034   4039   #endif
  4035   4040   
  4036   4041   #endif /* SQLITE_OMIT_DISKIO */

Changes to src/pager.h.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the sqlite page cache
    13     13   ** subsystem.  The page cache subsystem reads and writes a file a page
    14     14   ** at a time and provides a journal for rollback.
    15     15   **
    16         -** @(#) $Id: pager.h,v 1.53 2007/03/04 13:15:28 drh Exp $
           16  +** @(#) $Id: pager.h,v 1.54 2007/03/19 17:44:27 danielk1977 Exp $
    17     17   */
    18     18   
    19     19   #ifndef _PAGER_H_
    20     20   #define _PAGER_H_
    21     21   
    22     22   /*
    23     23   ** The default size of a database page.
................................................................................
    53     53   
    54     54   /*
    55     55   ** Each open file is managed by a separate instance of the "Pager" structure.
    56     56   */
    57     57   typedef struct Pager Pager;
    58     58   
    59     59   /*
    60         -** Allowed values for the flags parameter to sqlite3pager_open().
           60  +** Handle type for pages.
           61  +*/
           62  +typedef struct PgHdr DbPage;
           63  +
           64  +/*
           65  +** Allowed values for the flags parameter to sqlite3PagerOpen().
    61     66   **
    62     67   ** NOTE: This values must match the corresponding BTREE_ values in btree.h.
    63     68   */
    64     69   #define PAGER_OMIT_JOURNAL  0x0001    /* Do not use a rollback journal */
    65     70   #define PAGER_NO_READLOCK   0x0002    /* Omit readlocks on readonly files */
    66     71   
    67     72   
    68     73   /*
    69     74   ** See source code comments for a detailed description of the following
    70     75   ** routines:
    71     76   */
    72         -int sqlite3pager_open(Pager **ppPager, const char *zFilename,
           77  +int sqlite3PagerOpen(Pager **ppPager, const char *zFilename,
    73     78                        int nExtra, int flags);
    74         -void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler);
    75         -void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
    76         -void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
    77         -int sqlite3pager_set_pagesize(Pager*, int);
    78         -int sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
    79         -void sqlite3pager_set_cachesize(Pager*, int);
    80         -int sqlite3pager_close(Pager *pPager);
    81         -int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag);
    82         -#define sqlite3pager_get(A,B,C) sqlite3pager_acquire(A,B,C,0)
    83         -void *sqlite3pager_lookup(Pager *pPager, Pgno pgno);
    84         -int sqlite3pager_ref(void*);
    85         -int sqlite3pager_unref(void*);
    86         -Pgno sqlite3pager_pagenumber(void*);
    87         -int sqlite3pager_write(void*);
    88         -int sqlite3pager_iswriteable(void*);
    89         -int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void*);
    90         -int sqlite3pager_pagecount(Pager*);
    91         -int sqlite3pager_truncate(Pager*,Pgno);
    92         -int sqlite3pager_begin(void*, int exFlag);
    93         -int sqlite3pager_commit(Pager*);
    94         -int sqlite3pager_sync(Pager*,const char *zMaster, Pgno);
    95         -int sqlite3pager_rollback(Pager*);
    96         -int sqlite3pager_isreadonly(Pager*);
    97         -int sqlite3pager_stmt_begin(Pager*);
    98         -int sqlite3pager_stmt_commit(Pager*);
    99         -int sqlite3pager_stmt_rollback(Pager*);
   100         -void sqlite3pager_dont_rollback(void*);
   101         -void sqlite3pager_dont_write(Pager*, Pgno);
   102         -int sqlite3pager_refcount(Pager*);
   103         -int *sqlite3pager_stats(Pager*);
   104         -void sqlite3pager_set_safety_level(Pager*,int,int);
   105         -const char *sqlite3pager_filename(Pager*);
   106         -const char *sqlite3pager_dirname(Pager*);
   107         -const char *sqlite3pager_journalname(Pager*);
   108         -int sqlite3pager_nosync(Pager*);
   109         -int sqlite3pager_rename(Pager*, const char *zNewName);
   110         -void sqlite3pager_set_codec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
   111         -int sqlite3pager_movepage(Pager*,void*,Pgno);
   112         -int sqlite3pager_reset(Pager*);
   113         -int sqlite3pager_release_memory(int);
           79  +void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler);
           80  +void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int));
           81  +void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int));
           82  +int sqlite3PagerSetPagesize(Pager*, int);
           83  +int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
           84  +void sqlite3PagerSetCachesize(Pager*, int);
           85  +int sqlite3PagerClose(Pager *pPager);
           86  +int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
           87  +#define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
           88  +DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
           89  +int sqlite3PagerRef(DbPage*);
           90  +int sqlite3PagerUnref(DbPage*);
           91  +Pgno sqlite3PagerPagenumber(DbPage*);
           92  +int sqlite3PagerWrite(DbPage*);
           93  +int sqlite3PagerIswriteable(DbPage*);
           94  +int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void*);
           95  +int sqlite3PagerPagecount(Pager*);
           96  +int sqlite3PagerTruncate(Pager*,Pgno);
           97  +int sqlite3PagerBegin(DbPage*, int exFlag);
           98  +int sqlite3PagerCommit(Pager*);
           99  +int sqlite3PagerSync(Pager*,const char *zMaster, Pgno);
          100  +int sqlite3PagerRollback(Pager*);
          101  +int sqlite3PagerIsreadonly(Pager*);
          102  +int sqlite3PagerStmtBegin(Pager*);
          103  +int sqlite3PagerStmtCommit(Pager*);
          104  +int sqlite3PagerStmtRollback(Pager*);
          105  +void sqlite3PagerDontRollback(DbPage*);
          106  +void sqlite3PagerDontWrite(Pager*, Pgno);
          107  +int sqlite3PagerRefcount(Pager*);
          108  +int *sqlite3PagerStats(Pager*);
          109  +void sqlite3PagerSetSafetyLevel(Pager*,int,int);
          110  +const char *sqlite3PagerFilename(Pager*);
          111  +const char *sqlite3PagerDirname(Pager*);
          112  +const char *sqlite3PagerJournalname(Pager*);
          113  +int sqlite3PagerNosync(Pager*);
          114  +int sqlite3PagerRename(Pager*, const char *zNewName);
          115  +void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
          116  +int sqlite3PagerMovepage(Pager*,DbPage*,Pgno);
          117  +int sqlite3PagerReset(Pager*);
          118  +int sqlite3PagerReleaseMemory(int);
          119  +
          120  +void *sqlite3PagerGetData(DbPage *); 
          121  +void *sqlite3PagerGetExtra(DbPage *); 
   114    122   
   115    123   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
   116         -int sqlite3pager_lockstate(Pager*);
          124  +int sqlite3PagerLockstate(Pager*);
   117    125   #endif
   118    126   
   119    127   #ifdef SQLITE_TEST
   120         -void sqlite3pager_refdump(Pager*);
          128  +void sqlite3PagerRefdump(Pager*);
   121    129   int pager3_refinfo_enable;
   122    130   #endif
   123    131   
   124    132   #endif /* _PAGER_H_ */

Changes to src/pragma.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.128 2007/03/14 15:37:04 danielk1977 Exp $
           14  +** $Id: pragma.c,v 1.129 2007/03/19 17:44:28 danielk1977 Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include "os.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /* Ignore this whole file if pragmas are disabled
    21     21   */
................................................................................
   937    937         Pager *pPager;
   938    938         if( db->aDb[i].zName==0 ) continue;
   939    939         sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
   940    940         pBt = db->aDb[i].pBt;
   941    941         if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
   942    942           sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC);
   943    943         }else{
   944         -        int j = sqlite3pager_lockstate(pPager);
          944  +        int j = sqlite3PagerLockstate(pPager);
   945    945           sqlite3VdbeOp3(v, OP_String8, 0, 0, 
   946    946               (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
   947    947         }
   948    948         sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
   949    949       }
   950    950     }else
   951    951   #endif

Changes to src/test2.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the pager.c module in SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test2.c,v 1.40 2007/03/15 12:17:43 drh Exp $
           16  +** $Id: test2.c,v 1.41 2007/03/19 17:44:28 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "os.h"
    20     20   #include "pager.h"
    21     21   #include "tcl.h"
    22     22   #include <stdlib.h>
    23     23   #include <string.h>
................................................................................
    74     74     char zBuf[100];
    75     75     if( argc!=3 ){
    76     76       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    77     77          " FILENAME N-PAGE\"", 0);
    78     78       return TCL_ERROR;
    79     79     }
    80     80     if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
    81         -  rc = sqlite3pager_open(&pPager, argv[1], 0, 0);
           81  +  rc = sqlite3PagerOpen(&pPager, argv[1], 0, 0);
    82     82     if( rc!=SQLITE_OK ){
    83     83       Tcl_AppendResult(interp, errorName(rc), 0);
    84     84       return TCL_ERROR;
    85     85     }
    86         -  sqlite3pager_set_cachesize(pPager, nPage);
    87         -  sqlite3pager_set_pagesize(pPager, test_pagesize);
           86  +  sqlite3PagerSetCachesize(pPager, nPage);
           87  +  sqlite3PagerSetPagesize(pPager, test_pagesize);
    88     88     sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager);
    89     89     Tcl_AppendResult(interp, zBuf, 0);
    90     90     return TCL_OK;
    91     91   }
    92     92   
    93     93   /*
    94     94   ** Usage:   pager_close ID
................................................................................
   105    105     int rc;
   106    106     if( argc!=2 ){
   107    107       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   108    108          " ID\"", 0);
   109    109       return TCL_ERROR;
   110    110     }
   111    111     pPager = sqlite3TextToPtr(argv[1]);
   112         -  rc = sqlite3pager_close(pPager);
          112  +  rc = sqlite3PagerClose(pPager);
   113    113     if( rc!=SQLITE_OK ){
   114    114       Tcl_AppendResult(interp, errorName(rc), 0);
   115    115       return TCL_ERROR;
   116    116     }
   117    117     return TCL_OK;
   118    118   }
   119    119   
................................................................................
   132    132     int rc;
   133    133     if( argc!=2 ){
   134    134       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   135    135          " ID\"", 0);
   136    136       return TCL_ERROR;
   137    137     }
   138    138     pPager = sqlite3TextToPtr(argv[1]);
   139         -  rc = sqlite3pager_rollback(pPager);
          139  +  rc = sqlite3PagerRollback(pPager);
   140    140     if( rc!=SQLITE_OK ){
   141    141       Tcl_AppendResult(interp, errorName(rc), 0);
   142    142       return TCL_ERROR;
   143    143     }
   144    144     return TCL_OK;
   145    145   }
   146    146   
................................................................................
   159    159     int rc;
   160    160     if( argc!=2 ){
   161    161       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   162    162          " ID\"", 0);
   163    163       return TCL_ERROR;
   164    164     }
   165    165     pPager = sqlite3TextToPtr(argv[1]);
   166         -  rc = sqlite3pager_commit(pPager);
          166  +  rc = sqlite3PagerCommit(pPager);
   167    167     if( rc!=SQLITE_OK ){
   168    168       Tcl_AppendResult(interp, errorName(rc), 0);
   169    169       return TCL_ERROR;
   170    170     }
   171    171     return TCL_OK;
   172    172   }
   173    173   
................................................................................
   186    186     int rc;
   187    187     if( argc!=2 ){
   188    188       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   189    189          " ID\"", 0);
   190    190       return TCL_ERROR;
   191    191     }
   192    192     pPager = sqlite3TextToPtr(argv[1]);
   193         -  rc = sqlite3pager_stmt_begin(pPager);
          193  +  rc = sqlite3PagerStmtBegin(pPager);
   194    194     if( rc!=SQLITE_OK ){
   195    195       Tcl_AppendResult(interp, errorName(rc), 0);
   196    196       return TCL_ERROR;
   197    197     }
   198    198     return TCL_OK;
   199    199   }
   200    200   
................................................................................
   213    213     int rc;
   214    214     if( argc!=2 ){
   215    215       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   216    216          " ID\"", 0);
   217    217       return TCL_ERROR;
   218    218     }
   219    219     pPager = sqlite3TextToPtr(argv[1]);
   220         -  rc = sqlite3pager_stmt_rollback(pPager);
          220  +  rc = sqlite3PagerStmtRollback(pPager);
   221    221     if( rc!=SQLITE_OK ){
   222    222       Tcl_AppendResult(interp, errorName(rc), 0);
   223    223       return TCL_ERROR;
   224    224     }
   225    225     return TCL_OK;
   226    226   }
   227    227   
................................................................................
   240    240     int rc;
   241    241     if( argc!=2 ){
   242    242       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   243    243          " ID\"", 0);
   244    244       return TCL_ERROR;
   245    245     }
   246    246     pPager = sqlite3TextToPtr(argv[1]);
   247         -  rc = sqlite3pager_stmt_commit(pPager);
          247  +  rc = sqlite3PagerStmtCommit(pPager);
   248    248     if( rc!=SQLITE_OK ){
   249    249       Tcl_AppendResult(interp, errorName(rc), 0);
   250    250       return TCL_ERROR;
   251    251     }
   252    252     return TCL_OK;
   253    253   }
   254    254   
................................................................................
   267    267     int i, *a;
   268    268     if( argc!=2 ){
   269    269       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   270    270          " ID\"", 0);
   271    271       return TCL_ERROR;
   272    272     }
   273    273     pPager = sqlite3TextToPtr(argv[1]);
   274         -  a = sqlite3pager_stats(pPager);
          274  +  a = sqlite3PagerStats(pPager);
   275    275     for(i=0; i<9; i++){
   276    276       static char *zName[] = {
   277    277         "ref", "page", "max", "size", "state", "err",
   278    278         "hit", "miss", "ovfl",
   279    279       };
   280    280       char zBuf[100];
   281    281       Tcl_AppendElement(interp, zName[i]);
................................................................................
   300    300     char zBuf[100];
   301    301     if( argc!=2 ){
   302    302       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   303    303          " ID\"", 0);
   304    304       return TCL_ERROR;
   305    305     }
   306    306     pPager = sqlite3TextToPtr(argv[1]);
   307         -  sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3pager_pagecount(pPager));
          307  +  sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3PagerPagecount(pPager));
   308    308     Tcl_AppendResult(interp, zBuf, 0);
   309    309     return TCL_OK;
   310    310   }
   311    311   
   312    312   /*
   313    313   ** Usage:   page_get ID PGNO
   314    314   **
................................................................................
   318    318     void *NotUsed,
   319    319     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   320    320     int argc,              /* Number of arguments */
   321    321     const char **argv      /* Text of each argument */
   322    322   ){
   323    323     Pager *pPager;
   324    324     char zBuf[100];
   325         -  void *pPage;
          325  +  DbPage *pPage;
   326    326     int pgno;
   327    327     int rc;
   328    328     if( argc!=3 ){
   329    329       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   330    330          " ID PGNO\"", 0);
   331    331       return TCL_ERROR;
   332    332     }
   333    333     pPager = sqlite3TextToPtr(argv[1]);
   334    334     if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
   335         -  rc = sqlite3pager_get(pPager, pgno, &pPage);
          335  +  rc = sqlite3PagerGet(pPager, pgno, &pPage);
   336    336     if( rc!=SQLITE_OK ){
   337    337       Tcl_AppendResult(interp, errorName(rc), 0);
   338    338       return TCL_ERROR;
   339    339     }
   340    340     sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage);
   341    341     Tcl_AppendResult(interp, zBuf, 0);
   342    342     return TCL_OK;
................................................................................
   352    352     void *NotUsed,
   353    353     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   354    354     int argc,              /* Number of arguments */
   355    355     const char **argv      /* Text of each argument */
   356    356   ){
   357    357     Pager *pPager;
   358    358     char zBuf[100];
   359         -  void *pPage;
          359  +  DbPage *pPage;
   360    360     int pgno;
   361    361     if( argc!=3 ){
   362    362       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   363    363          " ID PGNO\"", 0);
   364    364       return TCL_ERROR;
   365    365     }
   366    366     pPager = sqlite3TextToPtr(argv[1]);
   367    367     if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
   368         -  pPage = sqlite3pager_lookup(pPager, pgno);
          368  +  pPage = sqlite3PagerLookup(pPager, pgno);
   369    369     if( pPage ){
   370    370       sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage);
   371    371       Tcl_AppendResult(interp, zBuf, 0);
   372    372     }
   373    373     return TCL_OK;
   374    374   }
   375    375   
................................................................................
   388    388     if( argc!=3 ){
   389    389       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   390    390          " ID PGNO\"", 0);
   391    391       return TCL_ERROR;
   392    392     }
   393    393     pPager = sqlite3TextToPtr(argv[1]);
   394    394     if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
   395         -  rc = sqlite3pager_truncate(pPager, pgno);
          395  +  rc = sqlite3PagerTruncate(pPager, pgno);
   396    396     if( rc!=SQLITE_OK ){
   397    397       Tcl_AppendResult(interp, errorName(rc), 0);
   398    398       return TCL_ERROR;
   399    399     }
   400    400     return TCL_OK;
   401    401   }
   402    402   
................................................................................
   408    408   */
   409    409   static int page_unref(
   410    410     void *NotUsed,
   411    411     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   412    412     int argc,              /* Number of arguments */
   413    413     const char **argv      /* Text of each argument */
   414    414   ){
   415         -  void *pPage;
          415  +  DbPage *pPage;
   416    416     int rc;
   417    417     if( argc!=2 ){
   418    418       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   419    419          " PAGE\"", 0);
   420    420       return TCL_ERROR;
   421    421     }
   422         -  pPage = sqlite3TextToPtr(argv[1]);
   423         -  rc = sqlite3pager_unref(pPage);
          422  +  pPage = (DbPage *)sqlite3TextToPtr(argv[1]);
          423  +  rc = sqlite3PagerUnref(pPage);
   424    424     if( rc!=SQLITE_OK ){
   425    425       Tcl_AppendResult(interp, errorName(rc), 0);
   426    426       return TCL_ERROR;
   427    427     }
   428    428     return TCL_OK;
   429    429   }
   430    430   
................................................................................
   436    436   static int page_read(
   437    437     void *NotUsed,
   438    438     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   439    439     int argc,              /* Number of arguments */
   440    440     const char **argv      /* Text of each argument */
   441    441   ){
   442    442     char zBuf[100];
   443         -  void *pPage;
          443  +  DbPage *pPage;
   444    444     if( argc!=2 ){
   445    445       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   446    446          " PAGE\"", 0);
   447    447       return TCL_ERROR;
   448    448     }
   449    449     pPage = sqlite3TextToPtr(argv[1]);
   450         -  memcpy(zBuf, pPage, sizeof(zBuf));
          450  +  memcpy(zBuf, sqlite3PagerGetData(pPage), sizeof(zBuf));
   451    451     Tcl_AppendResult(interp, zBuf, 0);
   452    452     return TCL_OK;
   453    453   }
   454    454   
   455    455   /*
   456    456   ** Usage:   page_number PAGE
   457    457   **
................................................................................
   460    460   static int page_number(
   461    461     void *NotUsed,
   462    462     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   463    463     int argc,              /* Number of arguments */
   464    464     const char **argv      /* Text of each argument */
   465    465   ){
   466    466     char zBuf[100];
   467         -  void *pPage;
          467  +  DbPage *pPage;
   468    468     if( argc!=2 ){
   469    469       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   470    470          " PAGE\"", 0);
   471    471       return TCL_ERROR;
   472    472     }
   473         -  pPage = sqlite3TextToPtr(argv[1]);
   474         -  sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3pager_pagenumber(pPage));
          473  +  pPage = (DbPage *)sqlite3TextToPtr(argv[1]);
          474  +  sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3PagerPagenumber(pPage));
   475    475     Tcl_AppendResult(interp, zBuf, 0);
   476    476     return TCL_OK;
   477    477   }
   478    478   
   479    479   /*
   480    480   ** Usage:   page_write PAGE DATA
   481    481   **
................................................................................
   483    483   */
   484    484   static int page_write(
   485    485     void *NotUsed,
   486    486     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   487    487     int argc,              /* Number of arguments */
   488    488     const char **argv      /* Text of each argument */
   489    489   ){
   490         -  void *pPage;
          490  +  DbPage *pPage;
          491  +  char *pData;
   491    492     int rc;
   492    493     if( argc!=3 ){
   493    494       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   494    495          " PAGE DATA\"", 0);
   495    496       return TCL_ERROR;
   496    497     }
   497         -  pPage = sqlite3TextToPtr(argv[1]);
   498         -  rc = sqlite3pager_write(pPage);
          498  +  pPage = (DbPage *)sqlite3TextToPtr(argv[1]);
          499  +  rc = sqlite3PagerWrite(pPage);
   499    500     if( rc!=SQLITE_OK ){
   500    501       Tcl_AppendResult(interp, errorName(rc), 0);
   501    502       return TCL_ERROR;
   502    503     }
   503         -  strncpy((char*)pPage, argv[2], test_pagesize-1);
   504         -  ((char*)pPage)[test_pagesize-1] = 0;
          504  +  pData = sqlite3PagerGetData(pPage);
          505  +  strncpy(pData, argv[2], test_pagesize-1);
          506  +  pData[test_pagesize-1] = 0;
   505    507     return TCL_OK;
   506    508   }
   507    509   
   508    510   #ifndef SQLITE_OMIT_DISKIO
   509    511   /*
   510    512   ** Usage:   fake_big_file  N  FILENAME
   511    513   **

Changes to src/test3.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the btree.c module in SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test3.c,v 1.70 2007/02/10 19:22:36 drh Exp $
           16  +** $Id: test3.c,v 1.71 2007/03/19 17:44:28 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "pager.h"
    20     20   #include "btree.h"
    21     21   #include "tcl.h"
    22     22   #include <stdlib.h>
    23     23   #include <string.h>
................................................................................
   507    507   
   508    508     if( argc!=2 ){
   509    509       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   510    510          " ID\"", 0);
   511    511       return TCL_ERROR;
   512    512     }
   513    513     pBt = sqlite3TextToPtr(argv[1]);
   514         -  a = sqlite3pager_stats(sqlite3BtreePager(pBt));
          514  +  a = sqlite3PagerStats(sqlite3BtreePager(pBt));
   515    515     for(i=0; i<11; i++){
   516    516       static char *zName[] = {
   517    517         "ref", "page", "max", "size", "state", "err",
   518    518         "hit", "miss", "ovfl", "read", "write"
   519    519       };
   520    520       char zBuf[100];
   521    521       Tcl_AppendElement(interp, zName[i]);
................................................................................
   541    541     if( argc!=2 ){
   542    542       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   543    543          " ID\"", 0);
   544    544       return TCL_ERROR;
   545    545     }
   546    546     pBt = sqlite3TextToPtr(argv[1]);
   547    547   #ifdef SQLITE_DEBUG
   548         -  sqlite3pager_refdump(sqlite3BtreePager(pBt));
          548  +  sqlite3PagerRefdump(sqlite3BtreePager(pBt));
   549    549   #endif
   550    550     return TCL_OK;
   551    551   }
   552    552   
   553    553   /*
   554    554   ** Usage:   btree_integrity_check ID ROOT ...
   555    555   **
................................................................................
  1278   1278     }
  1279   1279     dataSize = sqlite3BtreeGetPageSize(pBt) - sqlite3BtreeGetReserve(pBt);
  1280   1280     Tcl_DStringInit(&str);
  1281   1281     n = aResult[6] - aResult[8];
  1282   1282     n = (n + dataSize - 1)/dataSize;
  1283   1283     pgno = (u32)aResult[10];
  1284   1284     while( pgno && n-- ){
         1285  +    DbPage *pDbPage;
  1285   1286       sprintf(zElem, "%d", pgno);
  1286   1287       Tcl_DStringAppendElement(&str, zElem);
  1287         -    if( sqlite3pager_get(pPager, pgno, &pPage)!=SQLITE_OK ){
         1288  +    if( sqlite3PagerGet(pPager, pgno, &pDbPage)!=SQLITE_OK ){
  1288   1289         Tcl_DStringFree(&str);
  1289   1290         Tcl_AppendResult(interp, "unable to get page ", zElem, 0);
  1290   1291         return TCL_ERROR;
  1291   1292       }
         1293  +    pPage = sqlite3PagerGetData(pDbPage);
  1292   1294       pgno = get4byte((unsigned char*)pPage);
  1293         -    sqlite3pager_unref(pPage);
         1295  +    sqlite3PagerUnref(pDbPage);
  1294   1296     }
  1295   1297     Tcl_DStringResult(interp, &str);
  1296   1298     return SQLITE_OK;
  1297   1299   }
  1298   1300   
  1299   1301   /*
  1300   1302   ** The command is provided for the purpose of setting breakpoints.

Changes to src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.194 2007/03/15 15:33:32 danielk1977 Exp $
           17  +** $Id: util.c,v 1.195 2007/03/19 17:44:28 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <stdarg.h>
    22     22   #include <ctype.h>
    23     23   
    24     24   /*
................................................................................
    79     79     sqlite3ReleaseThreadData();
    80     80   }
    81     81   
    82     82   /*
    83     83   ** Release memory held by SQLite instances created by the current thread.
    84     84   */
    85     85   int sqlite3_release_memory(int n){
    86         -  return sqlite3pager_release_memory(n);
           86  +  return sqlite3PagerReleaseMemory(n);
    87     87   }
    88     88   #else
    89     89   /* If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, then define a version
    90     90   ** of sqlite3_release_memory() to be used by other code in this file.
    91     91   ** This is done for no better reason than to reduce the number of 
    92     92   ** pre-processor #ifndef statements.
    93     93   */