Lines Matching refs:pFile
14463 sqlite3_file *pFile, in sqlite3OsOpen() argument
14473 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut); in sqlite3OsOpen()
14474 assert( rc==SQLITE_OK || pFile->pMethods==0 ); in sqlite3OsOpen()
14544 sqlite3_file *pFile; in sqlite3OsOpenMalloc() local
14545 pFile = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile); in sqlite3OsOpenMalloc()
14546 if( pFile ){ in sqlite3OsOpenMalloc()
14547 rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags); in sqlite3OsOpenMalloc()
14549 sqlite3_free(pFile); in sqlite3OsOpenMalloc()
14551 *ppFile = pFile; in sqlite3OsOpenMalloc()
14556 SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *pFile){ in sqlite3OsCloseFree() argument
14558 assert( pFile ); in sqlite3OsCloseFree()
14559 rc = sqlite3OsClose(pFile); in sqlite3OsCloseFree()
14560 sqlite3_free(pFile); in sqlite3OsCloseFree()
22543 os2File *pFile = (os2File*)id;
22546 OSTRACE(( "CLOSE %d (%s)\n", pFile->h, pFile->zFullPathCp ));
22548 rc = DosClose( pFile->h );
22550 if( pFile->flags & SQLITE_OPEN_DELETEONCLOSE )
22551 DosForceDelete( (PSZ)pFile->zFullPathCp );
22553 free( pFile->zFullPathCp );
22554 pFile->zFullPathCp = NULL;
22555 pFile->locktype = NO_LOCK;
22556 pFile->h = (HFILE)-1;
22557 pFile->flags = 0;
22576 os2File *pFile = (os2File*)id;
22579 OSTRACE(( "READ %d lock=%d\n", pFile->h, pFile->locktype ));
22580 if( DosSetFilePtr(pFile->h, offset, FILE_BEGIN, &fileLocation) != NO_ERROR ){
22583 if( DosRead( pFile->h, pBuf, amt, &got ) != NO_ERROR ){
22608 os2File *pFile = (os2File*)id;
22612 OSTRACE(( "WRITE %d lock=%d\n", pFile->h, pFile->locktype ));
22613 if( DosSetFilePtr(pFile->h, offset, FILE_BEGIN, &fileLocation) != NO_ERROR ){
22618 ( rc = DosWrite( pFile->h, (PVOID)pBuf, amt, &wrote ) ) == NO_ERROR &&
22633 os2File *pFile = (os2File*)id;
22635 OSTRACE(( "TRUNCATE %d %lld\n", pFile->h, nByte ));
22643 if( pFile->szChunk ){
22644 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
22647 rc = DosSetFileSize( pFile->h, nByte );
22664 os2File *pFile = (os2File*)id;
22665 OSTRACE(( "SYNC %d lock=%d\n", pFile->h, pFile->locktype ));
22676 UNUSED_PARAMETER(pFile);
22679 return DosResetBuffer( pFile->h ) == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
22704 static int getReadLock( os2File *pFile ){
22714 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 1L );
22715 OSTRACE(( "GETREADLOCK %d res=%d\n", pFile->h, res ));
22770 os2File *pFile = (os2File*)id;
22773 assert( pFile!=0 );
22774 OSTRACE(( "LOCK %d %d was %d\n", pFile->h, locktype, pFile->locktype ));
22780 if( pFile->locktype>=locktype ){
22781 OSTRACE(( "LOCK %d %d ok (already held)\n", pFile->h, locktype ));
22787 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
22789 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK );
22795 newLocktype = pFile->locktype;
22796 if( pFile->locktype==NO_LOCK
22797 || (locktype==EXCLUSIVE_LOCK && pFile->locktype==RESERVED_LOCK)
22805 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, 100L, 0L );
22808 OSTRACE(( "LOCK %d pending lock boolean set. res=%d\n", pFile->h, res ));
22815 assert( pFile->locktype==NO_LOCK );
22816 res = getReadLock(pFile);
22820 OSTRACE(( "LOCK %d acquire shared lock. res=%d\n", pFile->h, res ));
22826 assert( pFile->locktype==SHARED_LOCK );
22831 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
22835 OSTRACE(( "LOCK %d acquire reserved lock. res=%d\n", pFile->h, res ));
22844 pFile->h ));
22850 assert( pFile->locktype>=SHARED_LOCK );
22851 res = unlockReadLock(pFile);
22857 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
22862 getReadLock(pFile);
22864 OSTRACE(( "LOCK %d acquire exclusive lock. res=%d\n", pFile->h, res ));
22876 r = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
22877 OSTRACE(( "LOCK %d unlocking pending/is shared. r=%d\n", pFile->h, r ));
22886 OSTRACE(( "LOCK FAILED %d trying for %d but got %d\n", pFile->h,
22890 pFile->locktype = newLocktype;
22891 OSTRACE(( "LOCK %d now %d\n", pFile->h, pFile->locktype ));
22902 os2File *pFile = (os2File*)id;
22903 assert( pFile!=0 );
22904 if( pFile->locktype>=RESERVED_LOCK ){
22906 OSTRACE(( "TEST WR-LOCK %d %d (local)\n", pFile->h, r ));
22917 rc = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
22918 OSTRACE(( "TEST WR-LOCK %d lock reserved byte rc=%d\n", pFile->h, rc ));
22925 rcu = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
22926 OSTRACE(( "TEST WR-LOCK %d unlock reserved byte r=%d\n", pFile->h, rcu ));
22929 OSTRACE(( "TEST WR-LOCK %d %d (remote)\n", pFile->h, r ));
22948 os2File *pFile = (os2File*)id;
22955 assert( pFile!=0 );
22957 OSTRACE(( "UNLOCK %d to %d was %d\n", pFile->h, locktype, pFile->locktype ));
22958 type = pFile->locktype;
22964 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
22965 OSTRACE(( "UNLOCK %d exclusive lock res=%d\n", pFile->h, res ));
22966 if( locktype==SHARED_LOCK && getReadLock(pFile) != NO_ERROR ){
22969 OSTRACE(( "UNLOCK %d to %d getReadLock() failed\n", pFile->h, locktype ));
22978 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
22979 OSTRACE(( "UNLOCK %d reserved res=%d\n", pFile->h, res ));
22982 res = unlockReadLock(pFile);
22984 pFile->h, type, locktype, res ));
22991 res = DosSetFileLocks( pFile->h, &UnlockArea, &LockArea, LOCK_TIMEOUT, 0L );
22992 OSTRACE(( "UNLOCK %d pending res=%d\n", pFile->h, res ));
22994 pFile->locktype = locktype;
22995 OSTRACE(( "UNLOCK %d now %d\n", pFile->h, pFile->locktype ));
23524 os2File *pFile = (os2File*)id;
23528 if( !pFile->pShmLink )
23529 rc = os2OpenSharedMemory( pFile, szRegion );
23532 pNode = pFile->pShmLink->pShmNode ;
23592 pFile->zFullPathCp, iRegion, szRegion, bExtend, rc))
23608 os2File *pFile = (os2File*)id;
23609 os2ShmLink *pLink = pFile->pShmLink;
23632 pFile->pShmLink = NULL;
23660 os2File *pFile = (os2File*)id;
23661 os2ShmLink *p = pFile->pShmLink; /* The shared memory being locked */
23917 os2File *pFile = (os2File*)id;
23965 memset( pFile, 0, sizeof(*pFile) );
23966 pFile->h = (HFILE)-1;
24039 pFile->zFullPathCp = convertUtf8PathToCp( zTmpname );
24040 pFile->pMethod = &os2IoMethod;
24041 pFile->flags = flags;
24042 pFile->h = h;
24045 OSTRACE(( "OPEN %d pOutFlags=%d\n", pFile->h, pOutFlags ));
25645 static void robust_close(unixFile *pFile, int h, int lineno){
25648 pFile ? pFile->zPath : 0, lineno);
25655 static void closePendingFds(unixFile *pFile){
25656 unixInodeInfo *pInode = pFile->pInode;
25661 robust_close(pFile, p->fd, __LINE__);
25673 static void releaseInodeInfo(unixFile *pFile){
25674 unixInodeInfo *pInode = pFile->pInode;
25680 closePendingFds(pFile);
25708 unixFile *pFile, /* Unix file with file desc used in the key */
25722 fd = pFile->h;
25725 pFile->lastErrno = errno;
25727 if( pFile->lastErrno==EOVERFLOW ) return SQLITE_NOLFS;
25743 if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
25746 pFile->lastErrno = errno;
25751 pFile->lastErrno = errno;
25760 fileId.pId = pFile->pId;
25797 unixFile *pFile = (unixFile*)id;
25801 assert( pFile );
25805 if( pFile->pInode->eFileLock>SHARED_LOCK ){
25812 if( !reserved && !pFile->pInode->bProcessLock ){
25818 if( osFcntl(pFile->h, F_GETLK, &lock) ){
25820 pFile->lastErrno = errno;
25828 OSTRACE(("TEST WR-LOCK %d %d %d (unix)\n", pFile->h, rc, reserved));
25853 static int unixFileLock(unixFile *pFile, struct flock *pLock){
25855 unixInodeInfo *pInode = pFile->pInode;
25858 if( ((pFile->ctrlFlags & UNIXFILE_EXCL)!=0 || pInode->bProcessLock)
25859 && ((pFile->ctrlFlags & UNIXFILE_RDONLY)==0)
25868 rc = osFcntl(pFile->h, F_SETLK, &lock);
25876 rc = osFcntl(pFile->h, F_SETLK, pLock);
25945 unixFile *pFile = (unixFile*)id;
25946 unixInodeInfo *pInode = pFile->pInode;
25950 assert( pFile );
25951 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
25952 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
25959 if( pFile->eFileLock>=eFileLock ){
25960 OSTRACE(("LOCK %d %s ok (already held) (unix)\n", pFile->h,
25970 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
25972 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
25977 pInode = pFile->pInode;
25982 if( (pFile->eFileLock!=pInode->eFileLock &&
25996 assert( pFile->eFileLock==0 );
25998 pFile->eFileLock = SHARED_LOCK;
26012 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
26016 if( unixFileLock(pFile, &lock) ){
26020 pFile->lastErrno = tErrno;
26038 if( unixFileLock(pFile, &lock) ){
26047 if( unixFileLock(pFile, &lock) && rc==SQLITE_OK ){
26055 pFile->lastErrno = tErrno;
26059 pFile->eFileLock = SHARED_LOCK;
26072 assert( 0!=pFile->eFileLock );
26084 if( unixFileLock(pFile, &lock) ){
26088 pFile->lastErrno = tErrno;
26101 && pFile->eFileLock<=SHARED_LOCK
26104 pFile->transCntrChng = 0;
26105 pFile->dbUpdate = 0;
26106 pFile->inNormalWrite = 1;
26112 pFile->eFileLock = eFileLock;
26115 pFile->eFileLock = PENDING_LOCK;
26121 OSTRACE(("LOCK %d %s %s (unix)\n", pFile->h, azFileLock(eFileLock),
26130 static void setPendingFd(unixFile *pFile){
26131 unixInodeInfo *pInode = pFile->pInode;
26132 UnixUnusedFd *p = pFile->pUnused;
26135 pFile->h = -1;
26136 pFile->pUnused = 0;
26153 unixFile *pFile = (unixFile*)id;
26159 assert( pFile );
26160 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
26161 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
26165 if( pFile->eFileLock<=eFileLock ){
26169 h = pFile->h;
26170 pInode = pFile->pInode;
26172 if( pFile->eFileLock>SHARED_LOCK ){
26173 assert( pInode->eFileLock==pFile->eFileLock );
26188 assert( pFile->inNormalWrite==0
26189 || pFile->dbUpdate==0
26190 || pFile->transCntrChng==1 );
26192 pFile->inNormalWrite = 0;
26219 if( unixFileLock(pFile, &lock)==(-1) ){
26223 pFile->lastErrno = tErrno;
26231 if( unixFileLock(pFile, &lock)==(-1) ){
26235 pFile->lastErrno = tErrno;
26243 if( unixFileLock(pFile, &lock)==(-1) ){
26247 pFile->lastErrno = tErrno;
26258 if( unixFileLock(pFile, &lock) ){
26266 pFile->lastErrno = errno;
26275 if( unixFileLock(pFile, &lock)==0 ){
26279 pFile->lastErrno = errno;
26296 if( unixFileLock(pFile, &lock)==0 ){
26300 pFile->lastErrno = errno;
26302 pFile->eFileLock = NO_LOCK;
26313 closePendingFds(pFile);
26319 if( rc==SQLITE_OK ) pFile->eFileLock = eFileLock;
26345 unixFile *pFile = (unixFile*)id;
26346 if( pFile->h>=0 ){
26347 robust_close(pFile, pFile->h, __LINE__);
26348 pFile->h = -1;
26351 if( pFile->pId ){
26352 if( pFile->isDelete ){
26353 osUnlink(pFile->pId->zCanonicalName);
26355 vxworksReleaseFileId(pFile->pId);
26356 pFile->pId = 0;
26359 OSTRACE(("CLOSE %-3d\n", pFile->h));
26361 sqlite3_free(pFile->pUnused);
26362 memset(pFile, 0, sizeof(unixFile));
26371 unixFile *pFile = (unixFile *)id;
26378 assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 );
26379 if( ALWAYS(pFile->pInode) && pFile->pInode->nLock ){
26385 setPendingFd(pFile);
26387 releaseInodeInfo(pFile);
26478 unixFile *pFile = (unixFile*)id;
26482 assert( pFile );
26485 if( pFile->eFileLock>SHARED_LOCK ){
26491 const char *zLockFile = (const char*)pFile->lockingContext;
26494 OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved));
26527 unixFile *pFile = (unixFile*)id;
26529 char *zLockFile = (char *)pFile->lockingContext;
26536 if( pFile->eFileLock > NO_LOCK ){
26537 pFile->eFileLock = eFileLock;
26557 pFile->lastErrno = tErrno;
26562 robust_close(pFile, fd, __LINE__);
26565 pFile->eFileLock = eFileLock;
26579 unixFile *pFile = (unixFile*)id;
26580 char *zLockFile = (char *)pFile->lockingContext;
26582 assert( pFile );
26583 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
26584 pFile->eFileLock, getpid()));
26588 if( pFile->eFileLock==eFileLock ){
26596 pFile->eFileLock = SHARED_LOCK;
26609 pFile->lastErrno = tErrno;
26613 pFile->eFileLock = NO_LOCK;
26623 unixFile *pFile = (unixFile*)id;
26625 sqlite3_free(pFile->lockingContext);
26673 unixFile *pFile = (unixFile*)id;
26677 assert( pFile );
26680 if( pFile->eFileLock>SHARED_LOCK ){
26687 int lrc = robust_flock(pFile->h, LOCK_EX | LOCK_NB);
26690 lrc = robust_flock(pFile->h, LOCK_UN);
26696 pFile->lastErrno = tErrno;
26706 pFile->lastErrno = tErrno;
26711 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
26754 unixFile *pFile = (unixFile*)id;
26756 assert( pFile );
26760 if (pFile->eFileLock > NO_LOCK) {
26761 pFile->eFileLock = eFileLock;
26767 if (robust_flock(pFile->h, LOCK_EX | LOCK_NB)) {
26772 pFile->lastErrno = tErrno;
26776 pFile->eFileLock = eFileLock;
26778 OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock),
26797 unixFile *pFile = (unixFile*)id;
26799 assert( pFile );
26800 OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock,
26801 pFile->eFileLock, getpid()));
26805 if( pFile->eFileLock==eFileLock ){
26811 pFile->eFileLock = eFileLock;
26816 if( robust_flock(pFile->h, LOCK_UN) ){
26822 pFile->eFileLock = NO_LOCK;
26863 unixFile *pFile = (unixFile*)id;
26867 assert( pFile );
26870 if( pFile->eFileLock>SHARED_LOCK ){
26876 sem_t *pSem = pFile->pInode->pSem;
26883 pFile->lastErrno = tErrno;
26886 reserved = (pFile->eFileLock < SHARED_LOCK);
26893 OSTRACE(("TEST WR-LOCK %d %d %d (sem)\n", pFile->h, rc, reserved));
26929 unixFile *pFile = (unixFile*)id;
26931 sem_t *pSem = pFile->pInode->pSem;
26936 if (pFile->eFileLock > NO_LOCK) {
26937 pFile->eFileLock = eFileLock;
26949 pFile->eFileLock = eFileLock;
26963 unixFile *pFile = (unixFile*)id;
26964 sem_t *pSem = pFile->pInode->pSem;
26966 assert( pFile );
26968 OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
26969 pFile->eFileLock, getpid()));
26973 if( pFile->eFileLock==eFileLock ){
26979 pFile->eFileLock = eFileLock;
26988 pFile->lastErrno = tErrno;
26992 pFile->eFileLock = NO_LOCK;
27001 unixFile *pFile = (unixFile*)id;
27003 assert( pFile );
27005 releaseInodeInfo(pFile);
27060 unixFile *pFile, /* Open file descriptor on path */
27072 pb.fd = pFile->h;
27075 (setLockFlag?"ON":"OFF"), pFile->h, (pb.fd==-1?"[testval-1]":""),
27090 pFile->lastErrno = tErrno;
27107 unixFile *pFile = (unixFile*)id;
27112 assert( pFile );
27113 context = (afpLockingContext *) pFile->lockingContext;
27121 if( pFile->pInode->eFileLock>SHARED_LOCK ){
27129 int lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1);
27133 lrc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
27144 OSTRACE(("TEST WR-LOCK %d %d %d (afp)\n", pFile->h, rc, reserved));
27176 unixFile *pFile = (unixFile*)id;
27177 unixInodeInfo *pInode = pFile->pInode;
27178 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
27180 assert( pFile );
27181 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h,
27182 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
27189 if( pFile->eFileLock>=eFileLock ){
27190 OSTRACE(("LOCK %d %s ok (already held) (afp)\n", pFile->h,
27200 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
27202 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
27207 pInode = pFile->pInode;
27212 if( (pFile->eFileLock!=pInode->eFileLock &&
27226 assert( pFile->eFileLock==0 );
27228 pFile->eFileLock = SHARED_LOCK;
27239 || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
27242 failed = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 1);
27264 lrc1 = afpSetLock(context->dbPath, pFile,
27267 lrc1Errno = pFile->lastErrno;
27270 lrc2 = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
27273 pFile->lastErrno = lrc1Errno;
27282 pFile->eFileLock = SHARED_LOCK;
27296 assert( 0!=pFile->eFileLock );
27297 if (eFileLock >= RESERVED_LOCK && pFile->eFileLock < RESERVED_LOCK) {
27299 failed = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1,1);
27310 if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST +
27314 failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST,
27316 if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
27335 pFile->eFileLock = eFileLock;
27338 pFile->eFileLock = PENDING_LOCK;
27344 OSTRACE(("LOCK %d %s %s (afp)\n", pFile->h, azFileLock(eFileLock),
27358 unixFile *pFile = (unixFile*)id;
27360 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
27363 int h = pFile->h;
27366 assert( pFile );
27367 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
27368 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
27372 if( pFile->eFileLock<=eFileLock ){
27376 pInode = pFile->pInode;
27378 if( pFile->eFileLock>SHARED_LOCK ){
27379 assert( pInode->eFileLock==pFile->eFileLock );
27393 assert( pFile->inNormalWrite==0
27394 || pFile->dbUpdate==0
27395 || pFile->transCntrChng==1 );
27396 pFile->inNormalWrite = 0;
27399 if( pFile->eFileLock==EXCLUSIVE_LOCK ){
27400 rc = afpSetLock(context->dbPath, pFile, SHARED_FIRST, SHARED_SIZE, 0);
27404 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 1);
27409 if( rc==SQLITE_OK && pFile->eFileLock>=PENDING_LOCK ){
27410 rc = afpSetLock(context->dbPath, pFile, PENDING_BYTE, 1, 0);
27412 if( rc==SQLITE_OK && pFile->eFileLock>=RESERVED_LOCK && context->reserved ){
27413 rc = afpSetLock(context->dbPath, pFile, RESERVED_BYTE, 1, 0);
27435 rc = afpSetLock(context->dbPath, pFile, sharedLockByte, 1, 0);
27439 pFile->eFileLock = NO_LOCK;
27446 closePendingFds(pFile);
27452 if( rc==SQLITE_OK ) pFile->eFileLock = eFileLock;
27462 unixFile *pFile = (unixFile*)id;
27465 if( pFile->pInode && pFile->pInode->nLock ){
27471 setPendingFd(pFile);
27473 releaseInodeInfo(pFile);
27474 sqlite3_free(pFile->lockingContext);
27582 unixFile *pFile = (unixFile *)id;
27589 assert( pFile->pUnused==0
27595 got = seekAndRead(pFile, offset, pBuf, amt);
27602 pFile->lastErrno = 0; /* not a system error */
27661 unixFile *pFile = (unixFile*)id;
27669 assert( pFile->pUnused==0
27682 if( pFile->inNormalWrite ){
27683 pFile->dbUpdate = 1; /* The database has been modified */
27688 rc = seekAndRead(pFile, 24, oldCntr, 4);
27691 pFile->transCntrChng = 1; /* The transaction counter has changed */
27697 while( amt>0 && (wrote = seekAndWrite(pFile, offset, pBuf, amt))>0 ){
27706 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
27710 pFile->lastErrno = 0; /* not a system error */
27902 unixFile *pFile = (unixFile*)id;
27917 assert( pFile );
27918 OSTRACE(("SYNC %-3d\n", pFile->h));
27919 rc = full_fsync(pFile->h, isFullsync, isDataOnly);
27922 pFile->lastErrno = errno;
27923 return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath);
27930 if( pFile->ctrlFlags & UNIXFILE_DIRSYNC ){
27932 OSTRACE(("DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n", pFile->zPath,
27934 rc = osOpenDirectory(pFile->zPath, &dirfd);
27937 robust_close(pFile, dirfd, __LINE__);
27941 pFile->ctrlFlags &= ~UNIXFILE_DIRSYNC;
27950 unixFile *pFile = (unixFile *)id;
27952 assert( pFile );
27960 if( pFile->szChunk ){
27961 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
27964 rc = robust_ftruncate(pFile->h, (off_t)nByte);
27966 pFile->lastErrno = errno;
27967 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
27977 if( pFile->inNormalWrite && nByte==0 ){
27978 pFile->transCntrChng = 1;
28027 static int fcntlSizeHint(unixFile *pFile, i64 nByte){
28028 if( pFile->szChunk>0 ){
28032 if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
28034 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
28043 err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
28056 if( robust_ftruncate(pFile->h, nSize) ){
28057 pFile->lastErrno = errno;
28058 return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
28062 int nWrite = seekAndWrite(pFile, iWrite, "", 1);
28077 unixFile *pFile = (unixFile*)id;
28080 *(int*)pArg = pFile->eFileLock;
28084 *(int*)pArg = pFile->lastErrno;
28088 pFile->szChunk = *(int *)pArg;
28094 rc = fcntlSizeHint(pFile, *(i64 *)pArg);
28101 *(int*)pArg = (pFile->ctrlFlags & UNIXFILE_PERSIST_WAL)!=0;
28103 pFile->ctrlFlags &= ~UNIXFILE_PERSIST_WAL;
28105 pFile->ctrlFlags |= UNIXFILE_PERSIST_WAL;
29512 sqlite3_file *pFile, /* The file descriptor to be filled in */
29516 unixFile *p = (unixFile *)pFile;
29667 ((unixFile*)pFile)->lastErrno = errno;
29672 ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS;
29705 rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock,
29708 rc = proxyTransformUnixFile((unixFile*)pFile, ":auto:");
29714 unixClose(pFile);
29723 rc = fillInUnixFile(pVfs, fd, syncDir, pFile, zPath, noLock,
30455 static int proxyBreakConchLock(unixFile *pFile, uuid_t myHostID){
30456 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
30498 robust_close(pFile, conchFile->h, __LINE__);
30506 robust_close(pFile, fd, __LINE__);
30516 static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
30517 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
30536 pFile->lastErrno = errno;
30556 pFile->lastErrno = errno;
30573 if( 0==proxyBreakConchLock(pFile, myHostID) ){
30594 static int proxyTakeConch(unixFile *pFile){
30595 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
30618 pFile->lastErrno = pError;
30621 rc = proxyConchLock(pFile, myHostID, SHARED_LOCK);
30629 pFile->lastErrno = conchFile->lastErrno;
30699 rc = proxyConchLock(pFile, myHostID, EXCLUSIVE_LOCK);
30724 int err = osFstat(pFile->h, &buf);
30753 OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h));
30754 if( rc==SQLITE_OK && pFile->openFlags ){
30756 if( pFile->h>=0 ){
30757 robust_close(pFile, pFile->h, __LINE__);
30759 pFile->h = -1;
30760 fd = robust_open(pCtx->dbPath, pFile->openFlags,
30764 pFile->h = fd;
30815 static int proxyReleaseConch(unixFile *pFile){
30820 pCtx = (proxyLockingContext *)pFile->lockingContext;
30882 static int switchLockProxyPath(unixFile *pFile, const char *path) {
30883 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
30887 if( pFile->eFileLock!=NO_LOCK ){
30918 static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
30920 if( pFile->pMethod == &afpIoMethods ){
30923 assert( (int)strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
30924 strlcpy(dbPath, ((afpLockingContext *)pFile->lockingContext)->dbPath, MAXPATHLEN);
30927 if( pFile->pMethod == &dotlockIoMethods ){
30930 int len = strlen((char *)pFile->lockingContext) - strlen(DOTLOCK_SUFFIX);
30931 memcpy(dbPath, (char *)pFile->lockingContext, len + 1);
30934 assert( strlen((char*)pFile->lockingContext)<=MAXPATHLEN );
30935 strlcpy(dbPath, (char *)pFile->lockingContext, MAXPATHLEN);
30948 static int proxyTransformUnixFile(unixFile *pFile, const char *path) {
30954 if( pFile->eFileLock!=NO_LOCK ){
30957 proxyGetDbPathForUnixFile(pFile, dbPath);
30964 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
30976 if( rc==SQLITE_CANTOPEN && ((pFile->openFlags&O_RDWR) == 0) ){
31012 pCtx->oldLockingContext = pFile->lockingContext;
31013 pFile->lockingContext = pCtx;
31014 pCtx->pOldMethod = pFile->pMethod;
31015 pFile->pMethod = &proxyIoMethods;
31025 OSTRACE(("TRANSPROXY %d %s\n", pFile->h,
31038 unixFile *pFile = (unixFile*)id;
31039 if( pFile->pMethod == &proxyIoMethods ){
31040 proxyLockingContext *pCtx = (proxyLockingContext*)pFile->lockingContext;
31041 proxyTakeConch(pFile);
31053 unixFile *pFile = (unixFile*)id;
31055 int isProxyStyle = (pFile->pMethod == &proxyIoMethods);
31068 (proxyLockingContext*)pFile->lockingContext;
31075 rc = switchLockProxyPath(pFile, proxyPath);
31079 rc = proxyTransformUnixFile(pFile, proxyPath);
31106 unixFile *pFile = (unixFile*)id;
31107 int rc = proxyTakeConch(pFile);
31109 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
31145 unixFile *pFile = (unixFile*)id;
31146 int rc = proxyTakeConch(pFile);
31148 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
31152 pFile->eFileLock = proxy->eFileLock;
31169 unixFile *pFile = (unixFile*)id;
31170 int rc = proxyTakeConch(pFile);
31172 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
31176 pFile->eFileLock = proxy->eFileLock;
31189 unixFile *pFile = (unixFile*)id;
31190 proxyLockingContext *pCtx = (proxyLockingContext *)pFile->lockingContext;
31205 rc = proxyReleaseConch(pFile);
31216 pFile->lockingContext = pCtx->oldLockingContext;
31217 pFile->pMethod = pCtx->pOldMethod;
31219 return pFile->pMethod->xClose(id);
32324 static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
32330 ZeroMemory(&pFile->local, sizeof(pFile->local));
32340 pFile->hMutex = CreateMutexW(NULL, FALSE, zName);
32341 if (!pFile->hMutex){
32342 pFile->lastErrno = GetLastError();
32349 winceMutexAcquire(pFile->hMutex);
32356 pFile->hShared = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
32369 if (pFile->hShared){
32370 pFile->shared = (winceLock*)MapViewOfFile(pFile->hShared,
32373 if (!pFile->shared){
32374 pFile->lastErrno = GetLastError();
32376 CloseHandle(pFile->hShared);
32377 pFile->hShared = NULL;
32382 if (pFile->hShared == NULL){
32383 winceMutexRelease(pFile->hMutex);
32384 CloseHandle(pFile->hMutex);
32385 pFile->hMutex = NULL;
32391 ZeroMemory(pFile->shared, sizeof(winceLock));
32394 winceMutexRelease(pFile->hMutex);
32401 static void winceDestroyLock(winFile *pFile){
32402 if (pFile->hMutex){
32404 winceMutexAcquire(pFile->hMutex);
32408 if (pFile->local.nReaders){
32409 pFile->shared->nReaders --;
32411 if (pFile->local.bReserved){
32412 pFile->shared->bReserved = FALSE;
32414 if (pFile->local.bPending){
32415 pFile->shared->bPending = FALSE;
32417 if (pFile->local.bExclusive){
32418 pFile->shared->bExclusive = FALSE;
32422 UnmapViewOfFile(pFile->shared);
32423 CloseHandle(pFile->hShared);
32426 winceMutexRelease(pFile->hMutex);
32427 CloseHandle(pFile->hMutex);
32428 pFile->hMutex = NULL;
32442 winFile *pFile = HANDLE_TO_WINFILE(phFile);
32448 if (!pFile->hMutex) return TRUE;
32449 winceMutexAcquire(pFile->hMutex);
32454 if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){
32455 pFile->shared->bExclusive = TRUE;
32456 pFile->local.bExclusive = TRUE;
32464 if (pFile->shared->bExclusive == 0){
32465 pFile->local.nReaders ++;
32466 if (pFile->local.nReaders == 1){
32467 pFile->shared->nReaders ++;
32476 if (pFile->shared->bPending == 0) {
32477 pFile->shared->bPending = TRUE;
32478 pFile->local.bPending = TRUE;
32485 if (pFile->shared->bReserved == 0) {
32486 pFile->shared->bReserved = TRUE;
32487 pFile->local.bReserved = TRUE;
32492 winceMutexRelease(pFile->hMutex);
32506 winFile *pFile = HANDLE_TO_WINFILE(phFile);
32512 if (!pFile->hMutex) return TRUE;
32513 winceMutexAcquire(pFile->hMutex);
32518 if (pFile->local.bExclusive){
32520 pFile->local.bExclusive = FALSE;
32521 pFile->shared->bExclusive = FALSE;
32526 else if (pFile->local.nReaders){
32528 pFile->local.nReaders --;
32529 if (pFile->local.nReaders == 0)
32531 pFile->shared->nReaders --;
32539 if (pFile->local.bPending){
32540 pFile->local.bPending = FALSE;
32541 pFile->shared->bPending = FALSE;
32547 if (pFile->local.bReserved) {
32548 pFile->local.bReserved = FALSE;
32549 pFile->shared->bReserved = FALSE;
32554 winceMutexRelease(pFile->hMutex);
32603 static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){
32618 dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
32620 pFile->lastErrno = GetLastError();
32621 winLogError(SQLITE_IOERR_SEEK, "seekWinFile", pFile->zPath);
32641 winFile *pFile = (winFile*)id;
32644 assert( pFile->pShm==0 );
32645 OSTRACE(("CLOSE %d\n", pFile->h));
32647 rc = CloseHandle(pFile->h);
32652 winceDestroyLock(pFile);
32653 if( pFile->zDeleteOnClose ){
32656 DeleteFileW(pFile->zDeleteOnClose)==0
32657 && GetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
32662 free(pFile->zDeleteOnClose);
32665 OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed"));
32668 : winLogError(SQLITE_IOERR_CLOSE, "winClose", pFile->zPath);
32682 winFile *pFile = (winFile*)id; /* file handle */
32688 OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype));
32690 if( seekWinFile(pFile, offset) ){
32693 while( !ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
32695 pFile->lastErrno = GetLastError();
32696 return winLogError(SQLITE_IOERR_READ, "winRead", pFile->zPath);
32719 winFile *pFile = (winFile*)id; /* File handle */
32723 assert( pFile );
32727 OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
32729 rc = seekWinFile(pFile, offset);
32736 if( !WriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
32745 pFile->lastErrno = GetLastError();
32751 if( ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
32752 || ( pFile->lastErrno==ERROR_DISK_FULL )){
32755 return winLogError(SQLITE_IOERR_WRITE, "winWrite", pFile->zPath);
32766 winFile *pFile = (winFile*)id; /* File handle object */
32769 assert( pFile );
32771 OSTRACE(("TRUNCATE %d %lld\n", pFile->h, nByte));
32779 if( pFile->szChunk>0 ){
32780 nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
32784 if( seekWinFile(pFile, nByte) ){
32785 rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate1", pFile->zPath);
32786 }else if( 0==SetEndOfFile(pFile->h) ){
32787 pFile->lastErrno = GetLastError();
32788 rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate2", pFile->zPath);
32791 OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok"));
32820 winFile *pFile = (winFile*)id;
32825 assert( pFile );
32831 OSTRACE(("SYNC %d lock=%d\n", pFile->h, pFile->locktype));
32853 rc = FlushFileBuffers(pFile->h);
32858 pFile->lastErrno = GetLastError();
32859 return winLogError(SQLITE_IOERR_FSYNC, "winSync", pFile->zPath);
32870 winFile *pFile = (winFile*)id;
32875 lowerBits = GetFileSize(pFile->h, &upperBits);
32879 pFile->lastErrno = error;
32880 return winLogError(SQLITE_IOERR_FSTAT, "winFileSize", pFile->zPath);
32898 static int getReadLock(winFile *pFile){
32905 res = LockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY,
32913 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
32914 res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
32918 pFile->lastErrno = GetLastError();
32927 static int unlockReadLock(winFile *pFile){
32930 res = UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
32935 res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
32939 pFile->lastErrno = GetLastError();
32940 winLogError(SQLITE_IOERR_UNLOCK, "unlockReadLock", pFile->zPath);
32976 winFile *pFile = (winFile*)id;
32981 pFile->h, locktype, pFile->locktype, pFile->sharedLockByte));
32987 if( pFile->locktype>=locktype ){
32993 assert( pFile->locktype!=NO_LOCK || locktype==SHARED_LOCK );
32995 assert( locktype!=RESERVED_LOCK || pFile->locktype==SHARED_LOCK );
33001 newLocktype = pFile->locktype;
33002 if( (pFile->locktype==NO_LOCK)
33004 && (pFile->locktype==RESERVED_LOCK))
33007 while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
33023 assert( pFile->locktype==NO_LOCK );
33024 res = getReadLock(pFile);
33035 assert( pFile->locktype==SHARED_LOCK );
33036 res = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
33054 assert( pFile->locktype>=SHARED_LOCK );
33055 res = unlockReadLock(pFile);
33057 res = LockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
33063 getReadLock(pFile);
33071 UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
33080 OSTRACE(("LOCK FAILED %d trying for %d but got %d\n", pFile->h,
33082 pFile->lastErrno = error;
33085 pFile->locktype = (u8)newLocktype;
33096 winFile *pFile = (winFile*)id;
33101 if( pFile->locktype>=RESERVED_LOCK ){
33103 OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
33105 rc = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
33107 UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
33110 OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
33129 winFile *pFile = (winFile*)id;
33131 assert( pFile!=0 );
33133 OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype,
33134 pFile->locktype, pFile->sharedLockByte));
33135 type = pFile->locktype;
33137 UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
33138 if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
33141 rc = winLogError(SQLITE_IOERR_UNLOCK, "winUnlock", pFile->zPath);
33145 UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
33148 unlockReadLock(pFile);
33151 UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
33153 pFile->locktype = (u8)locktype;
33161 winFile *pFile = (winFile*)id;
33164 *(int*)pArg = pFile->locktype;
33168 *(int*)pArg = (int)pFile->lastErrno;
33172 pFile->szChunk = *(int *)pArg;
33176 if( pFile->szChunk>0 ){
33194 *(int*)pArg = pFile->bPersistWal;
33196 pFile->bPersistWal = bPersist!=0;
33367 winShmNode *pFile, /* Apply locks to this open shared-memory segment */
33377 assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 );
33388 rc = UnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp);
33390 rc = LockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp);
33396 pFile->lastErrno = GetLastError();
33401 pFile->hFile.h,
33404 pFile->lastErrno));
34022 winFile *pFile = (winFile*)id;
34082 pFile->h = INVALID_HANDLE_VALUE;
34175 pFile->lastErrno = GetLastError();
34194 memset(pFile, 0, sizeof(*pFile));
34195 pFile->pMethod = &winIoMethod;
34196 pFile->h = h;
34197 pFile->lastErrno = NO_ERROR;
34198 pFile->pVfs = pVfs;
34199 pFile->pShm = 0;
34200 pFile->zPath = zName;
34201 pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
34205 && !winceCreateLock(zName, pFile)
34212 pFile->zDeleteOnClose = zConverted;
40928 sqlite3_file *pFile, /* Write the file descriptor here */
40939 rc = sqlite3OsOpen(pPager->pVfs, 0, pFile, vfsFlags, 0);
40940 assert( rc!=SQLITE_OK || isOpen(pFile) );
56746 static int backupTruncateFile(sqlite3_file *pFile, i64 iSize){
56748 int rc = sqlite3OsFileSize(pFile, &iCurrent);
56750 rc = sqlite3OsTruncate(pFile, iSize);
56906 sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
56910 assert( pFile );
56936 rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
56941 rc = backupTruncateFile(pFile, iSize);
70394 sqlite3_file *pFile; /* File iterator is reading from */
70452 rc = sqlite3OsRead(pIter->pFile, pIter->aAlloc, nRead, pIter->iReadOff);
70467 pIter->pFile, &pIter->aAlloc[nRead], nRead2, pIter->iReadOff+nRead
70488 sqlite3_file *pFile, /* File to write to */
70497 rc = sqlite3OsWrite(pFile, aVarint, nVarint, *piOffset);
70515 sqlite3_file *pFile, /* File to read from */
70523 rc = sqlite3OsRead(pFile, aVarint, 9, iOff);
70548 pIter->pFile = pSorter->pTemp1;
70639 if( p1->pFile==0 ){
70641 }else if( p2->pFile==0 ){
71018 assert( rc!=SQLITE_OK || pSorter->aIter[ pSorter->aTree[1] ].pFile );
71038 assert( pIter->pFile );
71065 *pbEof = (pSorter->aIter[pSorter->aTree[1]].pFile==0);
71085 *pbEof = (pSorter->aIter[pSorter->aTree[1]].pFile==0);
90750 sqlite3_file *pFile = sqlite3PagerFile(pPager);
90751 sqlite3OsFileControl(pFile, SQLITE_GET_LOCKPROXYFILE,
90763 sqlite3_file *pFile = sqlite3PagerFile(pPager);
90766 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,
90769 res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE,