+/*
+ * Make sure hole size is properly reported when punched in the middle of a file
+ */
+static int test21(int fd, int testnum)
+{
+ char *buf = NULL;
+ int bufsz, filsz;
+ int ret = 0;
+
+ if (!punch_hole) {
+ fprintf(stdout, "Test skipped as fs doesn't support punch hole.\n");
+ goto out;
+ }
+
+ if (default_behavior) {
+ fprintf(stdout, "Test skipped as fs doesn't support seeking a punched hole.\n");
+ goto out;
+ }
+
+ bufsz = alloc_size * 3;
+ buf = do_malloc(bufsz);
+ if (!buf) {
+ ret = -1;
+ goto out;
+ }
+ memset(buf, 'a', bufsz);
+
+ ret = do_pwrite(fd, buf, bufsz, 0);
+ if (ret)
+ goto out;
+
+ filsz = bufsz;
+ ret = do_fallocate(fd, alloc_size, alloc_size,
+ FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
+ if (ret < 0)
+ goto out;
+
+ ret += do_lseek(testnum, 1, fd, filsz, SEEK_DATA, 0, 0);
+ ret += do_lseek(testnum, 2, fd, filsz, SEEK_HOLE, 0, alloc_size);
+ ret += do_lseek(testnum, 3, fd, filsz, SEEK_DATA, alloc_size, alloc_size * 2);
+out:
+ if (buf)
+ free(buf);
+ return ret;
+}
+