root/memide.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ideinit
  2. ideintr
  3. iderw

   1 // Fake IDE disk; stores blocks in memory.
   2 // Useful for running kernel without scratch disk.
   3 
   4 #include "types.h"
   5 #include "defs.h"
   6 #include "param.h"
   7 #include "mmu.h"
   8 #include "proc.h"
   9 #include "x86.h"
  10 #include "traps.h"
  11 #include "spinlock.h"
  12 #include "fs.h"
  13 #include "buf.h"
  14 
  15 extern uchar _binary_fs_img_start[], _binary_fs_img_size[];
  16 
  17 static int disksize;
  18 static uchar *memdisk;
  19 
  20 void
  21 ideinit(void)
  22 {
  23   memdisk = _binary_fs_img_start;
  24   disksize = (uint)_binary_fs_img_size/BSIZE;
  25 }
  26 
  27 // Interrupt handler.
  28 void
  29 ideintr(void)
  30 {
  31   // no-op
  32 }
  33 
  34 // Sync buf with disk. 
  35 // If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID.
  36 // Else if B_VALID is not set, read buf from disk, set B_VALID.
  37 void
  38 iderw(struct buf *b)
  39 {
  40   uchar *p;
  41 
  42   if(!(b->flags & B_BUSY))
  43     panic("iderw: buf not busy");
  44   if((b->flags & (B_VALID|B_DIRTY)) == B_VALID)
  45     panic("iderw: nothing to do");
  46   if(b->dev != 1)
  47     panic("iderw: request not for disk 1");
  48   if(b->blockno >= disksize)
  49     panic("iderw: block out of range");
  50 
  51   p = memdisk + b->blockno*BSIZE;
  52   
  53   if(b->flags & B_DIRTY){
  54     b->flags &= ~B_DIRTY;
  55     memmove(p, b->data, BSIZE);
  56   } else
  57     memmove(b->data, p, BSIZE);
  58   b->flags |= B_VALID;
  59 }

/* [<][>][^][v][top][bottom][index][help] */