-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinode_loader.cpp
More file actions
54 lines (54 loc) · 1.8 KB
/
inode_loader.cpp
File metadata and controls
54 lines (54 loc) · 1.8 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
#include"inode_loader.h"
#include<cstdio>
string INodeLoader::GetINodePath(ID_T inode_id) {
stringstream sstream;
sstream << kINodeDir << "/" << inode_id << ".inode";
return sstream.str();
}
INodeStruct INodeLoader::LoadINode(ID_T inode_id) {
string filename = INodeLoader::GetINodePath(inode_id);
ifstream in;
in.open(filename, ios::in | ios::binary);
in.seekg(0, in.beg);
INodeStruct inode;
in.read((char *)&inode, sizeof(inode));
in.close();
return inode;
}
BOOL_T INodeLoader::IsNodeExist(ID_T inode_id) {
string filename = INodeLoader::GetINodePath(inode_id);
ifstream check(filename);
return bool(check);
}
void INodeLoader::SaveINode(const INodeStruct & inode) {
string filename = INodeLoader::GetINodePath(inode.id);
ofstream out;
out.open(filename, ios::out | ios::binary | ios::trunc);
out.seekp(0, out.beg);
out.write((char *)&inode, sizeof(inode));
out.close();
}
string ContentLoader::GetContentPath(ID_T content_id) {
stringstream sstream;
sstream << kContentDir << "/" << content_id << ".content";
return sstream.str();
}
void ContentLoader::GetContentIfStream(ID_T content_id, ifstream & in) {
string filename = ContentLoader::GetContentPath(content_id);
in.open(filename, ios::in | ios::binary);
}
void ContentLoader::GetContentOfStream(ID_T content_id, ofstream & out) {
string filename = ContentLoader::GetContentPath(content_id);
out.open(filename, fstream::binary | fstream::out | fstream::in);
}
void ContentLoader::CreateContentFile(ID_T content_id) {
string filename = ContentLoader::GetContentPath(content_id);
ofstream out;
out.open(filename, ios::out | ios::binary | ios::trunc);
out.close();
}
void ContentLoader::EmptyContentFile(ID_T content_id) {
string filename = ContentLoader::GetContentPath(content_id);
remove(filename.c_str());
ContentLoader::CreateContentFile(content_id);
}