|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.kernel.filesys.FileHeader
class FileHeader
This class defines the Nachos "file header" (in UNIX terms, the "i-node"), describing where on disk to find all of the data in the file. The file header is organized as a simple table of pointers to data blocks. The file header data structure can be stored in memory or on disk. When it is on disk, it is stored in a single sector -- this means that we assume the size of this data structure to be the same as one disk sector. Without indirect addressing, this limits the maximum file length to just under 4K bytes. The file header is used to locate where on disk the file's data is stored. We implement this as a fixed size table of pointers -- each entry in the table points to the disk sector containing that portion of the file data (in other words, there are no indirect or doubly indirect blocks). The table size is chosen so that the file header will be just big enough to fit in one disk sector, Unlike in a real system, we do not keep track of file permissions, ownership, last modification date, etc., in the file header. A file header can be initialized in two ways: for a new file, by modifying the in-memory data structure to point to the newly allocated data blocks; for a file already on disk, by reading the file header from disk.
Field Summary | |
---|---|
private int[] |
dataSectors
Disk sector numbers for each data block in the file. |
private static int |
MaxFileSize
Maximum file size that can be represented in the baseline system. |
private int |
numBytes
Number of bytes in the file. |
private static int |
NumDirect
Number of pointers to data blocks stored in a file header. |
private int |
numSectors
Number of data sectors in the file. |
Constructor Summary | |
---|---|
FileHeader()
Allocate a new "in-core" file header. |
Method Summary | |
---|---|
(package private) boolean |
allocate(BitMap freeMap,
int fileSize)
Initialize a fresh file header for a newly created file. |
(package private) int |
byteToSector(int offset)
Calculate which disk sector is storing a particular byte within the file. |
(package private) void |
deallocate(BitMap freeMap)
De-allocate all the space allocated for data blocks for this file. |
private void |
externalize(byte[] buffer,
int pos)
Export the fields of this FileHeader object to a buffer in a format suitable for writing to the disk. |
(package private) void |
fetchFrom(int sector)
Fetch contents of file header from disk. |
(package private) int |
fileLength()
Retrieve the number of bytes in the file. |
private void |
internalize(byte[] buffer,
int pos)
Initialize the fields of this FileHeader object using data read from the disk. |
(package private) void |
print()
Print the contents of the file header, and the contents of all the data blocks pointed to by the file header. |
private static int |
sizeOf()
Calculate the size of the on-disk representation of a FileHeader. |
(package private) void |
writeBack(int sector)
Write the modified contents of the file header back to disk. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int NumDirect
private static final int MaxFileSize
private int numBytes
private int numSectors
private int[] dataSectors
Constructor Detail |
---|
FileHeader()
Method Detail |
---|
private static int sizeOf()
private void internalize(byte[] buffer, int pos)
buffer
- A buffer holding the data read from the disk.pos
- Position in the buffer at which to start.private void externalize(byte[] buffer, int pos)
buffer
- A buffer into which to place the exported data.pos
- Position in the buffer at which to start.boolean allocate(BitMap freeMap, int fileSize)
freeMap
- is the bit map of free disk sectors.fileSize
- is size of the new file.void deallocate(BitMap freeMap)
freeMap
- is the bit map of free disk sectors.void fetchFrom(int sector)
sector
- is the disk sector containing the file header.void writeBack(int sector)
sector
- is the disk sector to contain the file header.int byteToSector(int offset)
offset
- The location within the file of the byte in question.
int fileLength()
void print()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |