tac0S
Template Affectional Command Operating System
Public Member Functions | Public Attributes | List of all members
FileHeader Class Reference

The following 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. More...

#include <filehdr.h>

Public Member Functions

bool Allocate (BitMap *bitMap, int fileSize)
 FileHeader::Allocate Initialize a fresh file header for a newly created file. Allocate data blocks for the file out of the map of free disk blocks. More...
 
void Deallocate (BitMap *bitMap)
 FileHeader::Deallocate De-allocate all the space allocated for data blocks for this file. More...
 
void FetchFrom (int sectorNumber)
 FileHeader::FetchFrom Fetch contents of file header from disk. More...
 
void WriteBack (int sectorNumber)
 FileHeader::WriteBack Write the modified contents of the file header back to disk. More...
 
int ByteToSector (int offset)
 FileHeader::ByteToSector. More...
 
int FileLength ()
 FileHeader::FileLength. More...
 
void Print ()
 FileHeader::Print Print the contents of the file header, and the contents of all the data blocks pointed to by the file header.
 
void test ()
 
int get_sector (int id_sector)
 
void set_sector (int id_sector, int sector)
 

Public Attributes

File_type type
 

Detailed Description

The following 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.

There is no constructor; rather the file header can be initialized by allocating blocks for the file (if it is a new file), or by reading it from disk.

Member Function Documentation

bool FileHeader::Allocate ( BitMap freeMap,
int  fileSize 
)

FileHeader::Allocate Initialize a fresh file header for a newly created file. Allocate data blocks for the file out of the map of free disk blocks.

Returns
Return FALSE if there are not enough free blocks to accomodate the new file.
Parameters
freeMapis the bit map of free disk sectors
fileSizeis the bit map of free disk sectors
int FileHeader::ByteToSector ( int  offset)

FileHeader::ByteToSector.

Returns
Return which disk sector is storing a particular byte within the file. This is essentially a translation from a virtual address (the offset in the file) to a physical address (the sector where the data at the offset is stored).
Parameters
offsetis the location within the file of the byte in question
void FileHeader::Deallocate ( BitMap freeMap)

FileHeader::Deallocate De-allocate all the space allocated for data blocks for this file.

Parameters
freeMapis the bit map of free disk sectors
void FileHeader::FetchFrom ( int  sector)

FileHeader::FetchFrom Fetch contents of file header from disk.

Parameters
sectoris the disk sector containing the file header
int FileHeader::FileLength ( )

FileHeader::FileLength.

Returns
Return the number of bytes in the file.
void FileHeader::WriteBack ( int  sector)

FileHeader::WriteBack Write the modified contents of the file header back to disk.

Parameters
sectoris the disk sector to contain the file header

The documentation for this class was generated from the following files: