summaryrefslogtreecommitdiffstats
path: root/src/examples/pfs_writer.c
blob: 80f08266c13d19ec432aebf15ba63d3a7102903f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Write on the disk.
 * Each time the buffer is filled with same character.
 * Different character every time!
 */

#include <syscall.h>
#include <stdio.h>
#include <string.h>
#include <random.h>

#include "pfs.h"


char buffer[BIG];

int main(int argc, char* argv[])
{
	int i;
	char c;
	int id;
	int write_count;
	char start;
	char end;

	random_init((int)argv[3][0]);
	printf("+\n");

	if (argc != 4 || strlen(argv[1]) != 1 || strlen(argv[2]) != 1)
		exit(1);

	start = argv[1][0];
	end   = argv[2][0];

	for (i = 0; i < TIMES / (end - start + 1) + 1; ++i)
	{
		for (c = start; c <= end; ++c)
		{
			memset(buffer, (int)c, BIG);

			id = open("file.1");

			seek(id,(random_ulong() % (TIMES-1)) * BIG);
			write_count = write(id, buffer, BIG);

			if ( write_count != BIG )
			{
				printf("TEST ERROR: write() wrote only %d bytes out of %d bytes\n",
						write_count, BIG);
				close(id);
				exit(-1);
			}
			close(id);
		}
	}
	printf("*+\n");
	exit(0);
}