mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Modify the OS layer so that I/O routines are called through a virtual function
table. The os_test.c module has been replaced by test6.c. The crash tests are busted now and need to be fixed. (CVS 2785) FossilOrigin-Name: 1f69aec285dd8e26bd739d5e44bb50fe03a9682a
This commit is contained in:
189
src/pager.c
189
src/pager.c
@@ -18,7 +18,7 @@
|
||||
** file simultaneously, or one process from reading the database while
|
||||
** another is writing.
|
||||
**
|
||||
** @(#) $Id: pager.c,v 1.217 2005/11/05 15:11:23 drh Exp $
|
||||
** @(#) $Id: pager.c,v 1.218 2005/11/26 00:25:03 drh Exp $
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_DISKIO
|
||||
#include "sqliteInt.h"
|
||||
@@ -413,7 +413,7 @@ static const unsigned char aJournalMagic[] = {
|
||||
static int read32bits(OsFile *fd, u32 *pRes){
|
||||
u32 res;
|
||||
int rc;
|
||||
rc = sqlite3OsRead(fd, &res, sizeof(res));
|
||||
rc = sqlite3Io.xRead(fd, &res, sizeof(res));
|
||||
if( rc==SQLITE_OK ){
|
||||
unsigned char ac[4];
|
||||
memcpy(ac, &res, 4);
|
||||
@@ -433,7 +433,7 @@ static int write32bits(OsFile *fd, u32 val){
|
||||
ac[1] = (val>>16) & 0xff;
|
||||
ac[2] = (val>>8) & 0xff;
|
||||
ac[3] = val & 0xff;
|
||||
return sqlite3OsWrite(fd, ac, 4);
|
||||
return sqlite3Io.xWrite(fd, ac, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -524,10 +524,10 @@ static int readMasterJournal(OsFile *pJrnl, char **pzMaster){
|
||||
|
||||
*pzMaster = 0;
|
||||
|
||||
rc = sqlite3OsFileSize(pJrnl, &szJ);
|
||||
rc = sqlite3Io.xFileSize(pJrnl, &szJ);
|
||||
if( rc!=SQLITE_OK || szJ<16 ) return rc;
|
||||
|
||||
rc = sqlite3OsSeek(pJrnl, szJ-16);
|
||||
rc = sqlite3Io.xSeek(pJrnl, szJ-16);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
rc = read32bits(pJrnl, &len);
|
||||
@@ -536,17 +536,17 @@ static int readMasterJournal(OsFile *pJrnl, char **pzMaster){
|
||||
rc = read32bits(pJrnl, &cksum);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
rc = sqlite3OsRead(pJrnl, aMagic, 8);
|
||||
rc = sqlite3Io.xRead(pJrnl, aMagic, 8);
|
||||
if( rc!=SQLITE_OK || memcmp(aMagic, aJournalMagic, 8) ) return rc;
|
||||
|
||||
rc = sqlite3OsSeek(pJrnl, szJ-16-len);
|
||||
rc = sqlite3Io.xSeek(pJrnl, szJ-16-len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
*pzMaster = (char *)sqliteMalloc(len+1);
|
||||
if( !*pzMaster ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
rc = sqlite3OsRead(pJrnl, *pzMaster, len);
|
||||
rc = sqlite3Io.xRead(pJrnl, *pzMaster, len);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqliteFree(*pzMaster);
|
||||
*pzMaster = 0;
|
||||
@@ -597,7 +597,7 @@ static int seekJournalHdr(Pager *pPager){
|
||||
assert( offset>=c );
|
||||
assert( (offset-c)<JOURNAL_HDR_SZ(pPager) );
|
||||
pPager->journalOff = offset;
|
||||
return sqlite3OsSeek(&pPager->jfd, pPager->journalOff);
|
||||
return sqlite3Io.xSeek(&pPager->jfd, pPager->journalOff);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -633,7 +633,7 @@ static int writeJournalHdr(Pager *pPager){
|
||||
** Actually maybe the whole journal header should be delayed until that
|
||||
** point. Think about this.
|
||||
*/
|
||||
rc = sqlite3OsWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
|
||||
rc = sqlite3Io.xWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
/* The nRec Field. 0xFFFFFFFF for no-sync journals. */
|
||||
@@ -657,9 +657,9 @@ static int writeJournalHdr(Pager *pPager){
|
||||
** file descriptor to the end of the journal header sector.
|
||||
*/
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff-1);
|
||||
rc = sqlite3Io.xSeek(&pPager->jfd, pPager->journalOff-1);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsWrite(&pPager->jfd, "\000", 1);
|
||||
rc = sqlite3Io.xWrite(&pPager->jfd, "\000", 1);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
@@ -697,7 +697,7 @@ static int readJournalHdr(
|
||||
return SQLITE_DONE;
|
||||
}
|
||||
|
||||
rc = sqlite3OsRead(&pPager->jfd, aMagic, sizeof(aMagic));
|
||||
rc = sqlite3Io.xRead(&pPager->jfd, aMagic, sizeof(aMagic));
|
||||
if( rc ) return rc;
|
||||
|
||||
if( memcmp(aMagic, aJournalMagic, sizeof(aMagic))!=0 ){
|
||||
@@ -723,7 +723,7 @@ static int readJournalHdr(
|
||||
if( rc ) return rc;
|
||||
|
||||
pPager->journalOff += JOURNAL_HDR_SZ(pPager);
|
||||
rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff);
|
||||
rc = sqlite3Io.xSeek(&pPager->jfd, pPager->journalOff);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -771,7 +771,7 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
|
||||
rc = write32bits(&pPager->jfd, PAGER_MJ_PGNO(pPager));
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
rc = sqlite3OsWrite(&pPager->jfd, zMaster, len);
|
||||
rc = sqlite3Io.xWrite(&pPager->jfd, zMaster, len);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
rc = write32bits(&pPager->jfd, len);
|
||||
@@ -780,7 +780,7 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
|
||||
rc = write32bits(&pPager->jfd, cksum);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
rc = sqlite3OsWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
|
||||
rc = sqlite3Io.xWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
|
||||
pPager->needSync = !pPager->noSync;
|
||||
return rc;
|
||||
}
|
||||
@@ -858,7 +858,7 @@ static void pager_reset(Pager *pPager){
|
||||
if( pPager->state>=PAGER_RESERVED ){
|
||||
sqlite3pager_rollback(pPager);
|
||||
}
|
||||
sqlite3OsUnlock(&pPager->fd, NO_LOCK);
|
||||
sqlite3Io.xUnlock(&pPager->fd, NO_LOCK);
|
||||
pPager->state = PAGER_UNLOCK;
|
||||
pPager->dbSize = -1;
|
||||
pPager->nRef = 0;
|
||||
@@ -907,13 +907,13 @@ static int pager_unwritelock(Pager *pPager){
|
||||
}
|
||||
sqlite3pager_stmt_commit(pPager);
|
||||
if( pPager->stmtOpen ){
|
||||
sqlite3OsClose(&pPager->stfd);
|
||||
sqlite3Io.xClose(&pPager->stfd);
|
||||
pPager->stmtOpen = 0;
|
||||
}
|
||||
if( pPager->journalOpen ){
|
||||
sqlite3OsClose(&pPager->jfd);
|
||||
sqlite3Io.xClose(&pPager->jfd);
|
||||
pPager->journalOpen = 0;
|
||||
sqlite3OsDelete(pPager->zJournal);
|
||||
sqlite3Io.xDelete(pPager->zJournal);
|
||||
sqliteFree( pPager->aInJournal );
|
||||
pPager->aInJournal = 0;
|
||||
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
|
||||
@@ -930,7 +930,7 @@ static int pager_unwritelock(Pager *pPager){
|
||||
assert( pPager->aInJournal==0 );
|
||||
assert( pPager->dirtyCache==0 || pPager->useJournal==0 );
|
||||
}
|
||||
rc = sqlite3OsUnlock(&pPager->fd, SHARED_LOCK);
|
||||
rc = sqlite3Io.xUnlock(&pPager->fd, SHARED_LOCK);
|
||||
pPager->state = PAGER_SHARED;
|
||||
pPager->origDbSize = 0;
|
||||
pPager->setMaster = 0;
|
||||
@@ -990,7 +990,7 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
|
||||
|
||||
rc = read32bits(jfd, &pgno);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
rc = sqlite3OsRead(jfd, &aData, pPager->pageSize);
|
||||
rc = sqlite3Io.xRead(jfd, &aData, pPager->pageSize);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
pPager->journalOff += pPager->pageSize + 4;
|
||||
|
||||
@@ -1040,9 +1040,9 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
|
||||
assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 );
|
||||
TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno);
|
||||
if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){
|
||||
rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
|
||||
rc = sqlite3Io.xSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize);
|
||||
rc = sqlite3Io.xWrite(&pPager->fd, aData, pPager->pageSize);
|
||||
}
|
||||
if( pPg ) pPg->dirty = 0;
|
||||
}
|
||||
@@ -1090,10 +1090,10 @@ static int pager_delmaster(const char *zMaster){
|
||||
** is running this routine also. Not that it makes too much difference.
|
||||
*/
|
||||
memset(&master, 0, sizeof(master));
|
||||
rc = sqlite3OsOpenReadOnly(zMaster, &master);
|
||||
rc = sqlite3Io.xOpenReadOnly(zMaster, &master);
|
||||
if( rc!=SQLITE_OK ) goto delmaster_out;
|
||||
master_open = 1;
|
||||
rc = sqlite3OsFileSize(&master, &nMasterJournal);
|
||||
rc = sqlite3Io.xFileSize(&master, &nMasterJournal);
|
||||
if( rc!=SQLITE_OK ) goto delmaster_out;
|
||||
|
||||
if( nMasterJournal>0 ){
|
||||
@@ -1108,12 +1108,12 @@ static int pager_delmaster(const char *zMaster){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto delmaster_out;
|
||||
}
|
||||
rc = sqlite3OsRead(&master, zMasterJournal, nMasterJournal);
|
||||
rc = sqlite3Io.xRead(&master, zMasterJournal, nMasterJournal);
|
||||
if( rc!=SQLITE_OK ) goto delmaster_out;
|
||||
|
||||
zJournal = zMasterJournal;
|
||||
while( (zJournal-zMasterJournal)<nMasterJournal ){
|
||||
if( sqlite3OsFileExists(zJournal) ){
|
||||
if( sqlite3Io.xFileExists(zJournal) ){
|
||||
/* One of the journals pointed to by the master journal exists.
|
||||
** Open it and check if it points at the master journal. If
|
||||
** so, return without deleting the master journal file.
|
||||
@@ -1122,13 +1122,13 @@ static int pager_delmaster(const char *zMaster){
|
||||
int c;
|
||||
|
||||
memset(&journal, 0, sizeof(journal));
|
||||
rc = sqlite3OsOpenReadOnly(zJournal, &journal);
|
||||
rc = sqlite3Io.xOpenReadOnly(zJournal, &journal);
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto delmaster_out;
|
||||
}
|
||||
|
||||
rc = readMasterJournal(&journal, &zMasterPtr);
|
||||
sqlite3OsClose(&journal);
|
||||
sqlite3Io.xClose(&journal);
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto delmaster_out;
|
||||
}
|
||||
@@ -1144,14 +1144,14 @@ static int pager_delmaster(const char *zMaster){
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3OsDelete(zMaster);
|
||||
sqlite3Io.xDelete(zMaster);
|
||||
|
||||
delmaster_out:
|
||||
if( zMasterJournal ){
|
||||
sqliteFree(zMasterJournal);
|
||||
}
|
||||
if( master_open ){
|
||||
sqlite3OsClose(&master);
|
||||
sqlite3Io.xClose(&master);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -1172,9 +1172,9 @@ static int pager_reload_cache(Pager *pPager){
|
||||
char zBuf[SQLITE_MAX_PAGE_SIZE];
|
||||
if( !pPg->dirty ) continue;
|
||||
if( (int)pPg->pgno <= pPager->origDbSize ){
|
||||
rc = sqlite3OsSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1));
|
||||
rc = sqlite3Io.xSeek(&pPager->fd, pPager->pageSize*(i64)(pPg->pgno-1));
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsRead(&pPager->fd, zBuf, pPager->pageSize);
|
||||
rc = sqlite3Io.xRead(&pPager->fd, zBuf, pPager->pageSize);
|
||||
}
|
||||
TRACE3("REFETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
|
||||
if( rc ) break;
|
||||
@@ -1205,7 +1205,7 @@ static int pager_reload_cache(Pager *pPager){
|
||||
*/
|
||||
static int pager_truncate(Pager *pPager, int nPage){
|
||||
assert( pPager->state>=PAGER_EXCLUSIVE );
|
||||
return sqlite3OsTruncate(&pPager->fd, pPager->pageSize*(i64)nPage);
|
||||
return sqlite3Io.xTruncate(&pPager->fd, pPager->pageSize*(i64)nPage);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1273,7 +1273,7 @@ static int pager_playback(Pager *pPager){
|
||||
** the journal is empty.
|
||||
*/
|
||||
assert( pPager->journalOpen );
|
||||
rc = sqlite3OsFileSize(&pPager->jfd, &szJ);
|
||||
rc = sqlite3Io.xFileSize(&pPager->jfd, &szJ);
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto end_playback;
|
||||
}
|
||||
@@ -1285,13 +1285,13 @@ static int pager_playback(Pager *pPager){
|
||||
*/
|
||||
rc = readMasterJournal(&pPager->jfd, &zMaster);
|
||||
assert( rc!=SQLITE_DONE );
|
||||
if( rc!=SQLITE_OK || (zMaster && !sqlite3OsFileExists(zMaster)) ){
|
||||
if( rc!=SQLITE_OK || (zMaster && !sqlite3Io.xFileExists(zMaster)) ){
|
||||
sqliteFree(zMaster);
|
||||
zMaster = 0;
|
||||
if( rc==SQLITE_DONE ) rc = SQLITE_OK;
|
||||
goto end_playback;
|
||||
}
|
||||
sqlite3OsSeek(&pPager->jfd, 0);
|
||||
sqlite3Io.xSeek(&pPager->jfd, 0);
|
||||
pPager->journalOff = 0;
|
||||
|
||||
/* This loop terminates either when the readJournalHdr() call returns
|
||||
@@ -1334,7 +1334,7 @@ static int pager_playback(Pager *pPager){
|
||||
pPager->dbSize = mxPg;
|
||||
}
|
||||
|
||||
/* rc = sqlite3OsSeek(&pPager->jfd, JOURNAL_HDR_SZ(pPager)); */
|
||||
/* rc = sqlite3Io.xSeek(&pPager->jfd, JOURNAL_HDR_SZ(pPager)); */
|
||||
if( rc!=SQLITE_OK ) goto end_playback;
|
||||
|
||||
/* Copy original pages out of the journal and back into the database file.
|
||||
@@ -1407,7 +1407,7 @@ static int pager_stmt_playback(Pager *pPager){
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
i64 os_szJ;
|
||||
rc = sqlite3OsFileSize(&pPager->jfd, &os_szJ);
|
||||
rc = sqlite3Io.xFileSize(&pPager->jfd, &os_szJ);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
assert( szJ==os_szJ );
|
||||
}
|
||||
@@ -1433,7 +1433,7 @@ static int pager_stmt_playback(Pager *pPager){
|
||||
/* Figure out how many records are in the statement journal.
|
||||
*/
|
||||
assert( pPager->stmtInUse && pPager->journalOpen );
|
||||
sqlite3OsSeek(&pPager->stfd, 0);
|
||||
sqlite3Io.xSeek(&pPager->stfd, 0);
|
||||
nRec = pPager->stmtNRec;
|
||||
|
||||
/* Copy original pages out of the statement journal and back into the
|
||||
@@ -1455,7 +1455,7 @@ static int pager_stmt_playback(Pager *pPager){
|
||||
** If it is not zero, then Pager.stmtHdrOff is the offset to the start
|
||||
** of the first journal header written during this statement transaction.
|
||||
*/
|
||||
rc = sqlite3OsSeek(&pPager->jfd, pPager->stmtJSize);
|
||||
rc = sqlite3Io.xSeek(&pPager->jfd, pPager->stmtJSize);
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto end_stmt_playback;
|
||||
}
|
||||
@@ -1515,7 +1515,7 @@ void sqlite3pager_set_cachesize(Pager *pPager, int mxPage){
|
||||
** or power failures by changing the number of syncs()s when writing
|
||||
** the rollback journal. There are three levels:
|
||||
**
|
||||
** OFF sqlite3OsSync() is never called. This is the default
|
||||
** OFF sqlite3Io.xSync() is never called. This is the default
|
||||
** for temporary and transient files.
|
||||
**
|
||||
** NORMAL The journal is synced once before writes begin on the
|
||||
@@ -1566,8 +1566,8 @@ static int sqlite3pager_opentemp(char *zFile, OsFile *fd){
|
||||
sqlite3_opentemp_count++; /* Used for testing and analysis only */
|
||||
do{
|
||||
cnt--;
|
||||
sqlite3OsTempFileName(zFile);
|
||||
rc = sqlite3OsOpenExclusive(zFile, fd, 1);
|
||||
sqlite3Io.xTempFileName(zFile);
|
||||
rc = sqlite3Io.xOpenExclusive(zFile, fd, 1);
|
||||
}while( cnt>0 && rc!=SQLITE_OK && rc!=SQLITE_NOMEM );
|
||||
return rc;
|
||||
}
|
||||
@@ -1619,32 +1619,32 @@ int sqlite3pager_open(
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
zFullPathname = sqlite3OsFullPathname(zFilename);
|
||||
zFullPathname = sqlite3Io.xFullPathname(zFilename);
|
||||
if( zFullPathname ){
|
||||
rc = sqlite3OsOpenReadWrite(zFullPathname, &fd, &readOnly);
|
||||
rc = sqlite3Io.xOpenReadWrite(zFullPathname, &fd, &readOnly);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
rc = sqlite3pager_opentemp(zTemp, &fd);
|
||||
zFilename = zTemp;
|
||||
zFullPathname = sqlite3OsFullPathname(zFilename);
|
||||
zFullPathname = sqlite3Io.xFullPathname(zFilename);
|
||||
if( rc==SQLITE_OK ){
|
||||
tempFile = 1;
|
||||
}
|
||||
}
|
||||
if( !zFullPathname ){
|
||||
sqlite3OsClose(&fd);
|
||||
sqlite3Io.xClose(&fd);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3OsClose(&fd);
|
||||
sqlite3Io.xClose(&fd);
|
||||
sqliteFree(zFullPathname);
|
||||
return rc;
|
||||
}
|
||||
nameLen = strlen(zFullPathname);
|
||||
pPager = sqliteMalloc( sizeof(*pPager) + nameLen*3 + 30 );
|
||||
if( pPager==0 ){
|
||||
sqlite3OsClose(&fd);
|
||||
sqlite3Io.xClose(&fd);
|
||||
sqliteFree(zFullPathname);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -1660,9 +1660,6 @@ int sqlite3pager_open(
|
||||
sqliteFree(zFullPathname);
|
||||
strcpy(&pPager->zJournal[nameLen], "-journal");
|
||||
pPager->fd = fd;
|
||||
#if OS_UNIX
|
||||
pPager->fd.pPager = pPager;
|
||||
#endif
|
||||
pPager->journalOpen = 0;
|
||||
pPager->useJournal = useJournal && !memDb;
|
||||
pPager->noReadlock = noReadlock && readOnly;
|
||||
@@ -1773,8 +1770,8 @@ void enable_simulated_io_errors(void){
|
||||
void sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
|
||||
memset(pDest, 0, N);
|
||||
if( MEMDB==0 ){
|
||||
sqlite3OsSeek(&pPager->fd, 0);
|
||||
sqlite3OsRead(&pPager->fd, pDest, N);
|
||||
sqlite3Io.xSeek(&pPager->fd, 0);
|
||||
sqlite3Io.xRead(&pPager->fd, pDest, N);
|
||||
clear_simulated_io_error();
|
||||
}
|
||||
}
|
||||
@@ -1794,7 +1791,7 @@ int sqlite3pager_pagecount(Pager *pPager){
|
||||
if( pPager->dbSize>=0 ){
|
||||
n = pPager->dbSize;
|
||||
} else {
|
||||
if( sqlite3OsFileSize(&pPager->fd, &n)!=SQLITE_OK ){
|
||||
if( sqlite3Io.xFileSize(&pPager->fd, &n)!=SQLITE_OK ){
|
||||
pPager->errMask |= PAGER_ERR_DISK;
|
||||
return 0;
|
||||
}
|
||||
@@ -1926,7 +1923,7 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
|
||||
rc = SQLITE_OK;
|
||||
}else{
|
||||
do {
|
||||
rc = sqlite3OsLock(&pPager->fd, locktype);
|
||||
rc = sqlite3Io.xLock(&pPager->fd, locktype);
|
||||
}while( rc==SQLITE_BUSY && sqlite3InvokeBusyHandler(pPager->pBusyHandler) );
|
||||
if( rc==SQLITE_OK ){
|
||||
pPager->state = locktype;
|
||||
@@ -1994,14 +1991,14 @@ int sqlite3pager_close(Pager *pPager){
|
||||
sqlite3pager_rollback(pPager);
|
||||
enable_simulated_io_errors();
|
||||
if( !MEMDB ){
|
||||
sqlite3OsUnlock(&pPager->fd, NO_LOCK);
|
||||
sqlite3Io.xUnlock(&pPager->fd, NO_LOCK);
|
||||
}
|
||||
assert( pPager->errMask || pPager->journalOpen==0 );
|
||||
break;
|
||||
}
|
||||
case PAGER_SHARED: {
|
||||
if( !MEMDB ){
|
||||
sqlite3OsUnlock(&pPager->fd, NO_LOCK);
|
||||
sqlite3Io.xUnlock(&pPager->fd, NO_LOCK);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -2025,16 +2022,16 @@ int sqlite3pager_close(Pager *pPager){
|
||||
TRACE2("CLOSE %d\n", PAGERID(pPager));
|
||||
assert( pPager->errMask || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
|
||||
if( pPager->journalOpen ){
|
||||
sqlite3OsClose(&pPager->jfd);
|
||||
sqlite3Io.xClose(&pPager->jfd);
|
||||
}
|
||||
sqliteFree(pPager->aInJournal);
|
||||
if( pPager->stmtOpen ){
|
||||
sqlite3OsClose(&pPager->stfd);
|
||||
sqlite3Io.xClose(&pPager->stfd);
|
||||
}
|
||||
sqlite3OsClose(&pPager->fd);
|
||||
sqlite3Io.xClose(&pPager->fd);
|
||||
/* Temp files are automatically deleted by the OS
|
||||
** if( pPager->tempFile ){
|
||||
** sqlite3OsDelete(pPager->zFilename);
|
||||
** sqlite3Io.xDelete(pPager->zFilename);
|
||||
** }
|
||||
*/
|
||||
|
||||
@@ -2143,7 +2140,7 @@ static int syncJournal(Pager *pPager){
|
||||
** with the nRec computed from the size of the journal file.
|
||||
*/
|
||||
i64 jSz;
|
||||
rc = sqlite3OsFileSize(&pPager->jfd, &jSz);
|
||||
rc = sqlite3Io.xFileSize(&pPager->jfd, &jSz);
|
||||
if( rc!=0 ) return rc;
|
||||
assert( pPager->journalOff==jSz );
|
||||
}
|
||||
@@ -2156,20 +2153,20 @@ static int syncJournal(Pager *pPager){
|
||||
*/
|
||||
if( pPager->fullSync ){
|
||||
TRACE2("SYNC journal of %d\n", PAGERID(pPager));
|
||||
rc = sqlite3OsSync(&pPager->jfd, 0);
|
||||
rc = sqlite3Io.xSync(&pPager->jfd, 0);
|
||||
if( rc!=0 ) return rc;
|
||||
}
|
||||
rc = sqlite3OsSeek(&pPager->jfd,
|
||||
rc = sqlite3Io.xSeek(&pPager->jfd,
|
||||
pPager->journalHdr + sizeof(aJournalMagic));
|
||||
if( rc ) return rc;
|
||||
rc = write32bits(&pPager->jfd, pPager->nRec);
|
||||
if( rc ) return rc;
|
||||
|
||||
rc = sqlite3OsSeek(&pPager->jfd, pPager->journalOff);
|
||||
rc = sqlite3Io.xSeek(&pPager->jfd, pPager->journalOff);
|
||||
if( rc ) return rc;
|
||||
}
|
||||
TRACE2("SYNC journal of %d\n", PAGERID(pPager));
|
||||
rc = sqlite3OsSync(&pPager->jfd, pPager->fullSync);
|
||||
rc = sqlite3Io.xSync(&pPager->jfd, pPager->fullSync);
|
||||
if( rc!=0 ) return rc;
|
||||
pPager->journalStarted = 1;
|
||||
}
|
||||
@@ -2213,7 +2210,7 @@ static int pager_write_pagelist(PgHdr *pList){
|
||||
|
||||
/* At this point there may be either a RESERVED or EXCLUSIVE lock on the
|
||||
** database file. If there is already an EXCLUSIVE lock, the following
|
||||
** calls to sqlite3OsLock() are no-ops.
|
||||
** calls to sqlite3Io.xLock() are no-ops.
|
||||
**
|
||||
** Moving the lock from RESERVED to EXCLUSIVE actually involves going
|
||||
** through an intermediate state PENDING. A PENDING lock prevents new
|
||||
@@ -2234,7 +2231,7 @@ static int pager_write_pagelist(PgHdr *pList){
|
||||
|
||||
while( pList ){
|
||||
assert( pList->dirty );
|
||||
rc = sqlite3OsSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize);
|
||||
rc = sqlite3Io.xSeek(&pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize);
|
||||
if( rc ) return rc;
|
||||
/* If there are dirty pages in the page cache with page numbers greater
|
||||
** than Pager.dbSize, this means sqlite3pager_truncate() was called to
|
||||
@@ -2244,7 +2241,8 @@ static int pager_write_pagelist(PgHdr *pList){
|
||||
if( pList->pgno<=pPager->dbSize ){
|
||||
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 6);
|
||||
TRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno);
|
||||
rc = sqlite3OsWrite(&pPager->fd, PGHDR_TO_DATA(pList), pPager->pageSize);
|
||||
rc = sqlite3Io.xWrite(&pPager->fd, PGHDR_TO_DATA(pList),
|
||||
pPager->pageSize);
|
||||
CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0);
|
||||
TEST_INCR(pPager->nWrite);
|
||||
}
|
||||
@@ -2290,10 +2288,10 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){
|
||||
*/
|
||||
static int hasHotJournal(Pager *pPager){
|
||||
if( !pPager->useJournal ) return 0;
|
||||
if( !sqlite3OsFileExists(pPager->zJournal) ) return 0;
|
||||
if( sqlite3OsCheckReservedLock(&pPager->fd) ) return 0;
|
||||
if( !sqlite3Io.xFileExists(pPager->zJournal) ) return 0;
|
||||
if( sqlite3Io.xCheckReservedLock(&pPager->fd) ) return 0;
|
||||
if( sqlite3pager_pagecount(pPager)==0 ){
|
||||
sqlite3OsDelete(pPager->zJournal);
|
||||
sqlite3Io.xDelete(pPager->zJournal);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
@@ -2370,9 +2368,9 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
|
||||
** second process will get to this point in the code and fail to
|
||||
** obtain it's own EXCLUSIVE lock on the database file.
|
||||
*/
|
||||
rc = sqlite3OsLock(&pPager->fd, EXCLUSIVE_LOCK);
|
||||
rc = sqlite3Io.xLock(&pPager->fd, EXCLUSIVE_LOCK);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3OsUnlock(&pPager->fd, NO_LOCK);
|
||||
sqlite3Io.xUnlock(&pPager->fd, NO_LOCK);
|
||||
pPager->state = PAGER_UNLOCK;
|
||||
return rc;
|
||||
}
|
||||
@@ -2386,9 +2384,9 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
|
||||
** a write lock, so there is never any chance of two or more
|
||||
** processes opening the journal at the same time.
|
||||
*/
|
||||
rc = sqlite3OsOpenReadOnly(pPager->zJournal, &pPager->jfd);
|
||||
rc = sqlite3Io.xOpenReadOnly(pPager->zJournal, &pPager->jfd);
|
||||
if( rc!=SQLITE_OK ){
|
||||
sqlite3OsUnlock(&pPager->fd, NO_LOCK);
|
||||
sqlite3Io.xUnlock(&pPager->fd, NO_LOCK);
|
||||
pPager->state = PAGER_UNLOCK;
|
||||
return SQLITE_BUSY;
|
||||
}
|
||||
@@ -2545,15 +2543,16 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
|
||||
}else{
|
||||
int rc;
|
||||
assert( MEMDB==0 );
|
||||
rc = sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
|
||||
rc = sqlite3Io.xSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3OsRead(&pPager->fd, PGHDR_TO_DATA(pPg), pPager->pageSize);
|
||||
rc = sqlite3Io.xRead(&pPager->fd, PGHDR_TO_DATA(pPg),
|
||||
pPager->pageSize);
|
||||
}
|
||||
TRACE3("FETCH %d page %d\n", PAGERID(pPager), pPg->pgno);
|
||||
CODEC(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
|
||||
if( rc!=SQLITE_OK ){
|
||||
i64 fileSize;
|
||||
if( sqlite3OsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK
|
||||
if( sqlite3Io.xFileSize(&pPager->fd,&fileSize)!=SQLITE_OK
|
||||
|| fileSize>=pgno*pPager->pageSize ){
|
||||
sqlite3pager_unref(PGHDR_TO_DATA(pPg));
|
||||
return rc;
|
||||
@@ -2675,7 +2674,8 @@ static int pager_open_journal(Pager *pPager){
|
||||
rc = SQLITE_NOMEM;
|
||||
goto failed_to_open_journal;
|
||||
}
|
||||
rc = sqlite3OsOpenExclusive(pPager->zJournal, &pPager->jfd,pPager->tempFile);
|
||||
rc = sqlite3Io.xOpenExclusive(pPager->zJournal, &pPager->jfd,
|
||||
pPager->tempFile);
|
||||
pPager->journalOff = 0;
|
||||
pPager->setMaster = 0;
|
||||
pPager->journalHdr = 0;
|
||||
@@ -2684,7 +2684,7 @@ static int pager_open_journal(Pager *pPager){
|
||||
}
|
||||
SET_FULLSYNC(pPager->jfd, pPager->fullSync);
|
||||
SET_FULLSYNC(pPager->fd, pPager->fullSync);
|
||||
sqlite3OsOpenDirectory(pPager->zDirectory, &pPager->jfd);
|
||||
sqlite3Io.xOpenDirectory(pPager->zDirectory, &pPager->jfd);
|
||||
pPager->journalOpen = 1;
|
||||
pPager->journalStarted = 0;
|
||||
pPager->needSync = 0;
|
||||
@@ -2712,7 +2712,7 @@ static int pager_open_journal(Pager *pPager){
|
||||
failed_to_open_journal:
|
||||
sqliteFree(pPager->aInJournal);
|
||||
pPager->aInJournal = 0;
|
||||
sqlite3OsUnlock(&pPager->fd, NO_LOCK);
|
||||
sqlite3Io.xUnlock(&pPager->fd, NO_LOCK);
|
||||
pPager->state = PAGER_UNLOCK;
|
||||
return rc;
|
||||
}
|
||||
@@ -2756,7 +2756,7 @@ int sqlite3pager_begin(void *pData, int exFlag){
|
||||
pPager->state = PAGER_EXCLUSIVE;
|
||||
pPager->origDbSize = pPager->dbSize;
|
||||
}else{
|
||||
rc = sqlite3OsLock(&pPager->fd, RESERVED_LOCK);
|
||||
rc = sqlite3Io.xLock(&pPager->fd, RESERVED_LOCK);
|
||||
if( rc==SQLITE_OK ){
|
||||
pPager->state = PAGER_RESERVED;
|
||||
if( exFlag ){
|
||||
@@ -2867,7 +2867,7 @@ int sqlite3pager_write(void *pData){
|
||||
store32bits(cksum, pPg, pPager->pageSize);
|
||||
szPg = pPager->pageSize+8;
|
||||
store32bits(pPg->pgno, pPg, -4);
|
||||
rc = sqlite3OsWrite(&pPager->jfd, &((char*)pData)[-4], szPg);
|
||||
rc = sqlite3Io.xWrite(&pPager->jfd, &((char*)pData)[-4], szPg);
|
||||
pPager->journalOff += szPg;
|
||||
TRACE4("JOURNAL %d page %d needSync=%d\n",
|
||||
PAGERID(pPager), pPg->pgno, pPg->needSync);
|
||||
@@ -2916,7 +2916,8 @@ int sqlite3pager_write(void *pData){
|
||||
}else{
|
||||
store32bits(pPg->pgno, pPg, -4);
|
||||
CODEC(pPager, pData, pPg->pgno, 7);
|
||||
rc = sqlite3OsWrite(&pPager->stfd,((char*)pData)-4, pPager->pageSize+4);
|
||||
rc = sqlite3Io.xWrite(&pPager->stfd,((char*)pData)-4,
|
||||
pPager->pageSize+4);
|
||||
TRACE3("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
|
||||
CODEC(pPager, pData, pPg->pgno, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
@@ -3119,7 +3120,7 @@ int sqlite3pager_commit(Pager *pPager){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
if( pPager->dirtyCache==0 ){
|
||||
/* Exit early (without doing the time-consuming sqlite3OsSync() calls)
|
||||
/* Exit early (without doing the time-consuming sqlite3Io.xSync() calls)
|
||||
** if there have been no changes to the database file. */
|
||||
assert( pPager->needSync==0 );
|
||||
rc = pager_unwritelock(pPager);
|
||||
@@ -3278,11 +3279,11 @@ int sqlite3pager_stmt_begin(Pager *pPager){
|
||||
assert( pPager->journalOpen );
|
||||
pPager->aInStmt = sqliteMalloc( pPager->dbSize/8 + 1 );
|
||||
if( pPager->aInStmt==0 ){
|
||||
sqlite3OsLock(&pPager->fd, SHARED_LOCK);
|
||||
sqlite3Io.xLock(&pPager->fd, SHARED_LOCK);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
rc = sqlite3OsFileSize(&pPager->jfd, &pPager->stmtJSize);
|
||||
rc = sqlite3Io.xFileSize(&pPager->jfd, &pPager->stmtJSize);
|
||||
if( rc ) goto stmt_begin_failed;
|
||||
assert( pPager->stmtJSize == pPager->journalOff );
|
||||
#endif
|
||||
@@ -3315,8 +3316,8 @@ int sqlite3pager_stmt_commit(Pager *pPager){
|
||||
PgHdr *pPg, *pNext;
|
||||
TRACE2("STMT-COMMIT %d\n", PAGERID(pPager));
|
||||
if( !MEMDB ){
|
||||
sqlite3OsSeek(&pPager->stfd, 0);
|
||||
/* sqlite3OsTruncate(&pPager->stfd, 0); */
|
||||
sqlite3Io.xSeek(&pPager->stfd, 0);
|
||||
/* sqlite3Io.xTruncate(&pPager->stfd, 0); */
|
||||
sqliteFree( pPager->aInStmt );
|
||||
pPager->aInStmt = 0;
|
||||
}
|
||||
@@ -3519,7 +3520,7 @@ int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){
|
||||
|
||||
/* Sync the database file. */
|
||||
if( !pPager->noSync ){
|
||||
rc = sqlite3OsSync(&pPager->fd, 0);
|
||||
rc = sqlite3Io.xSync(&pPager->fd, 0);
|
||||
}
|
||||
|
||||
pPager->state = PAGER_SYNCED;
|
||||
|
Reference in New Issue
Block a user