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 #if (MAJOR_NR != 9)
 156 
 157 #ifndef CURRENT
 158 #define CURRENT (blk_dev[MAJOR_NR].current_request)
 159 #endif
 160 
 161 #define CURRENT_DEV DEVICE_NR(CURRENT->dev)
 162 
 163 #ifdef DEVICE_INTR
 164 void (*DEVICE_INTR)(void) = NULL;
 165 #endif
 166 #ifdef DEVICE_TIMEOUT
 167 
 168 #define SET_TIMER \
 169 ((timer_table[DEVICE_TIMEOUT].expires = jiffies + TIMEOUT_VALUE), \
 170 (timer_active |= 1<<DEVICE_TIMEOUT))
 171 
 172 #define CLEAR_TIMER \
 173 timer_active &= ~(1<<DEVICE_TIMEOUT)
 174 
 175 #define SET_INTR(x) \
 176 if ((DEVICE_INTR = (x)) != NULL) \
 177         SET_TIMER; \
 178 else \
 179         CLEAR_TIMER;
 180 
 181 #else
 182 
 183 #define SET_INTR(x) (DEVICE_INTR = (x))
 184 
 185 #endif
 186 static void (DEVICE_REQUEST)(void);
 187 
 188 extern inline void unlock_buffer(struct buffer_head * bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 189 {
 190         if (!bh->b_lock)
 191                 printk(DEVICE_NAME ": free buffer being unlocked\n");
 192         bh->b_lock=0;
 193         wake_up(&bh->b_wait);
 194 }
 195 
 196 /* SCSI devices have their own version */
 197 #if (MAJOR_NR != 8 && MAJOR_NR != 9 && MAJOR_NR != 11)
 198 static void end_request(int uptodate)
     /* [previous][next][first][last][top][bottom][index][help] */
 199 {
 200         struct request * req;
 201         struct buffer_head * bh;
 202         struct task_struct * p;
 203 
 204         req = CURRENT;
 205         req->errors = 0;
 206         if (!uptodate) {
 207                 printk(DEVICE_NAME " I/O error\n\r");
 208                 printk("dev %04x, sector %d\n\r",req->dev,req->sector);
 209                 req->nr_sectors--;
 210                 req->nr_sectors &= ~SECTOR_MASK;
 211                 req->sector += (BLOCK_SIZE / 512);
 212                 req->sector &= ~SECTOR_MASK;            
 213         }
 214 
 215         if ((bh = req->bh) != NULL) {
 216                 req->bh = bh->b_reqnext;
 217                 bh->b_reqnext = NULL;
 218                 bh->b_uptodate = uptodate;
 219                 unlock_buffer(bh);
 220                 if ((bh = req->bh) != NULL) {
 221                         req->current_nr_sectors = bh->b_size >> 9;
 222                         if (req->nr_sectors < req->current_nr_sectors) {
 223                                 req->nr_sectors = req->current_nr_sectors;
 224                                 printk("end_request: buffer-list destroyed\n");
 225                         }
 226                         req->buffer = bh->b_data;
 227                         return;
 228                 }
 229         }
 230         DEVICE_OFF(req->dev);
 231         CURRENT = req->next;
 232         if ((p = req->waiting) != NULL) {
 233                 req->waiting = NULL;
 234                 p->state = TASK_RUNNING;
 235                 if (p->counter > current->counter)
 236                         need_resched = 1;
 237         }
 238         req->dev = -1;
 239         wake_up(&wait_for_request);
 240 }
 241 #endif
 242 
 243 #ifdef DEVICE_INTR
 244 #define CLEAR_INTR SET_INTR(NULL)
 245 #else
 246 #define CLEAR_INTR
 247 #endif
 248 
 249 #define INIT_REQUEST \
 250         if (!CURRENT) {\
 251                 CLEAR_INTR; \
 252                 return; \
 253         } \
 254         if (MAJOR(CURRENT->dev) != MAJOR_NR) \
 255                 panic(DEVICE_NAME ": request list destroyed"); \
 256         if (CURRENT->bh) { \
 257                 if (!CURRENT->bh->b_lock) \
 258                         panic(DEVICE_NAME ": block not locked"); \
 259         }
 260 
 261 #endif
 262 
 263 #endif
 264 #endif

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