root/kernel/blk_drv/blk.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. unlock_buffer
  2. end_request

   1 #ifndef _BLK_H
   2 #define _BLK_H
   3 
   4 #define NR_BLK_DEV      7
   5 #define NR_REQUEST      64
   6 
   7 /*
   8  * Ok, this is an expanded form so that we can use the same
   9  * request for paging requests when that is implemented. In
  10  * paging, 'bh' is NULL, and 'waiting' is used to wait for
  11  * read/write completion.
  12  */
  13 struct request {
  14         int dev;                /* -1 if no request */
  15         int cmd;                /* READ or WRITE */
  16         int errors;
  17         unsigned long sector;
  18         unsigned long nr_sectors;
  19         char * buffer;
  20         struct task_struct * waiting;
  21         struct buffer_head * bh;
  22         struct request * next;
  23 };
  24 
  25 #define IN_ORDER(s1,s2) \
  26 ((s1)->dev < (s2)->dev || ((s1)->dev == (s2)->dev && \
  27 (s1)->sector < (s2)->sector))
  28 
  29 struct blk_dev_struct {
  30         void (*request_fn)(void);
  31         struct request * current_request;
  32 };
  33 
  34 extern struct blk_dev_struct blk_dev[NR_BLK_DEV];
  35 extern struct request request[NR_REQUEST];
  36 extern struct task_struct * wait_for_request;
  37 
  38 #ifdef MAJOR_NR
  39 
  40 /*
  41  * Add entries as needed. Currently the only block devices
  42  * supported are hard-disks and floppies.
  43  */
  44 #if (MAJOR_NR == 2)
  45 /* floppy */
  46 #define DEVICE_NAME "floppy"
  47 #define DEVICE_INTR do_floppy
  48 #define DEVICE_REQUEST do_fd_request
  49 #define DEVICE_NR(device) ((device) & 3)
  50 #define DEVICE_ON(device) floppy_on(DEVICE_NR(device))
  51 #define DEVICE_OFF(device) floppy_off(DEVICE_NR(device))
  52 
  53 #elif (MAJOR_NR == 3)
  54 /* harddisk */
  55 #define DEVICE_NAME "harddisk"
  56 #define DEVICE_INTR do_hd
  57 #define DEVICE_REQUEST do_hd_request
  58 #define DEVICE_NR(device) (MINOR(device)/5)
  59 #define DEVICE_ON(device)
  60 #define DEVICE_OFF(device)
  61 
  62 #elif
  63 /* unknown blk device */
  64 #error "unknown blk device"
  65 
  66 #endif
  67 
  68 #define CURRENT (blk_dev[MAJOR_NR].current_request)
  69 #define CURRENT_DEV DEVICE_NR(CURRENT->dev)
  70 
  71 void (*DEVICE_INTR)(void) = NULL;
  72 static void (DEVICE_REQUEST)(void);
  73 
  74 extern inline void unlock_buffer(struct buffer_head * bh)
     /* [previous][next][first][last][top][bottom][index][help] */
  75 {
  76         if (!bh->b_lock)
  77                 printk(DEVICE_NAME ": free buffer being unlocked\n");
  78         bh->b_lock=0;
  79         wake_up(&bh->b_wait);
  80 }
  81 
  82 extern inline void end_request(int uptodate)
     /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84         DEVICE_OFF(CURRENT->dev);
  85         if (CURRENT->bh) {
  86                 CURRENT->bh->b_uptodate = uptodate;
  87                 unlock_buffer(CURRENT->bh);
  88         }
  89         if (!uptodate) {
  90                 printk(DEVICE_NAME " I/O error\n\r");
  91                 printk("dev %04x, block %d\n\r",CURRENT->dev,
  92                         CURRENT->bh->b_blocknr);
  93         }
  94         wake_up(&CURRENT->waiting);
  95         wake_up(&wait_for_request);
  96         CURRENT->dev = -1;
  97         CURRENT = CURRENT->next;
  98 }
  99 
 100 #define INIT_REQUEST \
 101 repeat: \
 102         if (!CURRENT) \
 103                 return; \
 104         if (MAJOR(CURRENT->dev) != MAJOR_NR) \
 105                 panic(DEVICE_NAME ": request list destroyed"); \
 106         if (CURRENT->bh) \
 107                 if (!CURRENT->bh->b_lock) \
 108                         panic(DEVICE_NAME ": block not locked"); \
 109                 else { \
 110                         CURRENT->bh->b_dirt = 0; \
 111                         CURRENT->bh->b_uptodate = 0; \
 112                 }
 113 
 114 #endif
 115 
 116 #endif

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