summaryrefslogtreecommitdiff
path: root/src/AbstractDiskWriter.cc
diff options
context:
space:
mode:
authorNils Maier <maierman@web.de>2014-03-27 19:54:24 +0100
committerNils Maier <maierman@web.de>2014-04-12 02:55:31 +0200
commit7600886d3d96be1f6f88dfc79a72c960f6d4934c (patch)
tree0d69cad75b70939d33e7821b24d41567553b600c /src/AbstractDiskWriter.cc
parenta95674aef3a0c7caeb65d43d59a4b585d86589ed (diff)
Implement falloc equivalent in OSX
Diffstat (limited to 'src/AbstractDiskWriter.cc')
-rw-r--r--src/AbstractDiskWriter.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc
index d7a6641a..f977769a 100644
--- a/src/AbstractDiskWriter.cc
+++ b/src/AbstractDiskWriter.cc
@@ -483,6 +483,24 @@ void AbstractDiskWriter::allocate(int64_t offset, int64_t length, bool sparse)
#ifdef HAVE_SOME_FALLOCATE
# ifdef __MINGW32__
truncate(offset+length);
+# elif defined(__APPLE__) && defined(__MACH__)
+ auto toalloc = offset + length - size();
+ if (toalloc > 0) {
+ fstore_t fstore = {F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE, 0, toalloc};
+ if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) {
+ // Retry non-contig.
+ fstore.fst_flags = F_ALLOCATEALL;
+ if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) {
+ int err = errno;
+ throw DL_ABORT_EX3(err,
+ fmt("fcntl(F_PREALLOCATE failed. cause: %s",
+ util::safeStrerror(err).c_str()),
+ error_code::FILE_IO_ERROR);
+ }
+ }
+ }
+ // This forces the allocation on disk.
+ ftruncate(fd_, offset + length);
# elif HAVE_FALLOCATE
// For linux, we use fallocate to detect file system supports
// fallocate or not.