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      12
   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 task_struct * 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 unsigned long hd_init(unsigned long mem_start, unsigned long mem_end);
  73 extern int is_read_only(int dev);
  74 extern void set_device_ro(int dev,int flag);
  75 
  76 extern void rd_load(void);
  77 extern long rd_init(long mem_start, int length);
  78 extern int ramdisk_size;
  79 
  80 #define RO_IOCTLS(dev,where) \
  81   case BLKROSET: if (!suser()) return -EPERM; \
  82                  set_device_ro((dev),get_fs_long((long *) (where))); return 0; \
  83   case BLKROGET: verify_area((void *) (where), sizeof(long)); \
  84                  put_fs_long(is_read_only(dev),(long *) (where)); return 0;
  85                  
  86 #ifdef MAJOR_NR
  87 
  88 /*
  89  * Add entries as needed. Currently the only block devices
  90  * supported are hard-disks and floppies.
  91  */
  92 
  93 #if (MAJOR_NR == 1)
  94 /* ram disk */
  95 #define DEVICE_NAME "ramdisk"
  96 #define DEVICE_REQUEST do_rd_request
  97 #define DEVICE_NR(device) ((device) & 7)
  98 #define DEVICE_ON(device) 
  99 #define DEVICE_OFF(device)
 100 
 101 #elif (MAJOR_NR == 2)
 102 /* floppy */
 103 #define DEVICE_NAME "floppy"
 104 #define DEVICE_INTR do_floppy
 105 #define DEVICE_REQUEST do_fd_request
 106 #define DEVICE_NR(device) ((device) & 3)
 107 #define DEVICE_ON(device) floppy_on(DEVICE_NR(device))
 108 #define DEVICE_OFF(device) floppy_off(DEVICE_NR(device))
 109 
 110 #elif (MAJOR_NR == 3)
 111 /* harddisk: timeout is 6 seconds.. */
 112 #define DEVICE_NAME "harddisk"
 113 #define DEVICE_INTR do_hd
 114 #define DEVICE_TIMEOUT HD_TIMER
 115 #define TIMEOUT_VALUE 600
 116 #define DEVICE_REQUEST do_hd_request
 117 #define DEVICE_NR(device) (MINOR(device)>>6)
 118 #define DEVICE_ON(device)
 119 #define DEVICE_OFF(device)
 120 
 121 #elif (MAJOR_NR == 8)
 122 /* scsi disk */
 123 #define DEVICE_NAME "scsidisk"
 124 #define DEVICE_INTR do_sd  
 125 #define TIMEOUT_VALUE 200
 126 #define DEVICE_REQUEST do_sd_request
 127 #define DEVICE_NR(device) (MINOR(device) >> 4)
 128 #define DEVICE_ON(device)
 129 #define DEVICE_OFF(device)
 130 
 131 #elif (MAJOR_NR == 9)
 132 /* scsi tape */
 133 #define DEVICE_NAME "scsitape"
 134 #define DEVICE_INTR do_st  
 135 #define DEVICE_REQUEST do_st_request
 136 #define DEVICE_NR(device) (MINOR(device))
 137 #define DEVICE_ON(device)
 138 #define DEVICE_OFF(device)
 139 
 140 #elif (MAJOR_NR == 11)
 141 /* scsi CD-ROM */
 142 #define DEVICE_NAME "CD-ROM"
 143 #define DEVICE_INTR do_sr
 144 #define DEVICE_REQUEST do_sr_request
 145 #define DEVICE_NR(device) (MINOR(device))
 146 #define DEVICE_ON(device)
 147 #define DEVICE_OFF(device)
 148 
 149 #else
 150 /* unknown blk device */
 151 #error "unknown blk device"
 152 
 153 #endif
 154 
 155 #ifndef CURRENT
 156 #define CURRENT (blk_dev[MAJOR_NR].current_request)
 157 #endif
 158 
 159 #define CURRENT_DEV DEVICE_NR(CURRENT->dev)
 160 
 161 #ifdef DEVICE_INTR
 162 void (*DEVICE_INTR)(void) = NULL;
 163 #endif
 164 #ifdef DEVICE_TIMEOUT
 165 
 166 #define SET_TIMER \
 167 ((timer_table[DEVICE_TIMEOUT].expires = jiffies + TIMEOUT_VALUE), \
 168 (timer_active |= 1<<DEVICE_TIMEOUT))
 169 
 170 #define CLEAR_TIMER \
 171 timer_active &= ~(1<<DEVICE_TIMEOUT)
 172 
 173 #define SET_INTR(x) \
 174 if ((DEVICE_INTR = (x)) != NULL) \
 175         SET_TIMER; \
 176 else \
 177         CLEAR_TIMER;
 178 
 179 #else
 180 
 181 #define SET_INTR(x) (DEVICE_INTR = (x))
 182 
 183 #endif
 184 static void (DEVICE_REQUEST)(void);
 185 
 186 extern inline void unlock_buffer(struct buffer_head * bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 187 {
 188         if (!bh->b_lock)
 189                 printk(DEVICE_NAME ": free buffer being unlocked\n");
 190         bh->b_lock=0;
 191         wake_up(&bh->b_wait);
 192 }
 193 
 194 /* SCSI devices have their own version */
 195 #if (MAJOR_NR != 8 && MAJOR_NR != 9 && MAJOR_NR != 11)
 196 static void end_request(int uptodate)
     /* [previous][next][first][last][top][bottom][index][help] */
 197 {
 198         struct request * req;
 199         struct buffer_head * bh;
 200         struct task_struct * p;
 201 
 202         req = CURRENT;
 203         req->errors = 0;
 204         if (!uptodate) {
 205                 printk(DEVICE_NAME " I/O error\n\r");
 206                 printk("dev %04x, sector %d\n\r",req->dev,req->sector);
 207                 req->nr_sectors--;
 208                 req->nr_sectors &= ~SECTOR_MASK;
 209                 req->sector += (BLOCK_SIZE / 512);
 210                 req->sector &= ~SECTOR_MASK;            
 211         }
 212 
 213         if ((bh = req->bh) != NULL) {
 214                 req->bh = bh->b_reqnext;
 215                 bh->b_reqnext = NULL;
 216                 bh->b_uptodate = uptodate;
 217                 unlock_buffer(bh);
 218                 if ((bh = req->bh) != NULL) {
 219                         req->current_nr_sectors = bh->b_size >> 9;
 220                         if (req->nr_sectors < req->current_nr_sectors) {
 221                                 req->nr_sectors = req->current_nr_sectors;
 222                                 printk("end_request: buffer-list destroyed\n");
 223                         }
 224                         req->buffer = bh->b_data;
 225                         return;
 226                 }
 227         }
 228         DEVICE_OFF(req->dev);
 229         CURRENT = req->next;
 230         if ((p = req->waiting) != NULL) {
 231                 req->waiting = NULL;
 232                 p->state = TASK_RUNNING;
 233                 if (p->counter > current->counter)
 234                         need_resched = 1;
 235         }
 236         req->dev = -1;
 237         wake_up(&wait_for_request);
 238 }
 239 #endif
 240 
 241 #ifdef DEVICE_INTR
 242 #define CLEAR_INTR SET_INTR(NULL)
 243 #else
 244 #define CLEAR_INTR
 245 #endif
 246 
 247 #define INIT_REQUEST \
 248         if (!CURRENT) {\
 249                 CLEAR_INTR; \
 250                 return; \
 251         } \
 252         if (MAJOR(CURRENT->dev) != MAJOR_NR) \
 253                 panic(DEVICE_NAME ": request list destroyed"); \
 254         if (CURRENT->bh) { \
 255                 if (!CURRENT->bh->b_lock) \
 256                         panic(DEVICE_NAME ": block not locked"); \
 257         }
 258 
 259 #endif
 260 
 261 #endif

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