[PATCH] D31831: posix_fallocate isn't support on all filesystems

Sid Manning via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 11:06:40 PDT 2017


sidneym created this revision.

Check the return from posix_fallocate and if the filesystem doesn't support it fall back to ftruncate.


Repository:
  rL LLVM

https://reviews.llvm.org/D31831

Files:
  lib/Support/Unix/Path.inc


Index: lib/Support/Unix/Path.inc
===================================================================
--- lib/Support/Unix/Path.inc
+++ lib/Support/Unix/Path.inc
@@ -421,8 +421,12 @@
 #if defined(HAVE_POSIX_FALLOCATE)
   // If we have posix_fallocate use it. Unlike ftruncate it always allocates
   // space, so we get an error if the disk is full.
-  if (int Err = ::posix_fallocate(FD, 0, Size))
-    return std::error_code(Err, std::generic_category());
+  if (int Err = ::posix_fallocate(FD, 0, Size)) {
+    if (Err != EOPNOTSUPP)
+      return std::error_code(Err, std::generic_category());
+  }
+  if (::ftruncate(FD, Size) == -1)
+    return std::error_code(errno, std::generic_category());
 #else
   // Use ftruncate as a fallback. It may or may not allocate space. At least on
   // OS X with HFS+ it does.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31831.94568.patch
Type: text/x-patch
Size: 816 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170410/8be9811e/attachment.bin>


More information about the llvm-commits mailing list