nachos.kernel.filesys
Class DirectoryEntry

java.lang.Object
  extended by nachos.kernel.filesys.DirectoryEntry

 class DirectoryEntry
extends java.lang.Object

This class defines a "directory entry", representing a file in the directory. Each entry gives the name of the file, and where the file's header is to be found on disk. Internal data structures kept non-private so that Directory operations can access them directly.


Field Summary
(package private) static int FileNameMaxLen
          Maximum length of a file name.
private  boolean inUse
          Is this directory entry in use?
private  java.lang.String name
          Text name for file (must be representable by a sequence of bytes no longer than FileNameMaxLen).
private  byte[] nameBytes
          On-disk representation of the file name.
private  int nameLen
          Length of filename.
private  int sector
          Location on disk to find the FileHeader for this file.
 
Constructor Summary
DirectoryEntry()
           
 
Method Summary
(package private)  void externalize(byte[] buffer, int pos)
          Export the fields of this DirectoryEntry object to a buffer in a format suitable for writing to the disk.
(package private)  java.lang.String getName()
          Get the file name stored in this DirectoryEntry.
(package private)  int getSector()
          Get the sector number stored in this DirectoryEntry.
(package private)  void internalize(byte[] buffer, int pos)
          Initialize the fields of this DirectoryEntry object using data read from the disk.
(package private)  boolean inUse()
          Determine if this DirectoryEntry is in use.
(package private)  void setUnused()
          Mark this directory entry as "unused".
(package private)  boolean setUsed(java.lang.String name, int sector)
          Mark this directory entry as "in use" and set the file name and disk sector number.
static int sizeOf()
          Calculate size of on-disk representation of a DirectoryEntry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FileNameMaxLen

static final int FileNameMaxLen
Maximum length of a file name. For simplicity, we assume file names are <= 9 characters long.

See Also:
Constant Field Values

inUse

private boolean inUse
Is this directory entry in use?


sector

private int sector
Location on disk to find the FileHeader for this file.


nameLen

private int nameLen
Length of filename.


name

private java.lang.String name
Text name for file (must be representable by a sequence of bytes no longer than FileNameMaxLen).


nameBytes

private byte[] nameBytes
On-disk representation of the file name.

Constructor Detail

DirectoryEntry

DirectoryEntry()
Method Detail

inUse

boolean inUse()
Determine if this DirectoryEntry is in use.

Returns:
true if the entry is in use, false if not.

getName

java.lang.String getName()
Get the file name stored in this DirectoryEntry.

Returns:
the file name stored in this DirectoryEntry, or null if the entry is not in use.

getSector

int getSector()
Get the sector number stored in this DirectoryEntry.

Returns:
the sector number stored in this DirectoryEntry.

setUsed

boolean setUsed(java.lang.String name,
                int sector)
Mark this directory entry as "in use" and set the file name and disk sector number.

Parameters:
name - The name of the file.
sector - The disk sector number of the file header.
Returns:
true if the operation was successful, false if the entry was already in use or the file name could not be represented within the maximum number of bytes.

setUnused

void setUnused()
Mark this directory entry as "unused".


sizeOf

public static int sizeOf()
Calculate size of on-disk representation of a DirectoryEntry.

Returns:
the number of bytes required to store a DirectoryEntry on the disk.

internalize

void internalize(byte[] buffer,
                 int pos)
Initialize the fields of this DirectoryEntry object using data read from the disk.

Parameters:
buffer - A buffer holding the data read from the disk.
pos - Position in the buffer at which to start.

externalize

void externalize(byte[] buffer,
                 int pos)
Export the fields of this DirectoryEntry object to a buffer in a format suitable for writing to the disk.

Parameters:
buffer - A buffer into which to place the exported data.
pos - Position in the buffer at which to start.