tac0S
Template Affectional Command Operating System
disk.h
Go to the documentation of this file.
1 
19 #ifndef DISK_H
20 #define DISK_H
21 
22 #include "copyright.h"
23 #include "utility.h"
24 
25 #define SectorSize 128 // number of bytes per disk sector
26 #define SectorsPerTrack 32 // number of sectors per disk track
27 #define NumTracks 32 // number of tracks per disk
28 #define NumSectors (SectorsPerTrack * NumTracks)
29  // total # of sectors per disk
30 
56 
57 class Disk {
58  public:
59  Disk(const char* name, VoidFunctionPtr callWhenDone, int callArg);
60  // Create a simulated disk.
61  // Invoke (*callWhenDone)(callArg)
62  // every time a request completes.
63  ~Disk(); // Deallocate the disk.
64 
65  void ReadRequest(int sectorNumber, char* data);
66  // Read/write an single disk sector.
67  // These routines send a request to
68  // the disk and return immediately.
69  // Only one request allowed at a time!
70  void WriteRequest(int sectorNumber, char* data);
71 
72  void HandleInterrupt(); // Interrupt handler, invoked when
73  // disk request finishes.
74 
75  int ComputeLatency(int newSector, bool writing);
76  // Return how long a request to
77  // newSector will take:
78  // (seek + rotational delay + transfer)
79 
80  private:
81  int fileno; // UNIX file number for simulated disk
82  VoidFunctionPtr handler; // Interrupt handler, to be invoked
83  // when any disk request finishes
84  int handlerArg; // Argument to interrupt handler
85  bool active; // Is a disk operation in progress?
86  int lastSector; // The previous disk request
87  int bufferInit; // When the track buffer started
88  // being loaded
89 
90  int TimeToSeek(int newSector, int *rotate); // time to get to the new track
91  int ModuloDiff(int to, int from); // # sectors between to and from
92  void UpdateLast(int newSector);
93 };
94 
95 #endif // DISK_H
int ComputeLatency(int newSector, bool writing)
Disk::ComputeLatency() Return how long will it take to read/write a disk sector, from the current pos...
Definition: disk.cc:236
The following 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).
Definition: disk.h:57
~Disk()
Disk::~Disk() Clean up disk simulation, by closing the UNIX file representing the disk...
Definition: disk.cc:79
Miscellaneous useful definitions, including debugging routines.
void HandleInterrupt()
Disk::HandleInterrupt() Called when it is time to invoke the disk interrupt handler, to tell the Nachos kernel that the disk request is done.
Definition: disk.cc:165
Disk(const char *name, VoidFunctionPtr callWhenDone, int callArg)
Disk::Disk() Initialize a simulated disk. Open the UNIX file (creating it if it doesn't exist)...
Definition: disk.cc:46
void ReadRequest(int sectorNumber, char *data)
Disk::ReadRequest/WriteRequest Simulate a request to read/write a single disk sector Do the read/writ...
Definition: disk.cc:119
Definition: out.c:36