Index: src/os_win.c ================================================================== --- src/os_win.c +++ src/os_win.c @@ -148,16 +148,18 @@ HANDLE hMutex; /* Mutex used to control access to shared lock */ HANDLE hShared; /* Shared memory segment used for locking */ winceLock local; /* Locks obtained by this instance of winFile */ winceLock *shared; /* Global shared lock memory for the file */ #endif +#if !defined(SQLITE_DISABLE_MMAP) int nFetchOut; /* Number of outstanding xFetch references */ HANDLE hMap; /* Handle for accessing memory mapping */ void *pMapRegion; /* Area memory mapped */ sqlite3_int64 mmapSize; /* Usable size of mapped region */ sqlite3_int64 mmapOrigsize; /* Actual size of mapped region */ sqlite3_int64 mmapLimit; /* Configured FCNTL_MMAP_LIMIT value */ +#endif }; /* ** Allowed values for winFile.ctrlFlags */ @@ -2091,12 +2093,14 @@ assert( pFile->pShm==0 ); #endif OSTRACE(("CLOSE %d\n", pFile->h)); assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE ); +#if !defined(SQLITE_DISABLE_MMAP) rc = winUnmapfile(pFile); if( rc!=SQLITE_OK ) return rc; +#endif do{ rc = osCloseHandle(pFile->h); /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); @@ -2840,16 +2844,18 @@ getTempname(pFile->pVfs->mxPathname, zTFile); *(char**)pArg = zTFile; } return SQLITE_OK; } +#if !defined(SQLITE_DISABLE_MMAP) case SQLITE_FCNTL_MMAP_LIMIT: { i64 newLimit = *(i64*)pArg; *(i64*)pArg = pFile->mmapLimit; if( newLimit>=0 ) pFile->mmapLimit = newLimit; return SQLITE_OK; } +#endif } return SQLITE_NOTFOUND; } /* @@ -3519,13 +3525,13 @@ #endif /* #ifndef SQLITE_OMIT_WAL */ /* ** Cleans up the mapped region of the specified file, if any. */ +#if !defined(SQLITE_DISABLE_MMAP) static int winUnmapfile(winFile *pFile){ assert( pFile!=0 ); -#if !defined(SQLITE_DISABLE_MMAP) if( pFile->pMapRegion ){ if( !osUnmapViewOfFile(pFile->pMapRegion) ){ pFile->lastErrno = osGetLastError(); return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno, "winUnmap1", pFile->zPath); @@ -3540,15 +3546,13 @@ return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno, "winUnmap2", pFile->zPath); } pFile->hMap = NULL; } -#endif return SQLITE_OK; } -#if !defined(SQLITE_DISABLE_MMAP) /* ** Memory map or remap the file opened by file-descriptor pFd (if the file ** is already mapped, the existing mapping is replaced by the new). Or, if ** there already exists a mapping for this file, and there are still ** outstanding xFetch() references to it, this function is a no-op. @@ -3647,11 +3651,13 @@ ** ** If this function does return a pointer, the caller must eventually ** release the reference by calling unixUnfetch(). */ static int winFetch(sqlite3_file *fd, i64 iOff, int nAmt, void **pp){ +#if !defined(SQLITE_DISABLE_MMAP) winFile *pFd = (winFile*)fd; /* The underlying database file */ +#endif *pp = 0; #if !defined(SQLITE_DISABLE_MMAP) if( pFd->mmapLimit>0 ){ if( pFd->pMapRegion==0 ){ @@ -3676,10 +3682,11 @@ ** Or, if the third argument is NULL, then this function is being called ** to inform the VFS layer that, according to POSIX, any existing mapping ** may now be invalid and should be unmapped. */ static int winUnfetch(sqlite3_file *fd, i64 iOff, void *p){ +#if !defined(SQLITE_DISABLE_MMAP) winFile *pFd = (winFile*)fd; /* The underlying database file */ /* If p==0 (unmap the entire file) then there must be no outstanding ** xFetch references. Or, if p!=0 (meaning it is an xFetch reference), ** then there must be at least one outstanding. */ @@ -3697,10 +3704,11 @@ ** performance. */ winUnmapfile(pFd); } assert( pFd->nFetchOut>=0 ); +#endif return SQLITE_OK; } /* ** Here ends the implementation of all sqlite3_file methods. @@ -4124,15 +4132,17 @@ if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){ pFile->ctrlFlags |= WINFILE_PSOW; } pFile->lastErrno = NO_ERROR; pFile->zPath = zName; +#if !defined(SQLITE_DISABLE_MMAP) pFile->hMap = NULL; pFile->pMapRegion = 0; pFile->mmapSize = 0; pFile->mmapOrigsize = 0; pFile->mmapLimit = sqlite3GlobalConfig.mxMmap; +#endif OpenCounter(+1); return rc; }