|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.machine.Disk
public class Disk
This class defines a physical disk I/O device. The disk has a single surface, split up into "tracks", and each track split up into "sectors" (the same number of sectors on each track, and each sector has the same number of bytes of storage). Addressing is by sector number -- each sector on the disk is given a unique number: track * SectorsPerTrack + offset within a track. 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 is invoked later to signal that the operation completed. The physical disk is in fact simulated via operations on a UNIX file. To make life a little more realistic, the simulated time for each operation reflects a "track buffer" -- RAM to store the contents of the current track as the disk head passes by. The idea is that the disk always transfers to the track buffer, in case that data is requested later on. This has the benefit of eliminating the need for "skip-sector" scheduling -- a read request which comes in shortly after the head has passed the beginning of the sector can be satisfied more quickly, because its contents are in the track buffer. Most disks these days now come with a track buffer.
Field Summary | |
---|---|
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 | |
---|---|
Disk(java.lang.String name,
InterruptHandler callWhenDone)
Create a simulated disk. |
Method Summary | |
---|---|
static int |
bytesToInt(byte[] buffer,
int pos)
Utility method to deserialize a sequence of bytes into an integer. |
static void |
intToBytes(int val,
byte[] buffer,
int pos)
Utility method to serialize an integer into a sequence of bytes. |
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. |
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 |
---|
public static final int SectorSize
public static final int SectorsPerTrack
public static final int NumTracks
public static final int NumSectors
Constructor Detail |
---|
public Disk(java.lang.String name, InterruptHandler callWhenDone)
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 |
---|
public void readRequest(int sectorNumber, byte[] data, int index)
sectorNumber
- The disk sector to read.data
- The buffer to hold the incoming bytes.public void writeRequest(int sectorNumber, byte[] data, int index)
sectorNumber
- The disk sector to write.data
- The bytes to be written.public static void printSector(boolean writing, int sector, byte[] data)
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.public static void intToBytes(int val, byte[] buffer, int pos)
val
- The integer 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.public static int bytesToInt(byte[] buffer, int pos)
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.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |