} /*NO_TEST*/ /* ** Query the size of the file in bytes. */ static int memjrnlFileSize(sqlite3_file pJfd, ref long pSize) { MemJournal p = (MemJournal)pJfd; pSize = p.endpoint.iOffset; return(SQLITE_OK); }
/* ** Open a journal file. */ static void sqlite3MemJournalOpen(sqlite3_file pJfd) { MemJournal p = (MemJournal)pJfd; //memset( p, 0, sqlite3MemJournalSize() ); p.pFirst = null; p.endpoint = new FilePoint(); p.readpoint = new FilePoint(); p.pMethods = MemJournalMethods; }
/* ** Write data to the file. */ static int memjrnlWrite( sqlite3_file pJfd, /* The journal file into which to write */ byte[] zBuf, /* Take data to be written from here */ int iAmt, /* Number of bytes to write */ sqlite3_int64 iOfst /* Begin writing at this offset into the file */ ) { MemJournal p = (MemJournal)pJfd; int nWrite = iAmt; byte[] zWrite = zBuf; int izWrite = 0; /* An in-memory journal file should only ever be appended to. Random ** access writes are not required by sqlite. */ Debug.Assert(iOfst == p.endpoint.iOffset); UNUSED_PARAMETER(iOfst); while (nWrite > 0) { FileChunk pChunk = p.endpoint.pChunk; int iChunkOffset = (int)(p.endpoint.iOffset % JOURNAL_CHUNKSIZE); int iSpace = MIN(nWrite, JOURNAL_CHUNKSIZE - iChunkOffset); if (iChunkOffset == 0) { /* New chunk is required to extend the file. */ FileChunk pNew = new FileChunk();// sqlite3_malloc( sizeof( FileChunk ) ); if (null == pNew) { return(SQLITE_IOERR_NOMEM); } pNew.pNext = null; if (pChunk != null) { Debug.Assert(p.pFirst != null); pChunk.pNext = pNew; } else { Debug.Assert(null == p.pFirst); p.pFirst = pNew; } p.endpoint.pChunk = pNew; } Buffer.BlockCopy(zWrite, izWrite, p.endpoint.pChunk.zChunk, iChunkOffset, iSpace); //memcpy( &p.endpoint.pChunk.zChunk[iChunkOffset], zWrite, iSpace ); izWrite += iSpace; //zWrite += iSpace; nWrite -= iSpace; p.endpoint.iOffset += iSpace; } return(SQLITE_OK); }
/* ** Read data from the in-memory journal file. This is the implementation ** of the sqlite3_vfs.xRead method. */ static int memjrnlRead( sqlite3_file pJfd, /* The journal file from which to read */ byte[] zBuf, /* Put the results here */ int iAmt, /* Number of bytes to read */ sqlite3_int64 iOfst /* Begin reading at this offset */ ) { MemJournal p = (MemJournal)pJfd; byte[] zOut = zBuf; int nRead = iAmt; int iChunkOffset; FileChunk pChunk; /* SQLite never tries to read past the end of a rollback journal file */ Debug.Assert(iOfst + iAmt <= p.endpoint.iOffset); if (p.readpoint.iOffset != iOfst || iOfst == 0) { int iOff = 0; for (pChunk = p.pFirst; ALWAYS(pChunk != null) && (iOff + JOURNAL_CHUNKSIZE) <= iOfst; pChunk = pChunk.pNext ) { iOff += JOURNAL_CHUNKSIZE; } } else { pChunk = p.readpoint.pChunk; } iChunkOffset = (int)(iOfst % JOURNAL_CHUNKSIZE); int izOut = 0; do { int iSpace = JOURNAL_CHUNKSIZE - iChunkOffset; int nCopy = MIN(nRead, (JOURNAL_CHUNKSIZE - iChunkOffset)); Buffer.BlockCopy(pChunk.zChunk, iChunkOffset, zOut, izOut, nCopy); //memcpy( zOut, pChunk.zChunk[iChunkOffset], nCopy ); izOut += nCopy; // zOut += nCopy; nRead -= iSpace; iChunkOffset = 0; } while (nRead >= 0 && (pChunk = pChunk.pNext) != null && nRead > 0); p.readpoint.iOffset = (int)(iOfst + iAmt); p.readpoint.pChunk = pChunk; return(SQLITE_OK); }
/* ** Truncate the file. */ static int memjrnlTruncate(sqlite3_file pJfd, sqlite3_int64 size) { MemJournal p = (MemJournal)pJfd; FileChunk pChunk; Debug.Assert(size == 0); UNUSED_PARAMETER(size); pChunk = p.pFirst; while (pChunk != null) { FileChunk pTmp = pChunk; pChunk = pChunk.pNext; //sqlite3_free( ref pTmp ); } sqlite3MemJournalOpen(pJfd); return(SQLITE_OK); }
/* ** Close the file. */ static int memjrnlClose(MemJournal pJfd) { memjrnlTruncate(pJfd, 0); return(SQLITE_OK); }
/* ** Close the file. */ static int memjrnlClose( MemJournal pJfd ) { memjrnlTruncate( pJfd, 0 ); return SQLITE_OK; }