• Home
  • Raw
  • Download

Lines Matching refs:pFile

24228   sqlite3_file *pFile,
24238 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
24239 assert( rc==SQLITE_OK || pFile->pMethods==0 );
24325 sqlite3_file *pFile;
24326 pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile);
24327 if( pFile ){
24328 rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags);
24330 sqlite3_free(pFile);
24333 *ppFile = pFile;
24342 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
24343 assert( pFile );
24344 sqlite3OsClose(pFile);
24345 sqlite3_free(pFile);
35528 int unixFileMutexHeld(unixFile *pFile){
35529 assert( pFile->pInode );
35530 return sqlite3_mutex_held(pFile->pInode->pLockMutex);
35532 int unixFileMutexNotheld(unixFile *pFile){
35533 assert( pFile->pInode );
35534 return sqlite3_mutex_notheld(pFile->pInode->pLockMutex);
35620 static void robust_close(unixFile *pFile, int h, int lineno){
35623 pFile ? pFile->zPath : 0, lineno);
35631 static void storeLastErrno(unixFile *pFile, int error){
35632 pFile->lastErrno = error;
35638 static void closePendingFds(unixFile *pFile){
35639 unixInodeInfo *pInode = pFile->pInode;
35642 assert( unixFileMutexHeld(pFile) );
35645 robust_close(pFile, p->fd, __LINE__);
35657 static void releaseInodeInfo(unixFile *pFile){
35658 unixInodeInfo *pInode = pFile->pInode;
35660 assert( unixFileMutexNotheld(pFile) );
35666 closePendingFds(pFile);
35695 unixFile *pFile, /* Unix file with file desc used in the key */
35709 fd = pFile->h;
35712 storeLastErrno(pFile, errno);
35714 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
35730 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
35733 storeLastErrno(pFile, errno);
35738 storeLastErrno(pFile, errno);
35747 fileId.pId = pFile->pId;
35786 static int fileHasMoved(unixFile *pFile){
35788 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
35791 return pFile->pInode!=0 &&
35792 (osStat(pFile->zPath, &buf)!=0
35793 || (u64)buf.st_ino!=pFile->pInode->fileId.ino);
35807 static void verifyDbFile(unixFile *pFile){
35812 if( pFile->ctrlFlags & UNIXFILE_NOLOCK ) return;
35814 rc = osFstat(pFile->h, &buf);
35816 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
35820 sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
35824 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
35827 if( fileHasMoved(pFile) ){
35828 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
35843 unixFile *pFile = (unixFile*)id;
35847 assert( pFile );
35848 assert( pFile->eFileLock<=SHARED_LOCK );
35849 sqlite3_mutex_enter(pFile->pInode->pLockMutex);
35852 if( pFile->pInode->eFileLock>SHARED_LOCK ){
35859 if( !reserved && !pFile->pInode->bProcessLock ){
35865 if( osFcntl(pFile->h, F_GETLK, &lock) ){
35867 storeLastErrno(pFile, errno);
35874 sqlite3_mutex_leave(pFile->pInode->pLockMutex);
35875 OSTRACE(("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved));
35903 unixFile *pFile /* Structure holding timeout value */
35905 int tm = pFile->iBusyTimeout;
35941 static int unixFileLock(unixFile *pFile, struct flock *pLock){
35943 unixInodeInfo *pInode = pFile->pInode;
35946 if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){
35954 rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile);
35962 rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile);
36032 unixFile *pFile = (unixFile*)id;
36037 assert( pFile );
36038 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
36039 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
36040 azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared,
36047 if( pFile->eFileLock>=eFileLock ){
36048 OSTRACE(("LOCK %d %s ok (already held) (unix)\n", pFile->h,
36058 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
36060 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
36064 pInode = pFile->pInode;
36070 if( (pFile->eFileLock!=pInode->eFileLock &&
36084 assert( pFile->eFileLock==0 );
36086 pFile->eFileLock = SHARED_LOCK;
36100 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
36104 if( unixFileLock(pFile, &lock) ){
36108 storeLastErrno(pFile, tErrno);
36126 if( unixFileLock(pFile, &lock) ){
36135 if( unixFileLock(pFile, &lock) && rc==SQLITE_OK ){
36143 storeLastErrno(pFile, tErrno);
36147 pFile->eFileLock = SHARED_LOCK;
36160 assert( 0!=pFile->eFileLock );
36172 if( unixFileLock(pFile, &lock) ){
36176 storeLastErrno(pFile, tErrno);
36189 && pFile->eFileLock<=SHARED_LOCK
36192 pFile->transCntrChng = 0;
36193 pFile->dbUpdate = 0;
36194 pFile->inNormalWrite = 1;
36200 pFile->eFileLock = eFileLock;
36203 pFile->eFileLock = PENDING_LOCK;
36209 OSTRACE(("LOCK %d %s %s (unix)\n", pFile->h, azFileLock(eFileLock),
36218 static void setPendingFd(unixFile *pFile){
36219 unixInodeInfo *pInode = pFile->pInode;
36220 UnixUnusedFd *p = pFile->pPreallocatedUnused;
36221 assert( unixFileMutexHeld(pFile) );
36224 pFile->h = -1;
36225 pFile->pPreallocatedUnused = 0;
36242 unixFile *pFile = (unixFile*)id;
36247 assert( pFile );
36248 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
36249 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
36253 if( pFile->eFileLock<=eFileLock ){
36256 pInode = pFile->pInode;
36259 if( pFile->eFileLock>SHARED_LOCK ){
36260 assert( pInode->eFileLock==pFile->eFileLock );
36271 pFile->inNormalWrite = 0;
36297 if( unixFileLock(pFile, &lock)==(-1) ){
36300 storeLastErrno(pFile, tErrno);
36307 if( unixFileLock(pFile, &lock)==(-1) ){
36311 storeLastErrno(pFile, tErrno);
36319 if( unixFileLock(pFile, &lock)==(-1) ){
36322 storeLastErrno(pFile, tErrno);
36332 if( unixFileLock(pFile, &lock) ){
36340 storeLastErrno(pFile, errno);
36349 if( unixFileLock(pFile, &lock)==0 ){
36353 storeLastErrno(pFile, errno);
36367 if( unixFileLock(pFile, &lock)==0 ){
36371 storeLastErrno(pFile, errno);
36373 pFile->eFileLock = NO_LOCK;
36383 if( pInode->nLock==0 ) closePendingFds(pFile);
36389 pFile->eFileLock = eFileLock;
36424 unixFile *pFile = (unixFile*)id;
36426 unixUnmapfile(pFile);
36428 if( pFile->h>=0 ){
36429 robust_close(pFile, pFile->h, __LINE__);
36430 pFile->h = -1;
36433 if( pFile->pId ){
36434 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
36435 osUnlink(pFile->pId->zCanonicalName);
36437 vxworksReleaseFileId(pFile->pId);
36438 pFile->pId = 0;
36442 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
36443 osUnlink(pFile->zPath);
36444 sqlite3_free(*(char**)&pFile->zPath);
36445 pFile->zPath = 0;
36448 OSTRACE(("CLOSE %-3d\n", pFile->h));
36450 sqlite3_free(pFile->pPreallocatedUnused);
36451 memset(pFile, 0, sizeof(unixFile));
36460 unixFile *pFile = (unixFile *)id;
36461 unixInodeInfo *pInode = pFile->pInode;
36464 verifyDbFile(pFile);
36466 assert( unixFileMutexNotheld(pFile) );
36472 assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 );
36480 setPendingFd(pFile);
36483 releaseInodeInfo(pFile);
36484 assert( pFile->pShm==0 );
36575 unixFile *pFile = (unixFile*)id;
36579 assert( pFile );
36580 reserved = osAccess((const char*)pFile->lockingContext, 0)==0;
36581 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
36614 unixFile *pFile = (unixFile*)id;
36615 char *zLockFile = (char *)pFile->lockingContext;
36622 if( pFile->eFileLock > NO_LOCK ){
36623 pFile->eFileLock = eFileLock;
36643 storeLastErrno(pFile, tErrno);
36650 pFile->eFileLock = eFileLock;
36664 unixFile *pFile = (unixFile*)id;
36665 char *zLockFile = (char *)pFile->lockingContext;
36668 assert( pFile );
36669 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
36670 pFile->eFileLock, osGetpid(0)));
36674 if( pFile->eFileLock==eFileLock ){
36682 pFile->eFileLock = SHARED_LOCK;
36695 storeLastErrno(pFile, tErrno);
36699 pFile->eFileLock = NO_LOCK;
36707 unixFile *pFile = (unixFile*)id;
36710 sqlite3_free(pFile->lockingContext);
36755 unixFile *pFile = (unixFile*)id;
36759 assert( pFile );
36762 if( pFile->eFileLock>SHARED_LOCK ){
36769 int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
36772 lrc = robust_flock(pFile->h, LOCK_UN);
36777 storeLastErrno(pFile, tErrno);
36786 storeLastErrno(pFile, tErrno);
36791 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
36834 unixFile *pFile = (unixFile*)id;
36836 assert( pFile );
36840 if (pFile->eFileLock > NO_LOCK) {
36841 pFile->eFileLock = eFileLock;
36847 if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
36852 storeLastErrno(pFile, tErrno);
36856 pFile->eFileLock = eFileLock;
36858 OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock),
36877 unixFile *pFile = (unixFile*)id;
36879 assert( pFile );
36880 OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock,
36881 pFile->eFileLock, osGetpid(0)));
36885 if( pFile->eFileLock==eFileLock ){
36891 pFile->eFileLock = eFileLock;
36896 if( robust_flock(pFile->h, LOCK_UN) ){
36902 pFile->eFileLock = NO_LOCK;
36942 unixFile *pFile = (unixFile*)id;
36946 assert( pFile );
36949 if( pFile->eFileLock>SHARED_LOCK ){
36955 sem_t *pSem = pFile->pInode->pSem;
36961 storeLastErrno(pFile, tErrno);
36964 reserved = (pFile->eFileLock < SHARED_LOCK);
36971 OSTRACE(("TEST WR-LOCK %d %d %d (sem)\n", pFile->h, rc, reserved));
37007 unixFile *pFile = (unixFile*)id;
37008 sem_t *pSem = pFile->pInode->pSem;
37013 if (pFile->eFileLock > NO_LOCK) {
37014 pFile->eFileLock = eFileLock;
37026 pFile->eFileLock = eFileLock;
37040 unixFile *pFile = (unixFile*)id;
37041 sem_t *pSem = pFile->pInode->pSem;
37043 assert( pFile );
37045 OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
37046 pFile->eFileLock, osGetpid(0)));
37050 if( pFile->eFileLock==eFileLock ){
37056 pFile->eFileLock = eFileLock;
37065 storeLastErrno(pFile, tErrno);
37069 pFile->eFileLock = NO_LOCK;
37078 unixFile *pFile = (unixFile*)id;
37080 assert( pFile );
37081 assert( unixFileMutexNotheld(pFile) );
37083 releaseInodeInfo(pFile);
37138 unixFile *pFile, /* Open file descriptor on path */
37150 pb.fd = pFile->h;
37153 (setLockFlag?"ON":"OFF"), pFile->h, (pb.fd==-1?"[testval-1]":""),
37168 storeLastErrno(pFile, tErrno);
37185 unixFile *pFile = (unixFile*)id;
37190 assert( pFile );
37191 context = (afpLockingContext *) pFile->lockingContext;
37196 sqlite3_mutex_enter(pFile->pInode->pLockMutex);
37198 if( pFile->pInode->eFileLock>SHARED_LOCK ){
37206 int lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1);
37210 lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
37220 sqlite3_mutex_leave(pFile->pInode->pLockMutex);
37221 OSTRACE(("TEST WR-LOCK %d %d %d (afp)\n", pFile->h, rc, reserved));
37253 unixFile *pFile = (unixFile*)id;
37254 unixInodeInfo *pInode = pFile->pInode;
37255 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
37257 assert( pFile );
37258 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h,
37259 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
37266 if( pFile->eFileLock>=eFileLock ){
37267 OSTRACE(("LOCK %d %s ok (already held) (afp)\n", pFile->h,
37277 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
37279 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
37283 pInode = pFile->pInode;
37289 if( (pFile->eFileLock!=pInode->eFileLock &&
37303 assert( pFile->eFileLock==0 );
37305 pFile->eFileLock = SHARED_LOCK;
37316 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
37319 failed = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 1);
37341 lrc1 = afpSetLock(context->dbPath, pFile,
37344 lrc1Errno = pFile->lastErrno;
37347 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
37350 storeLastErrno(pFile, lrc1Errno);
37359 pFile->eFileLock = SHARED_LOCK;
37373 assert( 0!=pFile->eFileLock );
37374 if (eFileLock >= RESERVED_LOCK && pFile->eFileLock < RESERVED_LOCK) {
37376 failed = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1);
37387 if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST +
37391 failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST,
37393 if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
37412 pFile->eFileLock = eFileLock;
37415 pFile->eFileLock = PENDING_LOCK;
37421 OSTRACE(("LOCK %d %s %s (afp)\n", pFile->h, azFileLock(eFileLock),
37435 unixFile *pFile = (unixFile*)id;
37437 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
37440 int h = pFile->h;
37443 assert( pFile );
37444 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
37445 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
37449 if( pFile->eFileLock<=eFileLock ){
37452 pInode = pFile->pInode;
37455 if( pFile->eFileLock>SHARED_LOCK ){
37456 assert( pInode->eFileLock==pFile->eFileLock );
37470 assert( pFile->inNormalWrite==0
37471 || pFile->dbUpdate==0
37472 || pFile->transCntrChng==1 );
37473 pFile->inNormalWrite = 0;
37476 if( pFile->eFileLock==EXCLUSIVE_LOCK ){
37477 rc = afpSetLock(context->dbPath, pFile, SHARED_FIRST, SHARED_SIZE, 0);
37481 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 1);
37486 if( rc==SQLITE_OK && pFile->eFileLock>=PENDING_LOCK ){
37487 rc = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
37489 if( rc==SQLITE_OK && pFile->eFileLock>=RESERVED_LOCK && context->reserved ){
37490 rc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
37512 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0);
37516 pFile->eFileLock = NO_LOCK;
37522 if( pInode->nLock==0 ) closePendingFds(pFile);
37528 pFile->eFileLock = eFileLock;
37538 unixFile *pFile = (unixFile*)id;
37541 assert( unixFileMutexNotheld(pFile) );
37543 if( pFile->pInode ){
37544 unixInodeInfo *pInode = pFile->pInode;
37552 setPendingFd(pFile);
37556 releaseInodeInfo(pFile);
37557 sqlite3_free(pFile->lockingContext);
37675 unixFile *pFile = (unixFile *)id;
37684 assert( pFile->pPreallocatedUnused==0
37693 if( offset<pFile->mmapSize ){
37694 if( offset+amt <= pFile->mmapSize ){
37695 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
37698 int nCopy = pFile->mmapSize - offset;
37699 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
37707 got = seekAndRead(pFile, offset, pBuf, amt);
37718 switch( pFile->lastErrno ){
37731 storeLastErrno(pFile, 0); /* not a system error */
37806 unixFile *pFile = (unixFile*)id;
37814 assert( pFile->pPreallocatedUnused==0
37827 if( pFile->inNormalWrite ){
37828 pFile->dbUpdate = 1; /* The database has been modified */
37833 rc = seekAndRead(pFile, 24, oldCntr, 4);
37836 pFile->transCntrChng = 1; /* The transaction counter has changed */
37845 if( offset<pFile->mmapSize ){
37846 if( offset+amt <= pFile->mmapSize ){
37847 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
37850 int nCopy = pFile->mmapSize - offset;
37851 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
37859 while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
37868 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
37872 storeLastErrno(pFile, 0); /* not a system error */
38070 unixFile *pFile = (unixFile*)id;
38085 assert( pFile );
38086 OSTRACE(("SYNC %-3d\n", pFile->h));
38087 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
38090 storeLastErrno(pFile, errno);
38091 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
38098 if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
38100 OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath,
38102 rc = osOpenDirectory(pFile->zPath, &dirfd);
38105 robust_close(pFile, dirfd, __LINE__);
38110 pFile->ctrlFlags &= ~UNIXFILE_DIRSYNC;
38119 unixFile *pFile = (unixFile *)id;
38121 assert( pFile );
38129 if( pFile->szChunk>0 ){
38130 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
38133 rc = robust_ftruncate(pFile->h, nByte);
38135 storeLastErrno(pFile, errno);
38136 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
38146 if( pFile->inNormalWrite && nByte==0 ){
38147 pFile->transCntrChng = 1;
38156 if( nByte<pFile->mmapSize ){
38157 pFile->mmapSize = nByte;
38206 static int fcntlSizeHint(unixFile *pFile, i64 nByte){
38207 if( pFile->szChunk>0 ){
38211 if( osFstat(pFile->h, &buf) ){
38215 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
38224 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
38244 nWrite = seekAndWrite(pFile, iWrite, "", 1);
38252 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
38254 if( pFile->szChunk<=0 ){
38255 if( robust_ftruncate(pFile->h, nByte) ){
38256 storeLastErrno(pFile, errno);
38257 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
38261 rc = unixMapfile(pFile, nByte);
38275 static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
38277 *pArg = (pFile->ctrlFlags & mask)!=0;
38279 pFile->ctrlFlags &= ~mask;
38281 pFile->ctrlFlags |= mask;
38295 unixFile *pFile = (unixFile*)id;
38299 int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE);
38303 int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE);
38307 int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE);
38313 *(int*)pArg = pFile->eFileLock;
38317 *(int*)pArg = pFile->lastErrno;
38321 pFile->szChunk = *(int *)pArg;
38327 rc = fcntlSizeHint(pFile, *(i64 *)pArg);
38332 unixModeBit(pFile, UNIXFILE_PERSIST_WAL, (int*)pArg);
38336 unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg);
38340 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
38344 char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
38346 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
38352 *(int*)pArg = fileHasMoved(pFile);
38357 int iOld = pFile->iBusyTimeout;
38358 pFile->iBusyTimeout = *(int*)pArg;
38378 *(i64*)pArg = pFile->mmapSizeMax;
38379 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
38380 pFile->mmapSizeMax = newLimit;
38381 if( pFile->mmapSize>0 ){
38382 unixUnmapfile(pFile);
38383 rc = unixMapfile(pFile, -1);
38454 static void setDeviceCharacteristics(unixFile *pFile){
38455 if( pFile->sectorSize == 0 ){
38459 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
38460 pFile->deviceCharacteristics = 0;
38461 if( fstatvfs(pFile->h, &fsInfo) == -1 ) {
38466 pFile->sectorSize = fsInfo.f_bsize;
38467 pFile->deviceCharacteristics =
38475 pFile->sectorSize = fsInfo.f_bsize;
38476 pFile->deviceCharacteristics =
38478 (pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) |
38485 pFile->sectorSize = fsInfo.f_bsize;
38486 pFile->deviceCharacteristics =
38494 pFile->sectorSize = fsInfo.f_bsize;
38495 pFile->deviceCharacteristics =
38497 ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 |
38502 pFile->sectorSize = fsInfo.f_bsize;
38503 pFile->deviceCharacteristics =
38505 ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 |
38510 pFile->deviceCharacteristics =
38519 if( pFile->sectorSize % 512 != 0 ){
38520 pFile->deviceCharacteristics = 0;
38521 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
38668 static int unixFcntlExternalReader(unixFile *pFile, int *piOut){
38671 if( pFile->pShm){
38672 unixShmNode *pShmNode = pFile->pShm->pShmNode;
38701 unixFile *pFile, /* Open connection to the WAL file */
38711 pShmNode = pFile->pInode->pShmNode;
38728 res = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile);
38731 rc = (pFile->iBusyTimeout ? SQLITE_BUSY_TIMEOUT : SQLITE_BUSY);
40401 sqlite3_file *pFile, /* The file descriptor to be filled in */
40405 unixFile *p = (unixFile *)pFile;
40612 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
40615 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
40643 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
40645 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
40651 unixClose(pFile);
40663 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
41537 static int proxyBreakConchLock(unixFile *pFile, uuid_t myHostID){
41538 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41579 robust_close(pFile, conchFile->h, __LINE__);
41587 robust_close(pFile, fd, __LINE__);
41597 static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
41598 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41617 storeLastErrno(pFile, errno);
41637 storeLastErrno(pFile, errno);
41654 if( 0==proxyBreakConchLock(pFile, myHostID) ){
41675 static int proxyTakeConch(unixFile *pFile){
41676 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41700 storeLastErrno(pFile, pError);
41703 rc = proxyConchLock(pFile, myHostID, SHARED_LOCK);
41711 storeLastErrno(pFile, conchFile->lastErrno);
41781 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
41784 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
41807 int err = osFstat(pFile->h, &buf);
41836 OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h));
41837 if( rc==SQLITE_OK && pFile->openFlags ){
41839 if( pFile->h>=0 ){
41840 robust_close(pFile, pFile->h, __LINE__);
41842 pFile->h = -1;
41843 fd = robust_open(pCtx->dbPath, pFile->openFlags, 0);
41846 pFile->h = fd;
41897 static int proxyReleaseConch(unixFile *pFile){
41902 pCtx = (proxyLockingContext *)pFile->lockingContext;
41964 static int switchLockProxyPath(unixFile *pFile, const char *path) {
41965 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
41969 if( pFile->eFileLock!=NO_LOCK ){
42000 static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
42002 if( pFile->pMethod == &afpIoMethods ){
42005 assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
42006 strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath,
42010 if( pFile->pMethod == &dotlockIoMethods ){
42013 int len = strlen((char *)pFile->lockingContext) - strlen(DOTLOCK_SUFFIX);
42014 memcpy(dbPath, (char *)pFile->lockingContext, len + 1);
42017 assert( strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
42018 strlcpy(dbPath, (char *)pFile->lockingContext, MAXPATHLEN);
42031 static int proxyTransformUnixFile(unixFile *pFile, const char *path) {
42037 if( pFile->eFileLock!=NO_LOCK ){
42040 proxyGetDbPathForUnixFile(pFile, dbPath);
42047 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
42059 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){
42095 pCtx->oldLockingContext = pFile->lockingContext;
42096 pFile->lockingContext = pCtx;
42097 pCtx->pOldMethod = pFile->pMethod;
42098 pFile->pMethod = &proxyIoMethods;
42108 OSTRACE(("TRANSPROXY %d %s\n", pFile->h,
42121 unixFile *pFile = (unixFile*)id;
42122 if( pFile->pMethod == &proxyIoMethods ){
42123 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
42124 proxyTakeConch(pFile);
42136 unixFile *pFile = (unixFile*)id;
42138 int isProxyStyle = (pFile->pMethod == &proxyIoMethods);
42154 (proxyLockingContext*)pFile->lockingContext;
42161 rc = switchLockProxyPath(pFile, proxyPath);
42165 rc = proxyTransformUnixFile(pFile, proxyPath);
42192 unixFile *pFile = (unixFile*)id;
42193 int rc = proxyTakeConch(pFile);
42195 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
42231 unixFile *pFile = (unixFile*)id;
42232 int rc = proxyTakeConch(pFile);
42234 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
42238 pFile->eFileLock = proxy->eFileLock;
42255 unixFile *pFile = (unixFile*)id;
42256 int rc = proxyTakeConch(pFile);
42258 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
42262 pFile->eFileLock = proxy->eFileLock;
42275 unixFile *pFile = (unixFile*)id;
42276 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
42291 rc = proxyReleaseConch(pFile);
42302 pFile->lockingContext = pCtx->oldLockingContext;
42303 pFile->pMethod = pCtx->pOldMethod;
42305 return pFile->pMethod->xClose(id);
44709 static int winceCreateLock(const char *zFilename, winFile *pFile){
44723 memset(&pFile->local, 0, sizeof(pFile->local));
44733 pFile->hMutex = osCreateMutexW(NULL, FALSE, zName);
44734 if (!pFile->hMutex){
44735 pFile->lastErrno = osGetLastError();
44737 return winLogError(SQLITE_IOERR, pFile->lastErrno,
44742 winceMutexAcquire(pFile->hMutex);
44749 pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
44763 if( pFile->hShared ){
44764 pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared,
44767 if( !pFile->shared ){
44768 pFile->lastErrno = osGetLastError();
44769 winLogError(SQLITE_IOERR, pFile->lastErrno,
44772 osCloseHandle(pFile->hShared);
44773 pFile->hShared = NULL;
44778 if( pFile->hShared==NULL ){
44780 pFile->lastErrno = lastErrno;
44781 winLogError(SQLITE_IOERR, pFile->lastErrno,
44785 winceMutexRelease(pFile->hMutex);
44786 osCloseHandle(pFile->hMutex);
44787 pFile->hMutex = NULL;
44793 memset(pFile->shared, 0, sizeof(winceLock));
44796 winceMutexRelease(pFile->hMutex);
44803 static void winceDestroyLock(winFile *pFile){
44804 if (pFile->hMutex){
44806 winceMutexAcquire(pFile->hMutex);
44810 if (pFile->local.nReaders){
44811 pFile->shared->nReaders --;
44813 if (pFile->local.bReserved){
44814 pFile->shared->bReserved = FALSE;
44816 if (pFile->local.bPending){
44817 pFile->shared->bPending = FALSE;
44819 if (pFile->local.bExclusive){
44820 pFile->shared->bExclusive = FALSE;
44824 osUnmapViewOfFile(pFile->shared);
44825 osCloseHandle(pFile->hShared);
44828 winceMutexRelease(pFile->hMutex);
44829 osCloseHandle(pFile->hMutex);
44830 pFile->hMutex = NULL;
44844 winFile *pFile = HANDLE_TO_WINFILE(phFile);
44850 if (!pFile->hMutex) return TRUE;
44851 winceMutexAcquire(pFile->hMutex);
44856 if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){
44857 pFile->shared->bExclusive = TRUE;
44858 pFile->local.bExclusive = TRUE;
44866 if (pFile->shared->bExclusive == 0){
44867 pFile->local.nReaders ++;
44868 if (pFile->local.nReaders == 1){
44869 pFile->shared->nReaders ++;
44879 if (pFile->shared->bPending == 0) {
44880 pFile->shared->bPending = TRUE;
44881 pFile->local.bPending = TRUE;
44889 if (pFile->shared->bReserved == 0) {
44890 pFile->shared->bReserved = TRUE;
44891 pFile->local.bReserved = TRUE;
44896 winceMutexRelease(pFile->hMutex);
44910 winFile *pFile = HANDLE_TO_WINFILE(phFile);
44916 if (!pFile->hMutex) return TRUE;
44917 winceMutexAcquire(pFile->hMutex);
44922 if (pFile->local.bExclusive){
44924 pFile->local.bExclusive = FALSE;
44925 pFile->shared->bExclusive = FALSE;
44930 else if (pFile->local.nReaders){
44933 pFile->local.nReaders --;
44934 if (pFile->local.nReaders == 0)
44936 pFile->shared->nReaders --;
44945 if (pFile->local.bPending){
44946 pFile->local.bPending = FALSE;
44947 pFile->shared->bPending = FALSE;
44954 if (pFile->local.bReserved) {
44955 pFile->local.bReserved = FALSE;
44956 pFile->shared->bReserved = FALSE;
44961 winceMutexRelease(pFile->hMutex);
45049 static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){
45056 OSTRACE(("SEEK file=%p, offset=%lld\n", pFile->h, iOffset));
45068 dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
45072 pFile->lastErrno = lastErrno;
45073 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
45074 "winSeekFile", pFile->zPath);
45075 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
45079 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
45090 bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN);
45093 pFile->lastErrno = osGetLastError();
45094 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
45095 "winSeekFile", pFile->zPath);
45096 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
45100 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
45124 winFile *pFile = (winFile*)id;
45128 assert( pFile->pShm==0 );
45130 assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE );
45132 osGetCurrentProcessId(), pFile, pFile->h));
45135 winUnmapfile(pFile);
45139 rc = osCloseHandle(pFile->h);
45145 winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData;
45147 winceDestroyLock(pFile);
45150 if( pFile->zDeleteOnClose ){
45153 osDeleteFileW(pFile->zDeleteOnClose)==0
45154 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
45159 sqlite3_free(pFile->zDeleteOnClose);
45163 pFile->h = NULL;
45167 osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed"));
45170 "winClose", pFile->zPath);
45187 winFile *pFile = (winFile*)id; /* file handle */
45196 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
45197 pFile->h, pBuf, amt, offset, pFile->locktype));
45202 if( offset<pFile->mmapSize ){
45203 if( offset+amt <= pFile->mmapSize ){
45204 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
45206 osGetCurrentProcessId(), pFile, pFile->h));
45209 int nCopy = (int)(pFile->mmapSize - offset);
45210 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
45219 if( winSeekFile(pFile, offset) ){
45221 osGetCurrentProcessId(), pFile, pFile->h));
45224 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
45229 while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) &&
45234 pFile->lastErrno = lastErrno;
45236 osGetCurrentProcessId(), pFile, pFile->h));
45237 return winLogError(SQLITE_IOERR_READ, pFile->lastErrno,
45238 "winRead", pFile->zPath);
45245 osGetCurrentProcessId(), pFile, pFile->h));
45250 osGetCurrentProcessId(), pFile, pFile->h));
45265 winFile *pFile = (winFile*)id; /* File handle */
45269 assert( pFile );
45274 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
45275 pFile->h, pBuf, amt, offset, pFile->locktype));
45280 if( offset<pFile->mmapSize ){
45281 if( offset+amt <= pFile->mmapSize ){
45282 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
45284 osGetCurrentProcessId(), pFile, pFile->h));
45287 int nCopy = (int)(pFile->mmapSize - offset);
45288 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
45297 rc = winSeekFile(pFile, offset);
45318 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
45320 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
45339 pFile->lastErrno = lastErrno;
45345 if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
45346 || ( pFile->lastErrno==ERROR_DISK_FULL )){
45348 osGetCurrentProcessId(), pFile, pFile->h));
45349 return winLogError(SQLITE_FULL, pFile->lastErrno,
45350 "winWrite1", pFile->zPath);
45353 osGetCurrentProcessId(), pFile, pFile->h));
45354 return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno,
45355 "winWrite2", pFile->zPath);
45360 osGetCurrentProcessId(), pFile, pFile->h));
45368 winFile *pFile = (winFile*)id; /* File handle object */
45373 if( pFile->nFetchOut>0 ){
45395 assert( pFile );
45398 osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype));
45405 if( pFile->szChunk>0 ){
45406 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
45410 if( pFile->pMapRegion ){
45411 oldMmapSize = pFile->mmapSize;
45415 winUnmapfile(pFile);
45419 if( winSeekFile(pFile, nByte) ){
45420 rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
45421 "winTruncate1", pFile->zPath);
45422 }else if( 0==osSetEndOfFile(pFile->h) &&
45424 pFile->lastErrno = lastErrno;
45425 rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
45426 "winTruncate2", pFile->zPath);
45432 winMapfile(pFile, -1);
45434 winMapfile(pFile, oldMmapSize);
45440 osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc)));
45469 winFile *pFile = (winFile*)id;
45474 assert( pFile );
45486 osGetCurrentProcessId(), pFile, pFile->h, flags,
45487 pFile->locktype));
45503 osGetCurrentProcessId(), pFile, pFile->h));
45507 if( pFile->pMapRegion ){
45508 if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
45511 pFile, pFile->pMapRegion));
45513 pFile->lastErrno = osGetLastError();
45516 pFile, pFile->pMapRegion));
45517 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
45518 "winSync1", pFile->zPath);
45522 rc = osFlushFileBuffers(pFile->h);
45526 osGetCurrentProcessId(), pFile, pFile->h));
45529 pFile->lastErrno = osGetLastError();
45531 osGetCurrentProcessId(), pFile, pFile->h));
45532 return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
45533 "winSync2", pFile->zPath);
45542 winFile *pFile = (winFile*)id;
45548 OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize));
45553 if( osGetFileInformationByHandleEx(pFile->h, FileStandardInfo,
45557 pFile->lastErrno = osGetLastError();
45558 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
45559 "winFileSize", pFile->zPath);
45568 lowerBits = osGetFileSize(pFile->h, &upperBits);
45572 pFile->lastErrno = lastErrno;
45573 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
45574 "winFileSize", pFile->zPath);
45579 pFile->h, pSize, *pSize, sqlite3ErrName(rc)));
45619 static int winGetReadLock(winFile *pFile){
45621 OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
45628 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
45630 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
45638 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
45639 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
45640 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
45644 pFile->lastErrno = osGetLastError();
45647 OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
45654 static int winUnlockReadLock(winFile *pFile){
45657 OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
45659 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
45663 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
45667 pFile->lastErrno = lastErrno;
45668 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
45669 "winUnlockReadLock", pFile->zPath);
45671 OSTRACE(("READ-UNLOCK file=%p, result=%d\n", pFile->h, res));
45706 winFile *pFile = (winFile*)id;
45711 pFile->h, pFile->locktype, pFile->sharedLockByte, locktype));
45717 if( pFile->locktype>=locktype ){
45718 OSTRACE(("LOCK-HELD file=%p, rc=SQLITE_OK\n", pFile->h));
45724 if( (pFile->ctrlFlags & WINFILE_RDONLY)!=0 && locktype>=RESERVED_LOCK ){
45730 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
45732 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK );
45738 newLocktype = pFile->locktype;
45739 if( pFile->locktype==NO_LOCK
45740 || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
45743 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
45753 pFile->h, cnt, res));
45755 pFile->lastErrno = lastErrno;
45758 pFile->h, cnt, sqlite3ErrName(rc)));
45772 assert( pFile->locktype==NO_LOCK );
45773 res = winGetReadLock(pFile);
45784 assert( pFile->locktype==SHARED_LOCK );
45785 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
45803 assert( pFile->locktype>=SHARED_LOCK );
45804 res = winUnlockReadLock(pFile);
45805 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
45811 winGetReadLock(pFile);
45819 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
45828 pFile->lastErrno = lastErrno;
45831 pFile->h, locktype, newLocktype));
45833 pFile->locktype = (u8)newLocktype;
45835 pFile->h, pFile->locktype, sqlite3ErrName(rc)));
45846 winFile *pFile = (winFile*)id;
45849 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut));
45852 if( pFile->locktype>=RESERVED_LOCK ){
45854 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
45856 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
45858 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
45861 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res));
45865 pFile->h, pResOut, *pResOut));
45882 winFile *pFile = (winFile*)id;
45884 assert( pFile!=0 );
45887 pFile->h, pFile->locktype, pFile->sharedLockByte, locktype));
45888 type = pFile->locktype;
45890 winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
45891 if( locktype==SHARED_LOCK && !winGetReadLock(pFile) ){
45895 "winUnlock", pFile->zPath);
45899 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
45902 winUnlockReadLock(pFile);
45905 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
45907 pFile->locktype = (u8)locktype;
45909 pFile->h, pFile->locktype, sqlite3ErrName(rc)));
45957 static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){
45959 *pArg = (pFile->ctrlFlags & mask)!=0;
45961 pFile->ctrlFlags &= ~mask;
45963 pFile->ctrlFlags |= mask;
45977 winFile *pFile = (winFile*)id;
45978 OSTRACE(("FCNTL file=%p, op=%d, pArg=%p\n", pFile->h, op, pArg));
45981 *(int*)pArg = pFile->locktype;
45982 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45986 *(int*)pArg = (int)pFile->lastErrno;
45987 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45991 pFile->szChunk = *(int *)pArg;
45992 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45996 if( pFile->szChunk>0 ){
46007 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
46010 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
46014 winModeBit(pFile, WINFILE_PERSIST_WAL, (int*)pArg);
46015 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
46019 winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
46020 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
46024 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
46025 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
46040 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
46045 *phFile = pFile->h;
46046 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
46052 HANDLE hOldFile = pFile->h;
46053 pFile->h = *phFile;
46056 hOldFile, pFile->h));
46062 int rc = winGetTempname(pFile->pVfs, &zTFile);
46066 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
46084 *(i64*)pArg = pFile->mmapSizeMax;
46085 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
46086 pFile->mmapSizeMax = newLimit;
46087 if( pFile->mmapSize>0 ){
46088 winUnmapfile(pFile);
46089 rc = winMapfile(pFile, -1);
46092 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
46097 OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
46252 winShmNode *pFile, /* Apply locks to this open shared-memory segment */
46260 assert( pFile->nRef==0 || sqlite3_mutex_held(pFile->mutex) );
46263 pFile->hFile.h, lockType, ofst, nByte));
46267 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
46272 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
46278 pFile->lastErrno = osGetLastError();
46283 pFile->hFile.h, (lockType == WINSHM_UNLCK) ? "winUnlockFile" :
46284 "winLockFile", pFile->lastErrno, sqlite3ErrName(rc)));
46820 static int winUnmapfile(winFile *pFile){
46821 assert( pFile!=0 );
46824 osGetCurrentProcessId(), pFile, pFile->hMap, pFile->pMapRegion,
46825 pFile->mmapSize, pFile->mmapSizeMax));
46826 if( pFile->pMapRegion ){
46827 if( !osUnmapViewOfFile(pFile->pMapRegion) ){
46828 pFile->lastErrno = osGetLastError();
46830 "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), pFile,
46831 pFile->pMapRegion));
46832 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
46833 "winUnmapfile1", pFile->zPath);
46835 pFile->pMapRegion = 0;
46836 pFile->mmapSize = 0;
46838 if( pFile->hMap!=NULL ){
46839 if( !osCloseHandle(pFile->hMap) ){
46840 pFile->lastErrno = osGetLastError();
46842 osGetCurrentProcessId(), pFile, pFile->hMap));
46843 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
46844 "winUnmapfile2", pFile->zPath);
46846 pFile->hMap = NULL;
46849 osGetCurrentProcessId(), pFile));
47468 winFile *pFile = (winFile*)id;
47526 assert( pFile!=0 );
47527 memset(pFile, 0, sizeof(winFile));
47528 pFile->h = INVALID_HANDLE_VALUE;
47696 pFile->lastErrno = lastErrno;
47697 winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name);
47720 && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
47730 pFile->zDeleteOnClose = zConverted;
47739 pFile->pVfs = pVfs;
47740 pFile->h = h;
47742 pFile->ctrlFlags |= WINFILE_RDONLY;
47747 pFile->ctrlFlags |= WINFILE_PSOW;
47749 pFile->lastErrno = NO_ERROR;
47750 pFile->zPath = zName;
47752 pFile->hMap = NULL;
47753 pFile->pMapRegion = 0;
47754 pFile->mmapSize = 0;
47755 pFile->mmapSizeMax = sqlite3GlobalConfig.szMmap;
48831 static int memdbClose(sqlite3_file *pFile){
48832 MemStore *p = ((MemFile*)pFile)->pStore;
48874 sqlite3_file *pFile,
48879 MemStore *p = ((MemFile*)pFile)->pStore;
48916 sqlite3_file *pFile,
48921 MemStore *p = ((MemFile*)pFile)->pStore;
48952 static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
48953 MemStore *p = ((MemFile*)pFile)->pStore;
48969 static int memdbSync(sqlite3_file *pFile, int flags){
48970 UNUSED_PARAMETER(pFile);
48978 static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
48979 MemStore *p = ((MemFile*)pFile)->pStore;
48989 static int memdbLock(sqlite3_file *pFile, int eLock){
48990 MemFile *pThis = (MemFile*)pFile;
49033 static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
49043 static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
49044 MemStore *p = ((MemFile*)pFile)->pStore;
49072 static int memdbSectorSize(sqlite3_file *pFile){
49080 static int memdbDeviceCharacteristics(sqlite3_file *pFile){
49081 UNUSED_PARAMETER(pFile);
49090 sqlite3_file *pFile,
49095 MemStore *p = ((MemFile*)pFile)->pStore;
49108 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
49109 MemStore *p = ((MemFile*)pFile)->pStore;
49128 MemFile *pFile = (MemFile*)pFd;
49133 memset(pFile, 0, sizeof(*pFile));
49191 pFile->pStore = p;
55475 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *pFile){
55476 int iRet = sqlite3OsSectorSize(pFile);
56455 sqlite3_file *pFile, /* Write the file descriptor here */
56466 rc = sqlite3OsOpen(pPager->pVfs, 0, pFile, vfsFlags, 0);
56467 assert( rc!=SQLITE_OK || isOpen(pFile) );
68446 sqlite3_file *pFile;
68456 pFile = sqlite3PagerFile(pBt->pPager);
68457 if( pFile->pMethods ){
68458 sqlite3OsFileControlHint(pFile, SQLITE_FCNTL_PDB, (void*)&pBt->db);
77018 static int backupTruncateFile(sqlite3_file *pFile, i64 iSize){
77020 int rc = sqlite3OsFileSize(pFile, &iCurrent);
77022 rc = sqlite3OsTruncate(pFile, iSize);
77197 sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
77203 assert( pFile );
77243 rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
77248 rc = backupTruncateFile(pFile, iSize);
96718 static int vdbeSorterMapFile(SortSubtask *pTask, SorterFile *pFile, u8 **pp){
96720 if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
96721 sqlite3_file *pFd = pFile->pFd;
96723 rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp);
96738 SorterFile *pFile, /* Sorter file to read from */
96751 pReadr->iEof = pFile->iEof;
96752 pReadr->pFd = pFile->pFd;
96754 rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap);
96831 SorterFile *pFile, /* Sorter file to read from */
96838 assert( pFile->iEof>iStart );
96843 rc = vdbePmaReaderSeek(pTask, pReadr, pFile, iStart);
131080 sqlite3_file *pFile = sqlite3PagerFile(pPager);
131081 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
131086 sqlite3_file *pFile = sqlite3PagerFile(pPager);
131089 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
131092 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
207007 static int rbuVfsClose(sqlite3_file *pFile){
207008 rbu_file *p = (rbu_file*)pFile;
207067 sqlite3_file *pFile,
207072 rbu_file *p = (rbu_file*)pFile;
207133 sqlite3_file *pFile,
207138 rbu_file *p = (rbu_file*)pFile;
207175 static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
207176 rbu_file *p = (rbu_file*)pFile;
207187 static int rbuVfsSync(sqlite3_file *pFile, int flags){
207188 rbu_file *p = (rbu_file *)pFile;
207201 static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
207202 rbu_file *p = (rbu_file *)pFile;
207222 static int rbuVfsLock(sqlite3_file *pFile, int eLock){
207223 rbu_file *p = (rbu_file*)pFile;
207244 static int rbuVfsUnlock(sqlite3_file *pFile, int eLock){
207245 rbu_file *p = (rbu_file *)pFile;
207252 static int rbuVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
207253 rbu_file *p = (rbu_file *)pFile;
207260 static int rbuVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
207261 rbu_file *p = (rbu_file *)pFile;
207316 static int rbuVfsSectorSize(sqlite3_file *pFile){
207317 rbu_file *p = (rbu_file *)pFile;
207324 static int rbuVfsDeviceCharacteristics(sqlite3_file *pFile){
207325 rbu_file *p = (rbu_file *)pFile;
207332 static int rbuVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
207333 rbu_file *p = (rbu_file*)pFile;
207371 sqlite3_file *pFile,
207377 rbu_file *p = (rbu_file*)pFile;
207428 static void rbuVfsShmBarrier(sqlite3_file *pFile){
207429 rbu_file *p = (rbu_file *)pFile;
207436 static int rbuVfsShmUnmap(sqlite3_file *pFile, int delFlag){
207437 rbu_file *p = (rbu_file*)pFile;
207458 sqlite3_file *pFile,
207484 rbu_file *pFd = (rbu_file *)pFile;
207539 pFile->pMethods = &rbuvfs_io_methods;