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. 00015 // 00016 // The other version is a "real" file system, built on top of 00017 // a disk simulator. The disk is simulated using the native UNIX 00018 // file system (in a file named "DISK"). 00019 // 00020 // In the "real" implementation, there are two key data structures used 00021 // in the file system. There is a single "root" directory, listing 00022 // all of the files in the file system; unlike UNIX, the baseline 00023 // system does not provide a hierarchical directory structure. 00024 // In addition, there is a bitmap for allocating 00025 // disk sectors. Both the root directory and the bitmap are themselves 00026 // stored as files in the Nachos file system -- this causes an interesting 00027 // bootstrap problem when the simulated disk is initialized. 00028 // 00029 // Copyright (c) 1992-1993 The Regents of the University of California. 00030 // All rights reserved. See copyright.h for copyright notice and limitation 00031 // of liability and disclaimer of warranty provisions. 00032 00033 #ifndef FS_H 00034 #define FS_H 00035 00036 #include "copyright.h" 00037 #include "sysdep.h" 00038 #include "openfile.h" 00039 00040 #ifdef FILESYS_STUB // Temporarily implement file system calls as 00041 // calls to UNIX, until the real file system 00042 // implementation is available 00043 class FileSystem { 00044 public: 00045 FileSystem() {} 00046 00047 bool Create(char *name) { 00048 int fileDescriptor = OpenForWrite(name); 00049 00050 if (fileDescriptor == -1) return FALSE; 00051 Close(fileDescriptor); 00052 return TRUE; 00053 } 00054 00055 OpenFile* Open(char *name) { 00056 int fileDescriptor = OpenForReadWrite(name, FALSE); 00057 00058 if (fileDescriptor == -1) return NULL; 00059 return new OpenFile(fileDescriptor); 00060 } 00061 00062 bool Remove(char *name) { return Unlink(name) == 0; } 00063 00064 }; 00065 00066 #else // FILESYS 00067 class FileSystem { 00068 public: 00069 FileSystem(bool format); // Initialize the file system. 00070 // Must be called *after* "synchDisk" 00071 // has been initialized. 00072 // If "format", there is nothing on 00073 // the disk, so initialize the directory 00074 // and the bitmap of free blocks. 00075 00076 bool Create(char *name, int initialSize); 00077 // Create a file (UNIX creat) 00078 00079 OpenFile* Open(char *name); // Open a file (UNIX open) 00080 00081 bool Remove(char *name); // Delete a file (UNIX unlink) 00082 00083 void List(); // List all the files in the file system 00084 00085 void Print(); // List all the files and their contents 00086 00087 private: 00088 OpenFile* freeMapFile; // Bit map of free disk blocks, 00089 // represented as a file 00090 OpenFile* directoryFile; // "Root" directory -- list of 00091 // file names, represented as a file 00092 }; 00093 00094 #endif // FILESYS 00095 00096 #endif // FS_H