Lines Matching refs:pFile
23117 sqlite3_file *pFile, in sqlite3OsOpen() argument
23127 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut); in sqlite3OsOpen()
23128 assert( rc==SQLITE_OK || pFile->pMethods==0 ); in sqlite3OsOpen()
23212 sqlite3_file *pFile; in sqlite3OsOpenMalloc() local
23213 pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile); in sqlite3OsOpenMalloc()
23214 if( pFile ){ in sqlite3OsOpenMalloc()
23215 rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags); in sqlite3OsOpenMalloc()
23217 sqlite3_free(pFile); in sqlite3OsOpenMalloc()
23219 *ppFile = pFile; in sqlite3OsOpenMalloc()
23226 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){ in sqlite3OsCloseFree() argument
23227 assert( pFile ); in sqlite3OsCloseFree()
23228 sqlite3OsClose(pFile); in sqlite3OsCloseFree()
23229 sqlite3_free(pFile); in sqlite3OsCloseFree()
34645 int unixFileMutexHeld(unixFile *pFile){
34646 assert( pFile->pInode );
34647 return sqlite3_mutex_held(pFile->pInode->pLockMutex);
34649 int unixFileMutexNotheld(unixFile *pFile){
34650 assert( pFile->pInode );
34651 return sqlite3_mutex_notheld(pFile->pInode->pLockMutex);
34737 static void robust_close(unixFile *pFile, int h, int lineno){
34740 pFile ? pFile->zPath : 0, lineno);
34748 static void storeLastErrno(unixFile *pFile, int error){
34749 pFile->lastErrno = error;
34755 static void closePendingFds(unixFile *pFile){
34756 unixInodeInfo *pInode = pFile->pInode;
34759 assert( unixFileMutexHeld(pFile) );
34762 robust_close(pFile, p->fd, __LINE__);
34774 static void releaseInodeInfo(unixFile *pFile){
34775 unixInodeInfo *pInode = pFile->pInode;
34777 assert( unixFileMutexNotheld(pFile) );
34783 closePendingFds(pFile);
34812 unixFile *pFile, /* Unix file with file desc used in the key */
34826 fd = pFile->h;
34829 storeLastErrno(pFile, errno);
34831 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
34847 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
34850 storeLastErrno(pFile, errno);
34855 storeLastErrno(pFile, errno);
34864 fileId.pId = pFile->pId;
34903 static int fileHasMoved(unixFile *pFile){
34905 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
34908 return pFile->pInode!=0 &&
34909 (osStat(pFile->zPath, &buf)!=0
34910 || (u64)buf.st_ino!=pFile->pInode->fileId.ino);
34924 static void verifyDbFile(unixFile *pFile){
34929 if( pFile->ctrlFlags & UNIXFILE_NOLOCK ) return;
34931 rc = osFstat(pFile->h, &buf);
34933 sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
34937 sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
34941 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
34944 if( fileHasMoved(pFile) ){
34945 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
34960 unixFile *pFile = (unixFile*)id;
34964 assert( pFile );
34965 assert( pFile->eFileLock<=SHARED_LOCK );
34966 sqlite3_mutex_enter(pFile->pInode->pLockMutex);
34969 if( pFile->pInode->eFileLock>SHARED_LOCK ){
34976 if( !reserved && !pFile->pInode->bProcessLock ){
34982 if( osFcntl(pFile->h, F_GETLK, &lock) ){
34984 storeLastErrno(pFile, errno);
34991 sqlite3_mutex_leave(pFile->pInode->pLockMutex);
34992 OSTRACE(("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved));
35017 unixFile *pFile /* Structure holding timeout value */
35019 int tm = pFile->iBusyTimeout;
35055 static int unixFileLock(unixFile *pFile, struct flock *pLock){
35057 unixInodeInfo *pInode = pFile->pInode;
35060 if( (pFile->ctrlFlags & (UNIXFILE_EXCL|UNIXFILE_RDONLY))==UNIXFILE_EXCL ){
35068 rc = osSetPosixAdvisoryLock(pFile->h, &lock, pFile);
35076 rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile);
35146 unixFile *pFile = (unixFile*)id;
35151 assert( pFile );
35152 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
35153 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
35154 azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared,
35161 if( pFile->eFileLock>=eFileLock ){
35162 OSTRACE(("LOCK %d %s ok (already held) (unix)\n", pFile->h,
35172 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
35174 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
35178 pInode = pFile->pInode;
35184 if( (pFile->eFileLock!=pInode->eFileLock &&
35198 assert( pFile->eFileLock==0 );
35200 pFile->eFileLock = SHARED_LOCK;
35214 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
35218 if( unixFileLock(pFile, &lock) ){
35222 storeLastErrno(pFile, tErrno);
35240 if( unixFileLock(pFile, &lock) ){
35249 if( unixFileLock(pFile, &lock) && rc==SQLITE_OK ){
35257 storeLastErrno(pFile, tErrno);
35261 pFile->eFileLock = SHARED_LOCK;
35274 assert( 0!=pFile->eFileLock );
35286 if( unixFileLock(pFile, &lock) ){
35290 storeLastErrno(pFile, tErrno);
35303 && pFile->eFileLock<=SHARED_LOCK
35306 pFile->transCntrChng = 0;
35307 pFile->dbUpdate = 0;
35308 pFile->inNormalWrite = 1;
35314 pFile->eFileLock = eFileLock;
35317 pFile->eFileLock = PENDING_LOCK;
35323 OSTRACE(("LOCK %d %s %s (unix)\n", pFile->h, azFileLock(eFileLock),
35332 static void setPendingFd(unixFile *pFile){
35333 unixInodeInfo *pInode = pFile->pInode;
35334 UnixUnusedFd *p = pFile->pPreallocatedUnused;
35335 assert( unixFileMutexHeld(pFile) );
35338 pFile->h = -1;
35339 pFile->pPreallocatedUnused = 0;
35356 unixFile *pFile = (unixFile*)id;
35361 assert( pFile );
35362 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
35363 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
35367 if( pFile->eFileLock<=eFileLock ){
35370 pInode = pFile->pInode;
35373 if( pFile->eFileLock>SHARED_LOCK ){
35374 assert( pInode->eFileLock==pFile->eFileLock );
35385 pFile->inNormalWrite = 0;
35411 if( unixFileLock(pFile, &lock)==(-1) ){
35414 storeLastErrno(pFile, tErrno);
35421 if( unixFileLock(pFile, &lock)==(-1) ){
35425 storeLastErrno(pFile, tErrno);
35433 if( unixFileLock(pFile, &lock)==(-1) ){
35436 storeLastErrno(pFile, tErrno);
35446 if( unixFileLock(pFile, &lock) ){
35454 storeLastErrno(pFile, errno);
35463 if( unixFileLock(pFile, &lock)==0 ){
35467 storeLastErrno(pFile, errno);
35481 if( unixFileLock(pFile, &lock)==0 ){
35485 storeLastErrno(pFile, errno);
35487 pFile->eFileLock = NO_LOCK;
35497 if( pInode->nLock==0 ) closePendingFds(pFile);
35503 pFile->eFileLock = eFileLock;
35538 unixFile *pFile = (unixFile*)id;
35540 unixUnmapfile(pFile);
35542 if( pFile->h>=0 ){
35543 robust_close(pFile, pFile->h, __LINE__);
35544 pFile->h = -1;
35547 if( pFile->pId ){
35548 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
35549 osUnlink(pFile->pId->zCanonicalName);
35551 vxworksReleaseFileId(pFile->pId);
35552 pFile->pId = 0;
35556 if( pFile->ctrlFlags & UNIXFILE_DELETE ){
35557 osUnlink(pFile->zPath);
35558 sqlite3_free(*(char**)&pFile->zPath);
35559 pFile->zPath = 0;
35562 OSTRACE(("CLOSE %-3d\n", pFile->h));
35564 sqlite3_free(pFile->pPreallocatedUnused);
35565 memset(pFile, 0, sizeof(unixFile));
35574 unixFile *pFile = (unixFile *)id;
35575 unixInodeInfo *pInode = pFile->pInode;
35578 verifyDbFile(pFile);
35580 assert( unixFileMutexNotheld(pFile) );
35586 assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 );
35594 setPendingFd(pFile);
35597 releaseInodeInfo(pFile);
35688 unixFile *pFile = (unixFile*)id;
35692 assert( pFile );
35693 reserved = osAccess((const char*)pFile->lockingContext, 0)==0;
35694 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
35727 unixFile *pFile = (unixFile*)id;
35728 char *zLockFile = (char *)pFile->lockingContext;
35735 if( pFile->eFileLock > NO_LOCK ){
35736 pFile->eFileLock = eFileLock;
35756 storeLastErrno(pFile, tErrno);
35763 pFile->eFileLock = eFileLock;
35777 unixFile *pFile = (unixFile*)id;
35778 char *zLockFile = (char *)pFile->lockingContext;
35781 assert( pFile );
35782 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
35783 pFile->eFileLock, osGetpid(0)));
35787 if( pFile->eFileLock==eFileLock ){
35795 pFile->eFileLock = SHARED_LOCK;
35808 storeLastErrno(pFile, tErrno);
35812 pFile->eFileLock = NO_LOCK;
35820 unixFile *pFile = (unixFile*)id;
35823 sqlite3_free(pFile->lockingContext);
35868 unixFile *pFile = (unixFile*)id;
35872 assert( pFile );
35875 if( pFile->eFileLock>SHARED_LOCK ){
35882 int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
35885 lrc = robust_flock(pFile->h, LOCK_UN);
35890 storeLastErrno(pFile, tErrno);
35899 storeLastErrno(pFile, tErrno);
35904 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
35947 unixFile *pFile = (unixFile*)id;
35949 assert( pFile );
35953 if (pFile->eFileLock > NO_LOCK) {
35954 pFile->eFileLock = eFileLock;
35960 if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
35965 storeLastErrno(pFile, tErrno);
35969 pFile->eFileLock = eFileLock;
35971 OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock),
35990 unixFile *pFile = (unixFile*)id;
35992 assert( pFile );
35993 OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock,
35994 pFile->eFileLock, osGetpid(0)));
35998 if( pFile->eFileLock==eFileLock ){
36004 pFile->eFileLock = eFileLock;
36009 if( robust_flock(pFile->h, LOCK_UN) ){
36015 pFile->eFileLock = NO_LOCK;
36055 unixFile *pFile = (unixFile*)id;
36059 assert( pFile );
36062 if( pFile->eFileLock>SHARED_LOCK ){
36068 sem_t *pSem = pFile->pInode->pSem;
36074 storeLastErrno(pFile, tErrno);
36077 reserved = (pFile->eFileLock < SHARED_LOCK);
36084 OSTRACE(("TEST WR-LOCK %d %d %d (sem)\n", pFile->h, rc, reserved));
36120 unixFile *pFile = (unixFile*)id;
36121 sem_t *pSem = pFile->pInode->pSem;
36126 if (pFile->eFileLock > NO_LOCK) {
36127 pFile->eFileLock = eFileLock;
36139 pFile->eFileLock = eFileLock;
36153 unixFile *pFile = (unixFile*)id;
36154 sem_t *pSem = pFile->pInode->pSem;
36156 assert( pFile );
36158 OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
36159 pFile->eFileLock, osGetpid(0)));
36163 if( pFile->eFileLock==eFileLock ){
36169 pFile->eFileLock = eFileLock;
36178 storeLastErrno(pFile, tErrno);
36182 pFile->eFileLock = NO_LOCK;
36191 unixFile *pFile = (unixFile*)id;
36193 assert( pFile );
36194 assert( unixFileMutexNotheld(pFile) );
36196 releaseInodeInfo(pFile);
36251 unixFile *pFile, /* Open file descriptor on path */
36263 pb.fd = pFile->h;
36266 (setLockFlag?"ON":"OFF"), pFile->h, (pb.fd==-1?"[testval-1]":""),
36281 storeLastErrno(pFile, tErrno);
36298 unixFile *pFile = (unixFile*)id;
36303 assert( pFile );
36304 context = (afpLockingContext *) pFile->lockingContext;
36309 sqlite3_mutex_enter(pFile->pInode->pLockMutex);
36311 if( pFile->pInode->eFileLock>SHARED_LOCK ){
36319 int lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1);
36323 lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
36333 sqlite3_mutex_leave(pFile->pInode->pLockMutex);
36334 OSTRACE(("TEST WR-LOCK %d %d %d (afp)\n", pFile->h, rc, reserved));
36366 unixFile *pFile = (unixFile*)id;
36367 unixInodeInfo *pInode = pFile->pInode;
36368 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
36370 assert( pFile );
36371 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h,
36372 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
36379 if( pFile->eFileLock>=eFileLock ){
36380 OSTRACE(("LOCK %d %s ok (already held) (afp)\n", pFile->h,
36390 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
36392 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
36396 pInode = pFile->pInode;
36402 if( (pFile->eFileLock!=pInode->eFileLock &&
36416 assert( pFile->eFileLock==0 );
36418 pFile->eFileLock = SHARED_LOCK;
36429 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
36432 failed = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 1);
36454 lrc1 = afpSetLock(context->dbPath, pFile,
36457 lrc1Errno = pFile->lastErrno;
36460 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
36463 storeLastErrno(pFile, lrc1Errno);
36472 pFile->eFileLock = SHARED_LOCK;
36486 assert( 0!=pFile->eFileLock );
36487 if (eFileLock >= RESERVED_LOCK && pFile->eFileLock < RESERVED_LOCK) {
36489 failed = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1);
36500 if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST +
36504 failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST,
36506 if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
36525 pFile->eFileLock = eFileLock;
36528 pFile->eFileLock = PENDING_LOCK;
36534 OSTRACE(("LOCK %d %s %s (afp)\n", pFile->h, azFileLock(eFileLock),
36548 unixFile *pFile = (unixFile*)id;
36550 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
36553 int h = pFile->h;
36556 assert( pFile );
36557 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
36558 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
36562 if( pFile->eFileLock<=eFileLock ){
36565 pInode = pFile->pInode;
36568 if( pFile->eFileLock>SHARED_LOCK ){
36569 assert( pInode->eFileLock==pFile->eFileLock );
36583 assert( pFile->inNormalWrite==0
36584 || pFile->dbUpdate==0
36585 || pFile->transCntrChng==1 );
36586 pFile->inNormalWrite = 0;
36589 if( pFile->eFileLock==EXCLUSIVE_LOCK ){
36590 rc = afpSetLock(context->dbPath, pFile, SHARED_FIRST, SHARED_SIZE, 0);
36594 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 1);
36599 if( rc==SQLITE_OK && pFile->eFileLock>=PENDING_LOCK ){
36600 rc = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
36602 if( rc==SQLITE_OK && pFile->eFileLock>=RESERVED_LOCK && context->reserved ){
36603 rc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
36625 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0);
36629 pFile->eFileLock = NO_LOCK;
36635 if( pInode->nLock==0 ) closePendingFds(pFile);
36641 pFile->eFileLock = eFileLock;
36651 unixFile *pFile = (unixFile*)id;
36654 assert( unixFileMutexNotheld(pFile) );
36656 if( pFile->pInode ){
36657 unixInodeInfo *pInode = pFile->pInode;
36665 setPendingFd(pFile);
36669 releaseInodeInfo(pFile);
36670 sqlite3_free(pFile->lockingContext);
36788 unixFile *pFile = (unixFile *)id;
36797 assert( pFile->pPreallocatedUnused==0
36806 if( offset<pFile->mmapSize ){
36807 if( offset+amt <= pFile->mmapSize ){
36808 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
36811 int nCopy = pFile->mmapSize - offset;
36812 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
36820 got = seekAndRead(pFile, offset, pBuf, amt);
36827 storeLastErrno(pFile, 0); /* not a system error */
36902 unixFile *pFile = (unixFile*)id;
36910 assert( pFile->pPreallocatedUnused==0
36923 if( pFile->inNormalWrite ){
36924 pFile->dbUpdate = 1; /* The database has been modified */
36929 rc = seekAndRead(pFile, 24, oldCntr, 4);
36932 pFile->transCntrChng = 1; /* The transaction counter has changed */
36941 if( offset<pFile->mmapSize ){
36942 if( offset+amt <= pFile->mmapSize ){
36943 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
36946 int nCopy = pFile->mmapSize - offset;
36947 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
36955 while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
36964 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
36968 storeLastErrno(pFile, 0); /* not a system error */
37166 unixFile *pFile = (unixFile*)id;
37181 assert( pFile );
37182 OSTRACE(("SYNC %-3d\n", pFile->h));
37183 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
37186 storeLastErrno(pFile, errno);
37187 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
37194 if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
37196 OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath,
37198 rc = osOpenDirectory(pFile->zPath, &dirfd);
37201 robust_close(pFile, dirfd, __LINE__);
37206 pFile->ctrlFlags &= ~UNIXFILE_DIRSYNC;
37215 unixFile *pFile = (unixFile *)id;
37217 assert( pFile );
37225 if( pFile->szChunk>0 ){
37226 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
37229 rc = robust_ftruncate(pFile->h, nByte);
37231 storeLastErrno(pFile, errno);
37232 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
37242 if( pFile->inNormalWrite && nByte==0 ){
37243 pFile->transCntrChng = 1;
37252 if( nByte<pFile->mmapSize ){
37253 pFile->mmapSize = nByte;
37302 static int fcntlSizeHint(unixFile *pFile, i64 nByte){
37303 if( pFile->szChunk>0 ){
37307 if( osFstat(pFile->h, &buf) ){
37311 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
37320 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
37340 nWrite = seekAndWrite(pFile, iWrite, "", 1);
37348 if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){
37350 if( pFile->szChunk<=0 ){
37351 if( robust_ftruncate(pFile->h, nByte) ){
37352 storeLastErrno(pFile, errno);
37353 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
37357 rc = unixMapfile(pFile, nByte);
37371 static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
37373 *pArg = (pFile->ctrlFlags & mask)!=0;
37375 pFile->ctrlFlags &= ~mask;
37377 pFile->ctrlFlags |= mask;
37388 unixFile *pFile = (unixFile*)id;
37392 int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE);
37396 int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE);
37400 int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE);
37406 *(int*)pArg = pFile->eFileLock;
37410 *(int*)pArg = pFile->lastErrno;
37414 pFile->szChunk = *(int *)pArg;
37420 rc = fcntlSizeHint(pFile, *(i64 *)pArg);
37425 unixModeBit(pFile, UNIXFILE_PERSIST_WAL, (int*)pArg);
37429 unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg);
37433 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
37437 char *zTFile = sqlite3_malloc64( pFile->pVfs->mxPathname );
37439 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
37445 *(int*)pArg = fileHasMoved(pFile);
37450 int iOld = pFile->iBusyTimeout;
37451 pFile->iBusyTimeout = *(int*)pArg;
37471 *(i64*)pArg = pFile->mmapSizeMax;
37472 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
37473 pFile->mmapSizeMax = newLimit;
37474 if( pFile->mmapSize>0 ){
37475 unixUnmapfile(pFile);
37476 rc = unixMapfile(pFile, -1);
37538 static void setDeviceCharacteristics(unixFile *pFile){
37539 if( pFile->sectorSize == 0 ){
37543 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
37544 pFile->deviceCharacteristics = 0;
37545 if( fstatvfs(pFile->h, &fsInfo) == -1 ) {
37550 pFile->sectorSize = fsInfo.f_bsize;
37551 pFile->deviceCharacteristics =
37559 pFile->sectorSize = fsInfo.f_bsize;
37560 pFile->deviceCharacteristics =
37562 (pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) |
37569 pFile->sectorSize = fsInfo.f_bsize;
37570 pFile->deviceCharacteristics =
37578 pFile->sectorSize = fsInfo.f_bsize;
37579 pFile->deviceCharacteristics =
37581 ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 |
37586 pFile->sectorSize = fsInfo.f_bsize;
37587 pFile->deviceCharacteristics =
37589 ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 |
37594 pFile->deviceCharacteristics =
37603 if( pFile->sectorSize % 512 != 0 ){
37604 pFile->deviceCharacteristics = 0;
37605 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
37750 unixFile *pFile, /* Open connection to the WAL file */
37760 pShmNode = pFile->pInode->pShmNode;
37777 res = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile);
37780 rc = (pFile->iBusyTimeout ? SQLITE_BUSY_TIMEOUT : SQLITE_BUSY);
39407 sqlite3_file *pFile, /* The file descriptor to be filled in */
39411 unixFile *p = (unixFile *)pFile;
39613 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
39616 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
39644 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
39646 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
39652 unixClose(pFile);
39664 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
40481 static int proxyBreakConchLock(unixFile *pFile, uuid_t myHostID){
40482 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
40523 robust_close(pFile, conchFile->h, __LINE__);
40531 robust_close(pFile, fd, __LINE__);
40541 static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
40542 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
40561 storeLastErrno(pFile, errno);
40581 storeLastErrno(pFile, errno);
40598 if( 0==proxyBreakConchLock(pFile, myHostID) ){
40619 static int proxyTakeConch(unixFile *pFile){
40620 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
40644 storeLastErrno(pFile, pError);
40647 rc = proxyConchLock(pFile, myHostID, SHARED_LOCK);
40655 storeLastErrno(pFile, conchFile->lastErrno);
40725 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
40728 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
40751 int err = osFstat(pFile->h, &buf);
40780 OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h));
40781 if( rc==SQLITE_OK && pFile->openFlags ){
40783 if( pFile->h>=0 ){
40784 robust_close(pFile, pFile->h, __LINE__);
40786 pFile->h = -1;
40787 fd = robust_open(pCtx->dbPath, pFile->openFlags, 0);
40790 pFile->h = fd;
40841 static int proxyReleaseConch(unixFile *pFile){
40846 pCtx = (proxyLockingContext *)pFile->lockingContext;
40908 static int switchLockProxyPath(unixFile *pFile, const char *path) {
40909 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
40913 if( pFile->eFileLock!=NO_LOCK ){
40944 static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
40946 if( pFile->pMethod == &afpIoMethods ){
40949 assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
40950 strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath,
40954 if( pFile->pMethod == &dotlockIoMethods ){
40957 int len = strlen((char *)pFile->lockingContext) - strlen(DOTLOCK_SUFFIX);
40958 memcpy(dbPath, (char *)pFile->lockingContext, len + 1);
40961 assert( strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
40962 strlcpy(dbPath, (char *)pFile->lockingContext, MAXPATHLEN);
40975 static int proxyTransformUnixFile(unixFile *pFile, const char *path) {
40981 if( pFile->eFileLock!=NO_LOCK ){
40984 proxyGetDbPathForUnixFile(pFile, dbPath);
40991 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
41003 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){
41039 pCtx->oldLockingContext = pFile->lockingContext;
41040 pFile->lockingContext = pCtx;
41041 pCtx->pOldMethod = pFile->pMethod;
41042 pFile->pMethod = &proxyIoMethods;
41052 OSTRACE(("TRANSPROXY %d %s\n", pFile->h,
41065 unixFile *pFile = (unixFile*)id;
41066 if( pFile->pMethod == &proxyIoMethods ){
41067 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
41068 proxyTakeConch(pFile);
41080 unixFile *pFile = (unixFile*)id;
41082 int isProxyStyle = (pFile->pMethod == &proxyIoMethods);
41098 (proxyLockingContext*)pFile->lockingContext;
41105 rc = switchLockProxyPath(pFile, proxyPath);
41109 rc = proxyTransformUnixFile(pFile, proxyPath);
41136 unixFile *pFile = (unixFile*)id;
41137 int rc = proxyTakeConch(pFile);
41139 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41175 unixFile *pFile = (unixFile*)id;
41176 int rc = proxyTakeConch(pFile);
41178 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41182 pFile->eFileLock = proxy->eFileLock;
41199 unixFile *pFile = (unixFile*)id;
41200 int rc = proxyTakeConch(pFile);
41202 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41206 pFile->eFileLock = proxy->eFileLock;
41219 unixFile *pFile = (unixFile*)id;
41220 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
41235 rc = proxyReleaseConch(pFile);
41246 pFile->lockingContext = pCtx->oldLockingContext;
41247 pFile->pMethod = pCtx->pOldMethod;
41249 return pFile->pMethod->xClose(id);
43829 static int winceCreateLock(const char *zFilename, winFile *pFile){
43843 memset(&pFile->local, 0, sizeof(pFile->local));
43853 pFile->hMutex = osCreateMutexW(NULL, FALSE, zName);
43854 if (!pFile->hMutex){
43855 pFile->lastErrno = osGetLastError();
43857 return winLogError(SQLITE_IOERR, pFile->lastErrno,
43862 winceMutexAcquire(pFile->hMutex);
43869 pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
43883 if( pFile->hShared ){
43884 pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared,
43887 if( !pFile->shared ){
43888 pFile->lastErrno = osGetLastError();
43889 winLogError(SQLITE_IOERR, pFile->lastErrno,
43892 osCloseHandle(pFile->hShared);
43893 pFile->hShared = NULL;
43898 if( pFile->hShared==NULL ){
43900 pFile->lastErrno = lastErrno;
43901 winLogError(SQLITE_IOERR, pFile->lastErrno,
43905 winceMutexRelease(pFile->hMutex);
43906 osCloseHandle(pFile->hMutex);
43907 pFile->hMutex = NULL;
43913 memset(pFile->shared, 0, sizeof(winceLock));
43916 winceMutexRelease(pFile->hMutex);
43923 static void winceDestroyLock(winFile *pFile){
43924 if (pFile->hMutex){
43926 winceMutexAcquire(pFile->hMutex);
43930 if (pFile->local.nReaders){
43931 pFile->shared->nReaders --;
43933 if (pFile->local.bReserved){
43934 pFile->shared->bReserved = FALSE;
43936 if (pFile->local.bPending){
43937 pFile->shared->bPending = FALSE;
43939 if (pFile->local.bExclusive){
43940 pFile->shared->bExclusive = FALSE;
43944 osUnmapViewOfFile(pFile->shared);
43945 osCloseHandle(pFile->hShared);
43948 winceMutexRelease(pFile->hMutex);
43949 osCloseHandle(pFile->hMutex);
43950 pFile->hMutex = NULL;
43964 winFile *pFile = HANDLE_TO_WINFILE(phFile);
43970 if (!pFile->hMutex) return TRUE;
43971 winceMutexAcquire(pFile->hMutex);
43976 if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){
43977 pFile->shared->bExclusive = TRUE;
43978 pFile->local.bExclusive = TRUE;
43986 if (pFile->shared->bExclusive == 0){
43987 pFile->local.nReaders ++;
43988 if (pFile->local.nReaders == 1){
43989 pFile->shared->nReaders ++;
43999 if (pFile->shared->bPending == 0) {
44000 pFile->shared->bPending = TRUE;
44001 pFile->local.bPending = TRUE;
44009 if (pFile->shared->bReserved == 0) {
44010 pFile->shared->bReserved = TRUE;
44011 pFile->local.bReserved = TRUE;
44016 winceMutexRelease(pFile->hMutex);
44030 winFile *pFile = HANDLE_TO_WINFILE(phFile);
44036 if (!pFile->hMutex) return TRUE;
44037 winceMutexAcquire(pFile->hMutex);
44042 if (pFile->local.bExclusive){
44044 pFile->local.bExclusive = FALSE;
44045 pFile->shared->bExclusive = FALSE;
44050 else if (pFile->local.nReaders){
44053 pFile->local.nReaders --;
44054 if (pFile->local.nReaders == 0)
44056 pFile->shared->nReaders --;
44065 if (pFile->local.bPending){
44066 pFile->local.bPending = FALSE;
44067 pFile->shared->bPending = FALSE;
44074 if (pFile->local.bReserved) {
44075 pFile->local.bReserved = FALSE;
44076 pFile->shared->bReserved = FALSE;
44081 winceMutexRelease(pFile->hMutex);
44169 static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){
44176 OSTRACE(("SEEK file=%p, offset=%lld\n", pFile->h, iOffset));
44188 dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
44192 pFile->lastErrno = lastErrno;
44193 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
44194 "winSeekFile", pFile->zPath);
44195 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
44199 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
44210 bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN);
44213 pFile->lastErrno = osGetLastError();
44214 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
44215 "winSeekFile", pFile->zPath);
44216 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
44220 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
44244 winFile *pFile = (winFile*)id;
44248 assert( pFile->pShm==0 );
44250 assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE );
44252 osGetCurrentProcessId(), pFile, pFile->h));
44255 winUnmapfile(pFile);
44259 rc = osCloseHandle(pFile->h);
44265 winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData;
44267 winceDestroyLock(pFile);
44270 if( pFile->zDeleteOnClose ){
44273 osDeleteFileW(pFile->zDeleteOnClose)==0
44274 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
44279 sqlite3_free(pFile->zDeleteOnClose);
44283 pFile->h = NULL;
44287 osGetCurrentProcessId(), pFile, pFile->h, rc ? "ok" : "failed"));
44290 "winClose", pFile->zPath);
44307 winFile *pFile = (winFile*)id; /* file handle */
44316 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
44317 pFile->h, pBuf, amt, offset, pFile->locktype));
44322 if( offset<pFile->mmapSize ){
44323 if( offset+amt <= pFile->mmapSize ){
44324 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
44326 osGetCurrentProcessId(), pFile, pFile->h));
44329 int nCopy = (int)(pFile->mmapSize - offset);
44330 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
44339 if( winSeekFile(pFile, offset) ){
44341 osGetCurrentProcessId(), pFile, pFile->h));
44344 while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
44349 while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) &&
44354 pFile->lastErrno = lastErrno;
44356 osGetCurrentProcessId(), pFile, pFile->h));
44357 return winLogError(SQLITE_IOERR_READ, pFile->lastErrno,
44358 "winRead", pFile->zPath);
44365 osGetCurrentProcessId(), pFile, pFile->h));
44370 osGetCurrentProcessId(), pFile, pFile->h));
44385 winFile *pFile = (winFile*)id; /* File handle */
44389 assert( pFile );
44394 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
44395 pFile->h, pBuf, amt, offset, pFile->locktype));
44400 if( offset<pFile->mmapSize ){
44401 if( offset+amt <= pFile->mmapSize ){
44402 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
44404 osGetCurrentProcessId(), pFile, pFile->h));
44407 int nCopy = (int)(pFile->mmapSize - offset);
44408 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
44417 rc = winSeekFile(pFile, offset);
44438 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
44440 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
44459 pFile->lastErrno = lastErrno;
44465 if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
44466 || ( pFile->lastErrno==ERROR_DISK_FULL )){
44468 osGetCurrentProcessId(), pFile, pFile->h));
44469 return winLogError(SQLITE_FULL, pFile->lastErrno,
44470 "winWrite1", pFile->zPath);
44473 osGetCurrentProcessId(), pFile, pFile->h));
44474 return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno,
44475 "winWrite2", pFile->zPath);
44480 osGetCurrentProcessId(), pFile, pFile->h));
44488 winFile *pFile = (winFile*)id; /* File handle object */
44493 if( pFile->nFetchOut>0 ){
44515 assert( pFile );
44518 osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype));
44525 if( pFile->szChunk>0 ){
44526 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
44530 if( pFile->pMapRegion ){
44531 oldMmapSize = pFile->mmapSize;
44535 winUnmapfile(pFile);
44539 if( winSeekFile(pFile, nByte) ){
44540 rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
44541 "winTruncate1", pFile->zPath);
44542 }else if( 0==osSetEndOfFile(pFile->h) &&
44544 pFile->lastErrno = lastErrno;
44545 rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
44546 "winTruncate2", pFile->zPath);
44552 winMapfile(pFile, -1);
44554 winMapfile(pFile, oldMmapSize);
44560 osGetCurrentProcessId(), pFile, pFile->h, sqlite3ErrName(rc)));
44589 winFile *pFile = (winFile*)id;
44594 assert( pFile );
44606 osGetCurrentProcessId(), pFile, pFile->h, flags,
44607 pFile->locktype));
44623 osGetCurrentProcessId(), pFile, pFile->h));
44627 if( pFile->pMapRegion ){
44628 if( osFlushViewOfFile(pFile->pMapRegion, 0) ){
44631 pFile, pFile->pMapRegion));
44633 pFile->lastErrno = osGetLastError();
44636 pFile, pFile->pMapRegion));
44637 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
44638 "winSync1", pFile->zPath);
44642 rc = osFlushFileBuffers(pFile->h);
44646 osGetCurrentProcessId(), pFile, pFile->h));
44649 pFile->lastErrno = osGetLastError();
44651 osGetCurrentProcessId(), pFile, pFile->h));
44652 return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
44653 "winSync2", pFile->zPath);
44662 winFile *pFile = (winFile*)id;
44668 OSTRACE(("SIZE file=%p, pSize=%p\n", pFile->h, pSize));
44673 if( osGetFileInformationByHandleEx(pFile->h, FileStandardInfo,
44677 pFile->lastErrno = osGetLastError();
44678 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
44679 "winFileSize", pFile->zPath);
44688 lowerBits = osGetFileSize(pFile->h, &upperBits);
44692 pFile->lastErrno = lastErrno;
44693 rc = winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
44694 "winFileSize", pFile->zPath);
44699 pFile->h, pSize, *pSize, sqlite3ErrName(rc)));
44739 static int winGetReadLock(winFile *pFile){
44741 OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
44748 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
44750 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
44758 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
44759 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
44760 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
44764 pFile->lastErrno = osGetLastError();
44767 OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
44774 static int winUnlockReadLock(winFile *pFile){
44777 OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
44779 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
44783 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
44787 pFile->lastErrno = lastErrno;
44788 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
44789 "winUnlockReadLock", pFile->zPath);
44791 OSTRACE(("READ-UNLOCK file=%p, result=%d\n", pFile->h, res));
44826 winFile *pFile = (winFile*)id;
44831 pFile->h, pFile->locktype, pFile->sharedLockByte, locktype));
44837 if( pFile->locktype>=locktype ){
44838 OSTRACE(("LOCK-HELD file=%p, rc=SQLITE_OK\n", pFile->h));
44844 if( (pFile->ctrlFlags & WINFILE_RDONLY)!=0 && locktype>=RESERVED_LOCK ){
44850 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
44852 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK );
44858 newLocktype = pFile->locktype;
44859 if( pFile->locktype==NO_LOCK
44860 || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
44863 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
44873 pFile->h, cnt, res));
44875 pFile->lastErrno = lastErrno;
44878 pFile->h, cnt, sqlite3ErrName(rc)));
44892 assert( pFile->locktype==NO_LOCK );
44893 res = winGetReadLock(pFile);
44904 assert( pFile->locktype==SHARED_LOCK );
44905 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
44923 assert( pFile->locktype>=SHARED_LOCK );
44924 res = winUnlockReadLock(pFile);
44925 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
44931 winGetReadLock(pFile);
44939 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
44948 pFile->lastErrno = lastErrno;
44951 pFile->h, locktype, newLocktype));
44953 pFile->locktype = (u8)newLocktype;
44955 pFile->h, pFile->locktype, sqlite3ErrName(rc)));
44966 winFile *pFile = (winFile*)id;
44969 OSTRACE(("TEST-WR-LOCK file=%p, pResOut=%p\n", pFile->h, pResOut));
44972 if( pFile->locktype>=RESERVED_LOCK ){
44974 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
44976 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
44978 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
44981 OSTRACE(("TEST-WR-LOCK file=%p, result=%d (remote)\n", pFile->h, res));
44985 pFile->h, pResOut, *pResOut));
45002 winFile *pFile = (winFile*)id;
45004 assert( pFile!=0 );
45007 pFile->h, pFile->locktype, pFile->sharedLockByte, locktype));
45008 type = pFile->locktype;
45010 winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
45011 if( locktype==SHARED_LOCK && !winGetReadLock(pFile) ){
45015 "winUnlock", pFile->zPath);
45019 winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
45022 winUnlockReadLock(pFile);
45025 winUnlockFile(&pFile->h, PENDING_BYTE, 0, 1, 0);
45027 pFile->locktype = (u8)locktype;
45029 pFile->h, pFile->locktype, sqlite3ErrName(rc)));
45077 static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){
45079 *pArg = (pFile->ctrlFlags & mask)!=0;
45081 pFile->ctrlFlags &= ~mask;
45083 pFile->ctrlFlags |= mask;
45097 winFile *pFile = (winFile*)id;
45098 OSTRACE(("FCNTL file=%p, op=%d, pArg=%p\n", pFile->h, op, pArg));
45101 *(int*)pArg = pFile->locktype;
45102 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45106 *(int*)pArg = (int)pFile->lastErrno;
45107 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45111 pFile->szChunk = *(int *)pArg;
45112 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45116 if( pFile->szChunk>0 ){
45127 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
45130 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45134 winModeBit(pFile, WINFILE_PERSIST_WAL, (int*)pArg);
45135 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45139 winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
45140 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45144 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
45145 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45160 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45165 *phFile = pFile->h;
45166 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
45172 HANDLE hOldFile = pFile->h;
45173 pFile->h = *phFile;
45176 hOldFile, pFile->h));
45182 int rc = winGetTempname(pFile->pVfs, &zTFile);
45186 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
45204 *(i64*)pArg = pFile->mmapSizeMax;
45205 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
45206 pFile->mmapSizeMax = newLimit;
45207 if( pFile->mmapSize>0 ){
45208 winUnmapfile(pFile);
45209 rc = winMapfile(pFile, -1);
45212 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
45217 OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
45372 winShmNode *pFile, /* Apply locks to this open shared-memory segment */
45380 assert( pFile->nRef==0 || sqlite3_mutex_held(pFile->mutex) );
45383 pFile->hFile.h, lockType, ofst, nByte));
45387 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
45392 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
45398 pFile->lastErrno = osGetLastError();
45403 pFile->hFile.h, (lockType == WINSHM_UNLCK) ? "winUnlockFile" :
45404 "winLockFile", pFile->lastErrno, sqlite3ErrName(rc)));
45940 static int winUnmapfile(winFile *pFile){
45941 assert( pFile!=0 );
45944 osGetCurrentProcessId(), pFile, pFile->hMap, pFile->pMapRegion,
45945 pFile->mmapSize, pFile->mmapSizeMax));
45946 if( pFile->pMapRegion ){
45947 if( !osUnmapViewOfFile(pFile->pMapRegion) ){
45948 pFile->lastErrno = osGetLastError();
45950 "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), pFile,
45951 pFile->pMapRegion));
45952 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
45953 "winUnmapfile1", pFile->zPath);
45955 pFile->pMapRegion = 0;
45956 pFile->mmapSize = 0;
45958 if( pFile->hMap!=NULL ){
45959 if( !osCloseHandle(pFile->hMap) ){
45960 pFile->lastErrno = osGetLastError();
45962 osGetCurrentProcessId(), pFile, pFile->hMap));
45963 return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
45964 "winUnmapfile2", pFile->zPath);
45966 pFile->hMap = NULL;
45969 osGetCurrentProcessId(), pFile));
46588 winFile *pFile = (winFile*)id;
46646 assert( pFile!=0 );
46647 memset(pFile, 0, sizeof(winFile));
46648 pFile->h = INVALID_HANDLE_VALUE;
46812 pFile->lastErrno = lastErrno;
46813 winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name);
46836 && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
46846 pFile->zDeleteOnClose = zConverted;
46854 pFile->pMethod = pAppData ? pAppData->pMethod : &winIoMethod;
46855 pFile->pVfs = pVfs;
46856 pFile->h = h;
46858 pFile->ctrlFlags |= WINFILE_RDONLY;
46863 pFile->ctrlFlags |= WINFILE_PSOW;
46865 pFile->lastErrno = NO_ERROR;
46866 pFile->zPath = zName;
46868 pFile->hMap = NULL;
46869 pFile->pMapRegion = 0;
46870 pFile->mmapSize = 0;
46871 pFile->mmapSizeMax = sqlite3GlobalConfig.szMmap;
47869 static int memdbClose(sqlite3_file *pFile){
47870 MemFile *p = (MemFile *)pFile;
47879 sqlite3_file *pFile,
47884 MemFile *p = (MemFile *)pFile;
47918 sqlite3_file *pFile,
47923 MemFile *p = (MemFile *)pFile;
47946 static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
47947 MemFile *p = (MemFile *)pFile;
47956 static int memdbSync(sqlite3_file *pFile, int flags){
47963 static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
47964 MemFile *p = (MemFile *)pFile;
47972 static int memdbLock(sqlite3_file *pFile, int eLock){
47973 MemFile *p = (MemFile *)pFile;
47987 static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
47996 static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
47997 MemFile *p = (MemFile *)pFile;
48023 static int memdbSectorSize(sqlite3_file *pFile){
48031 static int memdbDeviceCharacteristics(sqlite3_file *pFile){
48040 sqlite3_file *pFile,
48045 MemFile *p = (MemFile *)pFile;
48056 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
48057 MemFile *p = (MemFile *)pFile;
48068 sqlite3_file *pFile,
48072 MemFile *p = (MemFile*)pFile;
48074 return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags);
54243 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *pFile){
54244 int iRet = sqlite3OsSectorSize(pFile);
55214 sqlite3_file *pFile, /* Write the file descriptor here */
55225 rc = sqlite3OsOpen(pPager->pVfs, 0, pFile, vfsFlags, 0);
55226 assert( rc!=SQLITE_OK || isOpen(pFile) );
66926 sqlite3_file *pFile;
66936 pFile = sqlite3PagerFile(pBt->pPager);
66937 if( pFile->pMethods ){
66938 sqlite3OsFileControlHint(pFile, SQLITE_FCNTL_PDB, (void*)&pBt->db);
75158 static int backupTruncateFile(sqlite3_file *pFile, i64 iSize){
75160 int rc = sqlite3OsFileSize(pFile, &iCurrent);
75162 rc = sqlite3OsTruncate(pFile, iSize);
75337 sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
75343 assert( pFile );
75383 rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
75388 rc = backupTruncateFile(pFile, iSize);
94270 static int vdbeSorterMapFile(SortSubtask *pTask, SorterFile *pFile, u8 **pp){
94272 if( pFile->iEof<=(i64)(pTask->pSorter->db->nMaxSorterMmap) ){
94273 sqlite3_file *pFd = pFile->pFd;
94275 rc = sqlite3OsFetch(pFd, 0, (int)pFile->iEof, (void**)pp);
94290 SorterFile *pFile, /* Sorter file to read from */
94303 pReadr->iEof = pFile->iEof;
94304 pReadr->pFd = pFile->pFd;
94306 rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap);
94383 SorterFile *pFile, /* Sorter file to read from */
94390 assert( pFile->iEof>iStart );
94395 rc = vdbePmaReaderSeek(pTask, pReadr, pFile, iStart);
126377 sqlite3_file *pFile = sqlite3PagerFile(pPager);
126378 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
126383 sqlite3_file *pFile = sqlite3PagerFile(pPager);
126386 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
126389 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
199456 static int rbuVfsClose(sqlite3_file *pFile){
199457 rbu_file *p = (rbu_file*)pFile;
199516 sqlite3_file *pFile,
199521 rbu_file *p = (rbu_file*)pFile;
199582 sqlite3_file *pFile,
199587 rbu_file *p = (rbu_file*)pFile;
199624 static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
199625 rbu_file *p = (rbu_file*)pFile;
199636 static int rbuVfsSync(sqlite3_file *pFile, int flags){
199637 rbu_file *p = (rbu_file *)pFile;
199650 static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
199651 rbu_file *p = (rbu_file *)pFile;
199671 static int rbuVfsLock(sqlite3_file *pFile, int eLock){
199672 rbu_file *p = (rbu_file*)pFile;
199693 static int rbuVfsUnlock(sqlite3_file *pFile, int eLock){
199694 rbu_file *p = (rbu_file *)pFile;
199701 static int rbuVfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
199702 rbu_file *p = (rbu_file *)pFile;
199709 static int rbuVfsFileControl(sqlite3_file *pFile, int op, void *pArg){
199710 rbu_file *p = (rbu_file *)pFile;
199765 static int rbuVfsSectorSize(sqlite3_file *pFile){
199766 rbu_file *p = (rbu_file *)pFile;
199773 static int rbuVfsDeviceCharacteristics(sqlite3_file *pFile){
199774 rbu_file *p = (rbu_file *)pFile;
199781 static int rbuVfsShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
199782 rbu_file *p = (rbu_file*)pFile;
199818 sqlite3_file *pFile,
199824 rbu_file *p = (rbu_file*)pFile;
199875 static void rbuVfsShmBarrier(sqlite3_file *pFile){
199876 rbu_file *p = (rbu_file *)pFile;
199883 static int rbuVfsShmUnmap(sqlite3_file *pFile, int delFlag){
199884 rbu_file *p = (rbu_file*)pFile;
199905 sqlite3_file *pFile,
199931 rbu_file *pFd = (rbu_file *)pFile;
200000 pFile->pMethods = &rbuvfs_io_methods;