-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinode_index.cc
58 lines (51 loc) · 1.25 KB
/
inode_index.cc
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
#include "inode_index.h"
#include <cassert>
void InodeIndex::add(Inode::Ptr inode)
{
assert(refs_.find(inode->ino()) == refs_.end());
refs_[inode->ino()] = std::make_pair(1, inode);
}
void InodeIndex::get(Inode::Ptr inode)
{
auto it = refs_.find(inode->ino());
if (it == refs_.end())
refs_[inode->ino()] = std::make_pair(1, inode);
else {
assert(it->second.first > 0);
it->second.first++;
}
}
void InodeIndex::put(fuse_ino_t ino, long int dec)
{
auto it = refs_.find(ino);
assert(it != refs_.end());
assert(it->second.first > 0);
it->second.first -= dec;
assert(it->second.first >= 0);
if (it->second.first == 0)
refs_.erase(it);
}
Inode::Ptr InodeIndex::inode(fuse_ino_t ino)
{
return refs_.at(ino).second;
}
DirInode::Ptr InodeIndex::dir_inode(fuse_ino_t ino)
{
auto in = inode(ino);
assert(in->is_directory());
return std::static_pointer_cast<DirInode>(in);
}
SymlinkInode::Ptr InodeIndex::symlink_inode(fuse_ino_t ino)
{
auto in = inode(ino);
assert(in->is_symlink());
return std::static_pointer_cast<SymlinkInode>(in);
}
uint64_t InodeIndex::nfiles()
{
uint64_t ret = 0;
for (auto it = refs_.begin(); it != refs_.end(); it++)
if (it->second.second->i_st.st_mode & S_IFREG)
ret++;
return ret;
}