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 /*
   6  * NR_REQUEST is the number of entries in the request-queue.
   7  * NOTE that writes may use only the low 2/3 of these: reads
   8  * take precedence.
   9  *
  10  * 32 seems to be a reasonable number: enough to get some benefit
  11  * from the elevator-mechanism, but not so much as to lock a lot of
  12  * buffers when they are in the queue. 64 seems to be too many (easily
  13  * long pauses in reading when heavy writing/syncing is going on)
  14  */
  15 #define NR_REQUEST      32
  16 
  17 /*
  18  * Ok, this is an expanded form so that we can use the same
  19  * request for paging requests when that is implemented. In
  20  * paging, 'bh' is NULL, and 'waiting' is used to wait for
  21  * read/write completion.
  22  */
  23 struct request {
  24         int dev;                /* -1 if no request */
  25         int cmd;                /* READ or WRITE */
  26         int errors;
  27         unsigned long sector;
  28         unsigned long nr_sectors;
  29         char * buffer;
  30         struct task_struct * waiting;
  31         struct buffer_head * bh;
  32         struct request * next;
  33 };
  34 
  35 /*
  36  * This is used in the elevator algorithm: Note that
  37  * reads always go before writes. This is natural: reads
  38  * are much more time-critical than writes.
  39  */
  40 #define IN_ORDER(s1,s2) \
  41 ((s1)->cmd<(s2)->cmd || ((s1)->cmd==(s2)->cmd && \
  42 ((s1)->dev < (s2)->dev || (((s1)->dev == (s2)->dev && \
  43 (s1)->sector < (s2)->sector)))))
  44 
  45 struct blk_dev_struct {
  46         void (*request_fn)(void);
  47         struct request * current_request;
  48 };
  49 
  50 extern struct blk_dev_struct blk_dev[NR_BLK_DEV];
  51 extern struct request request[NR_REQUEST];
  52 extern struct task_struct * wait_for_request;
  53 
  54 extern int * blk_size[NR_BLK_DEV];
  55 
  56 #ifdef MAJOR_NR
  57 
  58 /*
  59  * Add entries as needed. Currently the only block devices
  60  * supported are hard-disks and floppies.
  61  */
  62 
  63 #if (MAJOR_NR == 1)
  64 /* ram disk */
  65 #define DEVICE_NAME "ramdisk"
  66 #define DEVICE_REQUEST do_rd_request
  67 #define DEVICE_NR(device) ((device) & 7)
  68 #define DEVICE_ON(device) 
  69 #define DEVICE_OFF(device)
  70 
  71 #elif (MAJOR_NR == 2)
  72 /* floppy */
  73 #define DEVICE_NAME "floppy"
  74 #define DEVICE_INTR do_floppy
  75 #define DEVICE_REQUEST do_fd_request
  76 #define DEVICE_NR(device) ((device) & 3)
  77 #define DEVICE_ON(device) floppy_on(DEVICE_NR(device))
  78 #define DEVICE_OFF(device) floppy_off(DEVICE_NR(device))
  79 
  80 #elif (MAJOR_NR == 3)
  81 /* harddisk: timeout is 6 seconds.. */
  82 #define DEVICE_NAME "harddisk"
  83 #define DEVICE_INTR do_hd
  84 #define DEVICE_TIMEOUT HD_TIMER
  85 #define TIMEOUT_VALUE 600
  86 #define DEVICE_REQUEST do_hd_request
  87 #define DEVICE_NR(device) (MINOR(device)>>6)
  88 #define DEVICE_ON(device)
  89 #define DEVICE_OFF(device)
  90 
  91 #elif
  92 /* unknown blk device */
  93 #error "unknown blk device"
  94 
  95 #endif
  96 
  97 #define CURRENT (blk_dev[MAJOR_NR].current_request)
  98 #define CURRENT_DEV DEVICE_NR(CURRENT->dev)
  99 
 100 #ifdef DEVICE_INTR
 101 void (*DEVICE_INTR)(void) = NULL;
 102 #endif
 103 #ifdef DEVICE_TIMEOUT
 104 
 105 #define SET_TIMER \
 106 ((timer_table[DEVICE_TIMEOUT].expires = jiffies + TIMEOUT_VALUE), \
 107 (timer_active |= 1<<DEVICE_TIMEOUT))
 108 
 109 #define CLEAR_TIMER \
 110 timer_active &= ~(1<<DEVICE_TIMEOUT)
 111 
 112 #define SET_INTR(x) \
 113 if (DEVICE_INTR = (x)) \
 114         SET_TIMER; \
 115 else \
 116         CLEAR_TIMER;
 117 
 118 #else
 119 
 120 #define SET_INTR(x) (DEVICE_INTR = (x))
 121 
 122 #endif
 123 static void (DEVICE_REQUEST)(void);
 124 
 125 extern inline void unlock_buffer(struct buffer_head * bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 126 {
 127         if (!bh->b_lock)
 128                 printk(DEVICE_NAME ": free buffer being unlocked\n");
 129         bh->b_lock=0;
 130         wake_up(&bh->b_wait);
 131 }
 132 
 133 extern inline void end_request(int uptodate)
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135         DEVICE_OFF(CURRENT->dev);
 136         if (CURRENT->bh) {
 137                 CURRENT->bh->b_uptodate = uptodate;
 138                 unlock_buffer(CURRENT->bh);
 139         }
 140         if (!uptodate) {
 141                 printk(DEVICE_NAME " I/O error\n\r");
 142                 printk("dev %04x, block %d\n\r",CURRENT->dev,
 143                         CURRENT->bh->b_blocknr);
 144         }
 145         wake_up(&CURRENT->waiting);
 146         wake_up(&wait_for_request);
 147         CURRENT->dev = -1;
 148         CURRENT = CURRENT->next;
 149 }
 150 
 151 #ifdef DEVICE_INTR
 152 #define CLEAR_INTR SET_INTR(NULL)
 153 #else
 154 #define CLEAR_INTR
 155 #endif
 156 
 157 #define INIT_REQUEST \
 158 repeat: \
 159         if (!CURRENT) {\
 160                 CLEAR_INTR; \
 161                 return; \
 162         } \
 163         if (MAJOR(CURRENT->dev) != MAJOR_NR) \
 164                 panic(DEVICE_NAME ": request list destroyed"); \
 165         if (CURRENT->bh) { \
 166                 if (!CURRENT->bh->b_lock) \
 167                         panic(DEVICE_NAME ": block not locked"); \
 168         }
 169 
 170 #endif
 171 
 172 #endif

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