From: Timo Sirainen Date: Thu, 21 Oct 2010 21:56:02 +0000 (+0100) Subject: file_preallocate(): Added support for OS X. X-Git-Tag: 2.0.7~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed7dbb42dd41a237b2ae737eb59482c640fd6f77;p=thirdparty%2Fdovecot%2Fcore.git file_preallocate(): Added support for OS X. --- diff --git a/src/lib/file-set-size.c b/src/lib/file-set-size.c index 8908cc25e3..c2370feda1 100644 --- a/src/lib/file-set-size.c +++ b/src/lib/file-set-size.c @@ -88,6 +88,24 @@ int file_preallocate(int fd ATTR_UNUSED, off_t size ATTR_UNUSED) if (fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, size) < 0) return errno == ENOSYS ? 0 : -1; return 1; +#elif defined (F_PREALLOCATE) + /* OSX */ + fstore_t fs; + + memset(&fs, 0, sizeof(fs)); + fs.fst_flags = F_ALLOCATECONTIG; + fs.fst_posmode = F_PEOFPOSMODE; + fs.fst_offset = 0; + fs.fst_length = size; + fs.fst_bytesalloc = 0; + if (fcntl(fd, F_PREALLOCATE, &fs) < 0) { + if (errno == ENOSPC) { + /* can't allocate contiguous block. just forget it. */ + return 0; + } + return -1; + } + return 0; #else return 0; #endif