Main Page   Class Hierarchy   Compound List   File List   Compound Members   File 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. 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. More...

#include <filehdr.h>

List of all members.

Public Methods

bool Allocate (BitMap *bitMap, int fileSize)
 Initialize a file header, including allocating space on disk for the file data. More...

void Deallocate (BitMap *bitMap)
 De-allocate this file's data blocks. More...

void FetchFrom (int sectorNumber)
 Initialize file header from disk. More...

void WriteBack (int sectorNumber)
 Write modifications to file header back to disk. More...

int ByteToSector (int offset)
 Convert a byte offset into the file to the disk sector containing the byte. More...

int FileLength ()
 Return the length of the file in bytes. More...

void Print ()
 Print the contents of the file. More...


Private Attributes

int numBytes
 Number of bytes in the file. More...

int numSectors
 Number of data sectors in the file. More...

int dataSectors [NumDirect]
 Disk sector numbers for each data block in the file. More...


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.

Definition at line 38 of file filehdr.h.


Member Function Documentation

bool FileHeader::Allocate ( BitMap * bitMap,
int fileSize )
 

Initialize a file header, including allocating space on disk for the file data.

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. Return FALSE if there are not enough free blocks to accomodate the new file.

"freeMap" is the bit map of free disk sectors "fileSize" is the bit map of free disk sectors

Definition at line 42 of file filehdr.cc.

Referenced by FileSystem::Create(), and FileSystem::FileSystem().

int FileHeader::ByteToSector ( int offset )
 

Convert a byte offset into the file to the disk sector containing the byte.

FileHeader::ByteToSector 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).

"offset" is the location within the file of the byte in question

Definition at line 107 of file filehdr.cc.

Referenced by OpenFile::ReadAt(), and OpenFile::WriteAt().

void FileHeader::Deallocate ( BitMap * bitMap )
 

De-allocate this file's data blocks.

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

"freeMap" is the bit map of free disk sectors

Definition at line 62 of file filehdr.cc.

Referenced by FileSystem::Remove().

void FileHeader::FetchFrom ( int sectorNumber )
 

Initialize file header from disk.

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

"sector" is the disk sector containing the file header

Definition at line 78 of file filehdr.cc.

Referenced by OpenFile::OpenFile(), FileSystem::Print(), Directory::Print(), and FileSystem::Remove().

int FileHeader::FileLength ( )
 

Return the length of the file in bytes.

FileHeader::FileLength Return the number of bytes in the file.

Definition at line 118 of file filehdr.cc.

Referenced by OpenFile::Length(), OpenFile::ReadAt(), and OpenFile::WriteAt().

void FileHeader::Print ( )
 

Print the contents of the file.

FileHeader::Print Print the contents of the file header, and the contents of all the data blocks pointed to by the file header.

Definition at line 130 of file filehdr.cc.

Referenced by FileSystem::Print(), and Directory::Print().

void FileHeader::WriteBack ( int sectorNumber )
 

Write modifications to file header back to disk.

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

"sector" is the disk sector to contain the file header

Definition at line 91 of file filehdr.cc.

Referenced by FileSystem::Create(), and FileSystem::FileSystem().


Member Data Documentation

int FileHeader::dataSectors [private]
 

Disk sector numbers for each data block in the file.

Definition at line 62 of file filehdr.h.

int FileHeader::numBytes [private]
 

Number of bytes in the file.

Definition at line 60 of file filehdr.h.

int FileHeader::numSectors [private]
 

Number of data sectors in the file.

Definition at line 61 of file filehdr.h.


The documentation for this class was generated from the following files:
Generated at Wed Jul 4 11:32:23 2001 for Nachos by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001