From c8ad23c52932cf33fac6e527ff18b5241ccceb04 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Tue, 7 Jan 2020 22:24:16 +0900 Subject: 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 --- src/util/system.cpp | 6 ++++-- 1 file 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(offset) + length); #else #if defined(__linux__) // Version using posix_fallocate -- cgit v1.2.3 From daf2fff236f8ebb75c785b33d2dd6dcd3cf86112 Mon Sep 17 00:00:00 2001 From: Karl-Johan Alm Date: Wed, 22 Jan 2020 17:13:53 +0900 Subject: test: add missing #include to fix compiler errors Github-Pull: #17980 Rebased-From: a5a2654bbc43b5c208418872e5d4c0acbadda5de --- src/test/cuckoocache_tests.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/cuckoocache_tests.cpp b/src/test/cuckoocache_tests.cpp index d38ede691a..2271aded1b 100644 --- a/src/test/cuckoocache_tests.cpp +++ b/src/test/cuckoocache_tests.cpp @@ -7,6 +7,7 @@ #include #include #include +#include /** Test Suite for CuckooCache * -- cgit v1.2.3