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

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