forked from sysprog21/fibdrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
77 lines (68 loc) · 1.76 KB
/
client.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
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include "big.h"
#define FIB_DEV "/dev/fibonacci"
void big_print(bigNum buf)
{
int i = part_num - 1;
while ((i >= 0) && (buf.part[i] == 0))
i--;
if (i < 0) {
printf("0");
return;
}
printf("%lld", buf.part[i--]);
while (i >= 0) {
printf("%08lld", buf.part[i]);
i--;
}
}
int main()
{
int fd;
long long sz;
bigNum buf;
char write_buf[] = "testing writing";
int offset = 100; // TODO: test something bigger than the limit
int i = 0;
long int ns;
struct timespec start, end;
FILE *ft = fopen("time", "w");
fd = open(FIB_DEV, O_RDWR);
if (fd < 0) {
perror("Failed to open character device");
exit(1);
}
for (i = 0; i <= offset; i++) {
sz = write(fd, write_buf, strlen(write_buf));
printf("Writing to " FIB_DEV ", returned the sequence %lld\n", sz);
}
for (i = 0; i <= offset; i++) {
memset(&buf, 0, sizeof(bigNum));
lseek(fd, i, SEEK_SET);
clock_gettime(CLOCK_MONOTONIC, &start);
sz = read(fd, &buf, sizeof(bigNum));
clock_gettime(CLOCK_MONOTONIC, &end);
printf("Reading from " FIB_DEV " at offset %d, returned the sequence ",
i);
big_print(buf);
printf(".\n");
}
for (i = offset; i >= 0; i--) {
lseek(fd, i, SEEK_SET);
memset(&buf, 0, sizeof(bigNum));
sz = read(fd, &buf, sizeof(bigNum));
printf("Reading from " FIB_DEV " at offset %d, returned the sequence ",
i);
big_print(buf);
printf(".\n");
}
close(ft);
close(fd);
return 0;
}