Main Page | Alphabetical List | Class List | File List | Class Members | File Members

Disk Class Reference

#include <disk.h>

List of all members.

Public Member Functions

 Disk (char *name, VoidFunctionPtr callWhenDone, int callArg)
 ~Disk ()
void ReadRequest (int sectorNumber, char *data)
void WriteRequest (int sectorNumber, char *data)
void HandleInterrupt ()
int ComputeLatency (int newSector, bool writing)


Constructor & Destructor Documentation

Disk::Disk char *  name,
VoidFunctionPtr  callWhenDone,
int  callArg
 

Definition at line 43 of file disk.cc.

References ASSERT, DEBUG(), DiskSize, FALSE, Lseek(), MagicNumber, MagicSize, OpenForReadWrite(), OpenForWrite(), Read(), VoidFunctionPtr, and WriteFile().

00044 { 00045 int magicNum; 00046 int tmp = 0; 00047 00048 DEBUG('d', "Initializing the disk, 0x%x 0x%x\n", callWhenDone, callArg); 00049 handler = callWhenDone; 00050 handlerArg = callArg; 00051 lastSector = 0; 00052 bufferInit = 0; 00053 00054 fileno = OpenForReadWrite(name, FALSE); 00055 if (fileno >= 0) { // file exists, check magic number 00056 Read(fileno, (char *) &magicNum, MagicSize); 00057 ASSERT(magicNum == MagicNumber); 00058 } else { // file doesn't exist, create it 00059 fileno = OpenForWrite(name); 00060 magicNum = MagicNumber; 00061 WriteFile(fileno, (char *) &magicNum, MagicSize); // write magic number 00062 00063 // need to write at end of file, so that reads will not return EOF 00064 Lseek(fileno, DiskSize - sizeof(int), 0); 00065 WriteFile(fileno, (char *)&tmp, sizeof(int)); 00066 } 00067 active = FALSE; 00068 }

Disk::~Disk  ) 
 

Definition at line 76 of file disk.cc.

References Close().

00077 { 00078 Close(fileno); 00079 }


Member Function Documentation

int Disk::ComputeLatency int  newSector,
bool  writing
 

Definition at line 233 of file disk.cc.

References DEBUG(), FALSE, RotationTime, stats, and Statistics::totalTicks.

Referenced by ReadRequest(), and WriteRequest().

00234 { 00235 int rotation; 00236 int seek = TimeToSeek(newSector, &rotation); 00237 int timeAfter = stats->totalTicks + seek + rotation; 00238 00239 #ifndef NOTRACKBUF // turn this on if you don't want the track buffer stuff 00240 // check if track buffer applies 00241 if ((writing == FALSE) && (seek == 0) 00242 && (((timeAfter - bufferInit) / RotationTime) 00243 > ModuloDiff(newSector, bufferInit / RotationTime))) { 00244 DEBUG('d', "Request latency = %d\n", RotationTime); 00245 return RotationTime; // time to transfer sector from the track buffer 00246 } 00247 #endif 00248 00249 rotation += ModuloDiff(newSector, timeAfter / RotationTime) * RotationTime; 00250 00251 DEBUG('d', "Request latency = %d\n", seek + rotation + RotationTime); 00252 return(seek + rotation + RotationTime); 00253 }

void Disk::HandleInterrupt  ) 
 

Definition at line 162 of file disk.cc.

References FALSE.

00163 { 00164 active = FALSE; 00165 (*handler)(handlerArg); 00166 }

void Disk::ReadRequest int  sectorNumber,
char *  data
 

Definition at line 116 of file disk.cc.

References ASSERT, ComputeLatency(), DEBUG(), DebugIsEnabled(), DiskInt, FALSE, interrupt, Lseek(), MagicSize, Statistics::numDiskReads, NumSectors, Read(), Interrupt::Schedule(), SectorSize, stats, and TRUE.

00117 { 00118 int ticks = ComputeLatency(sectorNumber, FALSE); 00119 00120 ASSERT(!active); // only one request at a time 00121 ASSERT((sectorNumber >= 0) && (sectorNumber < NumSectors)); 00122 00123 DEBUG('d', "Reading from sector %d\n", sectorNumber); 00124 Lseek(fileno, SectorSize * sectorNumber + MagicSize, 0); 00125 Read(fileno, data, SectorSize); 00126 if (DebugIsEnabled('d')) 00127 PrintSector(FALSE, sectorNumber, data); 00128 00129 active = TRUE; 00130 UpdateLast(sectorNumber); 00131 stats->numDiskReads++; 00132 interrupt->Schedule(DiskDone, (int) this, ticks, DiskInt); 00133 }

void Disk::WriteRequest int  sectorNumber,
char *  data
 

Definition at line 136 of file disk.cc.

References ASSERT, ComputeLatency(), DEBUG(), DebugIsEnabled(), DiskInt, interrupt, Lseek(), MagicSize, Statistics::numDiskWrites, NumSectors, Interrupt::Schedule(), SectorSize, stats, TRUE, and WriteFile().

00137 { 00138 int ticks = ComputeLatency(sectorNumber, TRUE); 00139 00140 ASSERT(!active); 00141 ASSERT((sectorNumber >= 0) && (sectorNumber < NumSectors)); 00142 00143 DEBUG('d', "Writing to sector %d\n", sectorNumber); 00144 Lseek(fileno, SectorSize * sectorNumber + MagicSize, 0); 00145 WriteFile(fileno, data, SectorSize); 00146 if (DebugIsEnabled('d')) 00147 PrintSector(TRUE, sectorNumber, data); 00148 00149 active = TRUE; 00150 UpdateLast(sectorNumber); 00151 stats->numDiskWrites++; 00152 interrupt->Schedule(DiskDone, (int) this, ticks, DiskInt); 00153 }


The documentation for this class was generated from the following files:
Generated on Thu Sep 16 12:33:48 2004 for NachOS by doxygen 1.3.8