forked from adamorad/XV6-DoubleIndirection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbig.c
54 lines (48 loc) · 1.02 KB
/
big.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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
void
bigfile(void)
{
char buf[512];
int fd, i, sectors;
unlink("big.file");
fd = open("big.file", O_CREATE | O_WRONLY);
if(fd < 0){
printf(2, "big: cannot open big.file for writing\n");
exit();
}
sectors = 0;
while(1){
*(int*)buf = sectors;
int cc = write(fd, buf, sizeof(buf));
if(cc <= 0)
break;
sectors++;
if (sectors % 100 == 0)
printf(2, ".");
}
printf(1, "\nwrote %d sectors\n", sectors);
close(fd);
fd = open("big.file", O_RDONLY);
if(fd < 0){
printf(2, "big: cannot re-open big.file for reading\n");
exit();
}
for(i = 0; i < sectors; i++){
int cc = read(fd, buf, sizeof(buf));
if(cc <= 0){
printf(2, "big: read error at sector %d\n", i);
exit();
}
if(*(int*)buf != i){
printf(2, "big: read the wrong data (%d) for sector %d\n",
*(int*)buf, i);
exit();
}
}
close(fd);
unlink("big.file");
printf(1, "bigfile test ok\n");
}