Minor changes to unixMapfile() function.
FossilOrigin-Name: 80c63443c438ec21cc02880801d4fb4ca5f4e23f
diff --git a/manifest b/manifest
index 47745be..e313b11 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Further\sfixes\sfor\stest\sscripts.
-D 2013-03-29T19:38:52.044
+C Minor\schanges\sto\sunixMapfile()\sfunction.
+D 2013-04-01T14:20:23.253
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in df3e48659d80e1b7765785d8d66c86b320f72cc7
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -160,7 +160,7 @@
F src/os.c 809d0707cec693e1b9b376ab229271ad74c3d35d
F src/os.h ae08bcc5f6ec6b339f4a2adf3931bb88cc14c3e4
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
-F src/os_unix.c 0bebbe673f2831ce29c8da5f58f74e6c40c231ab
+F src/os_unix.c 2c54787f5c60b850bd8a9ed6c029100cde2429dc
F src/os_win.c e4f17ddf79f2a9373e33ed70565e765d65324589
F src/pager.c 30009ae5800f80e21da1f118fabfc72b34d8c722
F src/pager.h 5cb78b8e1adfd5451e600be7719f5a99d87ac3b1
@@ -1040,7 +1040,7 @@
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P e8bcdf938eee2c307c24d60d0295e5529291373b
-R cc0ac784c7ba54170d377b8c12f52908
+P 23ffa4f9fbad2e39cbe4776c7fdb61f757b6fc78
+R 6cd4d6bb1af95ad5b626cb22e4b9f0a4
U dan
-Z d70c61b9811bd758a9987aa7e37737bb
+Z 2b8cf21f2c6587ad7587cd5c8a9f710d
diff --git a/manifest.uuid b/manifest.uuid
index d95677a..e09af81 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-23ffa4f9fbad2e39cbe4776c7fdb61f757b6fc78
\ No newline at end of file
+80c63443c438ec21cc02880801d4fb4ca5f4e23f
\ No newline at end of file
diff --git a/src/os_unix.c b/src/os_unix.c
index 53d3fec..3b19539 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4590,12 +4590,17 @@
** code otherwise.
*/
static int unixMapfile(unixFile *pFd, i64 nByte){
- i64 nMap = nByte;
+ i64 nMap; /* Number of bytes of file to map */
int rc;
assert( nMap>=0 || pFd->nFetchOut==0 );
if( pFd->nFetchOut>0 ) return SQLITE_OK;
+ /* Set variable nMap to the number of bytes of the file to map. This is
+ ** the smaller of argument nByte and the limit configured by
+ ** SQLITE_FCNTL_MMAP_LIMIT. Or, if nByte is less than zero, the smaller
+ ** of the file size or the SQLITE_FCNTL_MMAP_LIMIT value. */
+ nMap = nByte;
if( nMap<0 ){
struct stat statbuf; /* Low-level file information */
rc = osFstat(pFd->h, &statbuf);
@@ -4609,7 +4614,6 @@
}
if( nMap!=(pFd->aMmap[0].mmapSize + pFd->aMmap[1].mmapSize) ){
- void *pNew = 0;
/* If the request is for a mapping zero bytes in size, or there are
** currently already two mapping regions, or there is already a mapping
@@ -4617,7 +4621,7 @@
** everything. */
if( nMap==0
#if !HAVE_MREMAP
- || (pFd->aMmap[0].pMapRegion && pFd->aMmap[1].pMapRegion)
+ || (pFd->aMmap[0].pMapRegion && pFd->aMmap[1].pMapRegion)
|| (pFd->aMmap[0].mmapSize % pFd->szSyspage)
#endif
){
@@ -4626,61 +4630,53 @@
assert( pFd->aMmap[1].pMapRegion==0 );
if( nMap>0 ){
+ unixMapping *pMap = &pFd->aMmap[0]; /* First mapping object */
+ void *pNew = 0;
+ int iNew = 0;
int flags = PROT_READ;
if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
/* If there are currently no mappings, create a new one */
- if( pFd->aMmap[0].pMapRegion==0 ){
+ if( pMap->pMapRegion==0 ){
pNew = osMmap(0, nMap, flags, MAP_SHARED, pFd->h, 0);
- if( pNew==MAP_FAILED ){
- return SQLITE_IOERR_MMAP;
- }
- pFd->aMmap[0].pMapRegion = pNew;
- pFd->aMmap[0].mmapSize = nMap;
- pFd->aMmap[0].mmapOrigsize = nMap;
}
#if HAVE_MREMAP
/* If we have an mremap() call, resize the existing mapping. */
else{
- unixMapping *pMap = &pFd->aMmap[0];
pNew = osMremap(
pMap->pMapRegion, pMap->mmapOrigsize, nMap, MREMAP_MAYMOVE
);
- if( pNew==MAP_FAILED ){
- return SQLITE_IOERR_MMAP;
- }
- pFd->aMmap[0].pMapRegion = pNew;
- pFd->aMmap[0].mmapSize = nMap;
- pFd->aMmap[0].mmapOrigsize = nMap;
}
#else
/* Otherwise, create a second mapping. If the existing mapping is
** a multiple of the page-size in size, then request that the new
** mapping immediately follow the old in virtual memory. */
else{
- unixMapping *pMap = &pFd->aMmap[0];
- void *pAddr = 0;
+ i64 nNew; /* Bytes to map with this call */
+ void *pAddr = 0; /* Virtual address to request mapping at */
- nMap -= pMap->mmapSize;
-
+ nNew = nMap - pMap->mmapSize;
if( pMap->mmapSize==pMap->mmapOrigsize ){
pAddr = (void *)&((u8 *)pMap->pMapRegion)[pMap->mmapSize];
}
- pNew = osMmap(pAddr, nMap, flags, MAP_SHARED, pFd->h, pMap->mmapSize);
- if( pNew==MAP_FAILED ){
- return SQLITE_IOERR_MMAP;
- }
- if( pNew==pAddr ){
- pMap->mmapOrigsize += nMap;
- pMap->mmapSize += nMap;
+ pNew = osMmap(pAddr, nNew, flags, MAP_SHARED, pFd->h, pMap->mmapSize);
+
+ if( pAddr && pNew==pAddr ){
+ pNew = pMap->pMapRegion;
}else{
- pFd->aMmap[1].pMapRegion = pNew;
- pFd->aMmap[1].mmapSize = nMap;
- pFd->aMmap[1].mmapOrigsize = nMap;
+ iNew = 1;
+ nMap = nNew;
}
}
#endif
+
+ if( pNew==MAP_FAILED ){
+ return SQLITE_IOERR_MMAP;
+ }
+ pFd->aMmap[iNew].pMapRegion = pNew;
+ pFd->aMmap[iNew].mmapSize = nMap;
+ pFd->aMmap[iNew].mmapOrigsize = nMap;
}
}