-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock_init.cpp
More file actions
73 lines (50 loc) · 1.73 KB
/
block_init.cpp
File metadata and controls
73 lines (50 loc) · 1.73 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
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "head.h"
#include "file_op.h"
#include "index_handle.h"
using namespace lucifer;
const static tfs::MMapOption mmap_option = {1024000,4096,4096};//内存映射参数
const static uint32_t main_blcok_size = 1014*1024*64;//主块文件的大小
const static uint32_t bucket_size = 1000;//哈希桶的大小
static int32_t block_id = 1;
int main(int argc,char **argv)
{
std::string mainblock_path;
std::string index_path;
int32_t ret = tfs::TFS_SUCCESS;
std::cout<<"Type you bock id:"<<std::endl;
std::cin>>block_id;
if(block_id < 0){
std::cerr<<"Invalid blockid,exie"<<std::endl;
exit(-1);
}
//生成主块文件
std::stringstream tmp_stream;
tmp_stream << "."<< tfs::MAINLOCK_DIR_PREFIX <<block_id;
tmp_stream >> mainblock_path;
tfs::FileOperation * mainblock = new tfs::FileOperation(mainblock_path,O_RDWR|O_LARGEFILE|O_CREAT);
ret = mainblock->ftruncate_file(main_blcok_size);
if(ret != 0){
fprintf(stderr,"Fail to truncate file:%s\n",strerror(errno));
std::cerr<<"Fail to truncate file"<<std::endl;
delete mainblock;
exit(-2);
}
//生成索引文件
tfs::IndexHandle * index_handle = new tfs::IndexHandle(".",block_id);
if(tfs::DEBUG)
printf("Create index init\n");
ret = index_handle->create(block_id,bucket_size,mmap_option);
if(ret != tfs::TFS_SUCCESS)
{
fprintf(stderr,"Fail to create index:%s\n",strerror(errno));
delete mainblock;
index_handle->remove(block_id);
exit(-3);
}
mainblock->close_file();
index_handle->flush();
delete mainblock;
delete index_handle;
//other
return 0;
}