This source file includes following definitions.
- sd_open
- sd_release
- sd_geninit
- rw_intr
- do_sd_request
- requeue_sd_request
- check_scsidisk_media_change
- sd_init_done
- sd_init_onedisk
- sd_init
- sd_init1
- sd_attach
- revalidate_scsidisk
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/fs.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <asm/system.h>
19
20
21 #define MAJOR_NR 8
22
23 #include "../blk.h"
24 #include "scsi.h"
25 #include "hosts.h"
26 #include "sd.h"
27 #include "scsi_ioctl.h"
28
29 #include <linux/genhd.h>
30
31
32
33
34
35 #define MAX_RETRIES 5
36
37
38
39
40
41 #define SD_TIMEOUT 200
42
43 struct hd_struct * sd;
44
45 int NR_SD=0;
46 int MAX_SD=0;
47 Scsi_Disk * rscsi_disks;
48 static int * sd_sizes;
49
50
51 extern void resetup_one_dev(struct gendisk *, unsigned int);
52
53 extern int sd_ioctl(struct inode *, struct file *, unsigned int, unsigned int);
54
55 static sd_init_onedisk(int);
56
57 static void requeue_sd_request (Scsi_Cmnd * SCpnt);
58
59 static int sd_open(struct inode * inode, struct file * filp)
60 {
61 int target;
62 target = DEVICE_NR(MINOR(inode->i_rdev));
63
64 if(target >= NR_SD || !rscsi_disks[target].device)
65 return -ENODEV;
66
67
68
69
70 while (rscsi_disks[target].device->busy);
71
72 if(rscsi_disks[target].device->removable) {
73 check_disk_change(inode->i_rdev);
74
75 if(!rscsi_disks[target].device->access_count)
76 sd_ioctl(inode, NULL, SCSI_IOCTL_DOORLOCK, 0);
77 };
78 rscsi_disks[target].device->access_count++;
79 return 0;
80 }
81
82 static void sd_release(struct inode * inode, struct file * file)
83 {
84 int target;
85 sync_dev(inode->i_rdev);
86
87 target = DEVICE_NR(MINOR(inode->i_rdev));
88
89 rscsi_disks[target].device->access_count--;
90
91 if(rscsi_disks[target].device->removable) {
92 if(!rscsi_disks[target].device->access_count)
93 sd_ioctl(inode, NULL, SCSI_IOCTL_DOORUNLOCK, 0);
94 };
95 }
96
97 static struct gendisk sd_gendisk;
98
99 static void sd_geninit (void) {
100 int i;
101 for (i = 0; i < NR_SD; ++i)
102 sd[i << 4].nr_sects = rscsi_disks[i].capacity;
103 sd_gendisk.nr_real = NR_SD;
104 }
105
106 static struct file_operations sd_fops = {
107 NULL,
108 block_read,
109 block_write,
110 NULL,
111 NULL,
112 sd_ioctl,
113 NULL,
114 sd_open,
115 sd_release
116 };
117
118 static struct gendisk sd_gendisk = {
119 MAJOR_NR,
120 "sd",
121 4,
122 1 << 4,
123 0,
124 sd_geninit,
125 NULL,
126 NULL,
127 0,
128 NULL,
129 NULL
130 };
131
132
133
134
135
136
137
138 static void rw_intr (Scsi_Cmnd *SCpnt)
139 {
140 int result = SCpnt->result;
141 int this_count = SCpnt->bufflen >> 9;
142
143 #ifdef DEBUG
144 printk("sd%d : rw_intr(%d, %x)\n", MINOR(SCpnt->request.dev), SCpnt->host, result);
145 #endif
146
147
148
149
150
151
152
153 if (!result) {
154
155 #ifdef DEBUG
156 printk("sd%d : %d sectors remain.\n", MINOR(SCpnt->request.dev), SCpnt->request.nr_sectors);
157 printk("use_sg is %d\n ",SCpnt->use_sg);
158 #endif
159 if (SCpnt->use_sg) {
160 struct scatterlist * sgpnt;
161 int i;
162 sgpnt = (struct scatterlist *) SCpnt->buffer;
163 for(i=0; i<SCpnt->use_sg; i++) {
164 #ifdef DEBUG
165 printk(":%x %x %d\n",sgpnt[i].alt_address, sgpnt[i].address, sgpnt[i].length);
166 #endif
167 if (sgpnt[i].alt_address) {
168 if (SCpnt->request.cmd == READ)
169 memcpy(sgpnt[i].alt_address, sgpnt[i].address, sgpnt[i].length);
170 scsi_free(sgpnt[i].address, sgpnt[i].length);
171 };
172 };
173 scsi_free(SCpnt->buffer, SCpnt->sglist_len);
174 } else {
175 if (SCpnt->buffer != SCpnt->request.buffer) {
176 #ifdef DEBUG
177 printk("nosg: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
178 SCpnt->bufflen);
179 #endif
180 if (SCpnt->request.cmd == READ)
181 memcpy(SCpnt->request.buffer, SCpnt->buffer,
182 SCpnt->bufflen);
183 scsi_free(SCpnt->buffer, SCpnt->bufflen);
184 };
185 };
186
187
188
189
190
191 if (SCpnt->request.nr_sectors > this_count)
192 {
193 SCpnt->request.errors = 0;
194
195 if (!SCpnt->request.bh)
196 {
197 #ifdef DEBUG
198 printk("sd%d : handling page request, no buffer\n",
199 MINOR(SCpnt->request.dev));
200 #endif
201
202
203
204
205 printk("sd.c: linked page request. (%x %x)",
206 SCpnt->request.sector, this_count);
207 panic("Aiiiiiiiiiiiieeeeeeeee");
208 }
209 }
210 end_scsi_request(SCpnt, 1, this_count);
211 requeue_sd_request(SCpnt);
212 return;
213 }
214
215
216 if (SCpnt->use_sg) {
217 struct scatterlist * sgpnt;
218 int i;
219 sgpnt = (struct scatterlist *) SCpnt->buffer;
220 for(i=0; i<SCpnt->use_sg; i++) {
221 #ifdef DEBUG
222 printk("err: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
223 SCpnt->bufflen);
224 #endif
225 if (sgpnt[i].alt_address) {
226 scsi_free(sgpnt[i].address, sgpnt[i].length);
227 };
228 };
229 scsi_free(SCpnt->buffer, SCpnt->sglist_len);
230 } else {
231 #ifdef DEBUG
232 printk("nosgerr: %x %x %d\n",SCpnt->request.buffer, SCpnt->buffer,
233 SCpnt->bufflen);
234 #endif
235 if (SCpnt->buffer != SCpnt->request.buffer)
236 scsi_free(SCpnt->buffer, SCpnt->bufflen);
237 };
238
239
240
241
242
243
244
245 if (driver_byte(result) != 0) {
246 {
247 int i;
248 printk("Dumping sense buffer: ");
249 for(i=0;i<10;i++) printk(" %d",SCpnt->sense_buffer[i]);
250 };
251 if (sugestion(result) == SUGGEST_REMAP) {
252 #ifdef REMAP
253
254
255
256
257 if rscsi_disks[DEVICE_NR(SCpnt->request.dev)].remap
258 {
259 result = 0;
260 }
261 else
262
263 #endif
264 }
265
266 if ((SCpnt->sense_buffer[0] & 0x7f) == 0x70) {
267 if ((SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION) {
268
269
270
271 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->changed = 1;
272 end_scsi_request(SCpnt, 0, this_count);
273 requeue_sd_request(SCpnt);
274 return;
275 }
276 }
277
278
279
280
281
282
283
284
285
286 if (SCpnt->sense_buffer[2] == ILLEGAL_REQUEST) {
287 if (rscsi_disks[DEVICE_NR(SCpnt->request.dev)].ten) {
288 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].ten = 0;
289 requeue_sd_request(SCpnt);
290 result = 0;
291 } else {
292 }
293 }
294 }
295 if (result) {
296 printk("SCSI disk error : host %d id %d lun %d return code = %x\n",
297 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->host_no,
298 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->id,
299 rscsi_disks[DEVICE_NR(SCpnt->request.dev)].device->lun, result);
300
301 if (driver_byte(result) & DRIVER_SENSE)
302 printk("\tSense class %x, sense error %x, extended sense %x\n",
303 sense_class(SCpnt->sense_buffer[0]),
304 sense_error(SCpnt->sense_buffer[0]),
305 SCpnt->sense_buffer[2] & 0xf);
306
307 end_scsi_request(SCpnt, 0, SCpnt->request.current_nr_sectors);
308 requeue_sd_request(SCpnt);
309 return;
310 }
311 }
312
313
314
315
316
317
318
319 static void do_sd_request (void)
320 {
321 Scsi_Cmnd * SCpnt = NULL;
322 struct request * req = NULL;
323 int flag = 0;
324 while (1==1){
325 if (CURRENT != NULL && CURRENT->dev == -1) return;
326
327 INIT_REQUEST;
328
329
330
331
332
333
334
335
336
337
338
339
340 if (flag++ == 0)
341 SCpnt = allocate_device(&CURRENT,
342 rscsi_disks[DEVICE_NR(MINOR(CURRENT->dev))].device->index, 0);
343 else SCpnt = NULL;
344
345
346
347
348
349
350
351
352 if (!SCpnt && NR_SD > 1){
353 struct request *req1;
354 req1 = NULL;
355 cli();
356 req = CURRENT;
357 while(req){
358 SCpnt = request_queueable(req,
359 rscsi_disks[DEVICE_NR(MINOR(req->dev))].device->index);
360 if(SCpnt) break;
361 req1 = req;
362 req = req->next;
363 };
364 if (SCpnt) {
365 if (req == CURRENT)
366 CURRENT = CURRENT->next;
367 else
368 req1->next = req->next;
369 };
370 sti();
371 };
372
373 if (!SCpnt) return;
374
375 wake_up(&wait_for_request);
376
377
378 requeue_sd_request(SCpnt);
379 };
380 }
381
382 static void requeue_sd_request (Scsi_Cmnd * SCpnt)
383 {
384 int dev, block, this_count;
385 unsigned char cmd[10];
386 char * buff;
387
388 repeat:
389
390 if(SCpnt->request.dev <= 0)
391 return do_sd_request();
392
393 dev = MINOR(SCpnt->request.dev);
394 block = SCpnt->request.sector;
395 this_count = 0;
396
397 #ifdef DEBUG
398 printk("Doing sd request, dev = %d, block = %d\n", dev, block);
399 #endif
400
401 if (dev >= (NR_SD << 4) || block + SCpnt->request.nr_sectors > sd[dev].nr_sects)
402 {
403 end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
404 goto repeat;
405 }
406
407 block += sd[dev].start_sect;
408 dev = DEVICE_NR(dev);
409
410 if (rscsi_disks[dev].device->changed)
411 {
412
413
414
415
416 end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
417 goto repeat;
418 }
419
420 #ifdef DEBUG
421 printk("sd%d : real dev = /dev/sd%d, block = %d\n", MINOR(SCpnt->request.dev), dev, block);
422 #endif
423
424 switch (SCpnt->request.cmd)
425 {
426 case WRITE :
427 if (!rscsi_disks[dev].device->writeable)
428 {
429 end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
430 goto repeat;
431 }
432 cmd[0] = WRITE_6;
433 break;
434 case READ :
435 cmd[0] = READ_6;
436 break;
437 default :
438 printk ("Unknown sd command %d\r\n", SCpnt->request.cmd);
439 panic("");
440 }
441
442 SCpnt->this_count = 0;
443
444 if (!SCpnt->request.bh ||
445 (SCpnt->request.nr_sectors == SCpnt->request.current_nr_sectors)) {
446
447
448 this_count = SCpnt->request.nr_sectors;
449 buff = SCpnt->request.buffer;
450 SCpnt->use_sg = 0;
451
452 } else if (scsi_hosts[SCpnt->host].sg_tablesize == 0 ||
453 (need_isa_buffer &&
454 dma_free_sectors < 10)) {
455
456
457
458
459
460
461
462
463 if (scsi_hosts[SCpnt->host].sg_tablesize != 0 &&
464 need_isa_buffer &&
465 dma_free_sectors < 10)
466 printk("Warning: SCSI DMA buffer space running low. Using non scatter-gather I/O.\n");
467
468 this_count = SCpnt->request.current_nr_sectors;
469 buff = SCpnt->request.buffer;
470 SCpnt->use_sg = 0;
471
472 } else {
473
474
475 struct buffer_head * bh;
476 struct scatterlist * sgpnt;
477 int count, this_count_max;
478 bh = SCpnt->request.bh;
479 this_count = 0;
480 this_count_max = (rscsi_disks[dev].ten ? 0xffff : 0xff);
481 count = 0;
482 while(bh && count < scsi_hosts[SCpnt->host].sg_tablesize) {
483 if ((this_count + (bh->b_size >> 9)) > this_count_max) break;
484 this_count += (bh->b_size >> 9);
485 count++;
486 bh = bh->b_reqnext;
487 };
488 SCpnt->use_sg = count;
489 count = 512;
490 while( count < (SCpnt->use_sg * sizeof(struct scatterlist)))
491 count = count << 1;
492 SCpnt->sglist_len = count;
493 sgpnt = (struct scatterlist * ) scsi_malloc(count);
494 if (!sgpnt) {
495 printk("Warning - running *really* short on DMA buffers\n");
496 SCpnt->use_sg = 0;
497 this_count = SCpnt->request.current_nr_sectors;
498 buff = SCpnt->request.buffer;
499 } else {
500 buff = (char *) sgpnt;
501 count = 0;
502 bh = SCpnt->request.bh;
503 for(count = 0, bh = SCpnt->request.bh; count < SCpnt->use_sg;
504 count++, bh = bh->b_reqnext) {
505 sgpnt[count].address = bh->b_data;
506 sgpnt[count].alt_address = NULL;
507 sgpnt[count].length = bh->b_size;
508 if (((int) sgpnt[count].address) + sgpnt[count].length >
509 ISA_DMA_THRESHOLD & (scsi_hosts[SCpnt->host].unchecked_isa_dma)) {
510 sgpnt[count].alt_address = sgpnt[count].address;
511
512
513
514 if(dma_free_sectors < (bh->b_size >> 9) + 5) {
515 sgpnt[count].address = NULL;
516 } else {
517 sgpnt[count].address = scsi_malloc(sgpnt[count].length);
518 };
519
520
521
522
523 if(sgpnt[count].address == NULL){
524 printk("Warning: Running low on SCSI DMA buffers");
525
526 while(--count){
527 if(sgpnt[count].alt_address)
528 scsi_free(sgpnt[count].address, sgpnt[count].length);
529 };
530 this_count = SCpnt->request.current_nr_sectors;
531 buff = SCpnt->request.buffer;
532 SCpnt->use_sg = 0;
533 scsi_free(buff, SCpnt->sglist_len);
534 break;
535 };
536
537 if (SCpnt->request.cmd == WRITE)
538 memcpy(sgpnt[count].address, sgpnt[count].alt_address,
539 sgpnt[count].length);
540 };
541 };
542 };
543 };
544
545
546
547 if(SCpnt->use_sg == 0){
548 if (((int) buff) + (this_count << 9) > ISA_DMA_THRESHOLD &&
549 (scsi_hosts[SCpnt->host].unchecked_isa_dma)) {
550 buff = scsi_malloc(this_count << 9);
551 if(buff == NULL) panic("Ran out of DMA buffers.");
552 if (SCpnt->request.cmd == WRITE)
553 memcpy(buff, (char *)SCpnt->request.buffer, this_count << 9);
554 };
555 };
556
557 #ifdef DEBUG
558 printk("sd%d : %s %d/%d 512 byte blocks.\n", MINOR(SCpnt->request.dev),
559 (SCpnt->request.cmd == WRITE) ? "writing" : "reading",
560 this_count, SCpnt->request.nr_sectors);
561 #endif
562
563 cmd[1] = (SCpnt->lun << 5) & 0xe0;
564
565 if (((this_count > 0xff) || (block > 0x1fffff)) && rscsi_disks[dev].ten)
566 {
567 if (this_count > 0xffff)
568 this_count = 0xffff;
569
570 cmd[0] += READ_10 - READ_6 ;
571 cmd[2] = (unsigned char) (block >> 24) & 0xff;
572 cmd[3] = (unsigned char) (block >> 16) & 0xff;
573 cmd[4] = (unsigned char) (block >> 8) & 0xff;
574 cmd[5] = (unsigned char) block & 0xff;
575 cmd[6] = cmd[9] = 0;
576 cmd[7] = (unsigned char) (this_count >> 8) & 0xff;
577 cmd[8] = (unsigned char) this_count & 0xff;
578 }
579 else
580 {
581 if (this_count > 0xff)
582 this_count = 0xff;
583
584 cmd[1] |= (unsigned char) ((block >> 16) & 0x1f);
585 cmd[2] = (unsigned char) ((block >> 8) & 0xff);
586 cmd[3] = (unsigned char) block & 0xff;
587 cmd[4] = (unsigned char) this_count;
588 cmd[5] = 0;
589 }
590
591 scsi_do_cmd (SCpnt, (void *) cmd, buff, this_count << 9,
592 rw_intr, SD_TIMEOUT, MAX_RETRIES);
593 }
594
595 int check_scsidisk_media_change(int full_dev, int flag){
596 int retval;
597 int target;
598 struct inode inode;
599
600 target = DEVICE_NR(MINOR(full_dev));
601
602 if (target >= NR_SD) {
603 printk("SCSI disk request error: invalid device.\n");
604 return 0;
605 };
606
607 if(!rscsi_disks[target].device->removable) return 0;
608
609 inode.i_rdev = full_dev;
610 retval = sd_ioctl(&inode, NULL, SCSI_IOCTL_TEST_UNIT_READY, 0);
611
612 if(retval){
613
614
615
616
617 rscsi_disks[target].device->changed = 1;
618 return 1;
619
620 };
621
622 retval = rscsi_disks[target].device->changed;
623 if(!flag) rscsi_disks[target].device->changed = 0;
624 return retval;
625 }
626
627 static void sd_init_done (Scsi_Cmnd * SCpnt)
628 {
629 struct request * req;
630 struct task_struct * p;
631
632 req = &SCpnt->request;
633 req->dev = 0xfffe;
634
635 if ((p = req->waiting) != NULL) {
636 req->waiting = NULL;
637 p->state = TASK_RUNNING;
638 if (p->counter > current->counter)
639 need_resched = 1;
640 }
641 }
642
643 static int sd_init_onedisk(int i)
644 {
645 int j = 0;
646 unsigned char cmd[10];
647 unsigned char buffer[513];
648 int the_result, retries;
649 Scsi_Cmnd * SCpnt;
650
651
652
653
654
655 SCpnt = allocate_device(NULL, rscsi_disks[i].device->index, 1);
656
657 retries = 3;
658 do {
659 cmd[0] = READ_CAPACITY;
660 cmd[1] = (rscsi_disks[i].device->lun << 5) & 0xe0;
661 memset ((void *) &cmd[2], 0, 8);
662 SCpnt->request.dev = 0xffff;
663
664 scsi_do_cmd (SCpnt,
665 (void *) cmd, (void *) buffer,
666 512, sd_init_done, SD_TIMEOUT,
667 MAX_RETRIES);
668
669 if (current == task[0])
670 while(SCpnt->request.dev != 0xfffe);
671 else
672 if (SCpnt->request.dev != 0xfffe){
673 SCpnt->request.waiting = current;
674 current->state = TASK_UNINTERRUPTIBLE;
675 while (SCpnt->request.dev != 0xfffe) schedule();
676 };
677
678 the_result = SCpnt->result;
679 retries--;
680
681 } while(the_result && retries);
682
683 SCpnt->request.dev = -1;
684
685 wake_up(&scsi_devices[SCpnt->index].device_wait);
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702 if (the_result)
703 {
704 printk ("sd%d : READ CAPACITY failed.\n"
705 "sd%d : status = %x, message = %02x, host = %02x, driver = %02x \n",
706 i,i,
707 rscsi_disks[i].device->host_no, rscsi_disks[i].device->id,
708 rscsi_disks[i].device->lun,
709 status_byte(the_result),
710 msg_byte(the_result),
711 host_byte(the_result),
712 driver_byte(the_result)
713 );
714 if (driver_byte(the_result) & DRIVER_SENSE)
715 printk("sd%d : extended sense code = %1x \n", i, SCpnt->sense_buffer[2] & 0xf);
716 else
717 printk("sd%d : sense not available. \n", i);
718
719 printk("sd%d : block size assumed to be 512 bytes, disk size 1GB. \n", i);
720 rscsi_disks[i].capacity = 0xfffff;
721 rscsi_disks[i].sector_size = 512;
722 }
723 else
724 {
725 rscsi_disks[i].capacity = (buffer[0] << 24) |
726 (buffer[1] << 16) |
727 (buffer[2] << 8) |
728 buffer[3];
729
730 if ((rscsi_disks[i].sector_size = (buffer[4] << 24) |
731 (buffer[5] << 16) |
732 (buffer[6] << 8) |
733 buffer[7]) != 512)
734 {
735 printk ("sd%d : unsupported sector size %d.\n",
736 i, rscsi_disks[i].sector_size);
737 if(rscsi_disks[i].device->removable){
738 rscsi_disks[i].capacity = 0;
739 } else {
740 printk ("scsi : deleting disk entry.\n");
741 for (j=i; j < NR_SD - 1;)
742 rscsi_disks[j] = rscsi_disks[++j];
743 --i;
744 --NR_SD;
745 return i;
746 };
747 }
748 }
749
750 rscsi_disks[i].ten = 1;
751 rscsi_disks[i].remap = 1;
752 return i;
753 }
754
755
756
757
758
759
760 unsigned long sd_init(unsigned long memory_start, unsigned long memory_end)
761 {
762 int i;
763
764 blkdev_fops[MAJOR_NR] = &sd_fops;
765 if (MAX_SD == 0) return memory_start;
766
767 sd_sizes = (int *) memory_start;
768 memory_start += (MAX_SD << 4) * sizeof(int);
769 memset(sd_sizes, 0, (MAX_SD << 4) * sizeof(int));
770
771 sd = (struct hd_struct *) memory_start;
772 memory_start += (MAX_SD << 4) * sizeof(struct hd_struct);
773
774 sd_gendisk.max_nr = MAX_SD;
775 sd_gendisk.part = sd;
776 sd_gendisk.sizes = sd_sizes;
777 sd_gendisk.real_devices = (void *) rscsi_disks;
778
779 for (i = 0; i < NR_SD; ++i)
780 i = sd_init_onedisk(i);
781
782 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
783
784
785
786
787 if(scsi_hosts[rscsi_disks[0].device->host_no].sg_tablesize)
788 read_ahead[MAJOR_NR] = 16;
789 else
790 read_ahead[MAJOR_NR] = 4;
791
792 sd_gendisk.next = gendisk_head;
793 gendisk_head = &sd_gendisk;
794 return memory_start;
795 }
796
797 unsigned long sd_init1(unsigned long mem_start, unsigned long mem_end){
798 rscsi_disks = (Scsi_Disk *) mem_start;
799 mem_start += MAX_SD * sizeof(Scsi_Disk);
800 return mem_start;
801 };
802
803 void sd_attach(Scsi_Device * SDp){
804 rscsi_disks[NR_SD++].device = SDp;
805 if(NR_SD > MAX_SD) panic ("scsi_devices corrupt (sd)");
806 };
807
808 #define DEVICE_BUSY rscsi_disks[target].device->busy
809 #define USAGE rscsi_disks[target].device->access_count
810 #define CAPACITY rscsi_disks[target].capacity
811 #define MAYBE_REINIT sd_init_onedisk(target)
812 #define GENDISK_STRUCT sd_gendisk
813
814
815
816
817
818
819
820
821 int revalidate_scsidisk(int dev, int maxusage){
822 int target, major;
823 struct gendisk * gdev;
824 int max_p;
825 int start;
826 int i;
827
828 target = DEVICE_NR(MINOR(dev));
829 gdev = &GENDISK_STRUCT;
830
831 cli();
832 if (DEVICE_BUSY || USAGE > maxusage) {
833 sti();
834 printk("Device busy for revalidation (usage=%d)\n", USAGE);
835 return -EBUSY;
836 };
837 DEVICE_BUSY = 1;
838 sti();
839
840 max_p = gdev->max_p;
841 start = target << gdev->minor_shift;
842 major = MAJOR_NR << 8;
843
844 for (i=max_p - 1; i >=0 ; i--) {
845 sync_dev(major | start | i);
846 invalidate_inodes(major | start | i);
847 invalidate_buffers(major | start | i);
848 gdev->part[start+i].start_sect = 0;
849 gdev->part[start+i].nr_sects = 0;
850 };
851
852 #ifdef MAYBE_REINIT
853 MAYBE_REINIT;
854 #endif
855
856 gdev->part[start].nr_sects = CAPACITY;
857 resetup_one_dev(gdev, target);
858
859 DEVICE_BUSY = 0;
860 return 0;
861 }