#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

struct Entry
{
	int count;
	char string[50];
};


int main(int argc, char **argv)
{
	int fd;
	struct Entry *trans;
	int x;

	if((fd = creat(argv[1], 0666)) == -1)
	{
		printf("Could not open file %s\n", argv[1]);
		return 1;
	}
	

	for(x=0; x < 2000; ++x)
	{
		trans = malloc(sizeof(struct Entry));
		trans->count = x;
		strcpy(trans->string, "Blah Blah Blah Blah Blah Blah Blah");

		if(strcmp(argv[2],"fsync")== 0)
		{
			write(fd, (char *)trans, sizeof(struct Entry));
			
			if(fdatasync(fd) != 0)
			{
				perror("Error");
			}

		}
		else
		{
			write(fd, (char *)trans, sizeof(struct Entry));
		}
	
		free(trans);

	}
	close(fd);

}
