/* ** Close the file. */ static int jrnlClose(sqlite3_file pJfd){ JournalFile p = (JournalFile )pJfd; if( p.pReal ){ sqlite3OsClose(p.pReal); } sqlite3DbFree(db,p.zBuf); return SQLITE_OK; }
/* ** The following routines are convenience wrappers around methods ** of the sqlite3_file object. This is mostly just syntactic sugar. All ** of this would be completely automatic if SQLite were coded using ** C++ instead of plain old C. */ static int sqlite3OsClose (sqlite3_file pId) { int rc = SQLITE_OK; if (pId.pMethods != null) { rc = pId.pMethods.xClose (pId); pId.pMethods = null; } return rc; }
public virtual int SharedLockFile( sqlite3_file pFile, long offset, long length ) { Debug.Assert( length == SHARED_SIZE ); Debug.Assert( offset == SHARED_FIRST ); System.Threading.NativeOverlapped ovlp = new System.Threading.NativeOverlapped(); ovlp.OffsetLow = (int)offset; ovlp.OffsetHigh = 0; ovlp.EventHandle = IntPtr.Zero; return LockFileEx( pFile.fs.Handle, LOCKFILE_FAIL_IMMEDIATELY, 0, (uint)length, 0, ref ovlp ) ? 1 : 0; }
static int stmClose( sqlite3_file id ) { Debug.Assert( id != null ); #if SQLITE_TEST OSTRACE( "CLOSE %d %s\n", pFile.pIO.GetHashCode(), rc ? "ok" : "failed" ); OpenCounter( -1 ); #endif return SQLITE_OK; }
public override int SharedLockFile( sqlite3_file pFile, long offset, long length ) { Debug.Assert( length == SHARED_SIZE ); Debug.Assert( offset == SHARED_FIRST ); try { pFile.fs.Lock( offset + pFile.sharedLockByte, 1 ); } catch ( IOException ) { return 0; } return 1; }
/* ** Read data from a file into a buffer. Return SQLITE_OK if all ** bytes were read successfully and SQLITE_IOERR if anything goes ** wrong. */ static int stmRead( sqlite3_file id, /* File to read from */ byte[] pBuf, /* Write content into this buffer */ int amt, /* Number of bytes to read */ sqlite3_int64 offset /* Begin reading at this offset */ ) { //long rc; sqlite3_file pFile = id; int nRead; /* Number of bytes actually read from file */ Debug.Assert( id != null ); #if SQLITE_TEST if ( SimulateIOError() ) return SQLITE_IOERR_READ; #endif #if SQLITE_DEBUG OSTRACE( "READ %d lock=%d\n", pFile.pIO.GetHashCode(), pFile.locktype ); #endif if ( pFile.pIO.Seek(offset, SeekOrigin.Begin) != offset ) { return SQLITE_FULL; } try { nRead = pFile.pIO.Read( pBuf, 0, amt ); // i if( null==ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ } catch ( Exception ) { pFile.lastErrno = 1; return winLogError(SQLITE_IOERR_READ, "stmRead", pFile.zPath); } if ( nRead < amt ) { /* Unread parts of the buffer must be zero-filled */ Array.Clear( pBuf, (int)nRead, (int)( amt - nRead ) ); // memset(&((char)pBuf)[nRead], 0, amt-nRead); return SQLITE_IOERR_SHORT_READ; } return SQLITE_OK; }
//#define FILEHANDLEID(fd) ((int)fd) static int FILEHANDLEID( sqlite3_file fd ) { return fd.GetHashCode(); }
static int sqlite3OsWrite( sqlite3_file id, byte[] pBuf, int amt, i64 offset ) { DO_OS_MALLOC_TEST( id ); return id.pMethods.xWrite( id, pBuf, amt, offset ); }
//#define DO_OS_MALLOC_TEST(x) static void DO_OS_MALLOC_TEST( sqlite3_file x ) { }
/* ** Lock the file with the lock specified by parameter locktype - one ** of the following: ** ** (1) SHARED_LOCK ** (2) RESERVED_LOCK ** (3) PENDING_LOCK ** (4) EXCLUSIVE_LOCK ** ** Sometimes when requesting one lock state, additional lock states ** are inserted in between. The locking might fail on one of the later ** transitions leaving the lock state different from what it started but ** still short of its goal. The following chart shows the allowed ** transitions and the inserted intermediate states: ** ** UNLOCKED -> SHARED ** SHARED -> RESERVED ** SHARED -> (PENDING) -> EXCLUSIVE ** RESERVED -> (PENDING) -> EXCLUSIVE ** PENDING -> EXCLUSIVE ** ** This routine will only increase a lock. The winUnlock() routine ** erases all locks at once and returns us immediately to locking level 0. ** It is not possible to lower the locking level one step at a time. You ** must go straight to locking level 0. */ static int winLock(sqlite3_file id, int locktype) { int rc = SQLITE_OK; /* Return code from subroutines */ int res = 1; /* Result of a windows lock call */ int newLocktype; /* Set pFile.locktype to this value before exiting */ bool gotPendingLock = false; /* True if we acquired a PENDING lock this time */ sqlite3_file pFile = (sqlite3_file)id; DWORD error = NO_ERROR; Debug.Assert(id != null); /* If there is already a lock of this type or more restrictive on the ** OsFile, do nothing. Don't use the end_lock: exit path, as ** sqlite3OsEnterMutex() hasn't been called yet. */ if (pFile.locktype >= locktype) { return(SQLITE_OK); } /* Make sure the locking sequence is correct */ Debug.Assert(pFile.locktype != NO_LOCK || locktype == SHARED_LOCK); Debug.Assert(locktype != PENDING_LOCK); Debug.Assert(locktype != RESERVED_LOCK || pFile.locktype == SHARED_LOCK); /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of ** the PENDING_LOCK byte is temporary. */ newLocktype = pFile.locktype; if (pFile.locktype == NO_LOCK || ((locktype == EXCLUSIVE_LOCK) && (pFile.locktype == RESERVED_LOCK)) ) { int cnt = 3; res = 0; while (cnt-- > 0 && res == 0)//(res = LockFile(pFile.fs.SafeFileHandle.DangerousGetHandle().ToInt32(), PENDING_BYTE, 0, 1, 0)) == 0) { try { lockingStrategy.LockFile(pFile, PENDING_BYTE, 1); res = 1; } catch (Exception e) { /* Try 3 times to get the pending lock. The pending lock might be ** held by another reader process who will release it momentarily. */ Thread.Sleep(1); } } gotPendingLock = (res != 0); if (0 == res) { error = 1; } } /* Acquire a shared lock */ if (locktype == SHARED_LOCK && res != 0) { Debug.Assert(pFile.locktype == NO_LOCK); res = getReadLock(pFile); if (res != 0) { newLocktype = SHARED_LOCK; } else { error = 1; } } if ((locktype == RESERVED_LOCK) && res != 0) { Debug.Assert(pFile.locktype == SHARED_LOCK); try { lockingStrategy.LockFile(pFile, RESERVED_BYTE, 1);//res = LockFile(pFile.fs.SafeFileHandle.DangerousGetHandle().ToInt32(), RESERVED_BYTE, 0, 1, 0); newLocktype = RESERVED_LOCK; res = 1; } catch (Exception e) { res = 0; error = 1; } if (res != 0) { newLocktype = RESERVED_LOCK; } else { error = 1; } } /* Acquire a PENDING lock */ if (locktype == EXCLUSIVE_LOCK && res != 0) { newLocktype = PENDING_LOCK; gotPendingLock = false; } /* Acquire an EXCLUSIVE lock */ if (locktype == EXCLUSIVE_LOCK && res != 0) { Debug.Assert(pFile.locktype >= SHARED_LOCK); res = unlockReadLock(pFile); try { lockingStrategy.LockFile(pFile, SHARED_FIRST, SHARED_SIZE); newLocktype = EXCLUSIVE_LOCK; res = 1; } catch (Exception e) { res = 0; } if (res != 0) { newLocktype = EXCLUSIVE_LOCK; } else { error = 1; getReadLock(pFile); } } /* If we are holding a PENDING lock that ought to be released, then ** release it now. */ if (gotPendingLock && locktype == SHARED_LOCK) { lockingStrategy.UnlockFile(pFile, PENDING_BYTE, 1); } /* Update the state of the lock has held in the file descriptor then ** return the appropriate result code. */ if (res != 0) { rc = SQLITE_OK; } else { pFile.lastErrno = error; rc = SQLITE_BUSY; } pFile.locktype = (u8)newLocktype; return(rc); }
public virtual int SharedLockFile( sqlite3_file pFile, long offset, long length ) { #if !(SQLITE_SILVERLIGHT || WINDOWS_MOBILE) Debug.Assert( length == SHARED_SIZE ); Debug.Assert( offset == SHARED_FIRST ); NativeOverlapped ovlp = new NativeOverlapped(); ovlp.OffsetLow = (int)offset; ovlp.OffsetHigh = 0; ovlp.EventHandle = IntPtr.Zero; return LockFileEx( pFile.fs.Handle, LOCKFILE_FAIL_IMMEDIATELY, 0, (uint)length, 0, ref ovlp ) ? 1 : 0; #else return 1; #endif }
/* ** Sync the file. ** ** Syncing an in-memory journal is a no-op. And, in fact, this routine ** is never called in a working implementation. This implementation ** exists purely as a contingency, in case some malfunction in some other ** part of SQLite causes Sync to be called by mistake. */ static int memjrnlSync( sqlite3_file NotUsed, int NotUsed2 ) { UNUSED_PARAMETER2( NotUsed, NotUsed2 ); return SQLITE_OK; }
/* ** If the argument p points to a JournalFile structure, and the underlying ** file has not yet been created, create it now. */ int sqlite3JournalCreate(sqlite3_file p){ if( p.pMethods!=&JournalFileMethods ){ return SQLITE_OK; } return createFile((JournalFile )p); }
/* ** Copy nPage pages from the source b-tree to the destination. */ static public int sqlite3_backup_step(sqlite3_backup p, int nPage) { int rc; int destMode; /* Destination journal mode */ int pgszSrc = 0; /* Source page size */ int pgszDest = 0; /* Destination page size */ sqlite3_mutex_enter(p.pSrcDb.mutex); sqlite3BtreeEnter(p.pSrc); if (p.pDestDb != null) { sqlite3_mutex_enter(p.pDestDb.mutex); } rc = p.rc; if (!isFatalError(rc)) { Pager pSrcPager = sqlite3BtreePager(p.pSrc); /* Source pager */ Pager pDestPager = sqlite3BtreePager(p.pDest); /* Dest pager */ int ii; /* Iterator variable */ Pgno nSrcPage = 0; /* Size of source db in pages */ int bCloseTrans = 0; /* True if src db requires unlocking */ /* If the source pager is currently in a write-transaction, return ** SQLITE_BUSY immediately. */ if (p.pDestDb != null && p.pSrc.pBt.inTransaction == TRANS_WRITE) { rc = SQLITE_BUSY; } else { rc = SQLITE_OK; } /* Lock the destination database, if it is not locked already. */ if (SQLITE_OK == rc && p.bDestLocked == 0 && SQLITE_OK == (rc = sqlite3BtreeBeginTrans(p.pDest, 2)) ) { p.bDestLocked = 1; sqlite3BtreeGetMeta(p.pDest, BTREE_SCHEMA_VERSION, ref p.iDestSchema); } /* If there is no open read-transaction on the source database, open ** one now. If a transaction is opened here, then it will be closed ** before this function exits. */ if (rc == SQLITE_OK && !sqlite3BtreeIsInReadTrans(p.pSrc)) { rc = sqlite3BtreeBeginTrans(p.pSrc, 0); bCloseTrans = 1; } /* Do not allow backup if the destination database is in WAL mode ** and the page sizes are different between source and destination */ pgszSrc = sqlite3BtreeGetPageSize(p.pSrc); pgszDest = sqlite3BtreeGetPageSize(p.pDest); destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p.pDest)); if (SQLITE_OK == rc && destMode == PAGER_JOURNALMODE_WAL && pgszSrc != pgszDest) { rc = SQLITE_READONLY; } /* Now that there is a read-lock on the source database, query the ** source pager for the number of pages in the database. */ nSrcPage = sqlite3BtreeLastPage(p.pSrc); Debug.Assert(nSrcPage >= 0); for (ii = 0; (nPage < 0 || ii < nPage) && p.iNext <= nSrcPage && 0 == rc; ii++) { Pgno iSrcPg = p.iNext; /* Source page number */ if (iSrcPg != PENDING_BYTE_PAGE(p.pSrc.pBt)) { DbPage pSrcPg = null; /* Source page object */ rc = sqlite3PagerGet(pSrcPager, (u32)iSrcPg, ref pSrcPg); if (rc == SQLITE_OK) { rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg)); sqlite3PagerUnref(pSrcPg); } } p.iNext++; } if (rc == SQLITE_OK) { p.nPagecount = nSrcPage; p.nRemaining = (nSrcPage + 1 - p.iNext); if (p.iNext > nSrcPage) { rc = SQLITE_DONE; } else if (0 == p.isAttached) { attachBackupObject(p); } } /* Update the schema version field in the destination database. This ** is to make sure that the schema-version really does change in ** the case where the source and destination databases have the ** same schema version. */ if (rc == SQLITE_DONE && (rc = sqlite3BtreeUpdateMeta(p.pDest, 1, p.iDestSchema + 1)) == SQLITE_OK ) { Pgno nDestTruncate; if (p.pDestDb != null) { sqlite3ResetInternalSchema(p.pDestDb, -1); } /* Set nDestTruncate to the final number of pages in the destination ** database. The complication here is that the destination page ** size may be different to the source page size. ** ** If the source page size is smaller than the destination page size, ** round up. In this case the call to sqlite3OsTruncate() below will ** fix the size of the file. However it is important to call ** sqlite3PagerTruncateImage() here so that any pages in the ** destination file that lie beyond the nDestTruncate page mark are ** journalled by PagerCommitPhaseOne() before they are destroyed ** by the file truncation. */ Debug.Assert(pgszSrc == sqlite3BtreeGetPageSize(p.pSrc)); Debug.Assert(pgszDest == sqlite3BtreeGetPageSize(p.pDest)); if (pgszSrc < pgszDest) { int ratio = pgszDest / pgszSrc; nDestTruncate = (Pgno)((nSrcPage + ratio - 1) / ratio); if (nDestTruncate == (int)PENDING_BYTE_PAGE(p.pDest.pBt)) { nDestTruncate--; } } else { nDestTruncate = (Pgno)(nSrcPage * (pgszSrc / pgszDest)); } sqlite3PagerTruncateImage(pDestPager, nDestTruncate); if (pgszSrc < pgszDest) { /* If the source page-size is smaller than the destination page-size, ** two extra things may need to happen: ** ** * The destination may need to be truncated, and ** ** * Data stored on the pages immediately following the ** pending-byte page in the source database may need to be ** copied into the destination database. */ int iSize = (int)(pgszSrc * nSrcPage); sqlite3_file pFile = sqlite3PagerFile(pDestPager); i64 iOff; i64 iEnd; Debug.Assert(pFile != null); Debug.Assert((i64)nDestTruncate * (i64)pgszDest >= iSize || ( nDestTruncate == (int)(PENDING_BYTE_PAGE(p.pDest.pBt) - 1) && iSize >= PENDING_BYTE && iSize <= PENDING_BYTE + pgszDest )); /* This call ensures that all data required to recreate the original ** database has been stored in the journal for pDestPager and the ** journal synced to disk. So at this point we may safely modify ** the database file in any way, knowing that if a power failure ** occurs, the original database will be reconstructed from the ** journal file. */ rc = sqlite3PagerCommitPhaseOne(pDestPager, null, true); /* Write the extra pages and truncate the database file as required. */ iEnd = MIN(PENDING_BYTE + pgszDest, iSize); for ( iOff = PENDING_BYTE + pgszSrc; rc == SQLITE_OK && iOff < iEnd; iOff += pgszSrc ) { PgHdr pSrcPg = null; u32 iSrcPg = (u32)((iOff / pgszSrc) + 1); rc = sqlite3PagerGet(pSrcPager, iSrcPg, ref pSrcPg); if (rc == SQLITE_OK) { byte[] zData = sqlite3PagerGetData(pSrcPg); rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff); } sqlite3PagerUnref(pSrcPg); } if (rc == SQLITE_OK) { rc = backupTruncateFile(pFile, (int)iSize); } /* Sync the database file to disk. */ if (rc == SQLITE_OK) { rc = sqlite3PagerSync(pDestPager); } } else { rc = sqlite3PagerCommitPhaseOne(pDestPager, null, false); } /* Finish committing the transaction to the destination database. */ if (SQLITE_OK == rc && SQLITE_OK == (rc = sqlite3BtreeCommitPhaseTwo(p.pDest, 0)) ) { rc = SQLITE_DONE; } } /* If bCloseTrans is true, then this function opened a read transaction ** on the source database. Close the read transaction here. There is ** no need to check the return values of the btree methods here, as ** "committing" a read-only transaction cannot fail. */ if (bCloseTrans != 0) { #if !NDEBUG || SQLITE_COVERAGE_TEST //TESTONLY( int rc2 ); //TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p.pSrc, 0); //TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p.pSrc); int rc2; rc2 = sqlite3BtreeCommitPhaseOne(p.pSrc, ""); rc2 |= sqlite3BtreeCommitPhaseTwo(p.pSrc, 0); Debug.Assert(rc2 == SQLITE_OK); #else sqlite3BtreeCommitPhaseOne(p.pSrc, null); sqlite3BtreeCommitPhaseTwo(p.pSrc, 0); #endif } if (rc == SQLITE_IOERR_NOMEM) { rc = SQLITE_NOMEM; } p.rc = rc; } if (p.pDestDb != null) { sqlite3_mutex_leave(p.pDestDb.mutex); } sqlite3BtreeLeave(p.pSrc); sqlite3_mutex_leave(p.pSrcDb.mutex); return(rc); }
/* ** Return true if the file-handle passed as an argument is ** an in-memory journal */ static bool sqlite3IsMemJournal(sqlite3_file pJfd) { return(pJfd.pMethods == MemJournalMethods); }
/* ** Sync the file. ** ** Syncing an in-memory journal is a no-op. And, in fact, this routine ** is never called in a working implementation. This implementation ** exists purely as a contingency, in case some malfunction in some other ** part of SQLite causes Sync to be called by mistake. */ static int memjrnlSync(sqlite3_file NotUsed, int NotUsed2) { UNUSED_PARAMETER2(NotUsed, NotUsed2); return(SQLITE_OK); }
/* ** Open a file. */ static int winOpen( sqlite3_vfs pVfs, /* Not used */ string zName, /* Name of the file (UTF-8) */ sqlite3_file pFile, /* Write the SQLite file handle here */ int flags, /* Open mode flags */ ref int pOutFlags /* Status return flags */ ) { if (pFile.fs != null) { return(SQLITE_OK); } //HANDLE h; //pFile.fs = null; //fs = null; FileAccess dwDesiredAccess; FileShare dwShareMode; FileMode dwCreationDisposition; string zConverted; /* Filename in OS encoding */ string zUtf8Name = zName; /* Filename in UTF-8 encoding */ StringBuilder zTmpname = new StringBuilder(MAX_PATH + 1); /* Buffer used to create temp filename */ Debug.Assert(pFile != null); UNUSED_PARAMETER(pVfs); /* If the second argument to this function is NULL, generate a ** temporary file name to use */ if (String.IsNullOrEmpty(zUtf8Name)) { int rc = getTempname(MAX_PATH + 1, zTmpname); if (rc != SQLITE_OK) { return(rc); } zUtf8Name = zTmpname.ToString(); } // /* Convert the filename to the system encoding. */ zConverted = zUtf8Name;// convertUtf8Filename( zUtf8Name ); if (String.IsNullOrEmpty(zConverted)) { return(SQLITE_NOMEM); } if ((flags & SQLITE_OPEN_READWRITE) != 0) { dwDesiredAccess = FileAccess.Read | FileAccess.Write; // GENERIC_READ | GENERIC_WRITE; } else { dwDesiredAccess = FileAccess.Read; // GENERIC_READ; } /* SQLITE_OPEN_EXCLUSIVE is used to make sure that a new file is ** created. SQLite doesn't use it to indicate "exclusive access" ** as it is usually understood. */ Debug.Assert(0 == (flags & SQLITE_OPEN_EXCLUSIVE) || (flags & SQLITE_OPEN_CREATE) != 0); if ((flags & SQLITE_OPEN_EXCLUSIVE) != 0) { /* Creates a new file, only if it does not already exist. */ /* If the file exists, it fails. */ dwCreationDisposition = FileMode.CreateNew;// CREATE_NEW; } else if ((flags & SQLITE_OPEN_CREATE) != 0) { /* Open existing file, or create if it doesn't exist */ dwCreationDisposition = FileMode.OpenOrCreate;// OPEN_ALWAYS; } else { /* Opens a file, only if it exists. */ dwCreationDisposition = FileMode.Open; //OPEN_EXISTING; } dwShareMode = FileShare.Read | FileShare.Write; // FILE_SHARE_READ | FILE_SHARE_WRITE; if ((flags & SQLITE_OPEN_DELETEONCLOSE) != 0) { } else { } /* Reports from the internet are that performance is always ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */ if (isNT()) { int retries = 3; //while ( ( pFile.fs == null ) && ( retries > 0 ) ) while ((pFile.fs == null) && (retries > 0)) { try { retries--; //pFile.fs = new IsolatedStorageFileStream(zConverted, dwCreationDisposition, dwDesiredAccess, dwShareMode, pFile.store); pFile.fs = new IsolatedStorageFileStream(zConverted, dwCreationDisposition, dwDesiredAccess, dwShareMode, store); } catch (Exception e) { Thread.Sleep(100); } } /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. ** Since the ASCII version of these Windows API do not exist for WINCE, ** it's important to not reference them for WINCE builds. */ } //if ( pFile.fs == null if (pFile.fs == null || //!pFile.fs.CanRead !pFile.fs.CanRead ) { if ((flags & SQLITE_OPEN_READWRITE) != 0) { return(winOpen(pVfs, zName, pFile, ((flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE), ref pOutFlags)); } else { return(SQLITE_CANTOPEN_BKPT()); } } if ((flags & SQLITE_OPEN_READWRITE) != 0) { pOutFlags = SQLITE_OPEN_READWRITE; } else { pOutFlags = SQLITE_OPEN_READONLY; } //} pFile.Clear(); // memset(pFile, 0, sizeof(*pFile)); pFile.pMethods = winIoMethod; pFile.lastErrno = NO_ERROR; pFile.sectorSize = (ulong)getSectorSize(pVfs, zUtf8Name); return(SQLITE_OK); }
/* ** Return a vector of device characteristics. */ static int winDeviceCharacteristics(sqlite3_file id) { UNUSED_PARAMETER(id); return(0); }
/* ** Return the sector size in bytes of the underlying block device for ** the specified file. This is almost always 512 bytes, but may be ** larger for some devices. ** ** SQLite code assumes this function cannot fail. It also assumes that ** if two files are created in the same file-system directory (i.e. ** a database and its journal file) that the sector size will be the ** same for both. */ static int winSectorSize(sqlite3_file id) { Debug.Assert(id != null); return((int)(id.sectorSize)); }
/* ** Truncate the file. */ static int jrnlTruncate(sqlite3_file pJfd, sqlite_int64 size){ int rc = SQLITE_OK; JournalFile p = (JournalFile )pJfd; if( p.pReal ){ rc = sqlite3OsTruncate(p.pReal, size); }else if( size<p.iSize ){ p.iSize = size; } return rc; }
/* ** Query the size of the file in bytes. */ static int jrnlFileSize(sqlite3_file pJfd, sqlite_int64 pSize){ int rc = SQLITE_OK; JournalFile p = (JournalFile )pJfd; if( p.pReal ){ rc = sqlite3OsFileSize(p.pReal, pSize); }else{ pSize = (sqlite_int64) p.iSize; } return rc; }
/* ** Write data to the file. */ static int jrnlWrite( sqlite3_file pJfd, /* The journal file into which to write */
public virtual int SharedLockFile(sqlite3_file pFile, long offset, long length) { return(1); }
public virtual void UnlockFile(sqlite3_file pFile, long offset, long length) { }
/* ** 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;//(sqlite3_io_methods*)&MemJournalMethods; }
//#define DO_OS_MALLOC_TEST(x) static void DO_OS_MALLOC_TEST(sqlite3_file x) { }
public override int SharedLockFile( sqlite3_file pFile, long offset, long length ) { #if !(SQLITE_SILVERLIGHT || WINDOWS_MOBILE) Debug.Assert( length == SHARED_SIZE ); Debug.Assert( offset == SHARED_FIRST ); try { pFile.fs.Lock( offset + pFile.sharedLockByte, 1 ); } catch ( IOException ) { return 0; } #endif return 1; }
public override int SharedLockFile(sqlite3_file pFile, long offset, long length) { return(1); }
static int sqlite3OsWrite(sqlite3_file id, byte[] pBuf, int amt, i64 offset) { DO_OS_MALLOC_TEST(id); return(id.pMethods.xWrite(id, pBuf, amt, offset)); }
static int sqlite3OsTruncate(sqlite3_file id, i64 size) { return(id.pMethods.xTruncate(id, size)); }
static int sqlite3OsCloseFree( sqlite3_file pFile ) { int rc = SQLITE_OK; Debug.Assert( pFile != null ); rc = sqlite3OsClose( pFile ); //sqlite3_free( ref pFile ); return rc; }
static int sqlite3OsSync(sqlite3_file id, int flags) { DO_OS_MALLOC_TEST(id); return(id.pMethods.xSync(id, flags)); }
static int sqlite3OsRead( sqlite3_file id, byte[] pBuf, int amt, i64 offset ) { DO_OS_MALLOC_TEST( id ); if ( pBuf == null ) pBuf = sqlite3Malloc( amt ); return id.pMethods.xRead( id, pBuf, amt, offset ); }
static int sqlite3OsFileSize(sqlite3_file id, ref long pSize) { return(id.pMethods.xFileSize(id, ref pSize)); }
/* ** 2010 February 1 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface to the write-ahead logging ** system. Refer to the comments below and the header comment attached to ** the implementation of each function in log.c for further details. ************************************************************************* ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart ** C#-SQLite is an independent reimplementation of the SQLite software library ** ** SQLITE_SOURCE_ID: 2011-06-23 19:49:22 4374b7e83ea0a3fbc3691f9c0c936272862f32f2 ** ************************************************************************* */ //#if !_WAL_H_ //#define _WAL_H_ //#include "sqliteInt.h" #if SQLITE_OMIT_WAL //# define sqlite3WalOpen(x,y,z) 0 static int sqlite3WalOpen(sqlite3_vfs x, sqlite3_file y, string z) { return 0; }
static int sqlite3OsLock(sqlite3_file id, int lockType) { DO_OS_MALLOC_TEST(id); return(id.pMethods.xLock(id, lockType)); }
/* ** Write data to the file. */ static int jrnlWrite( sqlite3_file pJfd, /* The journal file into which to write */ string zBuf, /* Take data to be written from here */ int iAmt, /* Number of bytes to write */ sqlite_int64 iOfst /* Begin writing at this offset into the file */ ){ int rc = SQLITE_OK; JournalFile p = (JournalFile )pJfd; if( null==p.pReal && (iOfst+iAmt)>p.nBuf ){ rc = createFile(p); } if( rc==SQLITE_OK ){ if( p.pReal ){ rc = sqlite3OsWrite(p.pReal, zBuf, iAmt, iOfst); }else{ memcpy(p.zBuf[iOfst], zBuf, iAmt); if( p.iSize<(iOfst+iAmt) ){ p.iSize = (iOfst+iAmt); } } } return rc; }
static int sqlite3OsUnlock(sqlite3_file id, int lockType) { return(id.pMethods.xUnlock(id, lockType)); }
/* ** Sync the file. */ static int jrnlSync(sqlite3_file pJfd, int flags){ int rc; JournalFile p = (JournalFile )pJfd; if( p.pReal ){ rc = sqlite3OsSync(p.pReal, flags); }else{ rc = SQLITE_OK; } return rc; }
/* ** Read data from the file. */ static int jrnlRead( sqlite3_file *pJfd, /* The journal file from which to read */ void *zBuf, /* Put the results here */ int iAmt, /* Number of bytes to read */ sqlite_int64 iOfst /* Begin reading at this offset */ ){ int rc = SQLITE_OK; JournalFile *p = (JournalFile )pJfd; if( p->pReal ){ rc = sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst); }else if( (iAmt+iOfst)>p->iSize ){ rc = SQLITE_IOERR_SHORT_READ; }else{ memcpy(zBuf, &p->zBuf[iOfst], iAmt); } return rc; }
/* ** Open a journal file. */ int sqlite3JournalOpen( sqlite3_vfs pVfs, /* The VFS to use for actual file I/O */ string zName, /* Name of the journal file */ sqlite3_file pJfd, /* Preallocated, blank file handle */ int flags, /* Opening flags */ int nBuf /* Bytes buffered before opening the file */ ){ JournalFile p = (JournalFile )pJfd; memset(p, 0, sqlite3JournalSize(pVfs)); if( nBuf>0 ){ p.zBuf = sqlite3MallocZero(nBuf); if( null==p.zBuf ){ return SQLITE_NOMEM; } }else{ return sqlite3OsOpen(pVfs, zName, pJfd, flags, 0); } p.pMethod = JournalFileMethods; p.nBuf = nBuf; p.flags = flags; p.zJournal = zName; p.pVfs = pVfs; return SQLITE_OK; }
/* ** 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; }
static int sqlite3OsCheckReservedLock(sqlite3_file id, ref int pResOut) { DO_OS_MALLOC_TEST(id); return(id.pMethods.xCheckReservedLock(id, ref pResOut)); }
/* ** 2010 February 1 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface to the write-ahead logging ** system. Refer to the comments below and the header comment attached to ** the implementation of each function in log.c for further details. ************************************************************************* ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart ** C#-SQLite is an independent reimplementation of the SQLite software library ** ** SQLITE_SOURCE_ID: 2011-06-23 19:49:22 4374b7e83ea0a3fbc3691f9c0c936272862f32f2 ** ************************************************************************* */ //#if !_WAL_H_ //#define _WAL_H_ //#include "sqliteInt.h" #if SQLITE_OMIT_WAL //# define sqlite3WalOpen(x,y,z) 0 static int sqlite3WalOpen(sqlite3_vfs x, sqlite3_file y, string z) { return(0); }
/* ** 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; }
static int sqlite3OsFileControl(sqlite3_file id, u32 op, ref sqlite3_int64 pArg) { return(id.pMethods.xFileControl(id, (int)op, ref pArg)); }
/* ** 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; }
static int sqlite3OsSectorSize(sqlite3_file id) { dxSectorSize xSectorSize = id.pMethods.xSectorSize; return(xSectorSize != null ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE); }
/* ** 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; }
static int sqlite3OsDeviceCharacteristics(sqlite3_file id) { return(id.pMethods.xDeviceCharacteristics(id)); }
/* ** Return true if the file-handle passed as an argument is ** an in-memory journal */ static bool sqlite3IsMemJournal( sqlite3_file pJfd ) { return pJfd.pMethods == MemJournalMethods; }
static int sqlite3OsShmLock(sqlite3_file id, int offset, int n, int flags) { return(id.pMethods.xShmLock(id, offset, n, flags)); }
public virtual void UnlockFile( sqlite3_file pFile, long offset, long length ) { #if !(SQLITE_SILVERLIGHT || WINDOWS_MOBILE) pFile.fs.Unlock( offset, length ); #endif }
static void sqlite3OsShmBarrier(sqlite3_file id) { id.pMethods.xShmBarrier(id); }
/* ** If pFile is currently larger than iSize bytes, then truncate it to ** exactly iSize bytes. If pFile is not larger than iSize bytes, then ** this function is a no-op. ** ** Return SQLITE_OK if everything is successful, or an SQLite error ** code if an error occurs. */ static int backupTruncateFile( sqlite3_file pFile, int iSize ) { long iCurrent = 0; int rc = sqlite3OsFileSize( pFile, ref iCurrent ); if ( rc == SQLITE_OK && iCurrent > iSize ) { rc = sqlite3OsTruncate( pFile, iSize ); } return rc; }
static int sqlite3OsShmUnmap(sqlite3_file id, int deleteFlag) { return(id.pMethods.xShmUnmap(id, deleteFlag)); }