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 #include <linux/fs.h>
   5 
   6 /*
   7  * NR_REQUEST is the number of entries in the request-queue.
   8  * NOTE that writes may use only the low 2/3 of these: reads
   9  * take precedence.
  10  *
  11  * 32 seems to be a reasonable number: enough to get some benefit
  12  * from the elevator-mechanism, but not so much as to lock a lot of
  13  * buffers when they are in the queue. 64 seems to be too many (easily
  14  * long pauses in reading when heavy writing/syncing is going on)
  15  */
  16 #define NR_REQUEST      32
  17 
  18 /*
  19  * Ok, this is an expanded form so that we can use the same
  20  * request for paging requests when that is implemented. In
  21  * paging, 'bh' is NULL, and 'waiting' is used to wait for
  22  * read/write completion.
  23  */
  24 struct request {
  25         int dev;                /* -1 if no request */
  26         int cmd;                /* READ or WRITE */
  27         int errors;
  28         unsigned long sector;
  29         unsigned long nr_sectors;
  30         unsigned long current_nr_sectors;
  31         char * buffer;
  32         struct task_struct * waiting;
  33         struct buffer_head * bh;
  34         struct buffer_head * bhtail;
  35         struct request * next;
  36 };
  37 
  38 /*
  39  * This is used in the elevator algorithm: Note that
  40  * reads always go before writes. This is natural: reads
  41  * are much more time-critical than writes.
  42  */
  43 #define IN_ORDER(s1,s2) \
  44 ((s1)->cmd < (s2)->cmd || ((s1)->cmd == (s2)->cmd && \
  45 ((s1)->dev < (s2)->dev || (((s1)->dev == (s2)->dev && \
  46 (s1)->sector < (s2)->sector)))))
  47 
  48 struct blk_dev_struct {
  49         void (*request_fn)(void);
  50         struct request * current_request;
  51 };
  52 
  53 
  54 struct sec_size {
  55         unsigned block_size;
  56         unsigned block_size_bits;
  57 };
  58 
  59 /*
  60  * These will have to be changed to be aware of different buffer
  61  * sizes etc..
  62  */
  63 #define SECTOR_MASK ((1 << (BLOCK_SIZE_BITS - 9)) -1)
  64 #define SUBSECTOR(block) ((block) & SECTOR_MASK)
  65 
  66 extern struct sec_size * blk_sec[MAX_BLKDEV];
  67 extern struct blk_dev_struct blk_dev[MAX_BLKDEV];
  68 extern struct request request[NR_REQUEST];
  69 extern struct wait_queue * wait_for_request;
  70 
  71 extern int * blk_size[MAX_BLKDEV];
  72 
  73 extern unsigned long hd_init(unsigned long mem_start, unsigned long mem_end);
  74 extern int is_read_only(int dev);
  75 extern void set_device_ro(int dev,int flag);
  76 
  77 extern void rd_load(void);
  78 extern long rd_init(long mem_start, int length);
  79 extern int ramdisk_size;
  80 
  81 #define RO_IOCTLS(dev,where) \
  82   case BLKROSET: if (!suser()) return -EPERM; \
  83                  set_device_ro((dev),get_fs_long((long *) (where))); return 0; \
  84   case BLKROGET: verify_area((void *) (where), sizeof(long)); \
  85                  put_fs_long(is_read_only(dev),(long *) (where)); return 0;
  86                  
  87 #ifdef MAJOR_NR
  88 
  89 /*
  90  * Add entries as needed. Currently the only block devices
  91  * supported are hard-disks and floppies.
  92  */
  93 
  94 #if (MAJOR_NR == 1)
  95 /* ram disk */
  96 #define DEVICE_NAME "ramdisk"
  97 #define DEVICE_REQUEST do_rd_request
  98 #define DEVICE_NR(device) ((device) & 7)
  99 #define DEVICE_ON(device) 
 100 #define DEVICE_OFF(device)
 101 
 102 #elif (MAJOR_NR == 2)
 103 /* floppy */
 104 #define DEVICE_NAME "floppy"
 105 #define DEVICE_INTR do_floppy
 106 #define DEVICE_REQUEST do_fd_request
 107 #define DEVICE_NR(device) ((device) & 3)
 108 #define DEVICE_ON(device) floppy_on(DEVICE_NR(device))
 109 #define DEVICE_OFF(device) floppy_off(DEVICE_NR(device))
 110 
 111 #elif (MAJOR_NR == 3)
 112 /* harddisk: timeout is 6 seconds.. */
 113 #define DEVICE_NAME "harddisk"
 114 #define DEVICE_INTR do_hd
 115 #define DEVICE_TIMEOUT HD_TIMER
 116 #define TIMEOUT_VALUE 600
 117 #define DEVICE_REQUEST do_hd_request
 118 #define DEVICE_NR(device) (MINOR(device)>>6)
 119 #define DEVICE_ON(device)
 120 #define DEVICE_OFF(device)
 121 
 122 #elif (MAJOR_NR == 8)
 123 /* scsi disk */
 124 #define DEVICE_NAME "scsidisk"
 125 #define DEVICE_INTR do_sd  
 126 #define TIMEOUT_VALUE 200
 127 #define DEVICE_REQUEST do_sd_request
 128 #define DEVICE_NR(device) (MINOR(device) >> 4)
 129 #define DEVICE_ON(device)
 130 #define DEVICE_OFF(device)
 131 
 132 #elif (MAJOR_NR == 9)
 133 /* scsi tape */
 134 #define DEVICE_NAME "scsitape"
 135 #define DEVICE_INTR do_st  
 136 #define DEVICE_REQUEST do_st_request
 137 #define DEVICE_NR(device) (MINOR(device))
 138 #define DEVICE_ON(device)
 139 #define DEVICE_OFF(device)
 140 
 141 #elif (MAJOR_NR == 11)
 142 /* scsi CD-ROM */
 143 #define DEVICE_NAME "CD-ROM"
 144 #define DEVICE_INTR do_sr
 145 #define DEVICE_REQUEST do_sr_request
 146 #define DEVICE_NR(device) (MINOR(device))
 147 #define DEVICE_ON(device)
 148 #define DEVICE_OFF(device)
 149 
 150 #else
 151 /* unknown blk device */
 152 #error "unknown blk device"
 153 
 154 #endif
 155 
 156 #if (MAJOR_NR != 9)
 157 
 158 #ifndef CURRENT
 159 #define CURRENT (blk_dev[MAJOR_NR].current_request)
 160 #endif
 161 
 162 #define CURRENT_DEV DEVICE_NR(CURRENT->dev)
 163 
 164 #ifdef DEVICE_INTR
 165 void (*DEVICE_INTR)(void) = NULL;
 166 #endif
 167 #ifdef DEVICE_TIMEOUT
 168 
 169 #define SET_TIMER \
 170 ((timer_table[DEVICE_TIMEOUT].expires = jiffies + TIMEOUT_VALUE), \
 171 (timer_active |= 1<<DEVICE_TIMEOUT))
 172 
 173 #define CLEAR_TIMER \
 174 timer_active &= ~(1<<DEVICE_TIMEOUT)
 175 
 176 #define SET_INTR(x) \
 177 if ((DEVICE_INTR = (x)) != NULL) \
 178         SET_TIMER; \
 179 else \
 180         CLEAR_TIMER;
 181 
 182 #else
 183 
 184 #define SET_INTR(x) (DEVICE_INTR = (x))
 185 
 186 #endif
 187 static void (DEVICE_REQUEST)(void);
 188 
 189 extern inline void unlock_buffer(struct buffer_head * bh)
     /* [previous][next][first][last][top][bottom][index][help] */
 190 {
 191         if (!bh->b_lock)
 192                 printk(DEVICE_NAME ": free buffer being unlocked\n");
 193         bh->b_lock=0;
 194         wake_up(&bh->b_wait);
 195 }
 196 
 197 /* SCSI devices have their own version */
 198 #if (MAJOR_NR != 8 && MAJOR_NR != 9 && MAJOR_NR != 11)
 199 static void end_request(int uptodate)
     /* [previous][next][first][last][top][bottom][index][help] */
 200 {
 201         struct request * req;
 202         struct buffer_head * bh;
 203         struct task_struct * p;
 204 
 205         req = CURRENT;
 206         req->errors = 0;
 207         if (!uptodate) {
 208                 printk(DEVICE_NAME " I/O error\n\r");
 209                 printk("dev %04x, sector %d\n\r",req->dev,req->sector);
 210                 req->nr_sectors--;
 211                 req->nr_sectors &= ~SECTOR_MASK;
 212                 req->sector += (BLOCK_SIZE / 512);
 213                 req->sector &= ~SECTOR_MASK;            
 214         }
 215 
 216         if ((bh = req->bh) != NULL) {
 217                 req->bh = bh->b_reqnext;
 218                 bh->b_reqnext = NULL;
 219                 bh->b_uptodate = uptodate;
 220                 unlock_buffer(bh);
 221                 if ((bh = req->bh) != NULL) {
 222                         req->current_nr_sectors = bh->b_size >> 9;
 223                         if (req->nr_sectors < req->current_nr_sectors) {
 224                                 req->nr_sectors = req->current_nr_sectors;
 225                                 printk("end_request: buffer-list destroyed\n");
 226                         }
 227                         req->buffer = bh->b_data;
 228                         return;
 229                 }
 230         }
 231         DEVICE_OFF(req->dev);
 232         CURRENT = req->next;
 233         if ((p = req->waiting) != NULL) {
 234                 req->waiting = NULL;
 235                 p->state = TASK_RUNNING;
 236                 if (p->counter > current->counter)
 237                         need_resched = 1;
 238         }
 239         req->dev = -1;
 240         wake_up(&wait_for_request);
 241 }
 242 #endif
 243 
 244 #ifdef DEVICE_INTR
 245 #define CLEAR_INTR SET_INTR(NULL)
 246 #else
 247 #define CLEAR_INTR
 248 #endif
 249 
 250 #define INIT_REQUEST \
 251         if (!CURRENT) {\
 252                 CLEAR_INTR; \
 253                 return; \
 254         } \
 255         if (MAJOR(CURRENT->dev) != MAJOR_NR) \
 256                 panic(DEVICE_NAME ": request list destroyed"); \
 257         if (CURRENT->bh) { \
 258                 if (!CURRENT->bh->b_lock) \
 259                         panic(DEVICE_NAME ": block not locked"); \
 260         }
 261 
 262 #endif
 263 
 264 #endif
 265 #endif

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