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

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