nachos.machine
Class RK05Disk

java.lang.Object
  extended by nachos.machine.RK05Disk

public class RK05Disk
extends java.lang.Object

This version of the Disk class simulates a physical disk device with the geometry (203 cylinders, 2 heads, 12 sectors per track, 512 bytes per sector) of the old RK05 disk packs used on PDP-11 minicomputers in the mid-1970s. I wanted to make this an extension of the existing Disk class, but that would have required eliminating static members of that class, which would in turn have forced rewriting of portions of the file system. Maybe next semester!


Field Summary
static int NumCylinders
          Number of cylinders per disk.
static int NumHeads
          Number of surfaces per cylinder (i.e.
static int NumSectors
          Total number of sectors per disk.
static int NumTracks
          Number of tracks per disk.
static int SectorSize
          Number of bytes per disk sector.
static int SectorsPerTrack
          Number of sector per disk track.
 
Constructor Summary
RK05Disk(java.lang.String name, InterruptHandler callWhenDone)
          Create a simulated disk.
 
Method Summary
static short bytesToShort(byte[] buffer, int pos)
          Utility method to deserialize a sequence of two bytes into a short.
static void printSector(boolean writing, int sector, byte[] data)
          Dump the data in a disk read/write request, for debugging.
 void readRequest(int sectorNumber, byte[] data, int index)
          Called to submit a request to read a single disk sector.
static void shortToBytes(short val, byte[] buffer, int pos)
          Utility method to serialize a short into a sequence of two bytes.
 void writeRequest(int sectorNumber, byte[] data, int index)
          Called to submit a request to write a single disk sector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SectorSize

public static final int SectorSize
Number of bytes per disk sector.

See Also:
Constant Field Values

SectorsPerTrack

public static final int SectorsPerTrack
Number of sector per disk track.

See Also:
Constant Field Values

NumCylinders

public static final int NumCylinders
Number of cylinders per disk.

See Also:
Constant Field Values

NumHeads

public static final int NumHeads
Number of surfaces per cylinder (i.e. number of heads).

See Also:
Constant Field Values

NumTracks

public static final int NumTracks
Number of tracks per disk.

See Also:
Constant Field Values

NumSectors

public static final int NumSectors
Total number of sectors per disk.

See Also:
Constant Field Values
Constructor Detail

RK05Disk

public RK05Disk(java.lang.String name,
                InterruptHandler callWhenDone)
Create a simulated disk. Open the UNIX file (creating it if it doesn't exist), and check the magic number to make sure it's ok to treat it as Nachos disk storage.

Parameters:
name - Text name of the file simulating the Nachos disk.
callWhenDone - Interrupt handler to be notified each time disk read/write request completes.
Method Detail

readRequest

public void readRequest(int sectorNumber,
                        byte[] data,
                        int index)
Called to submit a request to read a single disk sector. The request is sent to the disk and the method returns immediately. The disk interrupt handler will be called back later, to notify the caller that the requested operation has completed. Note that a disk only allows an entire sector to be read, not part of a sector.

Parameters:
sectorNumber - The disk sector to read.
data - The buffer to hold the incoming bytes.

writeRequest

public void writeRequest(int sectorNumber,
                         byte[] data,
                         int index)
Called to submit a request to write a single disk sector. The request is sent to the disk and the method returns immediately. The disk interrupt handler will be called back later, to notify the caller that the requested operation has completed. Note that a disk only allows an entire sector to be written, not part of a sector.

Parameters:
sectorNumber - The disk sector to write.
data - The bytes to be written.

printSector

public static void printSector(boolean writing,
                               int sector,
                               byte[] data)
Dump the data in a disk read/write request, for debugging.

Parameters:
writing - True if the request is a write request.
sector - The sector number in the request.
data - The buffer for data read/written in the request.

shortToBytes

public static void shortToBytes(short val,
                                byte[] buffer,
                                int pos)
Utility method to serialize a short into a sequence of two bytes.

Parameters:
val - The short value to be serialized.
buffer - The buffer into which the value is to be serialized.
pos - Starting offset from the beginning of the buffer at which the serialized bytes representing the value are to be placed.

bytesToShort

public static short bytesToShort(byte[] buffer,
                                 int pos)
Utility method to deserialize a sequence of two bytes into a short.

Parameters:
buffer - The buffer from which the value is to be deserialized.
pos - Starting offset from the beginning of the buffer at which the serialized bytes representing the value exist.
Returns:
The integer value represented by the bytes in the buffer.