ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

NachOS sistem operative


Enviado por   •  19 de Noviembre de 2015  •  Apuntes  •  869 Palabras (4 Páginas)  •  88 Visitas

Página 1 de 4

<HTML><TITLE>./filesys/directory.cc</TITLE><BODY BGCOLOR=#ffffff><PRE>

<FONT COLOR=#ff0000>// directory.cc </FONT>

<FONT COLOR=#ff0000>// Routines to manage a directory of file names.</FONT>

<FONT COLOR=#ff0000>//</FONT>

<FONT COLOR=#ff0000>// The directory is a table of fixed length entries; each</FONT>

<FONT COLOR=#ff0000>// entry represents a single file, and contains the file name,</FONT>

<FONT COLOR=#ff0000>// and the location of the file header on disk. The fixed size</FONT>

<FONT COLOR=#ff0000>// of each directory entry means that we have the restriction</FONT>

<FONT COLOR=#ff0000>// of a fixed maximum size for file names.</FONT>

<FONT COLOR=#ff0000>//</FONT>

<FONT COLOR=#ff0000>// The constructor initializes an empty directory of a certain size;</FONT>

<FONT COLOR=#ff0000>// we use ReadFrom/WriteBack to fetch the contents of the directory</FONT>

<FONT COLOR=#ff0000>// from disk, and to write back any modifications back to disk.</FONT>

<FONT COLOR=#ff0000>//</FONT>

<FONT COLOR=#ff0000>// Also, this implementation has the restriction that the size</FONT>

<FONT COLOR=#ff0000>// of the directory cannot expand. In other words, once all the</FONT>

<FONT COLOR=#ff0000>// entries in the directory are used, no more files can be created.</FONT>

<FONT COLOR=#ff0000>// Fixing this is one of the parts to the assignment.</FONT>

<FONT COLOR=#ff0000>//</FONT>

<FONT COLOR=#ff0000>// Copyright (c) 1992-1993 The Regents of the University of California.</FONT>

<FONT COLOR=#ff0000>// All rights reserved. See copyright.h for copyright notice and limitation </FONT>

<FONT COLOR=#ff0000>// of liability and disclaimer of warranty provisions.</FONT>

<FONT COLOR=#ff00ff>#include <a href="copyright.h.html">"copyright.h"</a></FONT>

<FONT COLOR=#ff00ff>#include <a href="utility.h.html">"utility.h"</a></FONT>

<FONT COLOR=#ff00ff>#include <a href="filehdr.h.html">"filehdr.h"</a></FONT>

<FONT COLOR=#ff00ff>#include <a href="directory.h.html">"directory.h"</a></FONT>

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

<FONT COLOR=#ff0000>// Directory::Directory</FONT>

<FONT COLOR=#ff0000>// Initialize a directory; initially, the directory is completely</FONT>

<FONT COLOR=#ff0000>// empty. If the disk is being formatted, an empty directory</FONT>

<FONT COLOR=#ff0000>// is all we need, but otherwise, we need to call FetchFrom in order</FONT>

<FONT COLOR=#ff0000>// to initialize it from disk.</FONT>

<FONT COLOR=#ff0000>//</FONT>

<FONT COLOR=#ff0000>// "size" is the number of entries in the directory</FONT>

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

<A NAME=Directory>

<A HREF=.././filesys/directory.cc.html#Directory>Directory</A>::Directory(int size)

{

table = new DirectoryEntry[size];

tableSize = size;

for (int i = 0; i &lt; tableSize; i++)

table[i].inUse = FALSE;

}

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

<FONT COLOR=#ff0000>// Directory::~Directory</FONT>

<FONT COLOR=#ff0000>// De-allocate directory data structure.</FONT>

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

<A NAME=~Directory>

Directory::<A HREF=.././filesys/directory.cc.html#~Directory>~Directory</A>()

{

delete [] table;

}

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

<FONT COLOR=#ff0000>// Directory::FetchFrom</FONT>

<FONT COLOR=#ff0000>// Read the contents of the directory from disk.</FONT>

<FONT COLOR=#ff0000>//</FONT>

<FONT COLOR=#ff0000>// "file" -- file containing the directory contents</FONT>

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

void

<A NAME=FetchFrom>

Directory::<A HREF=.././userprog/bitmap.cc.html#FetchFrom>FetchFrom</A>(OpenFile *file)

{

(void) file-&gt;<A HREF=.././filesys/openfile.cc.html#ReadAt>ReadAt</A>((char *)table, tableSize * sizeof(DirectoryEntry), 0);

}

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

<FONT COLOR=#ff0000>// Directory::WriteBack</FONT>

<FONT COLOR=#ff0000>// Write any modifications to the directory back to disk</FONT>

<FONT COLOR=#ff0000>//</FONT>

<FONT COLOR=#ff0000>// "file" -- file to contain the new directory contents</FONT>

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

void

<A NAME=WriteBack>

Directory::<A HREF=.././userprog/bitmap.cc.html#WriteBack>WriteBack</A>(OpenFile *file)

{

(void) file-&gt;<A HREF=.././filesys/openfile.cc.html#WriteAt>WriteAt</A>((char *)table, tableSize * sizeof(DirectoryEntry), 0);

}

<FONT COLOR=#ff0000>//----------------------------------------------------------------------</FONT>

<FONT COLOR=#ff0000>// Directory::FindIndex</FONT>

<FONT COLOR=#ff0000>// Look up file name in directory, and return its location in the table of</FONT>

<FONT COLOR=#ff0000>// directory entries. Return -1 if the name isn't in the directory.</FONT>

<FONT COLOR=#ff0000>//</FONT>

...

Descargar como (para miembros actualizados) txt (10 Kb) pdf (51 Kb) docx (15 Kb)
Leer 3 páginas más »
Disponible sólo en Clubensayos.com