|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Disk
A software simulation of a Disk.
You may not change this class.
This disk is slow and ornery. It contains a number of blocks, all BLOCK_SIZE bytes long. All operations occur on individual blocks. You can't modify any more or any less data at a time.
To read or write from the disk, call beginRead() or beginWrite(). Each of these functions will start the action and return immediately. When the action has been completed, the Disk calls Kernel.interrupt() to let you know the Disk is ready for more.
It may take a while for the disk to seek from one block to another. Seek time is proportional to the difference in track numbers of the blocks.
Warning: Don't call beginRead() or beginWrite() while the disk is busy! If you don't treat the Disk gently, the system will crash! (Just like a real machine!)
This disk saves its contents in the Unix file DISK between runs. Since the file can be large, you should get in the habit of removing it before logging off.
Kernel
Field Summary | |
static int |
BLOCK_SIZE
The size of a disk block in bytes. |
protected boolean |
busy
An indication of whether an I/O operation is currently in progress. |
protected int |
currentBlock
Current location of the read/write head |
protected static int |
DELAY_PER_TRACK
Seek time per track, in ms |
int |
DISK_SIZE
Total size of this disk, in blocks. |
protected int |
targetBlock
The block number to be read/written by the current operation. |
static int |
TRACK_SIZE
The size of a track, in blocks. |
protected static int |
TRANSFER_TIME
Minimum time to transfer one block of data, in ms |
Constructor Summary | |
Disk(int size)
Creates a new Disk. |
Method Summary | |
void |
beginRead(int blockNumber,
byte[] buffer)
Starts a new read operation. |
void |
beginWrite(int blockNumber,
byte[] buffer)
Starts a new write operation. |
protected void |
delay(int targetBlock)
Sleeps for a while to simulate the delay in seeking and transferring data. |
protected void |
finishOperation()
Indicates to the CPU that the current operation has completed. |
void |
flush()
Saves the contents of this Disk. |
void |
run()
This method simulates the internal microprocessor of the disk controler. |
int |
trackOf(int blockNumber)
Computes the track number of a disk block. |
protected void |
waitForRequest()
Waits for a call to beginRead or beginWrite. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int BLOCK_SIZE
public static final int TRACK_SIZE
public final int DISK_SIZE
protected static final int DELAY_PER_TRACK
protected static final int TRANSFER_TIME
protected int currentBlock
protected boolean busy
protected int targetBlock
Constructor Detail |
public Disk(int size)
size
- the total size of this disk, in blocks.Method Detail |
public void flush()
public int trackOf(int blockNumber)
blockNumber
- a block (sector) number.protected void delay(int targetBlock)
targetBlock
- the block number to which we have to seek.public void beginRead(int blockNumber, byte[] buffer)
blockNumber
- The block number to read from.buffer
- A data area to hold the data read. This array must be
allocated by the caller and have length of at least
BLOCK_SIZE. If it is larger, only the first BLOCK_SIZE
bytes of the array will be modified.public void beginWrite(int blockNumber, byte[] buffer)
blockNumber
- The block number to write to.buffer
- A data area containing the data to be written. This array
must be allocated by the caller and have length of at least
BLOCK_SIZE. If it is larger, only the first BLOCK_SIZE
bytes of the array will be sent to the disk.protected void waitForRequest()
protected void finishOperation()
public void run()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |