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      10
   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         unsigned long current_nr_sectors;
  30         char * buffer;
  31         struct wait_queue * waiting;
  32         struct buffer_head * bh;
  33         struct buffer_head * bhtail;
  34         struct request * next;
  35 };
  36 
  37 /*
  38  * This is used in the elevator algorithm: Note that
  39  * reads always go before writes. This is natural: reads
  40  * are much more time-critical than writes.
  41  */
  42 #define IN_ORDER(s1,s2) \
  43 ((s1)->cmd < (s2)->cmd || ((s1)->cmd == (s2)->cmd && \
  44 ((s1)->dev < (s2)->dev || (((s1)->dev == (s2)->dev && \
  45 (s1)->sector < (s2)->sector)))))
  46 
  47 struct blk_dev_struct {
  48         void (*request_fn)(void);
  49         struct request * current_request;
  50 };
  51 
  52 
  53 struct sec_size {
  54         unsigned block_size;
  55         unsigned block_size_bits;
  56 };
  57 
  58 /*
  59  * These will have to be changed to be aware of different buffer
  60  * sizes etc..
  61  */
  62 #define SECTOR_MASK ((1 << (BLOCK_SIZE_BITS - 9)) -1)
  63 #define SUBSECTOR(block) ((block) & SECTOR_MASK)
  64 
  65 extern struct sec_size * blk_sec[NR_BLK_DEV];
  66 extern struct blk_dev_struct blk_dev[NR_BLK_DEV];
  67 extern struct request request[NR_REQUEST];
  68 extern struct wait_queue * wait_for_request;
  69 
  70 extern int * blk_size[NR_BLK_DEV];
  71 
  72 extern int is_read_only(int dev);
  73 extern void set_device_ro(int dev,int flag);
  74 
  75 #define RO_IOCTLS(dev,where) \
  76   case BLKROSET: if (!suser()) return -EPERM; \
  77                  set_device_ro((dev),get_fs_long((long *) (where))); return 0; \
  78   case BLKROGET: verify_area((void *) (where), sizeof(long)); \
  79                  put_fs_long(is_read_only(dev),(long *) (where)); return 0;
  80                  
  81 #ifdef MAJOR_NR
  82 
  83 /*
  84  * Add entries as needed. Currently the only block devices
  85  * supported are hard-disks and floppies.
  86  */
  87 
  88 #if (MAJOR_NR == 1)
  89 /* ram disk */
  90 #define DEVICE_NAME "ramdisk"
  91 #define DEVICE_REQUEST do_rd_request
  92 #define DEVICE_NR(device) ((device) & 7)
  93 #define DEVICE_ON(device) 
  94 #define DEVICE_OFF(device)
  95 
  96 #elif (MAJOR_NR == 2)
  97 /* floppy */
  98 #define DEVICE_NAME "floppy"
  99 #define DEVICE_INTR do_floppy
 100 #define DEVICE_REQUEST do_fd_request
 101 #define DEVICE_NR(device) ((device) & 3)
 102 #define DEVICE_ON(device) floppy_on(DEVICE_NR(device))
 103 #define DEVICE_OFF(device) floppy_off(DEVICE_NR(device))
 104 
 105 #elif (MAJOR_NR == 3)
 106 /* harddisk: timeout is 6 seconds.. */
 107 #define DEVICE_NAME "harddisk"
 108 #define DEVICE_INTR do_hd
 109 #define DEVICE_TIMEOUT HD_TIMER
 110 #define TIMEOUT_VALUE 600
 111 #define DEVICE_REQUEST do_hd_request
 112 #define DEVICE_NR(device) (MINOR(device)>>6)
 113 #define DEVICE_ON(device)
 114 #define DEVICE_OFF(device)
 115 
 116 #elif (MAJOR_NR == 8)
 117 /* scsi disk */
 118 #define DEVICE_NAME "scsidisk"
 119 #define DEVICE_INTR do_sd  
 120 #define TIMEOUT_VALUE 200
 121 #define DEVICE_REQUEST do_sd_request
 122 #define DEVICE_NR(device) (MINOR(device) >> 4)
 123 #define DEVICE_ON(device)
 124 #define DEVICE_OFF(device)
 125 
 126 #elif (MAJOR_NR == 9)
 127 /* scsi tape */
 128 #define DEVICE_NAME "scsitape"
 129 #define DEVICE_INTR do_st  
 130 #define DEVICE_REQUEST do_st_request
 131 #define DEVICE_NR(device) (MINOR(device))
 132 #define DEVICE_ON(device)
 133 #define DEVICE_OFF(device)
 134 
 135 #elif
 136 /* unknown blk device */
 137 #error "unknown blk device"
 138 
 139 #endif
 140 
 141 #ifndef CURRENT
 142 #define CURRENT (blk_dev[MAJOR_NR].current_request)
 143 #endif
 144 
 145 #define CURRENT_DEV DEVICE_NR(CURRENT->dev)
 146 
 147 #ifdef DEVICE_INTR
 148 void (*DEVICE_INTR)(void) = NULL;
 149 #endif
 150 #ifdef DEVICE_TIMEOUT
 151 
 152 #define SET_TIMER \
 153 ((timer_table[DEVICE_TIMEOUT].expires = jiffies + TIMEOUT_VALUE), \
 154 (timer_active |= 1<<DEVICE_TIMEOUT))
 155 
 156 #define CLEAR_TIMER \
 157 timer_active &= ~(1<<DEVICE_TIMEOUT)
 158 
 159 #define SET_INTR(x) \
 160 if (DEVICE_INTR = (x)) \
 161         SET_TIMER; \
 162 else \
 163         CLEAR_TIMER;
 164 
 165 #else
 166 
 167 #define SET_INTR(x) (DEVICE_INTR = (x))
 168 
 169 #endif
 170 static void (DEVICE_REQUEST)(void);
 171 
 172 extern inline void unlock_buffer(struct buffer_head * bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 173 {
 174         if (!bh->b_lock)
 175                 printk(DEVICE_NAME ": free buffer being unlocked\n");
 176         bh->b_lock=0;
 177         wake_up(&bh->b_wait);
 178 }
 179 
 180 static void end_request(int uptodate)
     /* [previous][next][first][last][top][bottom][index][help] */
 181 {
 182         struct request * req;
 183         struct buffer_head * bh;
 184 
 185         req = CURRENT;
 186         req->errors = 0;
 187         if (!uptodate) {
 188                 printk(DEVICE_NAME " I/O error\n\r");
 189                 printk("dev %04x, sector %d\n\r",req->dev,req->sector);
 190                 req->nr_sectors--;
 191                 req->nr_sectors &= ~SECTOR_MASK;
 192                 req->sector += (BLOCK_SIZE / 512);
 193                 req->sector &= ~SECTOR_MASK;            
 194         }
 195 
 196         if (bh = req->bh) {
 197                 req->bh = bh->b_reqnext;
 198                 bh->b_reqnext = NULL;
 199                 bh->b_uptodate = uptodate;
 200                 unlock_buffer(bh);
 201                 if (bh = req->bh) {
 202                         req->current_nr_sectors = bh->b_size >> 9;
 203                         if (req->nr_sectors < req->current_nr_sectors) {
 204                                 req->nr_sectors = req->current_nr_sectors;
 205                                 printk("end_request: buffer-list destroyed\n");
 206                         }
 207                         req->buffer = bh->b_data;
 208                         return;
 209                 }
 210         }
 211         DEVICE_OFF(req->dev);
 212         CURRENT = req->next;
 213         wake_up(&req->waiting);
 214         req->dev = -1;
 215         wake_up(&wait_for_request);
 216 }
 217 
 218 #ifdef DEVICE_INTR
 219 #define CLEAR_INTR SET_INTR(NULL)
 220 #else
 221 #define CLEAR_INTR
 222 #endif
 223 
 224 #define INIT_REQUEST \
 225         if (!CURRENT) {\
 226                 CLEAR_INTR; \
 227                 return; \
 228         } \
 229         if (MAJOR(CURRENT->dev) != MAJOR_NR) \
 230                 panic(DEVICE_NAME ": request list destroyed"); \
 231         if (CURRENT->bh) { \
 232                 if (!CURRENT->bh->b_lock) \
 233                         panic(DEVICE_NAME ": block not locked"); \
 234         }
 235 
 236 #endif
 237 
 238 #endif

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