Main Page   Compound List   File List   Compound Members   File Members  

Directory Class Reference

#include <directory.h>

List of all members.

Public Methods

 Directory (int size)
 ~Directory ()
void FetchFrom (OpenFile *file)
void WriteBack (OpenFile *file)
int Find (char *name)
bool Add (char *name, int newSector)
bool Remove (char *name)
void List ()
void Print ()

Private Methods

int FindIndex (char *name)

Private Attributes

int tableSize
DirectoryEntrytable


Constructor & Destructor Documentation

Directory::Directory int    size
 

Definition at line 38 of file directory.cc.

References FALSE, DirectoryEntry::inUse, table, and tableSize.

00039 {
00040     table = new DirectoryEntry[size];
00041     tableSize = size;
00042     for (int i = 0; i < tableSize; i++)
00043         table[i].inUse = FALSE;
00044 }

Directory::~Directory  
 

Definition at line 51 of file directory.cc.

References table.

00052 { 
00053     delete [] table;
00054 } 


Member Function Documentation

bool Directory::Add char *    name,
int    newSector
 

Definition at line 130 of file directory.cc.

References FALSE, FileNameMaxLen, FindIndex, DirectoryEntry::inUse, DirectoryEntry::sector, table, tableSize, and TRUE.

Referenced by FileSystem::Create.

00131 { 
00132     if (FindIndex(name) != -1)
00133         return FALSE;
00134 
00135     for (int i = 0; i < tableSize; i++)
00136         if (!table[i].inUse) {
00137             table[i].inUse = TRUE;
00138             strncpy(table[i].name, name, FileNameMaxLen); 
00139             table[i].sector = newSector;
00140         return TRUE;
00141         }
00142     return FALSE;       // no space.  Fix when we have extensible files.
00143 }

void Directory::FetchFrom OpenFile   file
 

Definition at line 64 of file directory.cc.

References OpenFile::ReadAt, table, and tableSize.

Referenced by FileSystem::Create, FileSystem::List, FileSystem::Open, FileSystem::Print, and FileSystem::Remove.

00065 {
00066     (void) file->ReadAt((char *)table, tableSize * sizeof(DirectoryEntry), 0);
00067 }

int Directory::Find char *    name
 

Definition at line 109 of file directory.cc.

References FindIndex, DirectoryEntry::sector, and table.

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

00110 {
00111     int i = FindIndex(name);
00112 
00113     if (i != -1)
00114         return table[i].sector;
00115     return -1;
00116 }

int Directory::FindIndex char *    name [private]
 

Definition at line 91 of file directory.cc.

References FileNameMaxLen, DirectoryEntry::inUse, table, and tableSize.

Referenced by Add, Find, and Remove.

00092 {
00093     for (int i = 0; i < tableSize; i++)
00094         if (table[i].inUse && !strncmp(table[i].name, name, FileNameMaxLen))
00095             return i;
00096     return -1;          // name not in directory
00097 }

void Directory::List  
 

Definition at line 170 of file directory.cc.

References DirectoryEntry::inUse, table, and tableSize.

Referenced by FileSystem::List.

00171 {
00172    for (int i = 0; i < tableSize; i++)
00173         if (table[i].inUse)
00174             printf("%s\n", table[i].name);
00175 }

void Directory::Print  
 

Definition at line 184 of file directory.cc.

References FileHeader::FetchFrom, DirectoryEntry::inUse, FileHeader::Print, table, and tableSize.

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

00185 { 
00186     FileHeader *hdr = new FileHeader;
00187 
00188     printf("Directory contents:\n");
00189     for (int i = 0; i < tableSize; i++)
00190         if (table[i].inUse) {
00191             printf("Name: %s, Sector: %d\n", table[i].name, table[i].sector);
00192             hdr->FetchFrom(table[i].sector);
00193             hdr->Print();
00194         }
00195     printf("\n");
00196     delete hdr;
00197 }

bool Directory::Remove char *    name
 

Definition at line 154 of file directory.cc.

References FALSE, FindIndex, DirectoryEntry::inUse, table, and TRUE.

Referenced by FileSystem::Remove.

00155 { 
00156     int i = FindIndex(name);
00157 
00158     if (i == -1)
00159         return FALSE;           // name not in directory
00160     table[i].inUse = FALSE;
00161     return TRUE;        
00162 }

void Directory::WriteBack OpenFile   file
 

Definition at line 77 of file directory.cc.

References table, tableSize, and OpenFile::WriteAt.

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

00078 {
00079     (void) file->WriteAt((char *)table, tableSize * sizeof(DirectoryEntry), 0);
00080 }


Member Data Documentation

DirectoryEntry* Directory::table [private]
 

Definition at line 76 of file directory.h.

Referenced by Add, Directory, FetchFrom, Find, FindIndex, List, Print, Remove, WriteBack, and ~Directory.

int Directory::tableSize [private]
 

Definition at line 75 of file directory.h.

Referenced by Add, Directory, FetchFrom, FindIndex, List, Print, and WriteBack.


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 09:54:54 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