-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperblock.cpp
More file actions
225 lines (194 loc) · 6.15 KB
/
Superblock.cpp
File metadata and controls
225 lines (194 loc) · 6.15 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "Superblock.hpp"
#include "Inode.hpp"
#include "Constants.hpp"
#include <cstring>
#include <cmath>
using std::strncpy;
Superblock::Superblock()
: signature(nullptr), diskSize(0), clusterSize(CLUSTER_SIZE),
clusterCount(0), inodeCount(0), bitmapClusterCount(0),
inodeClusterCount(0), dataClusterCount(0), bitmapStartAddress(0),
inodeStartAddress(0), dataStartAddress(0) {
signature = new char[SIGNATURE_LENGTH + 1];
strncpy(signature, SIGNATURE, SIGNATURE_LENGTH);
signature[SIGNATURE_LENGTH] = '\0';
}
Superblock::Superblock(int32_t diskSize)
: Superblock() {
this->diskSize = diskSize;
clusterCount = diskSize / CLUSTER_SIZE;
inodeClusterCount = clusterCount / 20;
inodeCount = (inodeClusterCount * CLUSTER_SIZE) / INODE_SIZE;
bitmapClusterCount = static_cast<int32_t>(ceil((clusterCount - inodeClusterCount - 1) / static_cast<float>(CLUSTER_SIZE)));
dataClusterCount = clusterCount - 1 - bitmapClusterCount - inodeClusterCount;
bitmapStartAddress = CLUSTER_SIZE;
inodeStartAddress = bitmapStartAddress + CLUSTER_SIZE * bitmapClusterCount;
dataStartAddress = inodeStartAddress + CLUSTER_SIZE * inodeClusterCount;
}
Superblock::Superblock(const Superblock& other)
: diskSize(other.diskSize), clusterSize(other.clusterSize),
clusterCount(other.clusterCount), inodeCount(other.inodeCount),
bitmapClusterCount(other.bitmapClusterCount), inodeClusterCount(other.inodeClusterCount),
dataClusterCount(other.dataClusterCount), bitmapStartAddress(other.bitmapStartAddress),
inodeStartAddress(other.inodeStartAddress), dataStartAddress(other.dataStartAddress),
signature(new char[SIGNATURE_LENGTH + 1]) {
strcpy(signature, other.signature);
}
Superblock& Superblock::operator=(const Superblock& other) {
if (this != &other) {
delete[] signature;
signature = new char[SIGNATURE_LENGTH + 1];
strcpy(signature, other.signature);
diskSize = other.diskSize;
clusterSize = other.clusterSize;
clusterCount = other.clusterCount;
inodeCount = other.inodeCount;
bitmapClusterCount = other.bitmapClusterCount;
inodeClusterCount = other.inodeClusterCount;
dataClusterCount = other.dataClusterCount;
bitmapStartAddress = other.bitmapStartAddress;
inodeStartAddress = other.inodeStartAddress;
dataStartAddress = other.dataStartAddress;
}
return *this;
}
Superblock::~Superblock() {
delete[] signature;
}
const char* Superblock::getSignature() const {
return signature;
}
/**
* Sets signature
*
* @param newSignature - new signature
*/
void Superblock::setSignature(const char* newSignature) {
if (newSignature) {
strncpy(signature, newSignature, SIGNATURE_LENGTH);
signature[SIGNATURE_LENGTH] = '\0';
}
}
/**
* Gets disk size
*
* @return disk size
*/
int32_t Superblock::getDiskSize() const { return diskSize; }
/**
* Sets disk size
*
* @param newDiskSize - new disk size
*/
void Superblock::setDiskSize(int32_t newDiskSize) { diskSize = newDiskSize; }
/**
* Gets cluster size
*
* @return cluster size
*/
int32_t Superblock::getClusterSize() const { return clusterSize; }
/**
* Sets cluster size
*
* @param newClusterSize - new cluster size
*/
void Superblock::setClusterSize(int32_t newClusterSize) { clusterSize = newClusterSize; }
/**
* Gets cluster count
*
* @return cluster count
*/
int32_t Superblock::getClusterCount() const { return clusterCount; }
/**
* Sets cluster count
*
* @param newClusterCount - new cluster count
*/
void Superblock::setClusterCount(int32_t newClusterCount) { clusterCount = newClusterCount; }
/**
* Gets inode count
*
* @return inode count
*/
int32_t Superblock::getInodeCount() const { return inodeCount; }
/**
* Sets inode count
*
* @param newInodeCount - new inode count
*/
void Superblock::setInodeCount(int32_t newInodeCount) { inodeCount = newInodeCount; }
/**
* Gets bitmap cluster count
*
* @return bitmap cluster count
*/
int32_t Superblock::getBitmapClusterCount() const { return bitmapClusterCount; }
/**
* Sets bitmap cluster count
*
* @param newBitmapClusterCount - new bitmap cluster count
*/
void Superblock::setBitmapClusterCount(int32_t newBitmapClusterCount) { bitmapClusterCount = newBitmapClusterCount; }
/**
* Gets inode cluster count
*
* @return inode cluster count
*/
int32_t Superblock::getInodeClusterCount() const { return inodeClusterCount; }
/**
* Sets inode cluster count
*
* @param newInodeClusterCount - new inode cluster count
*/
void Superblock::setInodeClusterCount(int32_t newInodeClusterCount) { inodeClusterCount = newInodeClusterCount; }
/**
* Gets data cluster count
*
* @return data cluster count
*/
int32_t Superblock::getDataClusterCount() const { return dataClusterCount; }
/**
* Sets data cluster count
*
* @param newDataClusterCount - new data cluster count
*/
void Superblock::setDataClusterCount(int32_t newDataClusterCount) { dataClusterCount = newDataClusterCount; }
/**
* Gets bitmap start address
*
* @return bitmap start address
*/
int32_t Superblock::getBitmapStartAddress() const { return bitmapStartAddress; }
/**
* Sets bitmap start address
*
* @param newBitmapStartAddress - new bitmap start address
*/
void Superblock::setBitmapStartAddress(int32_t newBitmapStartAddress) { bitmapStartAddress = newBitmapStartAddress; }
/**
* Gets inode start address
*
* @return inode start address
*/
int32_t Superblock::getInodeStartAddress() const { return inodeStartAddress; }
/**
* Sets inode start address
*
* @param newInodeStartAddress - new inode start address
*/
void Superblock::setInodeStartAddress(int32_t newInodeStartAddress) { inodeStartAddress = newInodeStartAddress; }
/**
* Gets data start address
*
* @return data start address
*/
int32_t Superblock::getDataStartAddress() const { return dataStartAddress; }
/**
* Sets data start address
*
* @param newDataStartAddress - new data start address
*/
void Superblock::setDataStartAddress(int32_t newDataStartAddress) { dataStartAddress = newDataStartAddress; }
Superblock* superblockInit(int32_t disk_size) {
return new Superblock(disk_size);
}