]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Ensure that when a file is extended using FCNTL_SIZE_HINT the last page is allocated...
authordan <dan@noemail.net>
Tue, 30 Dec 2014 19:58:31 +0000 (19:58 +0000)
committerdan <dan@noemail.net>
Tue, 30 Dec 2014 19:58:31 +0000 (19:58 +0000)
FossilOrigin-Name: c7f84717d61197afa9e0ac607c4b349361e6e2b7

manifest
manifest.uuid
src/os_unix.c

index 6c2e6952e99e77bab65a3359611db95df982d8fa..b8c410c1641d9cf4fc3456e29eada5480b340f1f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sthe\sthreadtest3\stest\sprogram\sso\sthat\sits\soutput\ssummary\sis\s\ncompatible\swith\sreleasetest.tcl.\s\sIn\sthreadtest3,\sdo\snot\srecord\serrors\nthat\scontain\sthe\sstring\s"no\ssuch\stable"\sas\sbeing\sfatal\serrors,\ssince\sthey\nhappen\ssometimes\sin\sa\srace\scondition\sin\sstress1.
-D 2014-12-30T19:26:07.267
+C Ensure\sthat\swhen\sa\sfile\sis\sextended\susing\sFCNTL_SIZE_HINT\sthe\slast\spage\sis\sallocated\son\sdisk,\seven\sif\sthe\sfile\swill\sonly\suse\spart\sof\sit.
+D 2014-12-30T19:58:31.340
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 40326b6d788007dd5e00587c54adcd2621832bb3
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -213,7 +213,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8
 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf
 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
-F src/os_unix.c 7f9ed5f05e4a9eb7275d1216e46d245d0cebfebb
+F src/os_unix.c 08c0346d2ea5e5ffd5b1a796f9becf1976d648d7
 F src/os_win.c 91d3d08e33ec0258d180d4c8255492f47d15e007
 F src/os_win.h 09e751b20bbc107ffbd46e13555dc73576d88e21
 F src/pager.c 2cbaf886a6157c53a8061ea7e677f81620ff46eb
@@ -1234,7 +1234,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 79693f0412ffb0486b974ee6c63b4231cfff5a77
-R 5cf8bac225464c2ed58e93713858c6ef
-U drh
-Z 61949e8b38696d2e4ed6889c396c567f
+P 98cb56e2401ae7e113b071df8997ba62265821d3
+R 42e94e61b93d775e47b58099deb363fd
+U dan
+Z 6763ecde934c72a96b9e8144b7d09293
index cee491506bb70106172c4653f03bfec50d27ba8a..1e1eaa02a9176e5998865c5c6f74a7d915854488 100644 (file)
@@ -1 +1 @@
-98cb56e2401ae7e113b071df8997ba62265821d3
\ No newline at end of file
+c7f84717d61197afa9e0ac607c4b349361e6e2b7
\ No newline at end of file
index 8314e4f678424d2e38f886c170d0ddb83635940b..f802d9cd1944567ee8cf50bc44f259a1a81f4a71 100644 (file)
@@ -3709,24 +3709,27 @@ static int fcntlSizeHint(unixFile *pFile, i64 nByte){
       }while( err==EINTR );
       if( err ) return SQLITE_IOERR_WRITE;
 #else
-      /* If the OS does not have posix_fallocate(), fake it. First use
-      ** ftruncate() to set the file size, then write a single byte to
-      ** the last byte in each block within the extended region. This
-      ** is the same technique used by glibc to implement posix_fallocate()
-      ** on systems that do not have a real fallocate() system call.
+      /* If the OS does not have posix_fallocate(), fake it. Write a 
+      ** single byte to the last byte in each block that falls entirely
+      ** within the extended region. Then, if required, a single byte
+      ** at offset (nSize-1), to set the size of the file correctly.
+      ** This is a similar technique to that used by glibc on systems
+      ** that do not have a real fallocate() call.
       */
       int nBlk = buf.st_blksize;  /* File-system block size */
       i64 iWrite;                 /* Next offset to write to */
 
       iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
-      while( iWrite<nSize ){
+      assert( iWrite>=buf.st_size );
+      assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
+      assert( ((iWrite+1)%nBlk)==0 );
+      for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
         int nWrite = seekAndWrite(pFile, iWrite, "", 1);
         if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
-        iWrite += nBlk;
       }
-      if( robust_ftruncate(pFile->h, nSize) ){
-        pFile->lastErrno = errno;
-        return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
+      if( nSize%nBlk ){
+        int nWrite = seekAndWrite(pFile, nSize-1, "", 1);
+        if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
       }
 #endif
     }