-
Notifications
You must be signed in to change notification settings - Fork 6
/
inode.cc
76 lines (64 loc) · 1.51 KB
/
inode.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "inode.h"
#include <cassert>
#include <fuse.h>
#include "gassy_fs.h"
#include "common.h"
Inode::Inode(time_t time, uid_t uid, gid_t gid, blksize_t blksize,
mode_t mode, GassyFs *fs) :
alloc_node(0), ino_set_(false), fs_(fs)
{
memset(&i_st, 0, sizeof(i_st));
i_st.st_atime = time;
i_st.st_mtime = time;
i_st.st_ctime = time;
i_st.st_uid = uid;
i_st.st_gid = gid;
i_st.st_blksize = blksize;
// DirInode will set this to 2
i_st.st_nlink = 1;
// Dir/Sym will set reset this
i_st.st_mode = mode;
}
/*
* FIXME: space should be freed here, but also when it is deleted, if there
* are no other open file handles. Otherwise, space is only freed after the
* file is deleted and the kernel releases its references.
*/
Inode::~Inode()
{
for (auto it = extents_.begin(); it != extents_.end(); it++)
fs_->free_space(&it->second);
extents_.clear();
}
void Inode::set_ino(fuse_ino_t ino)
{
assert(ino_set_ == false);
ino_ = ino;
i_st.st_ino = ino;
ino_set_ = true;
}
fuse_ino_t Inode::ino() const
{
assert(ino_set_);
return ino_;
}
bool Inode::is_directory() const
{
return i_st.st_mode & S_IFDIR;
}
bool Inode::is_symlink() const
{
return i_st.st_mode & S_IFLNK;
}
bool Inode::setlua_atime(std::string policy)
{
return lua_atime.assign(policy) == policy;
}
std::string Inode::getlua_atime()
{
std::string policy = lua_atime;
if (!lua_atime.empty())
printf("atime policy: \n===\n%s===\n", lua_atime.c_str());
std::string ret(lua_atime.c_str());
return lua_atime.c_str();
}