2 * sr.c Copyright (C) 1992 David Giller
3 * Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
6 * sd.c Copyright (C) 1992 Drew Eckhardt
7 * Linux scsi disk driver by
8 * Drew Eckhardt <drew@colorado.edu>
10 * Modified by Eric Youngdale ericy@andante.org to
11 * add scatter-gather, multiple outstanding request, and other
14 * Modified by Eric Youngdale eric@andante.org to support loadable
15 * low-level scsi drivers.
17 * Modified by Thomas Quinot thomas@melchior.cuivre.fdn.fr to
20 * Modified by Gerd Knorr <kraxel@cs.tu-berlin.de> to support the
21 * generic cdrom interface
23 * Modified by Jens Axboe <axboe@suse.de> - Uniform sr_packet()
24 * interface, capabilities probe additions, ioctl cleanups, etc.
26 * Modified by Richard Gooch <rgooch@atnf.csiro.au> to support devfs
28 * Modified by Jens Axboe <axboe@suse.de> - support DVD-RAM
29 * transparently and lose the GHOST hack
31 * Modified by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
32 * check resource allocation in sr_init and some cleanups
35 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
40 #include <linux/bio.h>
41 #include <linux/string.h>
42 #include <linux/errno.h>
43 #include <linux/cdrom.h>
44 #include <linux/interrupt.h>
45 #include <linux/init.h>
46 #include <linux/blkdev.h>
47 #include <asm/uaccess.h>
49 #include <scsi/scsi.h>
50 #include <scsi/scsi_dbg.h>
51 #include <scsi/scsi_device.h>
52 #include <scsi/scsi_driver.h>
53 #include <scsi/scsi_cmnd.h>
54 #include <scsi/scsi_eh.h>
55 #include <scsi/scsi_host.h>
56 #include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
58 #include "scsi_logging.h"
65 #define SR_TIMEOUT (30 * HZ)
66 #define SR_CAPABILITIES \
67 (CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
68 CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
69 CDC_PLAY_AUDIO|CDC_RESET|CDC_IOCTLS|CDC_DRIVE_STATUS| \
70 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
71 CDC_MRW|CDC_MRW_W|CDC_RAM)
73 static int sr_probe(struct device *);
74 static int sr_remove(struct device *);
75 static int sr_init_command(struct scsi_cmnd *);
77 static struct scsi_driver sr_template = {
84 .init_command = sr_init_command,
87 static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
88 static DEFINE_SPINLOCK(sr_index_lock);
90 /* This semaphore is used to mediate the 0->1 reference get in the
91 * face of object destruction (i.e. we can't allow a get on an
92 * object after last put) */
93 static DECLARE_MUTEX(sr_ref_sem);
95 static int sr_open(struct cdrom_device_info *, int);
96 static void sr_release(struct cdrom_device_info *);
98 static void get_sectorsize(struct scsi_cd *);
99 static void get_capabilities(struct scsi_cd *);
101 static int sr_media_change(struct cdrom_device_info *, int);
102 static int sr_packet(struct cdrom_device_info *, struct packet_command *);
104 static struct cdrom_device_ops sr_dops = {
106 .release = sr_release,
107 .drive_status = sr_drive_status,
108 .media_changed = sr_media_change,
109 .tray_move = sr_tray_move,
110 .lock_door = sr_lock_door,
111 .select_speed = sr_select_speed,
112 .get_last_session = sr_get_last_session,
113 .get_mcn = sr_get_mcn,
115 .audio_ioctl = sr_audio_ioctl,
116 .dev_ioctl = sr_dev_ioctl,
117 .capability = SR_CAPABILITIES,
118 .generic_packet = sr_packet,
121 static void sr_kref_release(struct kref *kref);
123 static inline struct scsi_cd *scsi_cd(struct gendisk *disk)
125 return container_of(disk->private_data, struct scsi_cd, driver);
129 * The get and put routines for the struct scsi_cd. Note this entity
130 * has a scsi_device pointer and owns a reference to this.
132 static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
134 struct scsi_cd *cd = NULL;
137 if (disk->private_data == NULL)
141 if (scsi_device_get(cd->device))
146 kref_put(&cd->kref, sr_kref_release);
153 static inline void scsi_cd_put(struct scsi_cd *cd)
155 struct scsi_device *sdev = cd->device;
158 kref_put(&cd->kref, sr_kref_release);
159 scsi_device_put(sdev);
164 * This function checks to see if the media has been changed in the
165 * CDROM drive. It is possible that we have already sensed a change,
166 * or the drive may have sensed one and not yet reported it. We must
167 * be ready for either case. This function always reports the current
168 * value of the changed bit. If flag is 0, then the changed bit is reset.
169 * This function could be done as an ioctl, but we would need to have
170 * an inode for that to work, and we do not always have one.
173 int sr_media_change(struct cdrom_device_info *cdi, int slot)
175 struct scsi_cd *cd = cdi->handle;
178 if (CDSL_CURRENT != slot) {
179 /* no changer support */
183 retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES);
185 /* Unable to test, unit probably not ready. This usually
186 * means there is no disc in the drive. Mark as changed,
187 * and we will figure it out later once the drive is
188 * available again. */
189 cd->device->changed = 1;
190 return 1; /* This will force a flush, if called from
191 * check_disk_change */
194 retval = cd->device->changed;
195 cd->device->changed = 0;
196 /* If the disk changed, the capacity will now be different,
197 * so we force a re-read of this information */
199 /* check multisession offset etc */
208 * rw_intr is the interrupt routine for the device driver.
210 * It will be notified on the end of a SCSI read / write, and will take on
211 * of several actions based on success or failure.
213 static void rw_intr(struct scsi_cmnd * SCpnt)
215 int result = SCpnt->result;
216 int this_count = SCpnt->bufflen;
217 int good_bytes = (result == 0 ? this_count : 0);
218 int block_sectors = 0;
220 struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
223 printk("sr.c done: %x\n", result);
227 * Handle MEDIUM ERRORs or VOLUME OVERFLOWs that indicate partial
228 * success. Since this is a relatively rare error condition, no
229 * care is taken to avoid unnecessary additional work such as
230 * memcpy's that could be avoided.
232 if (driver_byte(result) != 0 && /* An error occurred */
233 (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */
234 switch (SCpnt->sense_buffer[2]) {
236 case VOLUME_OVERFLOW:
237 case ILLEGAL_REQUEST:
238 if (!(SCpnt->sense_buffer[0] & 0x90))
240 if (!blk_fs_request(SCpnt->request))
242 error_sector = (SCpnt->sense_buffer[3] << 24) |
243 (SCpnt->sense_buffer[4] << 16) |
244 (SCpnt->sense_buffer[5] << 8) |
245 SCpnt->sense_buffer[6];
246 if (SCpnt->request->bio != NULL)
248 bio_sectors(SCpnt->request->bio);
249 if (block_sectors < 4)
251 if (cd->device->sector_size == 2048)
253 error_sector &= ~(block_sectors - 1);
254 good_bytes = (error_sector - SCpnt->request->sector) << 9;
255 if (good_bytes < 0 || good_bytes >= this_count)
258 * The SCSI specification allows for the value
259 * returned by READ CAPACITY to be up to 75 2K
260 * sectors past the last readable block.
261 * Therefore, if we hit a medium error within the
262 * last 75 2K sectors, we decrease the saved size
265 if (error_sector < get_capacity(cd->disk) &&
266 cd->capacity - error_sector < 4 * 75)
267 set_capacity(cd->disk, error_sector);
270 case RECOVERED_ERROR:
273 * An error occured, but it recovered. Inform the
274 * user, but make sure that it's not treated as a
277 scsi_print_sense("sr", SCpnt);
279 SCpnt->sense_buffer[0] = 0x0;
280 good_bytes = this_count;
289 * This calls the generic completion function, now that we know
290 * how many actual sectors finished, and how many sectors we need
291 * to say have failed.
293 scsi_io_completion(SCpnt, good_bytes, block_sectors << 9);
296 static int sr_init_command(struct scsi_cmnd * SCpnt)
298 int block=0, this_count, s_size, timeout = SR_TIMEOUT;
299 struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
301 SCSI_LOG_HLQUEUE(1, printk("Doing sr request, dev = %s, block = %d\n",
302 cd->disk->disk_name, block));
304 if (!cd->device || !scsi_device_online(cd->device)) {
305 SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n",
306 SCpnt->request->nr_sectors));
307 SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));
311 if (cd->device->changed) {
313 * quietly refuse to do anything to a changed disc until the
314 * changed bit has been reset
320 * these are already setup, just copy cdb basically
322 if (SCpnt->request->flags & REQ_BLOCK_PC) {
323 scsi_setup_blk_pc_cmnd(SCpnt);
325 if (SCpnt->timeout_per_command)
326 timeout = SCpnt->timeout_per_command;
331 if (!(SCpnt->request->flags & REQ_CMD)) {
332 blk_dump_rq_flags(SCpnt->request, "sr unsup command");
337 * we do lazy blocksize switching (when reading XA sectors,
338 * see CDROMREADMODE2 ioctl)
340 s_size = cd->device->sector_size;
343 sr_set_blocklength(cd, 2048);
345 printk("sr: can't switch blocksize: in interrupt\n");
348 if (s_size != 512 && s_size != 1024 && s_size != 2048) {
349 scmd_printk(KERN_ERR, SCpnt, "bad sector size %d\n", s_size);
353 if (rq_data_dir(SCpnt->request) == WRITE) {
354 if (!cd->device->writeable)
356 SCpnt->cmnd[0] = WRITE_10;
357 SCpnt->sc_data_direction = DMA_TO_DEVICE;
358 cd->cdi.media_written = 1;
359 } else if (rq_data_dir(SCpnt->request) == READ) {
360 SCpnt->cmnd[0] = READ_10;
361 SCpnt->sc_data_direction = DMA_FROM_DEVICE;
363 blk_dump_rq_flags(SCpnt->request, "Unknown sr command");
368 struct scatterlist *sg = SCpnt->request_buffer;
370 for (i = 0; i < SCpnt->use_sg; i++)
371 size += sg[i].length;
373 if (size != SCpnt->request_bufflen && SCpnt->use_sg) {
374 scmd_printk(KERN_ERR, SCpnt,
375 "mismatch count %d, bytes %d\n",
376 size, SCpnt->request_bufflen);
377 if (SCpnt->request_bufflen > size)
378 SCpnt->request_bufflen = SCpnt->bufflen = size;
383 * request doesn't start on hw block boundary, add scatter pads
385 if (((unsigned int)SCpnt->request->sector % (s_size >> 9)) ||
386 (SCpnt->request_bufflen % s_size)) {
387 scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n");
391 this_count = (SCpnt->request_bufflen >> 9) / (s_size >> 9);
394 SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n",
396 (rq_data_dir(SCpnt->request) == WRITE) ?
397 "writing" : "reading",
398 this_count, SCpnt->request->nr_sectors));
401 block = (unsigned int)SCpnt->request->sector / (s_size >> 9);
403 if (this_count > 0xffff) {
405 SCpnt->request_bufflen = SCpnt->bufflen =
409 SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;
410 SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
411 SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
412 SCpnt->cmnd[5] = (unsigned char) block & 0xff;
413 SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
414 SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
415 SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
418 * We shouldn't disconnect in the middle of a sector, so with a dumb
419 * host adapter, it's safe to assume that we can at least transfer
420 * this many bytes between each connect / disconnect.
422 SCpnt->transfersize = cd->device->sector_size;
423 SCpnt->underflow = this_count << 9;
426 SCpnt->allowed = MAX_RETRIES;
427 SCpnt->timeout_per_command = timeout;
430 * This is the completion routine we use. This is matched in terms
431 * of capability to this function.
433 SCpnt->done = rw_intr;
436 * This indicates that the command is ready from our end to be
442 static int sr_block_open(struct inode *inode, struct file *file)
444 struct gendisk *disk = inode->i_bdev->bd_disk;
448 if(!(cd = scsi_cd_get(disk)))
451 if((ret = cdrom_open(&cd->cdi, inode, file)) != 0)
457 static int sr_block_release(struct inode *inode, struct file *file)
460 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
461 ret = cdrom_release(&cd->cdi, file);
470 static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
473 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
474 struct scsi_device *sdev = cd->device;
477 * Send SCSI addressing ioctls directly to mid level, send other
478 * ioctls to cdrom/block level.
481 case SCSI_IOCTL_GET_IDLUN:
482 case SCSI_IOCTL_GET_BUS_NUMBER:
483 return scsi_ioctl(sdev, cmd, (void __user *)arg);
485 return cdrom_ioctl(file, &cd->cdi, inode, cmd, arg);
488 static int sr_block_media_changed(struct gendisk *disk)
490 struct scsi_cd *cd = scsi_cd(disk);
491 return cdrom_media_changed(&cd->cdi);
494 static struct block_device_operations sr_bdops =
496 .owner = THIS_MODULE,
497 .open = sr_block_open,
498 .release = sr_block_release,
499 .ioctl = sr_block_ioctl,
500 .media_changed = sr_block_media_changed,
502 * No compat_ioctl for now because sr_block_ioctl never
503 * seems to pass arbitary ioctls down to host drivers.
507 static int sr_open(struct cdrom_device_info *cdi, int purpose)
509 struct scsi_cd *cd = cdi->handle;
510 struct scsi_device *sdev = cd->device;
514 * If the device is in error recovery, wait until it is done.
515 * If the device is offline, then disallow any access to it.
518 if (!scsi_block_when_processing_errors(sdev))
527 static void sr_release(struct cdrom_device_info *cdi)
529 struct scsi_cd *cd = cdi->handle;
531 if (cd->device->sector_size > 2048)
532 sr_set_blocklength(cd, 2048);
536 static int sr_probe(struct device *dev)
538 struct scsi_device *sdev = to_scsi_device(dev);
539 struct gendisk *disk;
544 if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
548 cd = kmalloc(sizeof(*cd), GFP_KERNEL);
551 memset(cd, 0, sizeof(*cd));
553 kref_init(&cd->kref);
555 disk = alloc_disk(1);
559 spin_lock(&sr_index_lock);
560 minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
561 if (minor == SR_DISKS) {
562 spin_unlock(&sr_index_lock);
566 __set_bit(minor, sr_index_bits);
567 spin_unlock(&sr_index_lock);
569 disk->major = SCSI_CDROM_MAJOR;
570 disk->first_minor = minor;
571 sprintf(disk->disk_name, "sr%d", minor);
572 disk->fops = &sr_bdops;
573 disk->flags = GENHD_FL_CD;
577 cd->driver = &sr_template;
579 cd->capacity = 0x1fffff;
580 cd->device->changed = 1; /* force recheck CD type */
582 cd->readcd_known = 0;
585 cd->cdi.ops = &sr_dops;
588 cd->cdi.capacity = 1;
589 sprintf(cd->cdi.name, "sr%d", minor);
591 sdev->sector_size = 2048; /* A guess, just in case */
593 /* FIXME: need to handle a get_capabilities failure properly ?? */
594 get_capabilities(cd);
597 snprintf(disk->devfs_name, sizeof(disk->devfs_name),
598 "%s/cd", sdev->devfs_name);
599 disk->driverfs_dev = &sdev->sdev_gendev;
600 set_capacity(disk, cd->capacity);
601 disk->private_data = &cd->driver;
602 disk->queue = sdev->request_queue;
605 if (register_cdrom(&cd->cdi))
608 dev_set_drvdata(dev, cd);
609 disk->flags |= GENHD_FL_REMOVABLE;
612 sdev_printk(KERN_DEBUG, sdev,
613 "Attached scsi CD-ROM %s\n", cd->cdi.name);
625 static void get_sectorsize(struct scsi_cd *cd)
627 unsigned char cmd[10];
628 unsigned char *buffer;
629 int the_result, retries = 3;
631 request_queue_t *queue;
633 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
638 cmd[0] = READ_CAPACITY;
639 memset((void *) &cmd[1], 0, 9);
640 memset(buffer, 0, 8);
642 /* Do the command and wait.. */
643 the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
644 buffer, 8, NULL, SR_TIMEOUT,
649 } while (the_result && retries);
653 cd->capacity = 0x1fffff;
654 sector_size = 2048; /* A guess, just in case */
657 if (cdrom_get_last_written(&cd->cdi,
660 cd->capacity = 1 + ((buffer[0] << 24) |
664 sector_size = (buffer[4] << 24) |
665 (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
666 switch (sector_size) {
668 * HP 4020i CD-Recorder reports 2340 byte sectors
669 * Philips CD-Writers report 2352 byte sectors
671 * Use 2k sectors for them..
684 printk("%s: unsupported sector size %d.\n",
685 cd->cdi.name, sector_size);
689 cd->device->sector_size = sector_size;
692 * Add this so that we have the ability to correctly gauge
693 * what the device is capable of.
695 set_capacity(cd->disk, cd->capacity);
698 queue = cd->device->request_queue;
699 blk_queue_hardsect_size(queue, sector_size);
705 cd->capacity = 0x1fffff;
706 cd->device->sector_size = 2048; /* A guess, just in case */
710 static void get_capabilities(struct scsi_cd *cd)
712 unsigned char *buffer;
713 struct scsi_mode_data data;
714 unsigned char cmd[MAX_COMMAND_SIZE];
715 struct scsi_sense_hdr sshdr;
716 unsigned int the_result;
719 static const char *loadmech[] =
732 /* allocate transfer buffer */
733 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
735 printk(KERN_ERR "sr: out of memory.\n");
739 /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION
740 * conditions are gone, or a timeout happens
744 memset((void *)cmd, 0, MAX_COMMAND_SIZE);
745 cmd[0] = TEST_UNIT_READY;
747 the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL,
748 0, &sshdr, SR_TIMEOUT,
752 } while (retries < 5 &&
753 (!scsi_status_is_good(the_result) ||
754 (scsi_sense_valid(&sshdr) &&
755 sshdr.sense_key == UNIT_ATTENTION)));
757 /* ask for mode page 0x2a */
758 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
759 SR_TIMEOUT, 3, &data, NULL);
761 if (!scsi_status_is_good(rc)) {
762 /* failed, drive doesn't have capabilities mode page */
764 cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
765 CDC_DVD | CDC_DVD_RAM |
766 CDC_SELECT_DISC | CDC_SELECT_SPEED);
768 printk("%s: scsi-1 drive\n", cd->cdi.name);
772 n = data.header_length + data.block_descriptor_length;
773 cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
774 cd->readcd_known = 1;
775 cd->readcd_cdda = buffer[n + 5] & 0x01;
776 /* print some capability bits */
777 printk("%s: scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n", cd->cdi.name,
778 ((buffer[n + 14] << 8) + buffer[n + 15]) / 176,
780 buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */
781 buffer[n + 3] & 0x20 ? "dvd-ram " : "",
782 buffer[n + 2] & 0x02 ? "cd/rw " : "", /* can read rewriteable */
783 buffer[n + 4] & 0x20 ? "xa/form2 " : "", /* can read xa/from2 */
784 buffer[n + 5] & 0x01 ? "cdda " : "", /* can read audio data */
785 loadmech[buffer[n + 6] >> 5]);
786 if ((buffer[n + 6] >> 5) == 0)
787 /* caddy drives can't close tray... */
788 cd->cdi.mask |= CDC_CLOSE_TRAY;
789 if ((buffer[n + 2] & 0x8) == 0)
790 /* not a DVD drive */
791 cd->cdi.mask |= CDC_DVD;
792 if ((buffer[n + 3] & 0x20) == 0)
793 /* can't write DVD-RAM media */
794 cd->cdi.mask |= CDC_DVD_RAM;
795 if ((buffer[n + 3] & 0x10) == 0)
796 /* can't write DVD-R media */
797 cd->cdi.mask |= CDC_DVD_R;
798 if ((buffer[n + 3] & 0x2) == 0)
799 /* can't write CD-RW media */
800 cd->cdi.mask |= CDC_CD_RW;
801 if ((buffer[n + 3] & 0x1) == 0)
802 /* can't write CD-R media */
803 cd->cdi.mask |= CDC_CD_R;
804 if ((buffer[n + 6] & 0x8) == 0)
806 cd->cdi.mask |= CDC_OPEN_TRAY;
808 if ((buffer[n + 6] >> 5) == mechtype_individual_changer ||
809 (buffer[n + 6] >> 5) == mechtype_cartridge_changer)
811 cdrom_number_of_slots(&cd->cdi);
812 if (cd->cdi.capacity <= 1)
814 cd->cdi.mask |= CDC_SELECT_DISC;
815 /*else I don't think it can close its tray
816 cd->cdi.mask |= CDC_CLOSE_TRAY; */
819 * if DVD-RAM, MRW-W or CD-RW, we are randomly writable
821 if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
822 (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
823 cd->device->writeable = 1;
830 * sr_packet() is the entry point for the generic commands generated
831 * by the Uniform CD-ROM layer.
833 static int sr_packet(struct cdrom_device_info *cdi,
834 struct packet_command *cgc)
836 if (cgc->timeout <= 0)
837 cgc->timeout = IOCTL_TIMEOUT;
839 sr_do_ioctl(cdi->handle, cgc);
845 * sr_kref_release - Called to free the scsi_cd structure
846 * @kref: pointer to embedded kref
848 * sr_ref_sem must be held entering this routine. Because it is
849 * called on last put, you should always use the scsi_cd_get()
850 * scsi_cd_put() helpers which manipulate the semaphore directly
851 * and never do a direct kref_put().
853 static void sr_kref_release(struct kref *kref)
855 struct scsi_cd *cd = container_of(kref, struct scsi_cd, kref);
856 struct gendisk *disk = cd->disk;
858 spin_lock(&sr_index_lock);
859 clear_bit(disk->first_minor, sr_index_bits);
860 spin_unlock(&sr_index_lock);
862 unregister_cdrom(&cd->cdi);
864 disk->private_data = NULL;
871 static int sr_remove(struct device *dev)
873 struct scsi_cd *cd = dev_get_drvdata(dev);
875 del_gendisk(cd->disk);
878 kref_put(&cd->kref, sr_kref_release);
884 static int __init init_sr(void)
888 rc = register_blkdev(SCSI_CDROM_MAJOR, "sr");
891 return scsi_register_driver(&sr_template.gendrv);
894 static void __exit exit_sr(void)
896 scsi_unregister_driver(&sr_template.gendrv);
897 unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
900 module_init(init_sr);
901 module_exit(exit_sr);
902 MODULE_LICENSE("GPL");