-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperBlock.cc
122 lines (108 loc) · 2.74 KB
/
SuperBlock.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/** Rohit Sindhu [sindh010]
* Aravind Alagiri Ramkumar [alagi005]
* Aparna Mahadevan [mahad028]
*/
#include "SuperBlock.h"
#include <stdlib.h>
#include <string.h>
SuperBlock::SuperBlock()
{
}
void SuperBlock::setBlockSize( short newBlockSize )
{
blockSize = newBlockSize ;
}
short SuperBlock::getBlockSize()
{
return blockSize ;
}
void SuperBlock::setBlocks( int newBlocks )
{
blocks = newBlocks ;
}
int SuperBlock::getBlocks()
{
return blocks ;
}
/**
* Set the freeListBlockOffset (in blocks)
* @param newFreeListBlockOffset the new offset in blocks
*/
void SuperBlock::setFreeListBlockOffset( int newFreeListBlockOffset )
{
freeListBlockOffset = newFreeListBlockOffset ;
}
/**
* Get the free list block offset
* @return the free list block offset
*/
int SuperBlock::getFreeListBlockOffset()
{
return freeListBlockOffset ;
}
/**
* Set the inodeBlockOffset (in blocks)
* @param newInodeBlockOffset the new offset in blocks
*/
void SuperBlock::setInodeBlockOffset( int newInodeBlockOffset )
{
inodeBlockOffset = newInodeBlockOffset ;
}
/**
* Get the inode block offset (in blocks)
* @return inode block offset in blocks
*/
int SuperBlock::getInodeBlockOffset()
{
return inodeBlockOffset ;
}
/**
* Set the dataBlockOffset (in blocks)
* @param newDataBlockOffset the new offset in blocks
*/
void SuperBlock::setDataBlockOffset( int newDataBlockOffset )
{
dataBlockOffset = newDataBlockOffset ;
}
/**
* Get the dataBlockOffset (in blocks)
* @return the offset in blocks to the data block region
*/
int SuperBlock::getDataBlockOffset()
{
return dataBlockOffset ;
}
/**
* writes this SuperBlock at the current position of the specified file.
*/
void SuperBlock::write(fstream& file)
{
if(file.is_open() == true)
{
file.write(reinterpret_cast<char*>(&blockSize), sizeof(short));
file.write(reinterpret_cast<char*>(&blocks), sizeof(int));
file.write(reinterpret_cast<char*>(&freeListBlockOffset), sizeof(int));
file.write(reinterpret_cast<char*>(&inodeBlockOffset), sizeof(int));
file.write(reinterpret_cast<char*>(&dataBlockOffset), sizeof(int));
int nSize = sizeof(short) + sizeof(int)*4;
int dummySize = blockSize-nSize;
char * dummy = new char[dummySize];
memset(dummy, '\0', dummySize);
file.write(dummy, dummySize);
delete[] dummy;
}
}
/**
* reads this SuperBlock at the current position of the specified file.
*/
void SuperBlock::read(fstream& file)
{
if(file.is_open() == true)
{
file.read(reinterpret_cast<char*>(&blockSize), sizeof(short));
file.read(reinterpret_cast<char*>(&blocks), sizeof(int));
file.read(reinterpret_cast<char*>(&freeListBlockOffset), sizeof(int));
file.read(reinterpret_cast<char*>(&inodeBlockOffset), sizeof(int));
file.read(reinterpret_cast<char*>(&dataBlockOffset), sizeof(int));
}
}