changeset 12342:f6e45e83796b

file_preallocate(): Added support for OS X.
author Timo Sirainen <tss@iki.fi>
date Thu, 21 Oct 2010 22:56:02 +0100
parents 3b13bd2d64f4
children aaca506ea33b
files src/lib/file-set-size.c
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/file-set-size.c	Thu Oct 21 22:45:27 2010 +0100
+++ b/src/lib/file-set-size.c	Thu Oct 21 22:56:02 2010 +0100
@@ -88,6 +88,24 @@
 	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