root/memide.c

/* [previous][next][first][last][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 "sleeplock.h"
  13 #include "fs.h"
  14 #include "buf.h"
  15 
  16 extern uchar _binary_fs_img_start[], _binary_fs_img_size[];
  17 
  18 static int disksize;
  19 static uchar *memdisk;
  20 
  21 void
  22 ideinit(void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  23 {
  24   memdisk = _binary_fs_img_start;
  25   disksize = (uint)_binary_fs_img_size/BSIZE;
  26 }
  27 
  28 // Interrupt handler.
  29 void
  30 ideintr(void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  31 {
  32   // no-op
  33 }
  34 
  35 // Sync buf with disk.
  36 // If B_DIRTY is set, write buf to disk, clear B_DIRTY, set B_VALID.
  37 // Else if B_VALID is not set, read buf from disk, set B_VALID.
  38 void
  39 iderw(struct buf *b)
     /* [previous][next][first][last][top][bottom][index][help]  */
  40 {
  41   uchar *p;
  42 
  43   if(!holdingsleep(&b->lock))
  44     panic("iderw: buf not locked");
  45   if((b->flags & (B_VALID|B_DIRTY)) == B_VALID)
  46     panic("iderw: nothing to do");
  47   if(b->dev != 1)
  48     panic("iderw: request not for disk 1");
  49   if(b->blockno >= disksize)
  50     panic("iderw: block out of range");
  51 
  52   p = memdisk + b->blockno*BSIZE;
  53 
  54   if(b->flags & B_DIRTY){
  55     b->flags &= ~B_DIRTY;
  56     memmove(p, b->data, BSIZE);
  57   } else
  58     memmove(b->data, p, BSIZE);
  59   b->flags |= B_VALID;
  60 }

/* [previous][next][first][last][top][bottom][index][help]  */