root/drivers/scsi/sr.c

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

DEFINITIONS

This source file includes following definitions.
  1. sr_release
  2. check_cdrom_media_change
  3. rw_intr
  4. sr_photocd
  5. sr_open
  6. do_sr_request
  7. requeue_sr_request
  8. sr_detect
  9. sr_attach
  10. sr_init_done
  11. get_sectorsize
  12. sr_init
  13. sr_finish
  14. sr_detach
  15. init_module
  16. cleanup_module

   1 /*
   2  *  sr.c Copyright (C) 1992 David Giller
   3  *           Copyright (C) 1993, 1994, 1995 Eric Youngdale
   4  *
   5  *  adapted from:
   6  *      sd.c Copyright (C) 1992 Drew Eckhardt 
   7  *      Linux scsi disk driver by
   8  *              Drew Eckhardt <drew@colorado.edu>
   9  *
  10  *      Modified by Eric Youngdale ericy@cais.com to
  11  *      add scatter-gather, multiple outstanding request, and other
  12  *      enhancements.
  13  *
  14  *          Modified by Eric Youngdale eric@aib.com to support loadable
  15  *          low-level scsi drivers.
  16  *
  17  *       Modified by Thomas Quinot thomas@melchior.frmug.fr.net to
  18  *       provide auto-eject.
  19  *
  20  */
  21 
  22 #include <linux/module.h>
  23 
  24 #include <linux/fs.h>
  25 #include <linux/kernel.h>
  26 #include <linux/sched.h>
  27 #include <linux/mm.h>
  28 #include <linux/string.h>
  29 #include <linux/errno.h>
  30 #include <linux/cdrom.h>
  31 #include <asm/system.h>
  32 
  33 #define MAJOR_NR SCSI_CDROM_MAJOR
  34 #include <linux/blk.h>
  35 #include "scsi.h"
  36 #include "hosts.h"
  37 #include "sr.h"
  38 #include "scsi_ioctl.h"   /* For the door lock/unlock commands */
  39 #include "constants.h"
  40 
  41 #define MAX_RETRIES 3
  42 #define SR_TIMEOUT (150 * HZ)
  43 
  44 static int sr_init(void);
  45 static void sr_finish(void);
  46 static int sr_attach(Scsi_Device *);
  47 static int sr_detect(Scsi_Device *);
  48 static void sr_detach(Scsi_Device *);
  49 
  50 struct Scsi_Device_Template sr_template = {NULL, "cdrom", "sr", NULL, TYPE_ROM, 
  51                                                SCSI_CDROM_MAJOR, 0, 0, 0, 1,
  52                                                sr_detect, sr_init,
  53                                                sr_finish, sr_attach, sr_detach};
  54 
  55 Scsi_CD * scsi_CDs = NULL;
  56 static int * sr_sizes;
  57 
  58 static int * sr_blocksizes;
  59 
  60 static int sr_open(struct inode *, struct file *);
  61 static void get_sectorsize(int);
  62 
  63 extern int sr_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
  64 
  65 void requeue_sr_request (Scsi_Cmnd * SCpnt);
  66 static int check_cdrom_media_change(kdev_t);
  67 
  68 static void sr_release(struct inode * inode, struct file * file)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 {
  70         sync_dev(inode->i_rdev);
  71         if(! --scsi_CDs[MINOR(inode->i_rdev)].device->access_count)
  72         {
  73             sr_ioctl(inode, NULL, SCSI_IOCTL_DOORUNLOCK, 0);
  74             if (scsi_CDs[MINOR(inode->i_rdev)].auto_eject)
  75                 sr_ioctl(inode, NULL, CDROMEJECT, 0);
  76         }
  77         if (scsi_CDs[MINOR(inode->i_rdev)].device->host->hostt->usage_count)
  78             (*scsi_CDs[MINOR(inode->i_rdev)].device->host->hostt->usage_count)--;
  79         if(sr_template.usage_count) (*sr_template.usage_count)--;
  80 }
  81 
  82 static struct file_operations sr_fops = 
  83 {
  84         NULL,                   /* lseek - default */
  85         block_read,             /* read - general block-dev read */
  86         block_write,            /* write - general block-dev write */
  87         NULL,                   /* readdir - bad */
  88         NULL,                   /* select */
  89         sr_ioctl,               /* ioctl */
  90         NULL,                   /* mmap */
  91         sr_open,        /* special open code */
  92         sr_release,             /* release */
  93         NULL,                   /* fsync */
  94         NULL,                   /* fasync */
  95         check_cdrom_media_change,  /* Disk change */
  96         NULL                    /* revalidate */
  97 };
  98 
  99 /*
 100  * This function checks to see if the media has been changed in the
 101  * CDROM drive.  It is possible that we have already sensed a change,
 102  * or the drive may have sensed one and not yet reported it.  We must
 103  * be ready for either case. This function always reports the current
 104  * value of the changed bit.  If flag is 0, then the changed bit is reset.
 105  * This function could be done as an ioctl, but we would need to have
 106  * an inode for that to work, and we do not always have one.
 107  */
 108 
 109 int check_cdrom_media_change(kdev_t full_dev){
     /* [previous][next][first][last][top][bottom][index][help] */
 110         int retval, target;
 111         struct inode inode;
 112         int flag = 0;
 113     
 114         target =  MINOR(full_dev);
 115     
 116         if (target >= sr_template.nr_dev) {
 117                 printk("CD-ROM request error: invalid device.\n");
 118                 return 0;
 119         };
 120     
 121         inode.i_rdev = full_dev;  /* This is all we really need here */
 122         retval = sr_ioctl(&inode, NULL, SCSI_IOCTL_TEST_UNIT_READY, 0);
 123     
 124         if(retval){ /* Unable to test, unit probably not ready.  This usually
 125                  * means there is no disc in the drive.  Mark as changed,
 126                  * and we will figure it out later once the drive is
 127                  * available again.  */
 128         
 129         scsi_CDs[target].device->changed = 1;
 130         return 1; /* This will force a flush, if called from
 131                    * check_disk_change */
 132         };
 133     
 134         retval = scsi_CDs[target].device->changed;
 135         if(!flag) {
 136         scsi_CDs[target].device->changed = 0;
 137         /* If the disk changed, the capacity will now be different,
 138          * so we force a re-read of this information */
 139         if (retval) scsi_CDs[target].needs_sector_size = 1;
 140         };
 141         return retval;
 142 }
 143 
 144 /*
 145  * rw_intr is the interrupt routine for the device driver.  It will be notified on the 
 146  * end of a SCSI read / write, and will take on of several actions based on success or failure.
 147  */
 148 
 149 static void rw_intr (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 {
 151         int result = SCpnt->result;
 152         int this_count = SCpnt->this_count;
 153     
 154 #ifdef DEBUG
 155         printk("sr.c done: %x %x\n",result, SCpnt->request.bh->b_data);
 156 #endif
 157         if (!result)
 158     { /* No error */
 159         if (SCpnt->use_sg == 0) {
 160                     if (SCpnt->buffer != SCpnt->request.buffer)
 161             {
 162                 int offset;
 163                 offset = (SCpnt->request.sector % 4) << 9;
 164                 memcpy((char *)SCpnt->request.buffer, 
 165                        (char *)SCpnt->buffer + offset, 
 166                        this_count << 9);
 167                 /* Even though we are not using scatter-gather, we look
 168                  * ahead and see if there is a linked request for the
 169                  * other half of this buffer.  If there is, then satisfy
 170                  * it. */
 171                 if((offset == 0) && this_count == 2 &&
 172                    SCpnt->request.nr_sectors > this_count && 
 173                    SCpnt->request.bh &&
 174                    SCpnt->request.bh->b_reqnext &&
 175                    SCpnt->request.bh->b_reqnext->b_size == 1024) {
 176                     memcpy((char *)SCpnt->request.bh->b_reqnext->b_data, 
 177                            (char *)SCpnt->buffer + 1024, 
 178                            1024);
 179                     this_count += 2;
 180                 };
 181                 
 182                 scsi_free(SCpnt->buffer, 2048);
 183             }
 184         } else {
 185                     struct scatterlist * sgpnt;
 186                     int i;
 187                     sgpnt = (struct scatterlist *) SCpnt->buffer;
 188                     for(i=0; i<SCpnt->use_sg; i++) {
 189                 if (sgpnt[i].alt_address) {
 190                     if (sgpnt[i].alt_address != sgpnt[i].address) {
 191                         memcpy(sgpnt[i].alt_address, sgpnt[i].address, sgpnt[i].length);
 192                     };
 193                     scsi_free(sgpnt[i].address, sgpnt[i].length);
 194                 };
 195                     };
 196                     scsi_free(SCpnt->buffer, SCpnt->sglist_len);  /* Free list of scatter-gather pointers */
 197                     if(SCpnt->request.sector % 4) this_count -= 2;
 198             /* See   if there is a padding record at the end that needs to be removed */
 199                     if(this_count > SCpnt->request.nr_sectors)
 200                 this_count -= 2;
 201         };
 202         
 203 #ifdef DEBUG
 204                 printk("(%x %x %x) ",SCpnt->request.bh, SCpnt->request.nr_sectors, 
 205                        this_count);
 206 #endif
 207                 if (SCpnt->request.nr_sectors > this_count)
 208         {        
 209                         SCpnt->request.errors = 0;
 210                         if (!SCpnt->request.bh)
 211                             panic("sr.c: linked page request (%lx %x)",
 212                       SCpnt->request.sector, this_count);
 213         }
 214         
 215         SCpnt = end_scsi_request(SCpnt, 1, this_count);  /* All done */
 216         requeue_sr_request(SCpnt);
 217         return;
 218     } /* Normal completion */
 219     
 220         /* We only come through here if we have an error of some kind */
 221     
 222     /* Free up any indirection buffers we allocated for DMA purposes. */
 223         if (SCpnt->use_sg) {
 224         struct scatterlist * sgpnt;
 225         int i;
 226         sgpnt = (struct scatterlist *) SCpnt->buffer;
 227         for(i=0; i<SCpnt->use_sg; i++) {
 228             if (sgpnt[i].alt_address) {
 229                 scsi_free(sgpnt[i].address, sgpnt[i].length);
 230             };
 231         };
 232         scsi_free(SCpnt->buffer, SCpnt->sglist_len);  /* Free list of scatter-gather pointers */
 233         } else {
 234         if (SCpnt->buffer != SCpnt->request.buffer)
 235             scsi_free(SCpnt->buffer, SCpnt->bufflen);
 236         };
 237     
 238         if (driver_byte(result) != 0) {
 239                 if ((SCpnt->sense_buffer[0] & 0x7f) == 0x70) {
 240                         if ((SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION) {
 241                                 /* detected disc change.  set a bit and quietly refuse 
 242                                  * further access.      */
 243                 
 244                                 scsi_CDs[DEVICE_NR(SCpnt->request.rq_dev)].device->changed = 1;
 245                                 SCpnt = end_scsi_request(SCpnt, 0, this_count);
 246                                 requeue_sr_request(SCpnt);
 247                                 return;
 248                         }
 249                 }
 250             
 251                 if (SCpnt->sense_buffer[2] == ILLEGAL_REQUEST) {
 252                         printk("CD-ROM error: ");
 253                         print_sense("sr", SCpnt);
 254                         printk("command was: ");
 255                         print_command(SCpnt->cmnd);
 256                         if (scsi_CDs[DEVICE_NR(SCpnt->request.rq_dev)].ten) {
 257                                 scsi_CDs[DEVICE_NR(SCpnt->request.rq_dev)].ten = 0;
 258                                 requeue_sr_request(SCpnt);
 259                                 result = 0;
 260                                 return;
 261                         } else {
 262                                 SCpnt = end_scsi_request(SCpnt, 0, this_count);
 263                                 requeue_sr_request(SCpnt); /* Do next request */
 264                                 return;
 265                         }
 266             
 267                 }
 268         
 269                 if (SCpnt->sense_buffer[2] == NOT_READY) {
 270                         printk("CDROM not ready.  Make sure you have a disc in the drive.\n");
 271                         SCpnt = end_scsi_request(SCpnt, 0, this_count);
 272                         requeue_sr_request(SCpnt); /* Do next request */
 273                         return;
 274                 };
 275     }
 276         
 277         /* We only get this far if we have an error we have not recognized */
 278         if(result) {
 279         printk("SCSI CD error : host %d id %d lun %d return code = %03x\n", 
 280                scsi_CDs[DEVICE_NR(SCpnt->request.rq_dev)].device->host->host_no, 
 281                scsi_CDs[DEVICE_NR(SCpnt->request.rq_dev)].device->id,
 282                scsi_CDs[DEVICE_NR(SCpnt->request.rq_dev)].device->lun,
 283                result);
 284             
 285         if (status_byte(result) == CHECK_CONDITION)
 286             print_sense("sr", SCpnt);
 287         
 288         SCpnt = end_scsi_request(SCpnt, 0, SCpnt->request.current_nr_sectors);
 289         requeue_sr_request(SCpnt);
 290     }
 291 }
 292 
 293 /*
 294  * Here I tried to implement better support for PhotoCD's.
 295  * 
 296  * Much of this has do be done with vendor-specific SCSI-commands.
 297  * So I have to complete it step by step. Useful information is welcome.
 298  *
 299  * Actually works:
 300  *   - NEC:     Detection and support of multisession CD's. Special handling
 301  *              for XA-disks is not necessary.
 302  *     
 303  *   - TOSHIBA: setting density is done here now, mounting PhotoCD's should
 304  *              work now without running the program "set_density"
 305  *              Multisession CD's are supported too.
 306  *
 307  *   kraxel@cs.tu-berlin.de (Gerd Knorr)
 308  */
 309 /*
 310  * 19950704 operator@melchior.frmug.fr.net (Thomas Quinot)
 311  *
 312  *   - SONY:    Same as Nec.
 313  *
 314  *   - PIONEER: works with SONY code
 315  */
 316 
 317 static void sr_photocd(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 318 {
 319     unsigned long   sector,min,sec,frame;
 320     unsigned char   buf[40];    /* the buffer for the ioctl */
 321     unsigned char   *cmd;       /* the scsi-command */
 322     unsigned char   *send;      /* the data we send to the drive ... */
 323     unsigned char   *rec;       /* ... and get back */
 324     int             rc,is_xa,no_multi;
 325     
 326     if (scsi_CDs[MINOR(inode->i_rdev)].xa_flags & 0x02) {
 327 #ifdef DEBUG
 328         printk("sr_photocd: CDROM and/or the driver does not support multisession CD's");
 329 #endif
 330         return;
 331     }
 332     
 333     if (!suser()) {
 334         /* I'm not the superuser, so SCSI_IOCTL_SEND_COMMAND isn't allowed for me.
 335          * That's why mpcd_sector will be initialized with zero, because I'm not
 336          * able to get the right value. Necessary only if access_count is 1, else
 337          * no disk change happened since the last call of this function and we can
 338          * keep the old value.
 339          */
 340         if (1 == scsi_CDs[MINOR(inode->i_rdev)].device->access_count) {
 341             scsi_CDs[MINOR(inode->i_rdev)].mpcd_sector = 0;
 342             scsi_CDs[MINOR(inode->i_rdev)].xa_flags &= ~0x01;
 343         }
 344         return;
 345     }
 346     
 347     sector   = 0;
 348     is_xa    = 0;
 349     no_multi = 0;
 350     cmd = rec = &buf[8];
 351     
 352     switch(scsi_CDs[MINOR(inode->i_rdev)].device->manufacturer) {
 353         
 354     case SCSI_MAN_NEC:
 355 #ifdef DEBUG
 356         printk("sr_photocd: use NEC code\n");
 357 #endif
 358         memset(buf,0,40);
 359         *((unsigned long*)buf)   = 0x0;   /* we send nothing...     */
 360         *((unsigned long*)buf+1) = 0x16;  /* and receive 0x16 bytes */
 361         cmd[0] = 0xde;
 362         cmd[1] = 0x03;
 363         cmd[2] = 0xb0;
 364         rc = kernel_scsi_ioctl(scsi_CDs[MINOR(inode->i_rdev)].device,
 365                            SCSI_IOCTL_SEND_COMMAND, buf);
 366         if (rc != 0) {
 367             printk("sr_photocd: ioctl error (NEC): 0x%x\n",rc);
 368             break;
 369         }
 370         if (rec[14] != 0 && rec[14] != 0xb0) {
 371             printk("sr_photocd: Hmm, seems the CDROM doesn't support multisession CD's\n");
 372             no_multi = 1;
 373             break;
 374         }
 375         min   = (unsigned long) rec[15]/16*10 + (unsigned long) rec[15]%16;
 376         sec   = (unsigned long) rec[16]/16*10 + (unsigned long) rec[16]%16;
 377         frame = (unsigned long) rec[17]/16*10 + (unsigned long) rec[17]%16;
 378         sector = min*CD_SECS*CD_FRAMES + sec*CD_FRAMES + frame;
 379         is_xa  = (rec[14] == 0xb0);
 380 #ifdef DEBUG
 381         if (sector) {
 382             printk("sr_photocd: multisession CD detected. start: %lu\n",sector);
 383         }
 384 #endif
 385         break;
 386         
 387     case SCSI_MAN_TOSHIBA:
 388 #ifdef DEBUG
 389         printk("sr_photocd: use TOSHIBA code\n");
 390 #endif
 391         
 392         /* we request some disc information (is it a XA-CD ?,
 393          * where starts the last session ?) */
 394         memset(buf,0,40);
 395         *((unsigned long*)buf)   = 0;
 396         *((unsigned long*)buf+1) = 4;  /* we receive 4 bytes from the drive */
 397         cmd[0] = 0xc7;
 398         cmd[1] = 3;
 399         rc = kernel_scsi_ioctl(scsi_CDs[MINOR(inode->i_rdev)].device,
 400                                SCSI_IOCTL_SEND_COMMAND, buf);
 401         if (rc != 0) {
 402             if (rc == 0x28000002) {
 403                 /* Got a "not ready" - error. No chance to find out if this is
 404                  * because there is no CD in the drive or because the drive
 405                  * don't knows multisession CD's. So I need to do an extra check... */
 406                 if (kernel_scsi_ioctl(scsi_CDs[MINOR(inode->i_rdev)].device,
 407                                       SCSI_IOCTL_TEST_UNIT_READY, NULL)) {
 408                     printk("sr_photocd: drive not ready\n");
 409                 } else {
 410                     printk("sr_photocd: Hmm, seems the CDROM doesn't support multisession CD's\n");
 411                     no_multi = 1;
 412                 }
 413             } else
 414                 printk("sr_photocd: ioctl error (TOSHIBA #1): 0x%x\n",rc);
 415             break; /* if the first ioctl fails, we don't call the second one */
 416         }
 417         is_xa  = (rec[0] == 0x20);
 418         min    = (unsigned long) rec[1]/16*10 + (unsigned long) rec[1]%16;
 419         sec    = (unsigned long) rec[2]/16*10 + (unsigned long) rec[2]%16;
 420         frame  = (unsigned long) rec[3]/16*10 + (unsigned long) rec[3]%16;
 421         sector = min*CD_SECS*CD_FRAMES + sec*CD_FRAMES + frame;
 422         if (sector) {
 423             sector -= CD_BLOCK_OFFSET;
 424 #ifdef DEBUG
 425             printk("sr_photocd: multisession CD detected: start: %lu\n",sector);
 426 #endif
 427         }
 428         
 429         /* now we do a get_density... */
 430         memset(buf,0,40);
 431         *((unsigned long*)buf)   = 0;
 432         *((unsigned long*)buf+1) = 12;
 433         cmd[0] = 0x1a;
 434         cmd[2] = 1;
 435         cmd[4] = 12;
 436         rc = kernel_scsi_ioctl(scsi_CDs[MINOR(inode->i_rdev)].device,
 437                                SCSI_IOCTL_SEND_COMMAND, buf);
 438         if (rc != 0) {
 439             printk("sr_photocd: ioctl error (TOSHIBA #2): 0x%x\n",rc);
 440             break;
 441         }
 442 #ifdef DEBUG
 443         printk("sr_photocd: get_density: 0x%x\n",rec[4]);
 444 #endif
 445         
 446         /* ...and only if necessary a set_density */
 447         if ((rec[4] != 0x81 && is_xa) || (rec[4] != 0 && !is_xa)) {
 448 #ifdef DEBUG
 449             printk("sr_photocd: doing set_density\n");
 450 #endif
 451             memset(buf,0,40);
 452             *((unsigned long*)buf)   = 12;  /* sending 12 bytes... */
 453             *((unsigned long*)buf+1) = 0;
 454             cmd[0] = 0x15;
 455             cmd[1] = (1 << 4);
 456             cmd[4] = 12;
 457             send = &cmd[6];                 /* this is a 6-Byte command          */
 458             send[ 3] = 0x08;                /* the data for the command          */
 459             send[ 4] = (is_xa) ? 0x81 : 0;  /* density 0x81 for XA-CD's, 0 else  */
 460             send[10] = 0x08;
 461             rc = kernel_scsi_ioctl(scsi_CDs[MINOR(inode->i_rdev)].device,
 462                                    SCSI_IOCTL_SEND_COMMAND, buf);
 463             if (rc != 0) {
 464                 printk("sr_photocd: ioctl error (TOSHIBA #3): 0x%x\n",rc);
 465             }
 466             /* The set_density command may have changed the sector size or capacity. */
 467             scsi_CDs[MINOR(inode->i_rdev)].needs_sector_size = 1;
 468         }
 469         break;
 470 
 471     case SCSI_MAN_SONY: /* Thomas QUINOT <thomas@melchior.frmug.fr.net> */
 472     case SCSI_MAN_PIONEER:
 473 #ifdef DEBUG
 474         printk("sr_photocd: use SONY/PIONEER code\n");
 475 #endif
 476         memset(buf,0,40);
 477         *((unsigned long*)buf)   = 0x0;   /* we send nothing...     */
 478         *((unsigned long*)buf+1) = 0x0c;  /* and receive 0x0c bytes */
 479         cmd[0] = 0x43; /* Read TOC */
 480         cmd[8] = 0x0c;
 481         cmd[9] = 0x40;
 482         rc = kernel_scsi_ioctl(scsi_CDs[MINOR(inode->i_rdev)].device,
 483                                SCSI_IOCTL_SEND_COMMAND, buf);
 484         
 485         if ((rc != 0) || ((rec[0] << 8) + rec[1] != 0x0a)) {
 486             printk("sr_photocd: ioctl error (SONY): 0x%x\n",rc);
 487             break;
 488         }
 489         sector = rec[11] + (rec[10] << 8) + (rec[9] << 16) + (rec[8] << 24);
 490         is_xa = !!sector;
 491 #ifdef DEBUG
 492         if (sector)
 493             printk ("sr_photocd: multisession CD detected. start: %lu\n",sector);
 494 #endif
 495         break;
 496                 
 497     case SCSI_MAN_NEC_OLDCDR:
 498     case SCSI_MAN_UNKNOWN:
 499     default:
 500         sector = 0;
 501         no_multi = 1;
 502         break; }
 503     
 504     scsi_CDs[MINOR(inode->i_rdev)].mpcd_sector = sector;
 505     if (is_xa)
 506         scsi_CDs[MINOR(inode->i_rdev)].xa_flags |= 0x01;
 507     else
 508         scsi_CDs[MINOR(inode->i_rdev)].xa_flags &= ~0x01;
 509     if (no_multi)
 510         scsi_CDs[MINOR(inode->i_rdev)].xa_flags |= 0x02;
 511     return;
 512 }
 513 
 514 static int sr_open(struct inode * inode, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
 515 {
 516         if(MINOR(inode->i_rdev) >= sr_template.nr_dev || 
 517            !scsi_CDs[MINOR(inode->i_rdev)].device) return -ENXIO;   /* No such device */
 518     
 519         if (filp->f_mode & 2)  
 520             return -EROFS;
 521     
 522     check_disk_change(inode->i_rdev);
 523     
 524         if(!scsi_CDs[MINOR(inode->i_rdev)].device->access_count++)
 525         sr_ioctl(inode, NULL, SCSI_IOCTL_DOORLOCK, 0);
 526         if (scsi_CDs[MINOR(inode->i_rdev)].device->host->hostt->usage_count)
 527         (*scsi_CDs[MINOR(inode->i_rdev)].device->host->hostt->usage_count)++;
 528         if(sr_template.usage_count) (*sr_template.usage_count)++;
 529     
 530         sr_photocd(inode);
 531     
 532         /* If this device did not have media in the drive at boot time, then
 533          * we would have been unable to get the sector size.  Check to see if
 534          * this is the case, and try again.
 535          */
 536     
 537         if(scsi_CDs[MINOR(inode->i_rdev)].needs_sector_size)
 538         get_sectorsize(MINOR(inode->i_rdev));
 539     
 540         return 0;
 541 }
 542 
 543 
 544 /*
 545  * do_sr_request() is the request handler function for the sr driver.
 546  * Its function in life is to take block device requests, and
 547  * translate them to SCSI commands.  
 548  */
 549 
 550 static void do_sr_request (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 551 {
 552     Scsi_Cmnd * SCpnt = NULL;
 553     struct request * req = NULL;
 554     Scsi_Device * SDev;
 555     unsigned long flags;
 556     int flag = 0;
 557     
 558     while (1==1){
 559         save_flags(flags);
 560         cli();
 561         if (CURRENT != NULL && CURRENT->rq_status == RQ_INACTIVE) {
 562             restore_flags(flags);
 563             return;
 564         };
 565         
 566         INIT_SCSI_REQUEST;
 567  
 568         SDev = scsi_CDs[DEVICE_NR(CURRENT->rq_dev)].device;
 569         
 570         /*
 571          * I am not sure where the best place to do this is.  We need
 572          * to hook in a place where we are likely to come if in user
 573          * space.
 574          */
 575         if( SDev->was_reset )
 576         {
 577             /*
 578              * We need to relock the door, but we might
 579              * be in an interrupt handler.  Only do this
 580              * from user space, since we do not want to
 581              * sleep from an interrupt.
 582              */
 583             if( SDev->removable && !intr_count )
 584             {
 585                 scsi_ioctl(SDev, SCSI_IOCTL_DOORLOCK, 0);
 586             }
 587             SDev->was_reset = 0;
 588         }
 589         
 590         if (flag++ == 0)
 591             SCpnt = allocate_device(&CURRENT,
 592                                     scsi_CDs[DEVICE_NR(CURRENT->rq_dev)].device, 0); 
 593         else SCpnt = NULL;
 594         restore_flags(flags);
 595         
 596         /* This is a performance enhancement.  We dig down into the request list and
 597          * try and find a queueable request (i.e. device not busy, and host able to
 598          * accept another command.  If we find one, then we queue it. This can
 599          * make a big difference on systems with more than one disk drive.  We want
 600          * to have the interrupts off when monkeying with the request list, because
 601          * otherwise the kernel might try and slip in a request in between somewhere. */
 602         
 603         if (!SCpnt && sr_template.nr_dev > 1){
 604             struct request *req1;
 605             req1 = NULL;
 606             save_flags(flags);
 607             cli();
 608             req = CURRENT;
 609             while(req){
 610                 SCpnt = request_queueable(req,
 611                                           scsi_CDs[DEVICE_NR(req->rq_dev)].device);
 612                 if(SCpnt) break;
 613                 req1 = req;
 614                 req = req->next;
 615             };
 616             if (SCpnt && req->rq_status == RQ_INACTIVE) {
 617                 if (req == CURRENT) 
 618                     CURRENT = CURRENT->next;
 619                 else
 620                     req1->next = req->next;
 621             };
 622             restore_flags(flags);
 623         };
 624         
 625         if (!SCpnt)
 626             return; /* Could not find anything to do */
 627         
 628         wake_up(&wait_for_request);
 629 
 630         /* Queue command */
 631         requeue_sr_request(SCpnt);
 632     };  /* While */
 633 }    
 634 
 635 void requeue_sr_request (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 636 {
 637         unsigned int dev, block, realcount;
 638         unsigned char cmd[10], *buffer, tries;
 639         int this_count, start, end_rec;
 640     
 641         tries = 2;
 642     
 643  repeat:
 644         if(!SCpnt || SCpnt->request.rq_status == RQ_INACTIVE) {
 645                 do_sr_request();
 646                 return;
 647         }
 648     
 649         dev =  MINOR(SCpnt->request.rq_dev);
 650         block = SCpnt->request.sector;  
 651         buffer = NULL;
 652         this_count = 0;
 653     
 654         if (dev >= sr_template.nr_dev) {
 655                 /* printk("CD-ROM request error: invalid device.\n");                   */
 656                 SCpnt = end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
 657                 tries = 2;
 658                 goto repeat;
 659         }
 660     
 661         if (!scsi_CDs[dev].use) {
 662                 /* printk("CD-ROM request error: device marked not in use.\n");         */
 663                 SCpnt = end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
 664                 tries = 2;
 665                 goto repeat;
 666         }
 667     
 668         if (scsi_CDs[dev].device->changed) {
 669         /* 
 670          * quietly refuse to do anything to a changed disc 
 671          * until the changed bit has been reset
 672          */
 673                 /* printk("CD-ROM has been changed.  Prohibiting further I/O.\n");      */
 674                 SCpnt = end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
 675                 tries = 2;
 676                 goto repeat;
 677         }
 678         
 679         switch (SCpnt->request.cmd)
 680     {
 681     case WRITE:                 
 682         SCpnt = end_scsi_request(SCpnt, 0, SCpnt->request.nr_sectors);
 683         goto repeat;
 684         break;
 685     case READ : 
 686         cmd[0] = READ_6;
 687         break;
 688     default : 
 689         panic ("Unknown sr command %d\n", SCpnt->request.cmd);
 690     }
 691         
 692         cmd[1] = (SCpnt->lun << 5) & 0xe0;
 693     
 694     /*
 695      * Now do the grungy work of figuring out which sectors we need, and
 696      * where in memory we are going to put them.
 697      * 
 698      * The variables we need are:
 699      * 
 700      * this_count= number of 512 byte sectors being read 
 701      * block     = starting cdrom sector to read.
 702      * realcount = # of cdrom sectors to read
 703      * 
 704      * The major difference between a scsi disk and a scsi cdrom
 705      * is that we will always use scatter-gather if we can, because we can
 706      * work around the fact that the buffer cache has a block size of 1024,
 707      * and we have 2048 byte sectors.  This code should work for buffers that
 708      * are any multiple of 512 bytes long.
 709      */
 710     
 711         SCpnt->use_sg = 0;
 712     
 713         if (SCpnt->host->sg_tablesize > 0 &&
 714             (!need_isa_buffer ||
 715          dma_free_sectors >= 10)) {
 716         struct buffer_head * bh;
 717         struct scatterlist * sgpnt;
 718         int count, this_count_max;
 719         bh = SCpnt->request.bh;
 720         this_count = 0;
 721         count = 0;
 722         this_count_max = (scsi_CDs[dev].ten ? 0xffff : 0xff) << 4;
 723         /* Calculate how many links we can use.  First see if we need
 724          * a padding record at the start */
 725         this_count = SCpnt->request.sector % 4;
 726         if(this_count) count++;
 727         while(bh && count < SCpnt->host->sg_tablesize) {
 728             if ((this_count + (bh->b_size >> 9)) > this_count_max) break;
 729             this_count += (bh->b_size >> 9);
 730             count++;
 731             bh = bh->b_reqnext;
 732         };
 733         /* Fix up in case of an odd record at the end */
 734         end_rec = 0;
 735         if(this_count % 4) {
 736             if (count < SCpnt->host->sg_tablesize) {
 737                 count++;
 738                 end_rec = (4 - (this_count % 4)) << 9;
 739                 this_count += 4 - (this_count % 4);
 740             } else {
 741                 count--;
 742                 this_count -= (this_count % 4);
 743             };
 744         };
 745         SCpnt->use_sg = count;  /* Number of chains */
 746         count = 512;/* scsi_malloc can only allocate in chunks of 512 bytes*/
 747         while( count < (SCpnt->use_sg * sizeof(struct scatterlist))) 
 748             count = count << 1;
 749         SCpnt->sglist_len = count;
 750         sgpnt = (struct scatterlist * ) scsi_malloc(count);
 751         if (!sgpnt) {
 752             printk("Warning - running *really* short on DMA buffers\n");
 753             SCpnt->use_sg = 0;  /* No memory left - bail out */
 754         } else {
 755             buffer = (unsigned char *) sgpnt;
 756             count = 0;
 757             bh = SCpnt->request.bh;
 758             if(SCpnt->request.sector % 4) {
 759                 sgpnt[count].length = (SCpnt->request.sector % 4) << 9;
 760                 sgpnt[count].address = (char *) scsi_malloc(sgpnt[count].length);
 761                 if(!sgpnt[count].address) panic("SCSI DMA pool exhausted.");
 762                 sgpnt[count].alt_address = sgpnt[count].address; /* Flag to delete
 763                                                                     if needed */
 764                 count++;
 765             };
 766             for(bh = SCpnt->request.bh; count < SCpnt->use_sg; 
 767                 count++, bh = bh->b_reqnext) {
 768                 if (bh) { /* Need a placeholder at the end of the record? */
 769                     sgpnt[count].address = bh->b_data;
 770                     sgpnt[count].length = bh->b_size;
 771                     sgpnt[count].alt_address = NULL;
 772                 } else {
 773                     sgpnt[count].address = (char *) scsi_malloc(end_rec);
 774                     if(!sgpnt[count].address) panic("SCSI DMA pool exhausted.");
 775                     sgpnt[count].length = end_rec;
 776                     sgpnt[count].alt_address = sgpnt[count].address;
 777                     if (count+1 != SCpnt->use_sg) panic("Bad sr request list");
 778                     break;
 779                 };
 780                 if (((long) sgpnt[count].address) + sgpnt[count].length > ISA_DMA_THRESHOLD &&
 781                   SCpnt->host->unchecked_isa_dma) {
 782                     sgpnt[count].alt_address = sgpnt[count].address;
 783                     /* We try and avoid exhausting the DMA pool, since it is easier
 784                      * to control usage here.  In other places we might have a more
 785                      * pressing need, and we would be screwed if we ran out */
 786                     if(dma_free_sectors < (sgpnt[count].length >> 9) + 5) {
 787                         sgpnt[count].address = NULL;
 788                     } else {
 789                         sgpnt[count].address = (char *) scsi_malloc(sgpnt[count].length);
 790                     };
 791                     /* If we start running low on DMA buffers, we abort the scatter-gather
 792                      * operation, and free all of the memory we have allocated.  We want to
 793                      * ensure that all scsi operations are able to do at least a non-scatter/gather
 794                      * operation */
 795                     if(sgpnt[count].address == NULL){ /* Out of dma memory */
 796                         printk("Warning: Running low on SCSI DMA buffers");
 797                         /* Try switching back to a non scatter-gather operation. */
 798                         while(--count >= 0){
 799                             if(sgpnt[count].alt_address) 
 800                                 scsi_free(sgpnt[count].address, sgpnt[count].length);
 801                         };
 802                         SCpnt->use_sg = 0;
 803                         scsi_free(buffer, SCpnt->sglist_len);
 804                         break;
 805                     }; /* if address == NULL */
 806                 };  /* if need DMA fixup */
 807             };  /* for loop to fill list */
 808 #ifdef DEBUG
 809             printk("SR: %d %d %d %d %d *** ",SCpnt->use_sg, SCpnt->request.sector,
 810                    this_count, 
 811                    SCpnt->request.current_nr_sectors,
 812                    SCpnt->request.nr_sectors);
 813             for(count=0; count<SCpnt->use_sg; count++)
 814                 printk("SGlist: %d %x %x %x\n", count,
 815                        sgpnt[count].address, 
 816                        sgpnt[count].alt_address, 
 817                        sgpnt[count].length);
 818 #endif
 819         };  /* Able to allocate scatter-gather list */
 820         };
 821         
 822         if (SCpnt->use_sg == 0){
 823         /* We cannot use scatter-gather.  Do this the old fashion way */
 824         if (!SCpnt->request.bh)         
 825             this_count = SCpnt->request.nr_sectors;
 826         else
 827             this_count = (SCpnt->request.bh->b_size >> 9);
 828         
 829         start = block % 4;
 830         if (start)
 831             {                             
 832             this_count = ((this_count > 4 - start) ? 
 833                           (4 - start) : (this_count));
 834             buffer = (unsigned char *) scsi_malloc(2048);
 835             } 
 836         else if (this_count < 4)
 837             {
 838             buffer = (unsigned char *) scsi_malloc(2048);
 839             }
 840         else
 841             {
 842             this_count -= this_count % 4;
 843             buffer = (unsigned char *) SCpnt->request.buffer;
 844             if (((long) buffer) + (this_count << 9) > ISA_DMA_THRESHOLD &&
 845                 SCpnt->host->unchecked_isa_dma)
 846                 buffer = (unsigned char *) scsi_malloc(this_count << 9);
 847             }
 848         };
 849     
 850         if (scsi_CDs[dev].sector_size == 2048)
 851         block = block >> 2; /* These are the sectors that the cdrom uses */
 852         else
 853         block = block & 0xfffffffc;
 854     
 855         realcount = (this_count + 3) / 4;
 856     
 857         if (scsi_CDs[dev].sector_size == 512) realcount = realcount << 2;
 858     
 859         if (((realcount > 0xff) || (block > 0x1fffff)) && scsi_CDs[dev].ten) 
 860     {
 861                 if (realcount > 0xffff)
 862         {
 863                         realcount = 0xffff;
 864                         this_count = realcount * (scsi_CDs[dev].sector_size >> 9);
 865         }
 866         
 867                 cmd[0] += READ_10 - READ_6 ;
 868                 cmd[2] = (unsigned char) (block >> 24) & 0xff;
 869                 cmd[3] = (unsigned char) (block >> 16) & 0xff;
 870                 cmd[4] = (unsigned char) (block >> 8) & 0xff;
 871                 cmd[5] = (unsigned char) block & 0xff;
 872                 cmd[6] = cmd[9] = 0;
 873                 cmd[7] = (unsigned char) (realcount >> 8) & 0xff;
 874                 cmd[8] = (unsigned char) realcount & 0xff;
 875     }
 876         else
 877     {
 878         if (realcount > 0xff)
 879         {
 880             realcount = 0xff;
 881             this_count = realcount * (scsi_CDs[dev].sector_size >> 9);
 882         }
 883         
 884         cmd[1] |= (unsigned char) ((block >> 16) & 0x1f);
 885         cmd[2] = (unsigned char) ((block >> 8) & 0xff);
 886         cmd[3] = (unsigned char) block & 0xff;
 887         cmd[4] = (unsigned char) realcount;
 888         cmd[5] = 0;
 889     }   
 890     
 891 #ifdef DEBUG
 892     { 
 893         int i;
 894         printk("ReadCD: %d %d %d %d\n",block, realcount, buffer, this_count);
 895         printk("Use sg: %d\n", SCpnt->use_sg);
 896         printk("Dumping command: ");
 897         for(i=0; i<12; i++) printk("%2.2x ", cmd[i]);
 898         printk("\n");
 899     };
 900 #endif
 901     
 902     /* Some dumb host adapters can speed transfers by knowing the
 903      * minimum transfersize in advance.
 904      *
 905      * We shouldn't disconnect in the middle of a sector, but the cdrom
 906      * sector size can be larger than the size of a buffer and the
 907      * transfer may be split to the size of a buffer.  So it's safe to
 908      * assume that we can at least transfer the minimum of the buffer
 909      * size (1024) and the sector size between each connect / disconnect.
 910      */
 911     
 912     SCpnt->transfersize = (scsi_CDs[dev].sector_size > 1024) ?
 913         1024 : scsi_CDs[dev].sector_size;
 914     
 915         SCpnt->this_count = this_count;
 916         scsi_do_cmd (SCpnt, (void *) cmd, buffer, 
 917                  realcount * scsi_CDs[dev].sector_size, 
 918                  rw_intr, SR_TIMEOUT, MAX_RETRIES);
 919 }
 920 
 921 static int sr_detect(Scsi_Device * SDp){
     /* [previous][next][first][last][top][bottom][index][help] */
 922     
 923     if(SDp->type != TYPE_ROM && SDp->type != TYPE_WORM) return 0;
 924     
 925     printk("Detected scsi CD-ROM sr%d at scsi%d, channel %d, id %d, lun %d\n", 
 926            sr_template.dev_noticed++,
 927            SDp->host->host_no, SDp->channel, SDp->id, SDp->lun); 
 928     
 929     return 1;
 930 }
 931 
 932 static int sr_attach(Scsi_Device * SDp){
     /* [previous][next][first][last][top][bottom][index][help] */
 933     Scsi_CD * cpnt;
 934     int i;
 935     
 936     if(SDp->type != TYPE_ROM && SDp->type != TYPE_WORM) return 1;
 937     
 938     if (sr_template.nr_dev >= sr_template.dev_max)
 939     {
 940         SDp->attached--;
 941         return 1;
 942     }
 943     
 944     for(cpnt = scsi_CDs, i=0; i<sr_template.dev_max; i++, cpnt++) 
 945         if(!cpnt->device) break;
 946     
 947     if(i >= sr_template.dev_max) panic ("scsi_devices corrupt (sr)");
 948     
 949     SDp->scsi_request_fn = do_sr_request;
 950     scsi_CDs[i].device = SDp;
 951     sr_template.nr_dev++;
 952     if(sr_template.nr_dev > sr_template.dev_max)
 953         panic ("scsi_devices corrupt (sr)");
 954     return 0;
 955 }
 956 
 957 
 958 static void sr_init_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 959 {
 960     struct request * req;
 961     
 962     req = &SCpnt->request;
 963     req->rq_status = RQ_SCSI_DONE; /* Busy, but indicate request done */
 964     
 965     if (req->sem != NULL) {
 966         up(req->sem);
 967     }
 968 }
 969 
 970 static void get_sectorsize(int i){
     /* [previous][next][first][last][top][bottom][index][help] */
 971     unsigned char cmd[10];
 972     unsigned char *buffer;
 973     int the_result, retries;
 974     Scsi_Cmnd * SCpnt;
 975     
 976     buffer = (unsigned char *) scsi_malloc(512);
 977     SCpnt = allocate_device(NULL, scsi_CDs[i].device, 1);
 978     
 979     retries = 3;
 980     do {
 981         cmd[0] = READ_CAPACITY;
 982         cmd[1] = (scsi_CDs[i].device->lun << 5) & 0xe0;
 983         memset ((void *) &cmd[2], 0, 8);
 984         SCpnt->request.rq_status = RQ_SCSI_BUSY;  /* Mark as really busy */
 985         SCpnt->cmd_len = 0;
 986         
 987         memset(buffer, 0, 8);
 988 
 989         /* Do the command and wait.. */
 990         {
 991             struct semaphore sem = MUTEX_LOCKED;
 992             SCpnt->request.sem = &sem;
 993             scsi_do_cmd (SCpnt,
 994                          (void *) cmd, (void *) buffer,
 995                          512, sr_init_done,  SR_TIMEOUT,
 996                          MAX_RETRIES);
 997             down(&sem);
 998         }
 999         
1000         the_result = SCpnt->result;
1001         retries--;
1002         
1003     } while(the_result && retries);
1004     
1005     SCpnt->request.rq_status = RQ_INACTIVE;  /* Mark as not busy */
1006     
1007     wake_up(&SCpnt->device->device_wait); 
1008     
1009     if (the_result) {
1010         scsi_CDs[i].capacity = 0x1fffff;
1011         scsi_CDs[i].sector_size = 2048;  /* A guess, just in case */
1012         scsi_CDs[i].needs_sector_size = 1;
1013     } else {
1014         scsi_CDs[i].capacity = (buffer[0] << 24) |
1015             (buffer[1] << 16) | (buffer[2] << 8) | buffer[3];
1016         scsi_CDs[i].sector_size = (buffer[4] << 24) |
1017             (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
1018         if(scsi_CDs[i].sector_size == 0) scsi_CDs[i].sector_size = 2048;
1019         if(scsi_CDs[i].sector_size != 2048 && 
1020            scsi_CDs[i].sector_size != 512) {
1021             printk ("scd%d : unsupported sector size %d.\n",
1022                     i, scsi_CDs[i].sector_size);
1023             scsi_CDs[i].capacity = 0;
1024             scsi_CDs[i].needs_sector_size = 1;
1025         };
1026         if(scsi_CDs[i].sector_size == 2048)
1027             scsi_CDs[i].capacity *= 4;
1028         scsi_CDs[i].needs_sector_size = 0;
1029         sr_sizes[i] = scsi_CDs[i].capacity;
1030     };
1031     scsi_free(buffer, 512);
1032 }
1033 
1034 static int sr_registered = 0;
1035 
1036 static int sr_init()
     /* [previous][next][first][last][top][bottom][index][help] */
1037 {
1038         int i;
1039     
1040         if(sr_template.dev_noticed == 0) return 0;
1041     
1042         if(!sr_registered) {
1043         if (register_blkdev(MAJOR_NR,"sr",&sr_fops)) {
1044             printk("Unable to get major %d for SCSI-CD\n",MAJOR_NR);
1045             return 1;
1046         }
1047         sr_registered++;
1048         }
1049     
1050         
1051         if (scsi_CDs) return 0;
1052         sr_template.dev_max = sr_template.dev_noticed + SR_EXTRA_DEVS;
1053         scsi_CDs = (Scsi_CD *) scsi_init_malloc(sr_template.dev_max * sizeof(Scsi_CD), GFP_ATOMIC);
1054         memset(scsi_CDs, 0, sr_template.dev_max * sizeof(Scsi_CD));
1055     
1056         sr_sizes = (int *) scsi_init_malloc(sr_template.dev_max * sizeof(int), GFP_ATOMIC);
1057         memset(sr_sizes, 0, sr_template.dev_max * sizeof(int));
1058     
1059         sr_blocksizes = (int *) scsi_init_malloc(sr_template.dev_max * 
1060                                              sizeof(int), GFP_ATOMIC);
1061         for(i=0;i<sr_template.dev_max;i++) sr_blocksizes[i] = 2048;
1062         blksize_size[MAJOR_NR] = sr_blocksizes;
1063         return 0;
1064 }
1065 
1066 void sr_finish()
     /* [previous][next][first][last][top][bottom][index][help] */
1067 {
1068     int i;
1069     
1070         blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
1071         blk_size[MAJOR_NR] = sr_sizes;  
1072     
1073         for (i = 0; i < sr_template.nr_dev; ++i)
1074     {
1075         /* If we have already seen this, then skip it.  Comes up
1076          * with loadable modules. */
1077         if (scsi_CDs[i].capacity) continue;
1078         scsi_CDs[i].capacity = 0x1fffff;
1079         scsi_CDs[i].sector_size = 2048;  /* A guess, just in case */
1080         scsi_CDs[i].needs_sector_size = 1;
1081 #if 0
1082         /* seems better to leave this for later */
1083         get_sectorsize(i);
1084         printk("Scd sectorsize = %d bytes.\n", scsi_CDs[i].sector_size);
1085 #endif
1086         scsi_CDs[i].use = 1;
1087         scsi_CDs[i].ten = 1;
1088         scsi_CDs[i].remap = 1;
1089         scsi_CDs[i].auto_eject = 0; /* Default is not to eject upon unmount. */
1090         sr_sizes[i] = scsi_CDs[i].capacity;
1091     }
1092     
1093     
1094         /* If our host adapter is capable of scatter-gather, then we increase
1095          * the read-ahead to 16 blocks (32 sectors).  If not, we use
1096          * a two block (4 sector) read ahead. */
1097         if(scsi_CDs[0].device && scsi_CDs[0].device->host->sg_tablesize)
1098         read_ahead[MAJOR_NR] = 32;  /* 32 sector read-ahead.  Always removable. */
1099         else
1100         read_ahead[MAJOR_NR] = 4;  /* 4 sector read-ahead */
1101     
1102         return;
1103 }       
1104 
1105 static void sr_detach(Scsi_Device * SDp)
     /* [previous][next][first][last][top][bottom][index][help] */
1106 {
1107     Scsi_CD * cpnt;
1108     int i;
1109     
1110     for(cpnt = scsi_CDs, i=0; i<sr_template.dev_max; i++, cpnt++) 
1111         if(cpnt->device == SDp) {
1112             kdev_t devi = MKDEV(MAJOR_NR, i);
1113 
1114             /*
1115              * Since the cdrom is read-only, no need to sync the device.
1116              * We should be kind to our buffer cache, however.
1117              */
1118             invalidate_inodes(devi);
1119             invalidate_buffers(devi);
1120             
1121             /*
1122              * Reset things back to a sane state so that one can re-load a new
1123              * driver (perhaps the same one).
1124              */
1125             cpnt->device = NULL;
1126             cpnt->capacity = 0;
1127             SDp->attached--;
1128             sr_template.nr_dev--;
1129             sr_template.dev_noticed--;
1130             sr_sizes[i] = 0;
1131             return;
1132         }
1133     return;
1134 }
1135 
1136 
1137 #ifdef MODULE
1138 
1139 int init_module(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
1140     sr_template.usage_count = &mod_use_count_;
1141     return scsi_register_module(MODULE_SCSI_DEV, &sr_template);
1142 }
1143 
1144 void cleanup_module( void) 
     /* [previous][next][first][last][top][bottom][index][help] */
1145 {
1146     if (MOD_IN_USE) {
1147         printk(KERN_INFO __FILE__ ": module is in use, remove rejected\n");
1148         return;
1149     }
1150     scsi_unregister_module(MODULE_SCSI_DEV, &sr_template);
1151     unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
1152     sr_registered--;
1153     if(scsi_CDs != NULL) {
1154         scsi_init_free((char *) scsi_CDs,
1155                        (sr_template.dev_noticed + SR_EXTRA_DEVS) 
1156                        * sizeof(Scsi_CD));
1157         
1158         scsi_init_free((char *) sr_sizes, sr_template.dev_max * sizeof(int));
1159         scsi_init_free((char *) sr_blocksizes, sr_template.dev_max * sizeof(int));
1160     }
1161     
1162     blksize_size[MAJOR_NR] = NULL;
1163     blk_dev[MAJOR_NR].request_fn = NULL;
1164     blk_size[MAJOR_NR] = NULL;  
1165     read_ahead[MAJOR_NR] = 0;
1166     
1167     sr_template.dev_max = 0;
1168 }
1169 #endif /* MODULE */
1170 
1171 /*
1172  * Overrides for Emacs so that we follow Linus's tabbing style.
1173  * Emacs will notice this stuff at the end of the file and automatically
1174  * adjust the settings for this buffer only.  This must remain at the end
1175  * of the file.
1176  * ---------------------------------------------------------------------------
1177  * Local variables:
1178  * c-indent-level: 4
1179  * c-brace-imaginary-offset: 0
1180  * c-brace-offset: -4
1181  * c-argdecl-indent: 4
1182  * c-label-offset: -4
1183  * c-continued-statement-offset: 4
1184  * c-continued-brace-offset: 0
1185  * indent-tabs-mode: nil
1186  * tab-width: 8
1187  * End:
1188  */

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