-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.c
86 lines (73 loc) · 1.54 KB
/
base.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "filesys.h"
#define NUM_FILES 8
int main_loop (char *filename)
{
int fd1, fd2;
char buf[128];
int size, total_size, ret;
fd1 = s_open (filename, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);
if (fd1 == -1) {
printf ("Unable to open file descriptor1 in base.c\n");
return 0;
}
memset (buf, 1, 128);
total_size = 128000;
while (total_size) {
size = (rand() % 127) + 1;
if (size > total_size) {
size = total_size;
}
ret = s_write (fd1, buf, size);
if (ret != size) {
printf ("Unable to write to file\n");
return 0;
}
total_size -= size;
}
s_close (fd1);
fd2 = s_open (filename, O_RDONLY, 0);
if (fd2 == -1) {
printf ("Unable to open file descriptor2\n");
return 0;
}
total_size = 128000;
while (total_size) {
size = (total_size > 128) ? 128 : total_size;
ret = s_read (fd2, buf, size);
if (ret != size) {
printf ("Unable to read from file %d\n", ret);
return 0;
}
total_size -= size;
}
s_close (fd2);
return 0;
}
int main ()
{
int i;
int xd=open("FILESIZES.txt",O_RDWR | O_CREAT,0666);
for(i=0;i<NUM_FILES;i++){
lseek(xd,33*i,SEEK_SET);
write(xd,"0 ",33);
}
close(xd);
char filename[32];
system ("rm -rf foo*.txt");
if (filesys_init() == 1) {
printf ("Unable to init filesys\n");
return 0;
}
for (i = 0; i < NUM_FILES; i++) {
snprintf (filename, 32, "foo_%d.txt", i);
main_loop (filename);
}
return 0;
}