next up previous contents
Next: Directories Up: File System Physical Representation Previous: File System Physical Representation

File Header

Each Nachos file has an associated FileHeader structure. The FileHeader is similar to a Unix inode in that it contains all the essential information about a file, such as the file's current size and pointers to its physical disk blocks. Specifically, a Nachos' FileHeader contains the current size of the file in bytes, the number of sectors that have been allocated to the file and an array of sector numbers identifying the specific disk sector numbers where the file's data blocks are located. Recall that when a file is initially created, the caller specifies the size of the file. At file creation time, Nachos allocates enough sectors to match the requested size. Thus, as data is appended to the file, no sectors need be allocated. The current size field indicates how much of the file currently contains meaningful data.

Note that a FileHeader contains only ``direct'' pointers to the file's data blocks, limiting the maximum size of a Nachos file to just under 4K bytes.

The following FileHeader operations are supported:

bool Allocate(BitMap *bitMap, int fileSize):
Find and allocate enough free sectors for fileSize bytes of data. Nachos uses a bit vector to keep track of which sectors are allocated and which are free. Argument bitMap is the bit map from which data blocks are to be allocated (e.g., the freelist).

void Deallocate(BitMap *bitMap):
Return to the free list (e.g., bitMap) the blocks allocated to this file (header). Only the file's data blocks are deallocated; the sector containing the FileHeader itself must be freed separately. This operation is invoked when a file is deleted from the system.

void FetchFrom(int sectorNumber):
Read the FileHeader stored in sector sectorNumber from the underlying disk.

void WriteBack(int sectorNumber)
Write the FileHeader to sector number sectorNumber.

int FileLength():
Return the current size of the file.

int ByteToSector(int offset)
Map the offset within a file into the actual sector number that contains that data byte.

Because a FileHeader fits into a single sector, the sector number containing a FileHeader uniquely identifies that file. We will use fnode (for FileheaderNODE) to refer to a sector that contains a FileHeader.


next up previous contents
Next: Directories Up: File System Physical Representation Previous: File System Physical Representation

Thomas Narten
Mon Feb 3 15:00:27 EST 1997