#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif

#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>

// #include <linux/falloc.h>
#define FALLOC_FL_KEEP_SIZE	0x01
#define FALLOC_FL_PUNCH_HOLE	0x02 /* de-allocates range */
#define FALLOC_FL_COLLAPSE_RANGE	0x08
#define FALLOC_FL_ZERO_RANGE		0x10

int main(int argc, char **argv)
{
	int	fd;
	int	error;

	fd = open("test-file", O_WRONLY|O_LARGEFILE|O_CREAT|O_TRUNC, 0700);
	if (fd < 0) {
		perror("Error opening file");
		exit(EXIT_FAILURE);
	}

	error = syscall(SYS_fallocate, fd, 0, 0, 1024 * 1024);
	if (error < 0) {
		perror("fallocate failed");
		exit(1);
	}

	error = syscall(SYS_fallocate, fd,
			FALLOC_FL_KEEP_SIZE|FALLOC_FL_PUNCH_HOLE,
			32 * 1024, 32 * 1024);
	if (error < 0) {
		perror("punch hole failed");
		exit(1);
	}

	close(fd);
	return 0;
}
