-
Notifications
You must be signed in to change notification settings - Fork 0
/
csvToLba.cpp
56 lines (46 loc) · 1.05 KB
/
csvToLba.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char* getfield(char* line, FILE* Ofp)
{
const char* tok;
const char* op;
int i=0;
long long offset, size,len, lba, nr_page;
for (tok = strtok(line, ",");
tok && *tok;
tok = strtok(NULL, ",\n"), i++)
{
if(i==3) {
op = tok;
} else if(i==4) {
offset = atoll(tok);
} else if(i==5) {
size = atoll(tok);
}
}
// printf("size : %lld\n", size);
lba = offset / 4096;
// printf("offset : %lld, lba : %lld\n", offset, lba);
len = offset + size;
if(len % 4096 != 0) len = (len/4096) +1;
else len = (len / 4096);
nr_page = len - lba;
// printf("len : %lld, lba : %lld, nr_page : %lld\n", len, lba, nr_page);
if(strcmp(op,"Read")==0) {
fprintf(Ofp, "0 %lld %lld\n", lba, nr_page);
} else if(strcmp(op, "Write") ==0) {
fprintf(Ofp, "1 %lld %lld\n", lba, nr_page);
}
return NULL;
}
int main(int argc, char* argv[])
{
FILE* stream = fopen(argv[1], "r");
FILE* Ofp = fopen(argv[2], "w");
char line[1024];
while (fgets(line, 1024, stream))
{
getfield(line, Ofp);
}
}