aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl-Johan Alm <karljohan-alm@garage.co.jp>2020-01-07 22:24:16 +0900
committerfanquake <fanquake@gmail.com>2020-01-23 08:11:10 +0800
commitc8ad23c52932cf33fac6e527ff18b5241ccceb04 (patch)
treea24741679874dcbf1f2c3dead89ab7cfdcf3beeb
parent4cf73504220e95ea1c4961509ea757ce6d393a9b (diff)
downloadbitcoin-c8ad23c52932cf33fac6e527ff18b5241ccceb04.tar.xz
bug-fix macos: give free bytes to F_PREALLOCATE
The macos manpage for fcntl (for F_PEOFPOSMODE) states: > Allocate from the physical end of file. In this case, fst_length indicates the number of newly allocated bytes desired. Github-Pull: #17887 Rebased-From: 75163f4729c10c40d2843da28a8c79ab89193f6a
-rw-r--r--src/util/system.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp
index bbd7c9940a..5a3c68aa0c 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -1088,17 +1088,19 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
SetEndOfFile(hFile);
#elif defined(MAC_OSX)
// OSX specific version
+ // NOTE: Contrary to other OS versions, the OSX version assumes that
+ // NOTE: offset is the size of the file.
fstore_t fst;
fst.fst_flags = F_ALLOCATECONTIG;
fst.fst_posmode = F_PEOFPOSMODE;
fst.fst_offset = 0;
- fst.fst_length = (off_t)offset + length;
+ fst.fst_length = length; // mac os fst_length takes the # of free bytes to allocate, not desired file size
fst.fst_bytesalloc = 0;
if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
fst.fst_flags = F_ALLOCATEALL;
fcntl(fileno(file), F_PREALLOCATE, &fst);
}
- ftruncate(fileno(file), fst.fst_length);
+ ftruncate(fileno(file), static_cast<off_t>(offset) + length);
#else
#if defined(__linux__)
// Version using posix_fallocate