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