Main Page   Compound List   File List   Compound Members   File Members  

disk.h

Go to the documentation of this file.
00001 // disk.h 
00002 //      Data structures to emulate a physical disk.  A physical disk
00003 //      can accept (one at a time) requests to read/write a disk sector;
00004 //      when the request is satisfied, the CPU gets an interrupt, and 
00005 //      the next request can be sent to the disk.
00006 //
00007 //      Disk contents are preserved across machine crashes, but if
00008 //      a file system operation (eg, create a file) is in progress when the 
00009 //      system shuts down, the file system may be corrupted.
00010 //
00011 //  DO NOT CHANGE -- part of the machine emulation
00012 //
00013 // Copyright (c) 1992-1993 The Regents of the University of California.
00014 // All rights reserved.  See copyright.h for copyright notice and limitation 
00015 // of liability and disclaimer of warranty provisions.
00016 
00017 #ifndef DISK_H
00018 #define DISK_H
00019 
00020 #include "copyright.h"
00021 #include "utility.h"
00022 
00023 // The following class defines a physical disk I/O device.  The disk
00024 // has a single surface, split up into "tracks", and each track split
00025 // up into "sectors" (the same number of sectors on each track, and each
00026 // sector has the same number of bytes of storage).  
00027 //
00028 // Addressing is by sector number -- each sector on the disk is given
00029 // a unique number: track * SectorsPerTrack + offset within a track.
00030 //
00031 // As with other I/O devices, the raw physical disk is an asynchronous device --
00032 // requests to read or write portions of the disk return immediately,
00033 // and an interrupt is invoked later to signal that the operation completed.
00034 //
00035 // The physical disk is in fact simulated via operations on a UNIX file.
00036 //
00037 // To make life a little more realistic, the simulated time for
00038 // each operation reflects a "track buffer" -- RAM to store the contents
00039 // of the current track as the disk head passes by.  The idea is that the
00040 // disk always transfers to the track buffer, in case that data is requested
00041 // later on.  This has the benefit of eliminating the need for 
00042 // "skip-sector" scheduling -- a read request which comes in shortly after 
00043 // the head has passed the beginning of the sector can be satisfied more 
00044 // quickly, because its contents are in the track buffer.  Most 
00045 // disks these days now come with a track buffer.
00046 //
00047 // The track buffer simulation can be disabled by compiling with -DNOTRACKBUF
00048 
00049 #define SectorSize              128     // number of bytes per disk sector
00050 #define SectorsPerTrack         32      // number of sectors per disk track 
00051 #define NumTracks               32      // number of tracks per disk
00052 #define NumSectors              (SectorsPerTrack * NumTracks)
00053                                         // total # of sectors per disk
00054 
00055 class Disk {
00056   public:
00057     Disk(char* name, VoidFunctionPtr callWhenDone, int callArg);
00058                                         // Create a simulated disk.  
00059                                         // Invoke (*callWhenDone)(callArg) 
00060                                         // every time a request completes.
00061     ~Disk();                            // Deallocate the disk.
00062     
00063     void ReadRequest(int sectorNumber, char* data);
00064                                         // Read/write an single disk sector.
00065                                         // These routines send a request to 
00066                                         // the disk and return immediately.
00067                                         // Only one request allowed at a time!
00068     void WriteRequest(int sectorNumber, char* data);
00069 
00070     void HandleInterrupt();             // Interrupt handler, invoked when
00071                                         // disk request finishes.
00072 
00073     int ComputeLatency(int newSector, bool writing);    
00074                                         // Return how long a request to 
00075                                         // newSector will take: 
00076                                         // (seek + rotational delay + transfer)
00077 
00078   private:
00079     int fileno;                         // UNIX file number for simulated disk 
00080     VoidFunctionPtr handler;            // Interrupt handler, to be invoked 
00081                                         // when any disk request finishes
00082     int handlerArg;                     // Argument to interrupt handler 
00083     bool active;                        // Is a disk operation in progress?
00084     int lastSector;                     // The previous disk request 
00085     int bufferInit;                     // When the track buffer started 
00086                                         // being loaded
00087 
00088     int TimeToSeek(int newSector, int *rotate); // time to get to the new track
00089     int ModuloDiff(int to, int from);        // # sectors between to and from
00090     void UpdateLast(int newSector);
00091 };
00092 
00093 #endif // DISK_H

Generated on Mon Feb 10 09:54:45 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees