-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (45 loc) · 1.18 KB
/
main.cpp
File metadata and controls
60 lines (45 loc) · 1.18 KB
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
#include "mmap_file.h"
#include "head.h"
using namespace std;
using namespace lucifer;
static constexpr mode_t OPEN_MODE = 0644;
const static tfs::MMapOption mmap_option = {
.max_mmap_size_ = 10240000,
.first_mmap_size_ = 4096,
.per_mmap_size_ = 4096
};
int open_file(string file_name,int open_flags)
{
int fd = open(file_name.c_str(), open_flags, OPEN_MODE);
if (fd == -1)
{
perror("open");
return -errno;
}
return fd;
}
int main(void)
{
const char * filename = "./test.txt";
int fd = open_file(filename, O_RDWR | O_CREAT|O_LARGEFILE);
if (fd == -1)
{
fprintf(stderr, "open file error\n file name%s,error desc:%s\n", filename, strerror(-fd));
return -1;
}
tfs::MMapFile *map_file = new tfs::MMapFile(mmap_option,fd);
bool is_mapped = map_file->mmapFile(true);
if (!is_mapped)
{
fprintf(stderr, "mmap file error\n");
return -1;
}else
{
map_file->remapFile();
memset(map_file->getData(), '6', map_file->getSize());
map_file->syncFile();
map_file->mumapFile();
}
close(fd);
return 0;
}