-
Notifications
You must be signed in to change notification settings - Fork 2
/
INode.cc
100 lines (82 loc) · 2.09 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* File: INode.cpp
* Author: Tobias Fleig <tobifleig@gmail.com>
*
* Created on August 16, 2015, 4:30 PM
*/
#include "INode.h"
#include "Block.h"
#include <cstdint>
#include <iostream>
#include "Constants.inc"
#include "StreamUtils.inc"
#include "TimeUtils.inc"
namespace SDI4FS {
INode::INode(STREAM &input) : Block::Block(input) {
// read creationTime and size_b
read32(input, &creationTime);
read32(input, &size_b);
// read type (4 bits) + inlined (1bit)
uint8_t typeAndInline;
read8(input, &typeAndInline);
type = (typeAndInline >> 4) & 0xF;
inlined = (typeAndInline & 0x08) != 0 ? true : false;
// jump 1 byte forward
input.seekg(1, input.cur);
// read linkCounter
read16(input, &linkCounter);
}
INode::INode(uint32_t id, uint8_t type) : Block::Block(id),
size_b(0), inlined(true), linkCounter(0) {
creationTime = now();
// only 4bits on disk
if (type > 0xF) {
std::cout << "fs: error - illegal INode type: " << type << std::endl;
}
this->type = type;
}
INode::~INode() {
}
uint32_t INode::getCreationTime() {
return creationTime;
}
uint32_t INode::getInternalSize_b() {
return size_b;
}
void INode::setInternalSize_b(uint32_t size_b) {
this->size_b = size_b;
}
bool INode::isInlined() {
return inlined;
}
void INode::setInlined(bool inlined) {
this->inlined = inlined;
}
uint8_t INode::getType() {
return type;
}
uint16_t INode::getLinkCounter() {
return linkCounter;
}
void INode::save(STREAM &output) {
// call super first (*cough* anitpattern *cough*)
Block::save(output);
// write creationTime, size, type, inline, link counter
write32(output, creationTime);
write32(output, size_b);
uint8_t typeAndInline = type << 4 | inlined << 3;
write8(output, typeAndInline);
output.seekp(1, output.cur);
write16(output, linkCounter);
}
bool INode::incrementLinkCounter() {
if (linkCounter != SDI4FS_MAX_NUMBER_OF_LINKS_TO_INODE) {
++linkCounter;
return true;
}
return false;
}
void INode::decrementLinkCounter() {
--linkCounter;
}
} // SDI4FS