Lines Matching refs:pFile
24131 sqlite3_file *pFile,
24141 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
24142 assert( rc==SQLITE_OK || pFile->pMethods==0 );
24228 sqlite3_file *pFile;
24229 pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile);
24230 if( pFile ){
24231 rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
24233 sqlite3_free(pFile);
24236 *ppFile = pFile;
24245 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
24246 assert( pFile );
24247 sqlite3OsClose(pFile);
24248 sqlite3_free(pFile);
35431 int unixFileMutexHeld(unixFile *pFile){
35432 assert( pFile->pInode );
35433 return sqlite3_mutex_held(pFile->pInode->pLockMutex);
35435 int unixFileMutexNotheld(unixFile *pFile){
35436 assert( pFile->pInode );
35437 return sqlite3_mutex_notheld(pFile->pInode->pLockMutex);
35523 static void robust_close(unixFile *pFile, int h, int lineno){
35526 pFile ? pFile->zPath : 0, lineno);
35534 static void storeLastErrno(unixFile *pFile, int error){
35535 pFile->lastErrno = error;
35541 static void closePendingFds(unixFile *pFile){
35542 unixInodeInfo *pInode = pFile->pInode;
35545 assert( unixFileMutexHeld(pFile) );
35548 robust_close(pFile, p->fd, __LINE__);
35560 static void releaseInodeInfo(unixFile *pFile){
35561 unixInodeInfo *pInode = pFile->pInode;
35563 assert( unixFileMutexNotheld(pFile) );
35569 closePendingFds(pFile);
35598 unixFile *pFile, /* Unix file with file desc used in the key */
35612 fd = pFile->h;
35615 storeLastErrno(pFile, errno);
35617 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
35633 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
35636 storeLastErrno(pFile, errno);
35641 storeLastErrno(pFile, errno);
35650 fileId.pId = pFile->pId;
35689 static int fileHasMoved(unixFile *pFile){
35691 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
35694 return pFile->pInode!=0 &&
35695 (osStat(pFile->zPath, &buf)!=0
35696 || (u64)buf.st_ino!=pFile->pInode->fileId.ino);
35710 static void verifyDbFile(unixFile *pFile){
35715 if( pFile->ctrlFlags & UNIXFILE_NOLOCK ) return;
35717 rc = osFstat(pFile->h, &buf);
35719 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
35723 sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
35727 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
35730 if( fileHasMoved(pFile) ){
35731 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
35746 unixFile *pFile = (unixFile*)id;
35750 assert( pFile );
35751 assert( pFile->eFileLock<=SHARED_LOCK );
35752 sqlite3_mutex_enter(pFile->pInode->pLockMutex);
35755 if( pFile->pInode->eFileLock>SHARED_LOCK ){
35762 if( !reserved && !pFile->pInode->bProcessLock ){
35768 if( osFcntl(pFile->h, F_GETLK, &lock) ){
35770 storeLastErrno(pFile, errno);
35777 sqlite3_mutex_leave(pFile->pInode->pLockMutex);
35778 OSTRACE(("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved));
35806 unixFile *pFile /* Structure holding timeout value */
35808 int tm = pFile->iBusyTimeout;
35844 static int unixFileLock(unixFile *pFile, struct flock *pLock){
35846 unixInodeInfo *pInode = pFile->pInode;
35849 if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){
35857 rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile);
35865 rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile);
35935 unixFile *pFile = (unixFile*)id;
35940 assert( pFile );
35941 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
35942 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
35943 azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared,
35950 if( pFile->eFileLock>=eFileLock ){
35951 OSTRACE(("LOCK %d %s ok (already held) (unix)\n", pFile->h,
35961 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
35963 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
35967 pInode = pFile->pInode;
35973 if( (pFile->eFileLock!=pInode->eFileLock &&
35987 assert( pFile->eFileLock==0 );
35989 pFile->eFileLock = SHARED_LOCK;
36003 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
36007 if( unixFileLock(pFile, &lock) ){
36011 storeLastErrno(pFile, tErrno);
36029 if( unixFileLock(pFile, &lock) ){
36038 if( unixFileLock(pFile, &lock) && rc==SQLITE_OK ){
36046 storeLastErrno(pFile, tErrno);
36050 pFile->eFileLock = SHARED_LOCK;
36063 assert( 0!=pFile->eFileLock );
36075 if( unixFileLock(pFile, &lock) ){
36079 storeLastErrno(pFile, tErrno);
36092 && pFile->eFileLock<=SHARED_LOCK
36095 pFile->transCntrChng = 0;
36096 pFile->dbUpdate = 0;
36097 pFile->inNormalWrite = 1;
36103 pFile->eFileLock = eFileLock;
36106 pFile->eFileLock = PENDING_LOCK;
36112 OSTRACE(("LOCK %d %s %s (unix)\n", pFile->h, azFileLock(eFileLock),
36121 static void setPendingFd(unixFile *pFile){
36122 unixInodeInfo *pInode = pFile->pInode;
36123 UnixUnusedFd *p = pFile->pPreallocatedUnused;
36124 assert( unixFileMutexHeld(pFile) );
36127 pFile->h = -1;
36128 pFile->pPreallocatedUnused = 0;
36145 unixFile *pFile = (unixFile*)id;
36150 assert( pFile );
36151 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
36152 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
36156 if( pFile->eFileLock<=eFileLock ){
36159 pInode = pFile->pInode;
36162 if( pFile->eFileLock>SHARED_LOCK ){
36163 assert( pInode->eFileLock==pFile->eFileLock );
36174 pFile->inNormalWrite = 0;
36200 if( unixFileLock(pFile, &lock)==(-1) ){
36203 storeLastErrno(pFile, tErrno);
36210 if( unixFileLock(pFile, &lock)==(-1) ){
36214 storeLastErrno(pFile, tErrno);
36222 if( unixFileLock(pFile, &lock)==(-1) ){
36225 storeLastErrno(pFile, tErrno);
36235 if( unixFileLock(pFile, &lock) ){
36243 storeLastErrno(pFile, errno);
36252 if( unixFileLock(pFile, &lock)==0 ){
36256 storeLastErrno(pFile, errno);
36270 if( unixFileLock(pFile, &lock)==0 ){
36274 storeLastErrno(pFile, errno);
36276 pFile->eFileLock = NO_LOCK;
36286 if( pInode->nLock==0 ) closePendingFds(pFile);
36292 pFile->eFileLock = eFileLock;
36327 unixFile *pFile = (unixFile*)id;
36329 unixUnmapfile(pFile);
36331 if( pFile->h>=0 ){
36332 robust_close(pFile, pFile->h, __LINE__);
36333 pFile->h = -1;
36336 if( pFile->pId ){
36337 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
36338 osUnlink(pFile->pId->zCanonicalName);
36340 vxworksReleaseFileId(pFile->pId);
36341 pFile->pId = 0;
36345 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
36346 osUnlink(pFile->zPath);
36347 sqlite3_free(*(char**)&pFile->zPath);
36348 pFile->zPath = 0;
36351 OSTRACE(("CLOSE %-3d\n", pFile->h));
36353 sqlite3_free(pFile->pPreallocatedUnused);
36354 memset(pFile, 0, sizeof(unixFile));
36363 unixFile *pFile = (unixFile *)id;
36364 unixInodeInfo *pInode = pFile->pInode;
36367 verifyDbFile(pFile);
36369 assert( unixFileMutexNotheld(pFile) );
36375 assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 );
36383 setPendingFd(pFile);
36386 releaseInodeInfo(pFile);
36387 assert( pFile->pShm==0 );
36478 unixFile *pFile = (unixFile*)id;
36482 assert( pFile );
36483 reserved = osAccess((const char*)pFile->lockingContext, 0)==0;
36484 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
36517 unixFile *pFile = (unixFile*)id;
36518 char *zLockFile = (char *)pFile->lockingContext;
36525 if( pFile->eFileLock > NO_LOCK ){
36526 pFile->eFileLock = eFileLock;
36546 storeLastErrno(pFile, tErrno);
36553 pFile->eFileLock = eFileLock;
36567 unixFile *pFile = (unixFile*)id;
36568 char *zLockFile = (char *)pFile->lockingContext;
36571 assert( pFile );
36572 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
36573 pFile->eFileLock, osGetpid(0)));
36577 if( pFile->eFileLock==eFileLock ){
36585 pFile->eFileLock = SHARED_LOCK;
36598 storeLastErrno(pFile, tErrno);
36602 pFile->eFileLock = NO_LOCK;
36610 unixFile *pFile = (unixFile*)id;
36613 sqlite3_free(pFile->lockingContext);
36658 unixFile *pFile = (unixFile*)id;
36662 assert( pFile );
36665 if( pFile->eFileLock>SHARED_LOCK ){
36672 int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
36675 lrc = robust_flock(pFile->h, LOCK_UN);
36680 storeLastErrno(pFile, tErrno);
36689 storeLastErrno(pFile, tErrno);
36694 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
36737 unixFile *pFile = (unixFile*)id;
36739 assert( pFile );
36743 if (pFile->eFileLock > NO_LOCK) {
36744 pFile->eFileLock = eFileLock;
36750 if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
36755 storeLastErrno(pFile, tErrno);
36759 pFile->eFileLock = eFileLock;
36761 OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock),
36780 unixFile *pFile = (unixFile*)id;
36782 assert( pFile );
36783 OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock,
36784 pFile->eFileLock, osGetpid(0)));
36788 if( pFile->eFileLock==eFileLock ){
36794 pFile->eFileLock = eFileLock;
36799 if( robust_flock(pFile->h, LOCK_UN) ){
36805 pFile->eFileLock = NO_LOCK;
36845 unixFile *pFile = (unixFile*)id;
36849 assert( pFile );
36852 if( pFile->eFileLock>SHARED_LOCK ){
36858 sem_t *pSem = pFile->pInode->pSem;
36864 storeLastErrno(pFile, tErrno);
36867 reserved = (pFile->eFileLock < SHARED_LOCK);
36874 OSTRACE(("TEST WR-LOCK %d %d %d (sem)\n", pFile->h, rc, reserved));
36910 unixFile *pFile = (unixFile*)id;
36911 sem_t *pSem = pFile->pInode->pSem;
36916 if (pFile->eFileLock > NO_LOCK) {
36917 pFile->eFileLock = eFileLock;
36929 pFile->eFileLock = eFileLock;
36943 unixFile *pFile = (unixFile*)id;
36944 sem_t *pSem = pFile->pInode->pSem;
36946 assert( pFile );
36948 OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
36949 pFile->eFileLock, osGetpid(0)));
36953 if( pFile->eFileLock==eFileLock ){
36959 pFile->eFileLock = eFileLock;
36968 storeLastErrno(pFile, tErrno);
36972 pFile->eFileLock = NO_LOCK;
36981 unixFile *pFile = (unixFile*)id;
36983 assert( pFile );
36984 assert( unixFileMutexNotheld(pFile) );
36986 releaseInodeInfo(pFile);
37041 unixFile *pFile, /* Open file descriptor on path */
37053 pb.fd = pFile->h;
37056 (setLockFlag?"ON":"OFF"), pFile->h, (pb.fd==-1?"[testval-1]":""),
37071 storeLastErrno(pFile, tErrno);
37088 unixFile *pFile = (unixFile*)id;
37093 assert( pFile );
37094 context = (afpLockingContext *) pFile->lockingContext;
37099 sqlite3_mutex_enter(pFile->pInode->pLockMutex);
37101 if( pFile->pInode->eFileLock>SHARED_LOCK ){
37109 int lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1);
37113 lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
37123 sqlite3_mutex_leave(pFile->pInode->pLockMutex);
37124 OSTRACE(("TEST WR-LOCK %d %d %d (afp)\n", pFile->h, rc, reserved));
37156 unixFile *pFile = (unixFile*)id;
37157 unixInodeInfo *pInode = pFile->pInode;
37158 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
37160 assert( pFile );
37161 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h,
37162 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
37169 if( pFile->eFileLock>=eFileLock ){
37170 OSTRACE(("LOCK %d %s ok (already held) (afp)\n", pFile->h,
37180 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
37182 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
37186 pInode = pFile->pInode;
37192 if( (pFile->eFileLock!=pInode->eFileLock &&
37206 assert( pFile->eFileLock==0 );
37208 pFile->eFileLock = SHARED_LOCK;
37219 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
37222 failed = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 1);
37244 lrc1 = afpSetLock(context->dbPath, pFile,
37247 lrc1Errno = pFile->lastErrno;
37250 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
37253 storeLastErrno(pFile, lrc1Errno);
37262 pFile->eFileLock = SHARED_LOCK;
37276 assert( 0!=pFile->eFileLock );
37277 if (eFileLock >= RESERVED_LOCK && pFile->eFileLock < RESERVED_LOCK) {
37279 failed = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1);
37290 if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST +
37294 failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST,
37296 if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
37315 pFile->eFileLock = eFileLock;
37318 pFile->eFileLock = PENDING_LOCK;
37324 OSTRACE(("LOCK %d %s %s (afp)\n", pFile->h, azFileLock(eFileLock),
37338 unixFile *pFile = (unixFile*)id;
37340 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
37343 int h = pFile->h;
37346 assert( pFile );
37347 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
37348 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
37352 if( pFile->eFileLock<=eFileLock ){
37355 pInode = pFile->pInode;
37358 if( pFile->eFileLock>SHARED_LOCK ){
37359 assert( pInode->eFileLock==pFile->eFileLock );
37373 assert( pFile->inNormalWrite==0
37374 || pFile->dbUpdate==0
37375 || pFile->transCntrChng==1 );
37376 pFile->inNormalWrite = 0;
37379 if( pFile->eFileLock==EXCLUSIVE_LOCK ){
37380 rc = afpSetLock(context->dbPath, pFile, SHARED_FIRST, SHARED_SIZE, 0);
37384 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 1);
37389 if( rc==SQLITE_OK && pFile->eFileLock>=PENDING_LOCK ){
37390 rc = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
37392 if( rc==SQLITE_OK && pFile->eFileLock>=RESERVED_LOCK && context->reserved ){
37393 rc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
37415 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0);
37419 pFile->eFileLock = NO_LOCK;
37425 if( pInode->nLock==0 ) closePendingFds(pFile);
37431 pFile->eFileLock = eFileLock;
37441 unixFile *pFile = (unixFile*)id;
37444 assert( unixFileMutexNotheld(pFile) );
37446 if( pFile->pInode ){
37447 unixInodeInfo *pInode = pFile->pInode;
37455 setPendingFd(pFile);
37459 releaseInodeInfo(pFile);
37460 sqlite3_free(pFile->lockingContext);
37578 unixFile *pFile = (unixFile *)id;
37587 assert( pFile->pPreallocatedUnused==0
37596 if( offset<pFile->mmapSize ){
37597 if( offset+amt <= pFile->mmapSize ){
37598 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
37601 int nCopy = pFile->mmapSize - offset;
37602 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
37610 got = seekAndRead(pFile, offset, pBuf, amt);
37621 switch( pFile->lastErrno ){
37634 storeLastErrno(pFile, 0); /* not a system error */
37709 unixFile *pFile = (unixFile*)id;
37717 assert( pFile->pPreallocatedUnused==0
37730 if( pFile->inNormalWrite ){
37731 pFile->dbUpdate = 1; /* The database has been modified */
37736 rc = seekAndRead(pFile, 24, oldCntr, 4);
37739 pFile->transCntrChng = 1; /* The transaction counter has changed */
37748 if( offset<pFile->mmapSize ){
37749 if( offset+amt <= pFile->mmapSize ){
37750 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
37753 int nCopy = pFile->mmapSize - offset;
37754 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
37762 while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
37771 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
37775 storeLastErrno(pFile, 0); /* not a system error */
37973 unixFile *pFile = (unixFile*)id;
37988 assert( pFile );
37989 OSTRACE(("SYNC %-3d\n", pFile->h));
37990 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
37993 storeLastErrno(pFile, errno);
37994 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
38001 if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
38003 OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath,
38005 rc = osOpenDirectory(pFile->zPath, &dirfd);
38008 robust_close(pFile, dirfd, __LINE__);
38013 pFile->ctrlFlags &= ~UNIXFILE_DIRSYNC;
38022 unixFile *pFile = (unixFile *)id;
38024 assert( pFile );
38032 if( pFile->szChunk>0 ){
38033 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
38036 rc = robust_ftruncate(pFile->h, nByte);
38038 storeLastErrno(pFile, errno);
38039 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
38049 if( pFile->inNormalWrite && nByte==0 ){
38050 pFile->transCntrChng = 1;
38059 if( nByte<pFile->mmapSize ){
38060 pFile->mmapSize = nByte;
38109 static int fcntlSizeHint(unixFile *pFile, i64 nByte){
38110 if( pFile->szChunk>0 ){
38114 if( osFstat(pFile->h, &buf) ){
38118 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
38127 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
38147 nWrite = seekAndWrite(pFile, iWrite, "", 1);
38155 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
38157 if( pFile->szChunk<=0 ){
38158 if( robust_ftruncate(pFile->h, nByte) ){
38159 storeLastErrno(pFile, errno);
38160 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
38164 rc = unixMapfile(pFile, nByte);
38178 static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
38180 *pArg = (pFile->ctrlFlags & mask)!=0;
38182 pFile->ctrlFlags &= ~mask;
38184 pFile->ctrlFlags |= mask;
38198 unixFile *pFile = (unixFile*)id;
38202 int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE);
38206 int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE);
38210 int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE);
38216 *(int*)pArg = pFile->eFileLock;
38220 *(int*)pArg = pFile->lastErrno;
38224 pFile->szChunk = *(int *)pArg;
38230 rc = fcntlSizeHint(pFile, *(i64 *)pArg);
38235 unixModeBit(pFile, UNIXFILE_PERSIST_WAL, (int*)pArg);
38239 unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg);
38243 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
38247 char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
38249 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
38255 *(int*)pArg = fileHasMoved(pFile);
38260 int iOld = pFile->iBusyTimeout;
38261 pFile->iBusyTimeout = *(int*)pArg;
38281 *(i64*)pArg = pFile->mmapSizeMax;
38282 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
38283 pFile->mmapSizeMax = newLimit;
38284 if( pFile->mmapSize>0 ){
38285 unixUnmapfile(pFile);
38286 rc = unixMapfile(pFile, -1);
38357 static void setDeviceCharacteristics(unixFile *pFile){
38358 if( pFile->sectorSize == 0 ){
38362 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
38363 pFile->deviceCharacteristics = 0;
38364 if( fstatvfs(pFile->h, &fsInfo) == -1 ) {
38369 pFile->sectorSize = fsInfo.f_bsize;
38370 pFile->deviceCharacteristics =
38378 pFile->sectorSize = fsInfo.f_bsize;
38379 pFile->deviceCharacteristics =
38381 (pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) |
38388 pFile->sectorSize = fsInfo.f_bsize;
38389 pFile->deviceCharacteristics =
38397 pFile->sectorSize = fsInfo.f_bsize;
38398 pFile->deviceCharacteristics =
38400 ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 |
38405 pFile->sectorSize = fsInfo.f_bsize;
38406 pFile->deviceCharacteristics =
38408 ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 |
38413 pFile->deviceCharacteristics =
38422 if( pFile->sectorSize % 512 != 0 ){
38423 pFile->deviceCharacteristics = 0;
38424 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
38571 static int unixFcntlExternalReader(unixFile *pFile, int *piOut){
38574 if( pFile->pShm){
38575 unixShmNode *pShmNode = pFile->pShm->pShmNode;
38604 unixFile *pFile, /* Open connection to the WAL file */
38614 pShmNode = pFile->pInode->pShmNode;
38631 res = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile);
38634 rc = (pFile->iBusyTimeout ? SQLITE_BUSY_TIMEOUT : SQLITE_BUSY);
40304 sqlite3_file *pFile, /* The file descriptor to be filled in */
40308 unixFile *p = (unixFile *)pFile;
40515 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
40518 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
40546 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
40548 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
40554 unixClose(pFile);
40566 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
41440 static int proxyBreakConchLock(unixFile *pFile, uuid_t myHostID){
41441 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41482 robust_close(pFile, conchFile->h, __LINE__);
41490 robust_close(pFile, fd, __LINE__);
41500 static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
41501 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41520 storeLastErrno(pFile, errno);
41540 storeLastErrno(pFile, errno);
41557 if( 0==proxyBreakConchLock(pFile, myHostID) ){
41578 static int proxyTakeConch(unixFile *pFile){
41579 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41603 storeLastErrno(pFile, pError);
41606 rc = proxyConchLock(pFile, myHostID, SHARED_LOCK);
41614 storeLastErrno(pFile, conchFile->lastErrno);
41684 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
41687 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
41710 int err = osFstat(pFile->h, &buf);
41739 OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h));
41740 if( rc==SQLITE_OK && pFile->openFlags ){
41742 if( pFile->h>=0 ){
41743 robust_close(pFile, pFile->h, __LINE__);
41745 pFile->h = -1;
41746 fd = robust_open(pCtx->dbPath, pFile->openFlags, 0);
41749 pFile->h = fd;
41800 static int proxyReleaseConch(unixFile *pFile){
41805 pCtx = (proxyLockingContext *)pFile->lockingContext;
41867 static int switchLockProxyPath(unixFile *pFile, const char *path) {
41868 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
41872 if( pFile->eFileLock!=NO_LOCK ){
41903 static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
41905 if( pFile->pMethod == &afpIoMethods ){
41908 assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
41909 strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath,
41913 if( pFile->pMethod == &dotlockIoMethods ){
41916 int len = strlen((char *)pFile->lockingContext) - strlen(DOTLOCK_SUFFIX);
41917 memcpy(dbPath, (char *)pFile->lockingContext, len + 1);
41920 assert( strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
41921 strlcpy(dbPath, (char *)pFile->lockingContext, MAXPATHLEN);
41934 static int proxyTransformUnixFile(unixFile *pFile, const char *path) {
41940 if( pFile->eFileLock!=NO_LOCK ){
41943 proxyGetDbPathForUnixFile(pFile, dbPath);
41950 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
41962 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){
41998 pCtx->oldLockingContext = pFile->lockingContext;
41999 pFile->lockingContext = pCtx;
42000 pCtx->pOldMethod = pFile->pMethod;
42001 pFile->pMethod = &proxyIoMethods;
42011 OSTRACE(("TRANSPROXY %d %s\n", pFile->h,
42024 unixFile *pFile = (unixFile*)id;
42025 if( pFile->pMethod == &proxyIoMethods ){
42026 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
42027 proxyTakeConch(pFile);
42039 unixFile *pFile = (unixFile*)id;
42041 int isProxyStyle = (pFile->pMethod == &proxyIoMethods);
42057 (proxyLockingContext*)pFile->lockingContext;
42064 rc = switchLockProxyPath(pFile, proxyPath);
42068 rc = proxyTransformUnixFile(pFile, proxyPath);
42095 unixFile *pFile = (unixFile*)id;
42096 int rc = proxyTakeConch(pFile);
42098 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
42134 unixFile *pFile = (unixFile*)id;
42135 int rc = proxyTakeConch(pFile);
42137 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
42141 pFile->eFileLock = proxy->eFileLock;
42158 unixFile *pFile = (unixFile*)id;
42159 int rc = proxyTakeConch(pFile);
42161 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
42165 pFile->eFileLock = proxy->eFileLock;
42178 unixFile *pFile = (unixFile*)id;
42179 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
42194 rc = proxyReleaseConch(pFile);
42205 pFile->lockingContext = pCtx->oldLockingContext;
42206 pFile->pMethod = pCtx->pOldMethod;
42208 return pFile->pMethod->xClose(id);
44612 static int winceCreateLock(const char *zFilename, winFile *pFile){
44626 memset(&pFile->local, 0, sizeof(pFile->local));
44636 pFile->hMutex = osCreateMutexW(NULL, FALSE, zName);
44637 if (!pFile->hMutex){
44638 pFile->lastErrno = osGetLastError();
44640 return winLogError(SQLITE_IOERR, pFile->lastErrno,
44645 winceMutexAcquire(pFile->hMutex);
44652 pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
44666 if( pFile->hShared ){
44667 pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared,
44670 if( !pFile->shared ){
44671 pFile->lastErrno = osGetLastError();
44672 winLogError(SQLITE_IOERR, pFile->lastErrno,
44675 osCloseHandle(pFile->hShared);
44676 pFile->hShared = NULL;
44681 if( pFile->hShared==NULL ){
44683 pFile->lastErrno = lastErrno;
44684 winLogError(SQLITE_IOERR, pFile->lastErrno,
44688 winceMutexRelease(pFile->hMutex);
44689 osCloseHandle(pFile->hMutex);
44690 pFile->hMutex = NULL;
44696 memset(pFile->shared, 0, sizeof(winceLock));
44699 winceMutexRelease(pFile->hMutex);
44706 static void winceDestroyLock(winFile *pFile){
44707 if (pFile->hMutex){
44709 winceMutexAcquire(pFile->hMutex);
44713 if (pFile->local.nReaders){
44714 pFile->shared->nReaders --;
44716 if (pFile->local.bReserved){
44717 pFile->shared->bReserved = FALSE;
44719 if (pFile->local.bPending){
44720 pFile->shared->bPending = FALSE;
44722 if (pFile->local.bExclusive){
44723 pFile->shared->bExclusive = FALSE;
44727 osUnmapViewOfFile(pFile->shared);
44728 osCloseHandle(pFile->hShared);
44731 winceMutexRelease(pFile->hMutex);
44732 osCloseHandle(pFile->hMutex);
44733 pFile->hMutex = NULL;
44747 winFile *pFile = HANDLE_TO_WINFILE(phFile);
44753 if (!pFile->hMutex) return TRUE;
44754 winceMutexAcquire(pFile->hMutex);
44759 if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){
44760 pFile->shared->bExclusive = TRUE;
44761 pFile->local.bExclusive = TRUE;
44769 if (pFile->shared->bExclusive == 0){
44770 pFile->local.nReaders ++;
44771 if (pFile->local.nReaders == 1){
44772 pFile->shared->nReaders ++;
44782 if (pFile->shared->bPending == 0) {
44783 pFile->shared->bPending = TRUE;
44784 pFile->local.bPending = TRUE;
44792 if (pFile->shared->bReserved == 0) {
44793 pFile->shared->bReserved = TRUE;
44794 pFile->local.bReserved = TRUE;
44799 winceMutexRelease(pFile->hMutex);
44813 winFile *pFile = HANDLE_TO_WINFILE(phFile);
44819 if (!pFile->hMutex) return TRUE;
44820 winceMutexAcquire(pFile->hMutex);
44825 if (pFile->local.bExclusive){
44827 pFile->local.bExclusive = FALSE;
44828 pFile->shared->bExclusive = FALSE;
44833 else if (pFile->local.nReaders){
44836 pFile->local.nReaders --;
44837 if (pFile->local.nReaders == 0)
44839 pFile->shared->nReaders --;
44848 if (pFile->local.bPending){
44849 pFile->local.bPending = FALSE;
44850 pFile->shared->bPending = FALSE;
44857 if (pFile->local.bReserved) {
44858 pFile->local.bReserved = FALSE;
44859 pFile->shared->bReserved = FALSE;
44864 winceMutexRelease(pFile->hMutex);
44952 static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){
44959 OSTRACE(("SEEK file=%p, offset=%lld\n", pFile->h, iOffset));
44971 dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
44975 pFile->lastErrno = lastErrno;
44976 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
44977 "winSeekFile", pFile->zPath);
44978 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
44982 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
44993 bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN);
44996 pFile->lastErrno = osGetLastError();
44997 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
44998 "winSeekFile", pFile->zPath);
44999 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
45003 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
45027 winFile *pFile = (winFile*)id;
45031 assert( pFile->pShm==0 );
45033 assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE );
45035 osGetCurrentProcessId(), pFile, pFile->h));
45038 winUnmapfile(pFile);
45042 rc = osCloseHandle(pFile->h);
45048 winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData;
45050 winceDestroyLock(pFile);
45053 if( pFile->zDeleteOnClose ){
45056 osDeleteFileW(pFile->zDeleteOnClose)==0
45057 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
45062 sqlite3_free(pFile->zDeleteOnClose);
45066 pFile->h = NULL;
45070 osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed"));
45073 "winClose", pFile->zPath);
45090 winFile *pFile = (winFile*)id; /* file handle */
45099 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
45100 pFile->h, pBuf, amt, offset, pFile->locktype));
45105 if( offset<pFile->mmapSize ){
45106 if( offset+amt <= pFile->mmapSize ){
45107 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
45109 osGetCurrentProcessId(), pFile, pFile->h));
45112 int nCopy = (int)(pFile->mmapSize - offset);
45113 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
45122 if( winSeekFile(pFile, offset) ){
45124 osGetCurrentProcessId(), pFile, pFile->h));
45127 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
45132 while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) &&
45137 pFile->lastErrno = lastErrno;
45139 osGetCurrentProcessId(), pFile, pFile->h));
45140 return winLogError(SQLITE_IOERR_READ, pFile->lastErrno,
45141 "winRead", pFile->zPath);
45148 osGetCurrentProcessId(), pFile, pFile->h));
45153 osGetCurrentProcessId(), pFile, pFile->h));
45168 winFile *pFile = (winFile*)id; /* File handle */
45172 assert( pFile );
45177 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
45178 pFile->h, pBuf, amt, offset, pFile->locktype));
45183 if( offset<pFile->mmapSize ){
45184 if( offset+amt <= pFile->mmapSize ){
45185 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
45187 osGetCurrentProcessId(), pFile, pFile->h));
45190 int nCopy = (int)(pFile->mmapSize - offset);
45191 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
45200 rc = winSeekFile(pFile, offset);
45221 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
45223 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
45242 pFile->lastErrno = lastErrno;
45248 if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
45249 || ( pFile->lastErrno==ERROR_DISK_FULL )){
45251 osGetCurrentProcessId(), pFile, pFile->h));
45252 return winLogError(SQLITE_FULL, pFile->lastErrno,
45253 "winWrite1", pFile->zPath);
45256 osGetCurrentProcessId(), pFile, pFile->h));
45257 return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno,
45258 "winWrite2", pFile->zPath);
45263 osGetCurrentProcessId(), pFile, pFile->h));
45271 winFile *pFile = (winFile*)id; /* File handle object */
45276 if( pFile->nFetchOut>0 ){
45298 assert( pFile );
45301 osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype));
45308 if( pFile->szChunk>0 ){
45309 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
45313 if( pFile->pMapRegion ){
45314 oldMmapSize = pFile->mmapSize;
45318 winUnmapfile(pFile);
45322 if( winSeekFile(pFile, nByte) ){
45323 rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
45324 "winTruncate1", pFile->zPath);
45325 }else if( 0==osSetEndOfFile(pFile->h) &&
45327 pFile->lastErrno = lastErrno;
45328 rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
45329 "winTruncate2", pFile->zPath);
45335 winMapfile(pFile, -1);
45337 winMapfile(pFile, oldMmapSize);
45343 osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc)));
45372 winFile *pFile = (winFile*)id;
45377 assert( pFile );
45389 osGetCurrentProcessId(), pFile, pFile->h, flags,
45390 pFile->locktype));
45406 osGetCurrentProcessId(), pFile, pFile->h));
45410 if( pFile->pMapRegion ){
45411 if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
45414 pFile, pFile->pMapRegion));
45416 pFile->lastErrno = osGetLastError();
45419 pFile, pFile->pMapRegion));
45420 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
45421 "winSync1", pFile->zPath);
45425 rc = osFlushFileBuffers(pFile->h);
45429 osGetCurrentProcessId(), pFile, pFile->h));
45432 pFile->lastErrno = osGetLastError();
45434 osGetCurrentProcessId(), pFile, pFile->h));
45435 return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
45436 "winSync2", pFile->zPath);
45445 winFile *pFile = (winFile*)id;
45451 OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize));
45456 if( osGetFileInformationByHandleEx(pFile->h, FileStandardInfo,
45460 pFile->lastErrno = osGetLastError();
45461 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
45462 "winFileSize", pFile->zPath);
45471 lowerBits = osGetFileSize(pFile->h, &upperBits);
45475 pFile->lastErrno = lastErrno;
45476 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
45477 "winFileSize", pFile->zPath);
45482 pFile->h, pSize, *pSize, sqlite3ErrName(rc)));
45522 static int winGetReadLock(winFile *pFile){
45524 OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
45531 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
45533 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
45541 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
45542 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
45543 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
45547 pFile->lastErrno = osGetLastError();
45550 OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
45557 static int winUnlockReadLock(winFile *pFile){
45560 OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
45562 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
45566 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
45570 pFile->lastErrno = lastErrno;
45571 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
45572 "winUnlockReadLock", pFile->zPath);
45574 OSTRACE(("READ-UNLOCK file=%p, result=%d\n", pFile->h, res));
45609 winFile *pFile = (winFile*)id;
45614 pFile->h, pFile->locktype, pFile->sharedLockByte, locktype));
45620 if( pFile->locktype>=locktype ){
45621 OSTRACE(("LOCK-HELD file=%p, rc=SQLITE_OK\n", pFile->h));
45627 if( (pFile->ctrlFlags & WINFILE_RDONLY)!=0 && locktype>=RESERVED_LOCK ){
45633 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
45635 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK );
45641 newLocktype = pFile->locktype;
45642 if( pFile->locktype==NO_LOCK
45643 || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
45646 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
45656 pFile->h, cnt, res));
45658 pFile->lastErrno = lastErrno;
45661 pFile->h, cnt, sqlite3ErrName(rc)));
45675 assert( pFile->locktype==NO_LOCK );
45676 res = winGetReadLock(pFile);
45687 assert( pFile->locktype==SHARED_LOCK );
45688 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
45706 assert( pFile->locktype>=SHARED_LOCK );
45707 res = winUnlockReadLock(pFile);
45708 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
45714 winGetReadLock(pFile);
45722 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
45731 pFile->lastErrno = lastErrno;
45734 pFile->h, locktype, newLocktype));
45736 pFile->locktype = (u8)newLocktype;
45738 pFile->h, pFile->locktype, sqlite3ErrName(rc)));
45749 winFile *pFile = (winFile*)id;
45752 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut));
45755 if( pFile->locktype>=RESERVED_LOCK ){
45757 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
45759 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
45761 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
45764 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res));
45768 pFile->h, pResOut, *pResOut));
45785 winFile *pFile = (winFile*)id;
45787 assert( pFile!=0 );
45790 pFile->h, pFile->locktype, pFile->sharedLockByte, locktype));
45791 type = pFile->locktype;
45793 winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
45794 if( locktype==SHARED_LOCK && !winGetReadLock(pFile) ){
45798 "winUnlock", pFile->zPath);
45802 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
45805 winUnlockReadLock(pFile);
45808 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
45810 pFile->locktype = (u8)locktype;
45812 pFile->h, pFile->locktype, sqlite3ErrName(rc)));
45860 static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){
45862 *pArg = (pFile->ctrlFlags & mask)!=0;
45864 pFile->ctrlFlags &= ~mask;
45866 pFile->ctrlFlags |= mask;
45880 winFile *pFile = (winFile*)id;
45881 OSTRACE(("FCNTL file=%p, op=%d, pArg=%p\n", pFile->h, op, pArg));
45884 *(int*)pArg = pFile->locktype;
45885 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45889 *(int*)pArg = (int)pFile->lastErrno;
45890 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45894 pFile->szChunk = *(int *)pArg;
45895 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45899 if( pFile->szChunk>0 ){
45910 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
45913 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45917 winModeBit(pFile, WINFILE_PERSIST_WAL, (int*)pArg);
45918 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45922 winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
45923 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45927 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
45928 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45943 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45948 *phFile = pFile->h;
45949 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45955 HANDLE hOldFile = pFile->h;
45956 pFile->h = *phFile;
45959 hOldFile, pFile->h));
45965 int rc = winGetTempname(pFile->pVfs, &zTFile);
45969 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
45987 *(i64*)pArg = pFile->mmapSizeMax;
45988 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
45989 pFile->mmapSizeMax = newLimit;
45990 if( pFile->mmapSize>0 ){
45991 winUnmapfile(pFile);
45992 rc = winMapfile(pFile, -1);
45995 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
46000 OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
46155 winShmNode *pFile, /* Apply locks to this open shared-memory segment */
46163 assert( pFile->nRef==0 || sqlite3_mutex_held(pFile->mutex) );
46166 pFile->hFile.h, lockType, ofst, nByte));
46170 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
46175 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
46181 pFile->lastErrno = osGetLastError();
46186 pFile->hFile.h, (lockType == WINSHM_UNLCK) ? "winUnlockFile" :
46187 "winLockFile", pFile->lastErrno, sqlite3ErrName(rc)));
46723 static int winUnmapfile(winFile *pFile){
46724 assert( pFile!=0 );
46727 osGetCurrentProcessId(), pFile, pFile->hMap, pFile->pMapRegion,
46728 pFile->mmapSize, pFile->mmapSizeMax));
46729 if( pFile->pMapRegion ){
46730 if( !osUnmapViewOfFile(pFile->pMapRegion) ){
46731 pFile->lastErrno = osGetLastError();
46733 "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), pFile,
46734 pFile->pMapRegion));
46735 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
46736 "winUnmapfile1", pFile->zPath);
46738 pFile->pMapRegion = 0;
46739 pFile->mmapSize = 0;
46741 if( pFile->hMap!=NULL ){
46742 if( !osCloseHandle(pFile->hMap) ){
46743 pFile->lastErrno = osGetLastError();
46745 osGetCurrentProcessId(), pFile, pFile->hMap));
46746 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
46747 "winUnmapfile2", pFile->zPath);
46749 pFile->hMap = NULL;
46752 osGetCurrentProcessId(), pFile));
47371 winFile *pFile = (winFile*)id;
47429 assert( pFile!=0 );
47430 memset(pFile, 0, sizeof(winFile));
47431 pFile->h = INVALID_HANDLE_VALUE;
47599 pFile->lastErrno = lastErrno;
47600 winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name);
47623 && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
47633 pFile->zDeleteOnClose = zConverted;
47642 pFile->pVfs = pVfs;
47643 pFile->h = h;
47645 pFile->ctrlFlags |= WINFILE_RDONLY;
47650 pFile->ctrlFlags |= WINFILE_PSOW;
47652 pFile->lastErrno = NO_ERROR;
47653 pFile->zPath = zName;
47655 pFile->hMap = NULL;
47656 pFile->pMapRegion = 0;
47657 pFile->mmapSize = 0;
47658 pFile->mmapSizeMax = sqlite3GlobalConfig.szMmap;
48734 static int memdbClose(sqlite3_file *pFile){
48735 MemStore *p = ((MemFile*)pFile)->pStore;
48777 sqlite3_file *pFile,
48782 MemStore *p = ((MemFile*)pFile)->pStore;
48819 sqlite3_file *pFile,
48824 MemStore *p = ((MemFile*)pFile)->pStore;
48855 static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
48856 MemStore *p = ((MemFile*)pFile)->pStore;
48872 static int memdbSync(sqlite3_file *pFile, int flags){
48873 UNUSED_PARAMETER(pFile);
48881 static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
48882 MemStore *p = ((MemFile*)pFile)->pStore;
48892 static int memdbLock(sqlite3_file *pFile, int eLock){
48893 MemFile *pThis = (MemFile*)pFile;
48936 static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
48946 static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
48947 MemStore *p = ((MemFile*)pFile)->pStore;
48975 static int memdbSectorSize(sqlite3_file *pFile){
48983 static int memdbDeviceCharacteristics(sqlite3_file *pFile){
48984 UNUSED_PARAMETER(pFile);
48993 sqlite3_file *pFile,
48998 MemStore *p = ((MemFile*)pFile)->pStore;
49011 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
49012 MemStore *p = ((MemFile*)pFile)->pStore;
49031 MemFile *pFile = (MemFile*)pFd;
49036 memset(pFile, 0, sizeof(*pFile));
49094 pFile->pStore = p;
55298 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *pFile){
55299 int iRet = sqlite3OsSectorSize(pFile);
56276 sqlite3_file *pFile, /* Write the file descriptor here */
56287 rc = sqlite3OsOpen(pPager->pVfs, 0, pFile, vfsFlags, 0);
56288 assert( rc!=SQLITE_OK || isOpen(pFile) );
68202 sqlite3_file *pFile;
68212 pFile = sqlite3PagerFile(pBt->pPager);
68213 if( pFile->pMethods ){
68214 sqlite3OsFileControlHint(pFile, SQLITE_FCNTL_PDB, (void*)&pBt->db);
76749 static int backupTruncateFile(sqlite3_file *pFile, i64 iSize){
76751 int rc = sqlite3OsFileSize(pFile, &iCurrent);
76753 rc = sqlite3OsTruncate(pFile, iSize);
76928 sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
76934 assert( pFile );
76974 rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
76979 rc = backupTruncateFile(pFile, iSize);
96306 static int vdbeSorterMapFile(SortSubtask *pTask, SorterFile *pFile, u8 **pp){
96308 if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
96309 sqlite3_file *pFd = pFile->pFd;
96311 rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp);
96326 SorterFile *pFile, /* Sorter file to read from */
96339 pReadr->iEof = pFile->iEof;
96340 pReadr->pFd = pFile->pFd;
96342 rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap);
96419 SorterFile *pFile, /* Sorter file to read from */
96426 assert( pFile->iEof>iStart );
96431 rc = vdbePmaReaderSeek(pTask, pReadr, pFile, iStart);
130557 sqlite3_file *pFile = sqlite3PagerFile(pPager);
130558 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
130563 sqlite3_file *pFile = sqlite3PagerFile(pPager);
130566 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
130569 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
206332 static int rbuVfsClose(sqlite3_file *pFile){
206333 rbu_file *p = (rbu_file*)pFile;
206392 sqlite3_file *pFile,
206397 rbu_file *p = (rbu_file*)pFile;
206458 sqlite3_file *pFile,
206463 rbu_file *p = (rbu_file*)pFile;
206500 static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
206501 rbu_file *p = (rbu_file*)pFile;
206512 static int rbuVfsSync(sqlite3_file *pFile, int flags){
206513 rbu_file *p = (rbu_file *)pFile;
206526 static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
206527 rbu_file *p = (rbu_file *)pFile;
206547 static int rbuVfsLock(sqlite3_file *pFile, int eLock){
206548 rbu_file *p = (rbu_file*)pFile;
206569 static int rbuVfsUnlock(sqlite3_file *pFile, int eLock){
206570 rbu_file *p = (rbu_file *)pFile;
206577 static int rbuVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
206578 rbu_file *p = (rbu_file *)pFile;
206585 static int rbuVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
206586 rbu_file *p = (rbu_file *)pFile;
206641 static int rbuVfsSectorSize(sqlite3_file *pFile){
206642 rbu_file *p = (rbu_file *)pFile;
206649 static int rbuVfsDeviceCharacteristics(sqlite3_file *pFile){
206650 rbu_file *p = (rbu_file *)pFile;
206657 static int rbuVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
206658 rbu_file *p = (rbu_file*)pFile;
206696 sqlite3_file *pFile,
206702 rbu_file *p = (rbu_file*)pFile;
206753 static void rbuVfsShmBarrier(sqlite3_file *pFile){
206754 rbu_file *p = (rbu_file *)pFile;
206761 static int rbuVfsShmUnmap(sqlite3_file *pFile, int delFlag){
206762 rbu_file *p = (rbu_file*)pFile;
206783 sqlite3_file *pFile,
206809 rbu_file *pFd = (rbu_file *)pFile;
206864 pFile->pMethods = &rbuvfs_io_methods;