Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFSreadfile.java
More file actions
Latest commit
109 lines (95 loc) · 2.03 KB
/
Copy pathFSreadfile.java
File metadata and controls
109 lines (95 loc) · 2.03 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
packageexternal_tools;
importjava.io.*;
publicclassFSreadfile {
privateStringf;
privateRandomAccessFilefile;
privatelongdirectoryBlockPos = 4096;
publicvoidstart(Stringf, Stringfilename) {
try {
file = newRandomAccessFile(filename,"rw");
intblockNum = getBlockNum(f);
readFile(blockNum);
}
catch ( IOExceptione ) {
System.out.print("IO Exception - BlockDevice file not found.");
}
}
privateintgetBlockNum(Stringf) throwsIOException {
//A byte equal to null is 0x00000000
longcurrPos = directoryBlockPos;
while ( currPos <= 8191 ) {
file.seek(currPos);
byte[] bytes = newbyte[12];
char[] chars = newchar[12];
intc = 0;
while ( c < 12 ) {
bytes[c] = (byte)file.read();
chars[c] = (char)bytes[c];
if ( (int)chars[c] == 0 ) {
break;
}
c++;
}
Strings = "";
c = 0;
while ( c < 12 ) {
if ( (int)chars[c] == 0 ) {
break;
}
s += chars[c];
c++;
}
if ( s.equals(f) ) {
currPos += 12;
file.seek(currPos);
intblock = file.readInt();
if ( block == 0 ) {
thrownewRuntimeException("File was deleted.");
}
returnblock;
}
currPos += 16;
}
if ( currPos > 8191 ) {
thrownewRuntimeException("File not found.");
}
return0;
}
privatevoidreadFile(intblockNum) throwsIOException {
//Iterate to inode
longinodePos = 8192;
intc = blockNum;
while ( c > 2 ) {
inodePos += 4096;
c--;
}
file.seek(inodePos);
//Read immediate data
c = 0;
while ( c < 2044 ) {
System.out.print(""+(char)file.readByte());
c++;
}
//Loop through direct indices, printing out 4096 chars at a time
inodePos += 2048;
while ( true ) {
file.seek(inodePos);
longpos = 8192;
c = file.readInt();
if ( c == 0 ) {
break;
}
inodePos += 4;
while ( c > 2 ) {
pos += 4096;
c--;
}
file.seek(pos);
c = 0;
while ( c < 4096 ) {
System.out.print(""+(char)file.readByte());
c++;
}
}
}
}