Main Page   Compound List   File List   Compound Members   File Members  

FileHeader Class Reference

#include <filehdr.h>

List of all members.

Public Methods

bool Allocate (BitMap *bitMap, int fileSize)
void Deallocate (BitMap *bitMap)
void FetchFrom (int sectorNumber)
void WriteBack (int sectorNumber)
int ByteToSector (int offset)
int FileLength ()
void Print ()

Private Attributes

int numBytes
int numSectors
int dataSectors [NumDirect]


Member Function Documentation

bool FileHeader::Allocate BitMap   bitMap,
int    fileSize
 

Definition at line 42 of file filehdr.cc.

References dataSectors, divRoundUp, FALSE, BitMap::Find, numBytes, BitMap::NumClear, numSectors, SectorSize, and TRUE.

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

00043 { 
00044     numBytes = fileSize;
00045     numSectors  = divRoundUp(fileSize, SectorSize);
00046     if (freeMap->NumClear() < numSectors)
00047         return FALSE;           // not enough space
00048 
00049     for (int i = 0; i < numSectors; i++)
00050         dataSectors[i] = freeMap->Find();
00051     return TRUE;
00052 }

int FileHeader::ByteToSector int    offset
 

Definition at line 107 of file filehdr.cc.

References dataSectors, and SectorSize.

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

00108 {
00109     return(dataSectors[offset / SectorSize]);
00110 }

void FileHeader::Deallocate BitMap   bitMap
 

Definition at line 62 of file filehdr.cc.

References ASSERT, BitMap::Clear, dataSectors, numSectors, and BitMap::Test.

Referenced by FileSystem::Remove.

00063 {
00064     for (int i = 0; i < numSectors; i++) {
00065         ASSERT(freeMap->Test((int) dataSectors[i]));  // ought to be marked!
00066         freeMap->Clear((int) dataSectors[i]);
00067     }
00068 }

void FileHeader::FetchFrom int    sectorNumber
 

Definition at line 78 of file filehdr.cc.

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

00079 {
00080     synchDisk->ReadSector(sector, (char *)this);
00081 }

int FileHeader::FileLength  
 

Definition at line 118 of file filehdr.cc.

References numBytes.

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

00119 {
00120     return numBytes;
00121 }

void FileHeader::Print  
 

Definition at line 130 of file filehdr.cc.

References dataSectors, j, numBytes, numSectors, and SectorSize.

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

00131 {
00132     int i, j, k;
00133     char *data = new char[SectorSize];
00134 
00135     printf("FileHeader contents.  File size: %d.  File blocks:\n", numBytes);
00136     for (i = 0; i < numSectors; i++)
00137         printf("%d ", dataSectors[i]);
00138     printf("\nFile contents:\n");
00139     for (i = k = 0; i < numSectors; i++) {
00140         synchDisk->ReadSector(dataSectors[i], data);
00141         for (j = 0; (j < SectorSize) && (k < numBytes); j++, k++) {
00142             if ('\040' <= data[j] && data[j] <= '\176')   // isprint(data[j])
00143                 printf("%c", data[j]);
00144             else
00145                 printf("\\%x", (unsigned char)data[j]);
00146         }
00147         printf("\n"); 
00148     }
00149     delete [] data;
00150 }

void FileHeader::WriteBack int    sectorNumber
 

Definition at line 91 of file filehdr.cc.

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

00092 {
00093     synchDisk->WriteSector(sector, (char *)this); 
00094 }


Member Data Documentation

int FileHeader::dataSectors[NumDirect] [private]
 

Definition at line 62 of file filehdr.h.

Referenced by Allocate, ByteToSector, Deallocate, and Print.

int FileHeader::numBytes [private]
 

Definition at line 60 of file filehdr.h.

Referenced by Allocate, FileLength, and Print.

int FileHeader::numSectors [private]
 

Definition at line 61 of file filehdr.h.

Referenced by Allocate, Deallocate, and Print.


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 09:54:55 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees