
#include <stdio.h>
#include <fcntl.h>
/* #define USE_SPARSE */
#define INIT_WRITE
#define USE_OSYNC

int main()
{
	char zbuffer[8192];
	int nbytes;
	int fd;
	char *tpath="xlog_testfile";

	fd = open(tpath, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
#ifdef INIT_WRITE
#ifdef USE_SPARSE
/*  the sparse file makes things worse here */
	lseek(fd, 16*1024*1024 - 1, SEEK_SET);
	write(fd, 0, 1);
#else
	memset(zbuffer, '\0', sizeof(zbuffer));
	for (nbytes = 0; nbytes < 16*1024*1024; nbytes += sizeof(zbuffer))
	{
		write(fd, zbuffer, sizeof(zbuffer));
	}
#endif
#endif
	/* no fsync here, since close does it for us */
	close (fd);

#ifdef USE_OSYNC
	fd = open(tpath, O_RDWR | O_SYNC, S_IRUSR | S_IWUSR);
#else
	fd = open(tpath, O_RDWR , S_IRUSR | S_IWUSR);
#endif

	memset(zbuffer, 'X', sizeof(zbuffer));
	nbytes = 0;
	do 
	{
		lseek(fd, nbytes, SEEK_SET); 
		write(fd, zbuffer, sizeof(zbuffer));
#ifndef USE_OSYNC
		fsync(fd);
#endif
		nbytes += sizeof(zbuffer);
	} while (nbytes < 16*1024*1024);

}
