-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_create_non_cont_file.c
93 lines (70 loc) · 1.61 KB
/
test_create_non_cont_file.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
87
88
89
90
91
92
93
#include <sys/mman.h>
#include <stdio.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <mlfs/mlfs_interface.h>
#define SIZE 4096
#define FILEPATH "/mlfs/foo"
#define AUX_FILEPATH "/mlfs/aux"
void create_actual_file(char buf[]) {
int ret;
int fd;
char temp;
fd = open(FILEPATH, O_CREAT | O_RDWR | O_EXCL, 0644);
assert(fd >= 0);
printf("The fd is %d\n", fd);
ret = ftruncate(fd, 0);
assert(ret == 0);
temp = buf[SIZE-1];
buf[SIZE-1] = 'a';
ret = write(fd, buf, SIZE);
assert(ret == SIZE);
buf[SIZE-1] = temp;
close(fd);
make_digest_request_async(100);
wait_on_digesting();
}
void create_aux_file(char buf[]) {
int ret;
int fd;
fd = open(AUX_FILEPATH, O_CREAT | O_RDWR | O_EXCL, 0644);
assert(fd >= 0);
printf("The fd is %d\n", fd);
ret = write(fd, buf, SIZE);
assert(ret == SIZE);
close(fd);
make_digest_request_async(100);
wait_on_digesting();
}
void write_actual_file(char buf[]) {
int ret;
int fd;
fd = open(FILEPATH, O_RDWR, 0644);
assert(fd >= 0);
printf("The fd is %d\n", fd);
ret = pwrite(fd, buf, SIZE, SIZE);
assert(ret == SIZE);
close(fd);
make_digest_request_async(100);
wait_on_digesting();
}
int main() {
init_fs();
int fd, fd2;
int ret;
int i;
void* addr;
char buf[SIZE];
for(i=0; i<SIZE; i++) {
buf[i] = 'a';
}
buf[SIZE-1] = '\0';
create_actual_file(buf);
create_aux_file(buf);
write_actual_file(buf);
shutdown_fs();
}