-
Notifications
You must be signed in to change notification settings - Fork 2
/
INode.h
147 lines (119 loc) · 3.38 KB
/
INode.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* File: INode.h
* Author: Tobias Fleig <tobifleig@gmail.com>
*
* Created on August 16, 2015, 4:30 PM
*/
#ifndef SDI4FS_INODE_H
#define SDI4FS_INODE_H
#define SDI4FS_INODE_TYPE_DIR 1
#define SDI4FS_INODE_TYPE_REGULARFILE 2
#define SDI4FS_INODE_TYPE_SYMLINK 3
#include "Block.h"
#include <cstdint>
#include <iostream>
#include "StreamSelectorHeader.inc"
namespace SDI4FS {
/**
* Superclass for INodes, holds common values (creation time, size, type, inline flag, link counter)
*/
class INode : public Block {
public:
/**
* Creates an INode by reading contents from the stream.
* Will read up to SDI4FS_BLOCK_SIZE bytes from the stream.
* The caller must call seekg beforehand.
* @param input the stream to read from
*/
INode(STREAM &input);
/**
* Creates a new INode with the given parameters.
* @param id the new unique block id
* @param type the type of this INode
*/
INode(uint32_t id, uint8_t type);
/**
* Returns the creation time of this block.
* @return UNIX-timestamp, creation of this block
*/
uint32_t getCreationTime();
/**
* Returns the type of this INode.
* On of the TYPE defines above.
* Attention: Only uint4_t on disk!
* @return the type of this INode
*/
uint8_t getType();
/**
* Returns the size in bytes of this INode or its content.
* Exact meaning depends on type/subclass.
* Example: Dirs usually return the size the directory data structures use on disk,
* files return the number of bytes of the actual content (omitting fs overhead).
* @return user visible size in bytes
*/
virtual uint32_t getUserVisibleSize_b() = 0;
/**
* Returns the size of the actual content of this INode in bytes.
* @return the size of the actual content in bytes
*/
uint32_t getInternalSize_b();
/**
* Sets the size of the actual content of this INode in bytes.
* @param size_b new size in bytes
*/
virtual void setInternalSize_b(uint32_t size_b);
/**
* Returns true, iff the content of this INode is inlined.
* @return true, iff inlined
*/
bool isInlined();
/**
* Returns the number of links to this INode.
* @return the number of links to this INode
*/
uint16_t getLinkCounter();
/**
* Increments the link counter by one, if possible.
* @return true, iff successful
*/
bool incrementLinkCounter();
/**
* Decrements the link counter by one.
*/
void decrementLinkCounter();
virtual ~INode();
virtual void save(STREAM &output);
protected:
/**
* Sets the inlined-flag to the given value.
* @param inlined the new inline flag
*/
void setInlined(bool inlined);
private:
/**
* UNIX-timestamp, time of INode creation.
*/
uint32_t creationTime;
/**
* Size of the content of this INode.
* Exact meaning depends on type/subclass.
*/
uint32_t size_b;
/**
* Type of this INode,
* one of the TYPE defines above.
* Attention: Only uint4_t on disk!
*/
uint8_t type;
/**
* True, iff content is inlined.
* This means everything is saved within the data part of this INode.
*/
bool inlined;
/**
* Number of other INodes pointing to this INode.
*/
uint16_t linkCounter;
};
} // SDI4FS
#endif // SDI4FS_INODE_H