|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.kernel.filesys.FileSystem
nachos.kernel.filesys.FileSystemReal
class FileSystemReal
This class manages the overall operation of the file system. It implements methods to map from textual file names to files. Each file in the file system has: A file header, stored in a sector on disk (the size of the file header data structure is arranged to be precisely the size of 1 disk sector); A number of data blocks; An entry in the file system directory. The file system consists of several data structures: A bitmap of free disk sectors (cf. bitmap.h); A directory of file names and file headers. Both the bitmap and the directory are represented as normal files. Their file headers are located in specific sectors (sector 0 and sector 1), so that the file system can find them on bootup. The file system assumes that the bitmap and directory files are kept "open" continuously while Nachos is running. For those operations (such as create, remove) that modify the directory and/or bitmap, if the operation succeeds, the changes are written immediately back to disk (the two files are kept open during all this time). If the operation fails, and we have modified part of the directory and/or bitmap, we simply discard the changed version, without writing it back to disk. Our implementation at this point has the following restrictions: there is no synchronization for concurrent accesses; files have a fixed size, set when the file is created; files cannot be bigger than about 3KB in size; there is no hierarchical directory structure, and only a limited number of files can be added to the system; there is no attempt to make the system robust to failures (if Nachos exits in the middle of an operation that modifies the file system, it may corrupt the disk). A file system is a set of files stored on disk, organized into directories. Operations on the file system have to do with "naming" -- creating, opening, and deleting files, given a textual file name. Operations on an individual "open" file (read, write, close) are to be found in the OpenFile class (OpenFile.java). We define two separate implementations of the file system. This version is a "real" file system, built on top of a disk simulator. The disk is simulated using the native file system on the host platform (in a file named "DISK"). In the "real" implementation, there are two key data structures used in the file system. There is a single "root" directory, listing all of the files in the file system; unlike UNIX, the baseline system does not provide a hierarchical directory structure. In addition, there is a bitmap for allocating disk sectors. Both the root directory and the bitmap are themselves stored as files in the Nachos file system -- this causes an interesting bootstrap problem when the simulated disk is initialized.
Field Summary | |
---|---|
private OpenFile |
directoryFile
"Root" directory -- list of file names, represented as a file. |
private static int |
DirectoryFileSize
The initial size of a directory file. |
private static int |
DirectorySector
The disk sector containing the directory of files. |
private OpenFile |
freeMapFile
Bit map of free disk blocks, represented as a file. |
private static int |
FreeMapFileSize
The initial file size for the bitmap file. |
private static int |
FreeMapSector
The disk sector containing the bitmap of free sectors. |
private static int |
NumDirEntries
The maximum number of entries in a directory. |
Constructor Summary | |
---|---|
protected |
FileSystemReal(boolean format)
Initialize the file system. |
Method Summary | |
---|---|
boolean |
create(java.lang.String name,
long initialSize)
Create a file in the Nachos file system (similar to UNIX create). |
void |
list()
List all the files in the file system directory (for debugging). |
OpenFile |
open(java.lang.String name)
Open a file for reading and writing. |
void |
print()
Print everything about the file system (for debugging): the contents of the bitmap; the contents of the directory; for each file in the directory: the contents of the file header; the data in the file. |
boolean |
remove(java.lang.String name)
Delete a file from the file system. |
Methods inherited from class nachos.kernel.filesys.FileSystem |
---|
init |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int FreeMapSector
private static final int DirectorySector
private static final int FreeMapFileSize
private static final int NumDirEntries
private static final int DirectoryFileSize
private OpenFile freeMapFile
private OpenFile directoryFile
Constructor Detail |
---|
protected FileSystemReal(boolean format)
format
- Should we initialize the disk?Method Detail |
---|
public boolean create(java.lang.String name, long initialSize)
create
in class FileSystem
name
- The name of file to be created.initialSize
- The size of file to be created.
public OpenFile open(java.lang.String name)
open
in class FileSystem
name
- The text name of the file to be opened.
public boolean remove(java.lang.String name)
remove
in class FileSystem
name
- The text name of the file to be removed.
public void list()
list
in class FileSystem
public void print()
print
in class FileSystem
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |