diff options
author | Wladimir J. van der Laan <laanwj@protonmail.com> | 2020-01-22 16:26:53 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@protonmail.com> | 2020-01-22 16:48:31 +0100 |
commit | 04f78b818f02279d32c3ad3a1140e9410bfb26bf (patch) | |
tree | ffc46ab184a12318ea68707c96c87e5271e20717 /src/util | |
parent | 0038e536de6ecbdcf027f07cb14af420d52033c2 (diff) | |
parent | 75163f4729c10c40d2843da28a8c79ab89193f6a (diff) |
Merge #17887: bug-fix macos: give free bytes to F_PREALLOCATE
75163f4729c10c40d2843da28a8c79ab89193f6a bug-fix macos: give free bytes to F_PREALLOCATE (Karl-Johan Alm)
Pull request description:
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.
This would result in the rev files being essentially pre-allocating 2x their necessary size (this is the case for block files as well, but these are flushed down to their right sizes every time) as they would pre-allocate `pos + length` **free** bytes, rather than allocating `length` bytes after `pos`, as expected.
Fixes #17827.
ACKs for top commit:
eriknylund:
ACK 75163f4729c10c40d2843da28a8c79ab89193f6a built locally. All tests passing. Manual test as per my previous comment above on an older commit, using an APFS unencrypted disk image with 3 GB.
laanwj:
code review ACK 75163f4729c10c40d2843da28a8c79ab89193f6a
Tree-SHA512: 105c8d56c20acad8febdf0583f1e5721b63376ace325a7a62c2e4b15a442c7131404ed604c32c0cda716791d7ca5aa9f5b6a774ff86e39838bc7e87ca3c42760
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/system.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp index d1bd1de5d1..588ddc1fcf 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -974,17 +974,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 |