140 likes | 754 Views
Project: Disk Driver ICS 145B L. Bic file system disk driver disk controller disk 1 2 emulation software Assignment implement a driver for a simulated disk fs requests reading/writing of logical disk blocks (0:L-1)
E N D
Project: Disk Driver ICS 145B L. Bic
file system disk driver disk controller disk 1 2 emulation software Assignment • implement a driver for a simulated disk • fs requests reading/writing of logical disk blocks (0:L-1) • disk driver interacts with HW controller via register interface to read/write blocks
Organization of the Disk (pg 369) • each surface consist of tracks • each track consist of sectors (blocks) • each sector consist of bytes • tracks with same diameter is a cylinder • thus a cylinder also consist of tracks • sector is the smallest unit of transfer
FS/Driver Interface (1) • read_block(int i, char *p) • write_block(int i, char *p) copy block i to/from main memory (ptr) • init_disk(…) • save_disk(…) file system disk driver disk controller disk 1 2 emulation software
Disk Driver • principles of operation (see Section 11.4.3, page 379) driver SW
Disk Driver • valid opcodes • SEEK • READ • WRITE • REPORT • writing opcode (OP reg) starts operation • controller becomes busy (BUSY reg) • driver must await completion • await_intrpt() for SEEK/READ/WRITE • busy-wait for REPORT (test BUSY reg)
Disk Driver • SEEK/READ/WRITE operation may fail • permanent failure (e.g., invalid parameter) • transient failure (generated at random) • driver must check status after every operation • write REPORT opcode • busy-wait until report operation completes • test STAT register • repeat operation if error is transient; report is permanent
Controller Registers (2) • writable registers • OP: SEEK, READ, WRITE, REPORT • CYL: 0..CYL_NO-1 (used by SEEK) • SURF: 0..NO_SURF-1 (used by READ/WRITE) • SECT: 0..NO_SECT-1 (used by READ/WRITE) • MEM: pointer (used by READ/WRITE) • read-only registers • BUSY: TRUE/FALSE • STAT: OK, ILL_OP, ILL_CYL, ILL_SURF, ILL_SECT, ERROR (transient error) file system disk driver disk controller disk 1 2 emulation software
Controller Interface Functions • int read_reg(int reg_no) • read value of BUSY or STAT • int write_int_reg(int reg_no, int v) • write v into OP, CYL, SURF, SECT register • writing OP also starts operation (if not busy) • int write_mem_reg(char* v) • write starting location in memory (v) into MEM • int await_intrpt() • block process until completion interrupt
Controller Interface Functions • int init_disk(int no_cyl, int no_surf, int no_sect, int sect_len, char disk_cont[]) • create/initialized disk • disk_cont[] is the initialization file; if nonexistent, disk is filled with blanks • int save_disk(char disk_cont[]) • save the current disk contents in the file disk_cont[]
Driver Protocol • translate logical block number into a disk address (cylinder #, surface #, sector #) • if read/write head is already at desired cylinder, skip to step 3; else perform seek: • write cylinder # into the CYL register • write opcode SEEK into OP register • wait for interrupt (by calling await_intrpt() ) • write opcode REPORT into OP register • busy-wait until BUSY register becomes FALSE • read STAT register • if operation ok, go to step 3; else retry SEEK
Driver Protocol -- cont 3. Perform READ or WRITE operation: • write parameters into controller registers (SURF, SECT, MEM) • write opcode READ or WRITE into OP register • wait for interrupt (by calling await_intrpt() ) • write opcode REPORT into OP register • busy-wait until BUSY register becomes FALSE • read STAT register • if operation ok, go to step 1; else retry READ/WRITE
Using Simulation Software • the following files are on the web page • controller.c • internal.h • interface.h • DO NOT MODIFY THESE IN ANY WAY • compile these into controller.o • compile/link your program with controller.o • your program must include interface.h, i.e.: • #include ”interface.h” • your program uses the disk by invoking the controller interface functions (see protocol)
Summary of tasks • design/implement driver • test driver (handling transient errors) • develop presentation/test shell (optional) • turn in design documentation • hard copy of high-level documentation to Distribution Center • commented code to Masterhit • code will be tested as part of FS project