This is an archive of the discontinued LLVM Phabricator instance.

posix_fallocate isn't support on all filesystems
AcceptedPublic

Authored by sidneym on Apr 7 2017, 2:53 PM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

sidneym created this revision.Apr 7 2017, 2:53 PM
shankare accepted this revision.Apr 10 2017, 6:34 PM
This revision is now accepted and ready to land.Apr 10 2017, 6:34 PM
sidneym updated this revision to Diff 94968.Apr 12 2017, 7:42 AM

Remove braces

sidneym requested review of this revision.Apr 22 2017, 6:35 AM
sidneym edited edge metadata.
rafael edited edge metadata.Apr 25 2017, 6:33 AM

Please don't duplicate the code in the compile time and runtime checks. Can you do something like

#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.

int Err = ::posix_fallocate(FD, 0, Size);
if (!Err)

return std::error_code();

if (Err && Err != EOPNOTSUPP)

  return std::error_code(Err, std::generic_category());

// Add a comment about which file systems don't support posix_fallocate.

#endif

// Use ftruncate as a fallback. It may or may not allocate space. At least on
// OS X with HFS+ it does.
if (::ftruncate(FD, Size) == -1)
  return std::error_code(errno, std::generic_category());
This revision is now accepted and ready to land.Apr 25 2017, 6:33 AM
sidneym updated this revision to Diff 97457.May 2 2017, 8:57 AM

Removed duplicated code.

espindola edited reviewers, added: espindola; removed: rafael.Mar 14 2018, 4:53 PM