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 pathFSformat.java
More file actions
Latest commit
58 lines (46 loc) · 1.34 KB
/
Copy pathFSformat.java
File metadata and controls
58 lines (46 loc) · 1.34 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
packageexternal_tools;
importjava.io.*;
publicclassFSformat {
privateRandomAccessFilefile;
privateintmagic = 0x1234ABCD;
privatelongmagicPosition = 0;
privatelongcurrPositon = 0;
privateintdirectoryBlock = 1;
privatelongdirectoryPosition = 8;
privateintfirstFreeBlock = 2;
privatelongfreePosition = 12;
publicvoidstart(Stringfilename) {
try {
file = newRandomAccessFile(filename,"rw");
if ( testFormated() ) {
System.out.println("Already formated.");
}
else {
format();
}
}
catch ( IOExceptione ) {
System.out.print("IO Exception - BlockDevice file not found.");
}
}
privatebooleantestFormated() throwsIOException {
file.seek(magicPosition);
intkey = file.readInt(); //read and writes advances file pos pointer
if ( key == magic ) {
returntrue;
}
else {
returnfalse;
}
}
privatevoidformat() throwsIOException {
//Write magic number as the first 32bit word on the super block
file.seek(magicPosition);
file.writeInt(magic);
//Set directory block number as third 32bit word
file.seek(directoryPosition);
file.writeInt(directoryBlock);
//Set block number of start of free block chain as fourth 32bit word, which is after the directory block number in the super block
file.writeInt(firstFreeBlock);
}
}