-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinode_cache.cpp
More file actions
37 lines (37 loc) · 950 Bytes
/
inode_cache.cpp
File metadata and controls
37 lines (37 loc) · 950 Bytes
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
#include"inode_cache.h"
#include "inode_loader.h"
INodeCache::INodeCache() {
inodes = new INodeStruct*[kINODE_MAXN];
memset(inodes, NULL, sizeof(INodeStruct *) * kINODE_MAXN);
}
INodeStruct * INodeCache::GetINode(ID_T inode_id) {
if (inodes[inode_id] == NULL) {
if (INodeLoader::IsNodeExist(inode_id)) {
inodes[inode_id] = new INodeStruct(INodeLoader::LoadINode(inode_id));
}
}
return inodes[inode_id];
}
INodeStruct * INodeCache::SetINode(const INodeStruct & target) {
if (inodes[target.id] != NULL) {
delete inodes[target.id];
}
inodes[target.id] = new INodeStruct(target);
return inodes[target.id];
}
INodeCache::~INodeCache() {
for (ID_T i = 0; i < kINODE_MAXN; i++) {
if(inodes[i]!=NULL){
//INodeLoader::SaveINode(*inodes[i]);
delete inodes[i];
}
}
delete [] inodes;
}
void INodeCache::SaveAll() {
for (ID_T i = 0; i < kINODE_MAXN; i++) {
if (inodes[i] != NULL) {
INodeLoader::SaveINode(*inodes[i]);
}
}
}