Bug 791301 - Generic fallocate code is broken for files smaller than system block size. r=taras
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Mon, 17 Sep 2012 13:27:24 +0200
changeset 107219 00be82b962919407576c0ec6501047dad8736320
parent 107218 b581153778607d6abb20337a6f228f8d7d293815
child 107220 05ce8d0d6e98bc393a883a79deff38130bcda3a7
push id14915
push usergpascutto@mozilla.com
push dateMon, 17 Sep 2012 11:28:08 +0000
treeherdermozilla-inbound@00be82b96291 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs791301
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 791301 - Generic fallocate code is broken for files smaller than system block size. r=taras
xpcom/glue/FileUtils.cpp
--- a/xpcom/glue/FileUtils.cpp
+++ b/xpcom/glue/FileUtils.cpp
@@ -78,20 +78,21 @@ mozilla::fallocate(PRFileDesc *aFD, int6
   if (!nBlk)
     return false;
 
   if (ftruncate(fd, aLength))
     return false;
 
   int nWrite; // Return value from write()
   int64_t iWrite = ((buf.st_size + 2 * nBlk - 1) / nBlk) * nBlk - 1; // Next offset to write to
-  do {
+  while (iWrite < aLength) {
     nWrite = 0;
     if (PR_Seek64(aFD, iWrite, PR_SEEK_SET) == iWrite)
       nWrite = PR_Write(aFD, "", 1);
+    if (nWrite != 1) break;
     iWrite += nBlk;
-  } while (nWrite == 1 && iWrite < aLength);
+  }
 
   PR_Seek64(aFD, oldpos, PR_SEEK_SET);
   return nWrite == 1;
 #endif
   return false;
 }