+#ifdef FALLOCATE
+/* fallocate is basically a no-op unless extending, then a lot like a truncate */
+void
+dofallocate(unsigned offset, unsigned length)
+{
+ unsigned end_offset;
+ int keep_size;
+
+ if (length == 0) {
+ if (!quiet && testcalls > simulatedopcount)
+ prt("skipping zero length fallocate\n");
+ log4(OP_SKIPPED, OP_FALLOCATE, offset, length);
+ return;
+ }
+
+ keep_size = random() % 2;
+
+ end_offset = keep_size ? 0 : offset + length;
+
+ if (end_offset > biggest) {
+ biggest = end_offset;
+ if (!quiet && testcalls > simulatedopcount)
+ prt("fallocating to largest ever: 0x%x\n", end_offset);
+ }
+
+ /*
+ * last arg:
+ * 1: allocate past EOF
+ * 2: extending prealloc
+ * 3: interior prealloc
+ */
+ log4(OP_FALLOCATE, offset, length, (end_offset > file_size) ? (keep_size ? 1 : 2) : 3);
+
+ if (end_offset > file_size) {
+ memset(good_buf + file_size, '\0', end_offset - file_size);
+ file_size = end_offset;
+ }
+
+ if (testcalls <= simulatedopcount)
+ return;
+
+ if ((progressinterval && testcalls % progressinterval == 0) ||
+ (debug && (monitorstart == -1 || monitorend == -1 ||
+ end_offset <= monitorend)))
+ prt("%lu falloc\tfrom 0x%x to 0x%x\n", testcalls, offset, length);
+ if (fallocate(fd, keep_size ? FALLOC_FL_KEEP_SIZE : 0, (loff_t)offset, (loff_t)length) == -1) {
+ prt("fallocate: %x to %x\n", offset, length);
+ prterr("dofallocate: fallocate");
+ report_failure(161);
+ }
+}
+#else
+void
+dofallocate(unsigned offset, unsigned length)
+{
+ return;
+}
+#endif