Main Page   Compound List   File List   Compound Members   File Members  

filesys.h

Go to the documentation of this file.
00001 // filesys.h 
00002 //      Data structures to represent the Nachos file system.
00003 //
00004 //      A file system is a set of files stored on disk, organized
00005 //      into directories.  Operations on the file system have to
00006 //      do with "naming" -- creating, opening, and deleting files,
00007 //      given a textual file name.  Operations on an individual
00008 //      "open" file (read, write, close) are to be found in the OpenFile
00009 //      class (openfile.h).
00010 //
00011 //      We define two separate implementations of the file system. 
00012 //      The "STUB" version just re-defines the Nachos file system 
00013 //      operations as operations on the native UNIX file system on the machine
00014 //      running the Nachos simulation.  This is provided in case the
00015 //      multiprogramming and virtual memory assignments (which make use
00016 //      of the file system) are done before the file system assignment.
00017 //
00018 //      The other version is a "real" file system, built on top of 
00019 //      a disk simulator.  The disk is simulated using the native UNIX 
00020 //      file system (in a file named "DISK"). 
00021 //
00022 //      In the "real" implementation, there are two key data structures used 
00023 //      in the file system.  There is a single "root" directory, listing
00024 //      all of the files in the file system; unlike UNIX, the baseline
00025 //      system does not provide a hierarchical directory structure.  
00026 //      In addition, there is a bitmap for allocating
00027 //      disk sectors.  Both the root directory and the bitmap are themselves
00028 //      stored as files in the Nachos file system -- this causes an interesting
00029 //      bootstrap problem when the simulated disk is initialized. 
00030 //
00031 // Copyright (c) 1992-1993 The Regents of the University of California.
00032 // All rights reserved.  See copyright.h for copyright notice and limitation 
00033 // of liability and disclaimer of warranty provisions.
00034 
00035 #ifndef FS_H
00036 #define FS_H
00037 
00038 #include "copyright.h"
00039 #include "openfile.h"
00040 
00041 #ifdef FILESYS_STUB             // Temporarily implement file system calls as 
00042                                 // calls to UNIX, until the real file system
00043                                 // implementation is available
00044 class FileSystem {
00045   public:
00046     FileSystem(bool format) {}
00047 
00048     bool Create(char *name, int initialSize) { 
00049         int fileDescriptor = OpenForWrite(name);
00050 
00051         if (fileDescriptor == -1) return FALSE;
00052         Close(fileDescriptor); 
00053         return TRUE; 
00054         }
00055 
00056     OpenFile* Open(char *name) {
00057           int fileDescriptor = OpenForReadWrite(name, FALSE);
00058 
00059           if (fileDescriptor == -1) return NULL;
00060           return new OpenFile(fileDescriptor);
00061       }
00062 
00063     bool Remove(char *name) { return Unlink(name) == 0; }
00064 
00065 };
00066 
00067 #else // FILESYS
00068 class FileSystem {
00069   public:
00070     FileSystem(bool format);            // Initialize the file system.
00071                                         // Must be called *after* "synchDisk" 
00072                                         // has been initialized.
00073                                         // If "format", there is nothing on
00074                                         // the disk, so initialize the directory
00075                                         // and the bitmap of free blocks.
00076 
00077     bool Create(char *name, int initialSize);   
00078                                         // Create a file (UNIX creat)
00079 
00080     OpenFile* Open(char *name);         // Open a file (UNIX open)
00081 
00082     bool Remove(char *name);            // Delete a file (UNIX unlink)
00083 
00084     void List();                        // List all the files in the file system
00085 
00086     void Print();                       // List all the files and their contents
00087 
00088   private:
00089    OpenFile* freeMapFile;               // Bit map of free disk blocks,
00090                                         // represented as a file
00091    OpenFile* directoryFile;             // "Root" directory -- list of 
00092                                         // file names, represented as a file
00093 };
00094 
00095 #endif // FILESYS
00096 
00097 #endif // FS_H

Generated on Mon Feb 10 09:54:45 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