-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperBlock.java
More file actions
84 lines (68 loc) · 2.54 KB
/
Copy pathSuperBlock.java
File metadata and controls
84 lines (68 loc) · 2.54 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
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.io.IOException;
public class SuperBlock {
private Ext2File file;
private String volumeName;
private int magicNumber;
private int inodesCount;
private int inodeSize;
private int blocksCount;
private int blocksPerGroup;
private int inodesPerGroup;
private ByteBuffer byteBuffer;
public SuperBlock(Ext2File file) throws IOException {
this.file = file;
process();
}
private void process() throws IOException {
byteBuffer = ByteBuffer.wrap(file.read(Constants.SUPERBLOCK_OFFSET, 136)).order(ByteOrder.LITTLE_ENDIAN);
magicNumber = byteBuffer.getInt(Constants.MAGIC_NUMBER_OFFSET); // magic number offset
inodesCount = byteBuffer.getInt(Constants.INODES_COUNT_OFFSET); // inodes count offset
inodeSize = byteBuffer.getInt(Constants.INODES_SIZE_OFFSET); // inodes size offset
blocksCount = byteBuffer.getInt(Constants.BLOCKS_COUNT_OFFSET); // blocks count offset
blocksPerGroup = byteBuffer.getInt(Constants.BLOCKS_PER_GROUP_OFFSET); // blocks per group offset
inodesPerGroup = byteBuffer.getInt(Constants.INODES_PER_GROUP_OFFSET); // inodes per group offset
byte[] volumeBytes = new byte[16];
int index = 0;
for (int i = Constants.VOLUME_NAME_OFFSET; i < 136; i++)
volumeBytes[index++] = byteBuffer.get(i);
volumeName = new String(volumeBytes);
System.out.println(this);
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("==================Superblock Contents==================\n");
stringBuilder.append(String.format("Magic Number: 0x%02X", magicNumber));
stringBuilder.append("\nInodes Count: " + inodesCount);
stringBuilder.append("\nInode Size: " + inodeSize);
stringBuilder.append("\nBlocks Count: " + blocksCount);
stringBuilder.append("\nBlocks Per Group: " + blocksPerGroup);
stringBuilder.append("\nInodes Per Group: " + inodesPerGroup);
stringBuilder.append("\nVolume Name: " + volumeName);
stringBuilder.append("\n=======================================================");
return stringBuilder.toString();
}
public String getVolumeName() {
return this.volumeName;
}
public int getMagicNumber() {
return this.magicNumber;
}
public int getInodesCount() {
return this.inodesCount;
}
public int getInodeSize() {
return this.inodeSize;
}
public int getBlocksCount() {
return this.blocksCount;
}
public int getBlocksPerGroup() {
return this.blocksPerGroup;
}
public int getInodesPerGroup() {
return this.inodesPerGroup;
}
}