nachos.kernel.devices
Class DiskDriver

java.lang.Object
  extended by nachos.kernel.devices.DiskDriver

public class DiskDriver
extends java.lang.Object

This class defines a "synchronous" disk abstraction. As with other I/O devices, the raw physical disk is an asynchronous device -- requests to read or write portions of the disk return immediately, and an interrupt occurs later to signal that the operation completed. (Also, the physical characteristics of the disk device assume that only one operation can be requested at a time). This class provides the abstraction that for any individual thread making a request, it waits around until the operation finishes before returning.


Nested Class Summary
private  class DiskDriver.DiskIntHandler
          DiskDriver interrupt handler class.
 
Field Summary
private  nachos.machine.Disk disk
          Raw disk device.
private  Lock lock
          Only one read/write request can be sent to the disk at a time.
private  Semaphore semaphore
          To synchronize requesting thread with the interrupt handler.
 
Constructor Summary
DiskDriver(java.lang.String name)
          Initialize the synchronous interface to the physical disk, in turn initializing the physical disk.
 
Method Summary
 void readSector(int sectorNumber, byte[] data, int index)
          Read the contents of a disk sector into a buffer.
 void writeSector(int sectorNumber, byte[] data, int index)
          Write the contents of a buffer into a disk sector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

disk

private nachos.machine.Disk disk
Raw disk device.


semaphore

private Semaphore semaphore
To synchronize requesting thread with the interrupt handler.


lock

private Lock lock
Only one read/write request can be sent to the disk at a time.

Constructor Detail

DiskDriver

public DiskDriver(java.lang.String name)
Initialize the synchronous interface to the physical disk, in turn initializing the physical disk.

Parameters:
name - UNIX file name to be used as storage for the disk data (usually, "DISK")
Method Detail

readSector

public void readSector(int sectorNumber,
                       byte[] data,
                       int index)
Read the contents of a disk sector into a buffer. Return only after the data has been read.

Parameters:
sectorNumber - The disk sector to read.
data - The buffer to hold the contents of the disk sector.
index - Offset in the buffer at which to place the data.

writeSector

public void writeSector(int sectorNumber,
                        byte[] data,
                        int index)
Write the contents of a buffer into a disk sector. Return only after the data has been written.

Parameters:
sectorNumber - The disk sector to be written.
data - The new contents of the disk sector.
index - Offset in the buffer from which to get the data.