|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.kernel.filesys.Directory
class Directory
This class class defines a UNIX-like "directory". Each entry in the directory describes a file, and where to find it on disk. The directory is a table of fixed length entries; each entry represents a single file, and contains the file name, and the location of the file header on disk. The fixed size of each directory entry means that we have the restriction of a fixed maximum size for file names. Also, this implementation has the restriction that the size of the directory cannot expand. In other words, once all the entries in the directory are used, no more files can be created. Fixing this is one of the parts to the assignment. The directory data structure can be stored in memory, or on disk. When it is on disk, it is stored as a regular Nachos file. The constructor initializes a directory structure in memory; the fetchFrom/writeBack operations shuffle the directory information from/to disk. We assume mutual exclusion is provided by the caller.
Field Summary | |
---|---|
private DirectoryEntry[] |
table
Table of pairs: file name/file header location. |
private int |
tableSize
Number of entries in the directory. |
Constructor Summary | |
---|---|
Directory(int size)
Initialize a directory; initially, the directory is completely empty. |
Method Summary | |
---|---|
(package private) boolean |
add(java.lang.String name,
int newSector)
Add a file into the directory. |
(package private) void |
fetchFrom(OpenFile file)
Read the contents of the directory from disk. |
(package private) int |
find(java.lang.String name)
Look up file name in directory, and return the disk sector number where the file's header is stored. |
private int |
findIndex(java.lang.String name)
Look up file name in directory, and return its location in the table of directory entries. |
(package private) void |
list()
List all the file names in the directory (for debugging). |
(package private) void |
print()
List all the file names in the directory, their FileHeader locations, and the contents of each file (for debugging). |
(package private) boolean |
remove(java.lang.String name)
Remove a file name from the directory. |
(package private) void |
writeBack(OpenFile file)
Write any modifications to the directory back to disk |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private int tableSize
private DirectoryEntry[] table
Constructor Detail |
---|
Directory(int size)
size
- The number of entries in the directory.Method Detail |
---|
void fetchFrom(OpenFile file)
file
- The file containing the directory contents.void writeBack(OpenFile file)
file
- The file to contain the new directory contents.private int findIndex(java.lang.String name)
name
- The file name to look up.
int find(java.lang.String name)
name
- The file name to look up.
boolean add(java.lang.String name, int newSector)
name
- The name of the file being added.newSector
- The disk sector containing the added file's header.
boolean remove(java.lang.String name)
name
- The file name to be removed.void list()
void print()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |