+ output_debug(size, 0, "truncate done");
+}
+
+void
+do_punch_hole(unsigned int offset, unsigned int length)
+{
+ int max_offset = 0;
+ int max_len = 0;
+ int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
+ int fd;
+
+ tf = get_tf();
+ fd = tf->fd;
+ if (length == 0) {
+ if (!quiet && testcalls > simulatedopcount) {
+ prt("skipping zero length punch hole\n");
+ log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, length);
+ }
+ return;
+ }
+
+ if (file_size <= (loff_t)offset) {
+ if (!quiet && testcalls > simulatedopcount) {
+ prt("skipping hole punch off the end of the file\n");
+ log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, length);
+ }
+ return;
+ }
+
+ log4(OP_PUNCH_HOLE, offset, length, 0);
+
+ if (testcalls <= simulatedopcount)
+ return;
+
+ output_line(tf, OP_PUNCH_HOLE, offset, length);
+ if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
+ prt("punch hole: %x to %x\n", offset, length);
+ prterr("fallocate");
+ report_failure(161);
+ }
+ output_debug(offset, length, "zero_range done");
+
+ max_offset = offset < file_size ? offset : file_size;
+ max_len = max_offset + length <= file_size ? length :
+ file_size - max_offset;
+ memset(good_buf + max_offset, '\0', max_len);
+}
+
+void
+do_zero_range(unsigned int offset, unsigned int length)
+{
+ unsigned int end_offset;
+ int mode = FALLOC_FL_ZERO_RANGE;
+ int keep_size;
+ int fd;
+
+ tf = get_tf();
+ fd = tf->fd;
+ if (length == 0) {
+ if (!quiet && testcalls > simulatedopcount) {
+ prt("skipping zero length zero range\n");
+ log4(OP_SKIPPED, OP_ZERO_RANGE, 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("zero_range to largest ever: 0x%x\n", end_offset);