]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
file_preallocate(): Added support for OS X.
authorTimo Sirainen <tss@iki.fi>
Thu, 21 Oct 2010 21:56:02 +0000 (22:56 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 21 Oct 2010 21:56:02 +0000 (22:56 +0100)
src/lib/file-set-size.c

index 8908cc25e3d5107d53c6ad435be2559e77133599..c2370feda17a3a66e536c44628dc836f9f3091f7 100644 (file)
@@ -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