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

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