Skip to content

Commit

Permalink
Merge bitcoin#15650: Handle the result of posix_fallocate system call
Browse files Browse the repository at this point in the history
5d35ae3 Handle the result of posix_fallocate system call (Luca Venturini)

Pull request description:

  The system call `posix_fallocate` is not supported on some filesystems.

  - catches the result of posix_allocate and fall back to the default behaviour if the return value is different from 0 (success)

  Fixes bitcoin#15624

ACKs for commit 5d35ae:
  MarcoFalke:
    utACK 5d35ae3
  sipa:
    utACK 5d35ae3, though the Yoda condition is an uncommon style in this project.
  hebasto:
    utACK 5d35ae3
  practicalswift:
    utACK 5d35ae3

Tree-SHA512: 7ab3b35fb633926f28a58b2b07ffde8e31bb997c80a716b1b45ee716fe9ff4ddcef0a05810bd4423530e220cfc62f8925517d27a8b92b05a524272063e43f746
  • Loading branch information
MarcoFalke authored and PastaPastaPasta committed Jun 27, 2021
1 parent 5f776c1 commit b504998
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,11 +1015,12 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
fcntl(fileno(file), F_PREALLOCATE, &fst);
}
ftruncate(fileno(file), fst.fst_length);
#elif defined(__linux__)
#else
#if defined(__linux__)
// Version using posix_fallocate
off_t nEndPos = (off_t)offset + length;
posix_fallocate(fileno(file), 0, nEndPos);
#else
if (0 == posix_fallocate(fileno(file), 0, nEndPos)) return;
#endif
// Fallback version
// TODO: just write one byte per block
static const char buf[65536] = {};
Expand Down

0 comments on commit b504998

Please sign in to comment.