-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInodeTable.java
More file actions
59 lines (50 loc) · 2.06 KB
/
Copy pathInodeTable.java
File metadata and controls
59 lines (50 loc) · 2.06 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
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class InodeTable {
private Ext2File file;
public Inode rootInode;
private Inode inodes[];
private int blocksCount;
private int inodesPerGroup;
private int inodeSize;
private int offset;
private GroupDescriptor groupDescriptor;
public InodeTable(Ext2File file, SuperBlock superBlock, GroupDescriptor groupDescriptor) {
obtainInfo(file, superBlock, groupDescriptor);
populateInodes();
}
private void obtainInfo(Ext2File file, SuperBlock superBlock, GroupDescriptor groupDescriptor) {
this.file = file;
this.groupDescriptor = groupDescriptor;
inodes = new Inode[superBlock.getInodesCount()];
inodeSize = superBlock.getInodeSize();
inodesPerGroup = superBlock.getInodesPerGroup();
blocksCount = superBlock.getInodesCount() / superBlock.getInodesPerGroup();
}
/**
* Loops n times where n is the blocks count and each iteration it reads the inode table pointer location + 4 (getInt) multiplied by 1024. There is another inner loop that loops 5136 times in which the inode table is populated.
*/
private void populateInodes() {
ByteBuffer tempBuffer;
for (int i = 0; i < blocksCount; i++) {
tempBuffer = ByteBuffer.wrap(file.read(groupDescriptor.getInodeTablePointersLocations()[i], 1024)).order(ByteOrder.LITTLE_ENDIAN);
offset = tempBuffer.getInt() * Constants.BLOCK_SIZE;
// i(0), j -> 1712; i(1), j -> 1712 * 2 = 3424; i(2), j -> 1712 * 3 = 5136;
for(int j = inodesPerGroup*i; j < inodesPerGroup*(i+1); j++)
{
inodes[j] = new Inode(offset, file);
offset += inodeSize;
if (j == 1) rootInode = inodes[j];
}
}
}
public Inode getRootInode() {
return rootInode;
}
public Inode[] getInodes() {
return inodes;
}
public int getBlocksCount() {
return blocksCount;
}
}