2019-05-19 20:08:20 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* sr.c Copyright (C) 1992 David Giller
|
|
|
|
* Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
|
|
|
|
*
|
|
|
|
* adapted from:
|
|
|
|
* sd.c Copyright (C) 1992 Drew Eckhardt
|
|
|
|
* Linux scsi disk driver by
|
|
|
|
* Drew Eckhardt <drew@colorado.edu>
|
|
|
|
*
|
|
|
|
* Modified by Eric Youngdale ericy@andante.org to
|
|
|
|
* add scatter-gather, multiple outstanding request, and other
|
|
|
|
* enhancements.
|
|
|
|
*
|
|
|
|
* Modified by Eric Youngdale eric@andante.org to support loadable
|
|
|
|
* low-level scsi drivers.
|
|
|
|
*
|
|
|
|
* Modified by Thomas Quinot thomas@melchior.cuivre.fdn.fr to
|
|
|
|
* provide auto-eject.
|
|
|
|
*
|
|
|
|
* Modified by Gerd Knorr <kraxel@cs.tu-berlin.de> to support the
|
|
|
|
* generic cdrom interface
|
|
|
|
*
|
|
|
|
* Modified by Jens Axboe <axboe@suse.de> - Uniform sr_packet()
|
|
|
|
* interface, capabilities probe additions, ioctl cleanups, etc.
|
|
|
|
*
|
|
|
|
* Modified by Richard Gooch <rgooch@atnf.csiro.au> to support devfs
|
|
|
|
*
|
|
|
|
* Modified by Jens Axboe <axboe@suse.de> - support DVD-RAM
|
|
|
|
* transparently and lose the GHOST hack
|
|
|
|
*
|
|
|
|
* Modified by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
* check resource allocation in sr_init and some cleanups
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/cdrom.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/blkdev.h>
|
2018-09-27 05:01:03 +08:00
|
|
|
#include <linux/blk-pm.h>
|
2006-01-11 20:16:10 +08:00
|
|
|
#include <linux/mutex.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2013-01-23 15:09:31 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_dbg.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
#include <scsi/scsi_driver.h>
|
2005-06-13 11:21:29 +08:00
|
|
|
#include <scsi/scsi_cmnd.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <scsi/scsi_eh.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
|
|
|
|
|
|
|
|
#include "scsi_logging.h"
|
|
|
|
#include "sr.h"
|
|
|
|
|
|
|
|
|
2006-03-08 16:14:20 +08:00
|
|
|
MODULE_DESCRIPTION("SCSI cdrom (sr) driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_CDROM_MAJOR);
|
[SCSI] modalias for scsi devices
The following patch adds support for sysfs/uevent modalias
attribute for scsi devices (like disks, tapes, cdroms etc),
based on whatever current sd.c, sr.c, st.c and osst.c drivers
supports.
The modalias format is like this:
scsi:type-0x04
(for TYPE_WORM, handled by sr.c now).
Several comments.
o This hexadecimal type value is because all TYPE_XXX constants
in include/scsi/scsi.h are given in hex, but __stringify() will
not convert them to decimal (so it will NOT be scsi:type-4).
Since it does not really matter in which format it is, while
both modalias in module and modalias attribute match each other,
I descided to go for that 0x%02x format (and added a comment in
include/scsi/scsi.h to keep them that way), instead of changing
them all to decimal.
o There was no .uevent routine for SCSI bus. It might be a good
idea to add some more ueven environment variables in there.
o osst.c driver handles tapes too, like st.c, but only SOME tapes.
With this setup, hotplug scripts (or whatever is used by the
user) will try to load both st and osst modules for all SCSI
tapes found, because both modules have scsi:type-0x01 alias).
It is not harmful, but one extra module is no good either.
It is possible to solve this, by exporting more info in
modalias attribute, including vendor and device identification
strings, so that modalias becomes something like
scsi:type-0x12:vendor-Adaptec LTD:device-OnStream Tape Drive
and having that, match for all 3 attributes, not only device
type. But oh well, vendor and device strings may be large,
and they do contain spaces and whatnot.
So I left them for now, awaiting for comments first.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
2006-10-27 20:02:37 +08:00
|
|
|
MODULE_ALIAS_SCSI_DEVICE(TYPE_ROM);
|
|
|
|
MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM);
|
2006-03-08 16:14:20 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define SR_DISKS 256
|
|
|
|
|
|
|
|
#define SR_CAPABILITIES \
|
|
|
|
(CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
|
|
|
|
CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
|
2006-03-23 19:00:15 +08:00
|
|
|
CDC_PLAY_AUDIO|CDC_RESET|CDC_DRIVE_STATUS| \
|
2005-04-17 06:20:36 +08:00
|
|
|
CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
|
|
|
|
CDC_MRW|CDC_MRW_W|CDC_RAM)
|
|
|
|
|
2010-06-02 20:28:52 +08:00
|
|
|
static DEFINE_MUTEX(sr_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int sr_probe(struct device *);
|
|
|
|
static int sr_remove(struct device *);
|
2018-11-09 21:42:39 +08:00
|
|
|
static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt);
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-07 02:17:12 +08:00
|
|
|
static int sr_done(struct scsi_cmnd *);
|
2013-01-23 15:09:31 +08:00
|
|
|
static int sr_runtime_suspend(struct device *dev);
|
|
|
|
|
2016-08-29 04:17:38 +08:00
|
|
|
static const struct dev_pm_ops sr_pm_ops = {
|
2013-01-23 15:09:31 +08:00
|
|
|
.runtime_suspend = sr_runtime_suspend,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct scsi_driver sr_template = {
|
|
|
|
.gendrv = {
|
|
|
|
.name = "sr",
|
2014-11-13 01:34:51 +08:00
|
|
|
.owner = THIS_MODULE,
|
2005-04-17 06:20:36 +08:00
|
|
|
.probe = sr_probe,
|
|
|
|
.remove = sr_remove,
|
2013-01-23 15:09:31 +08:00
|
|
|
.pm = &sr_pm_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
},
|
2014-05-01 22:51:04 +08:00
|
|
|
.init_command = sr_init_command,
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-07 02:17:12 +08:00
|
|
|
.done = sr_done,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
|
|
|
|
static DEFINE_SPINLOCK(sr_index_lock);
|
|
|
|
|
|
|
|
/* This semaphore is used to mediate the 0->1 reference get in the
|
|
|
|
* face of object destruction (i.e. we can't allow a get on an
|
|
|
|
* object after last put) */
|
2006-01-11 20:16:10 +08:00
|
|
|
static DEFINE_MUTEX(sr_ref_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int sr_open(struct cdrom_device_info *, int);
|
|
|
|
static void sr_release(struct cdrom_device_info *);
|
|
|
|
|
|
|
|
static void get_sectorsize(struct scsi_cd *);
|
|
|
|
static void get_capabilities(struct scsi_cd *);
|
|
|
|
|
2010-12-17 00:52:17 +08:00
|
|
|
static unsigned int sr_check_events(struct cdrom_device_info *cdi,
|
|
|
|
unsigned int clearing, int slot);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int sr_packet(struct cdrom_device_info *, struct packet_command *);
|
|
|
|
|
2017-02-14 08:25:26 +08:00
|
|
|
static const struct cdrom_device_ops sr_dops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = sr_open,
|
|
|
|
.release = sr_release,
|
|
|
|
.drive_status = sr_drive_status,
|
2010-12-17 00:52:17 +08:00
|
|
|
.check_events = sr_check_events,
|
2005-04-17 06:20:36 +08:00
|
|
|
.tray_move = sr_tray_move,
|
|
|
|
.lock_door = sr_lock_door,
|
|
|
|
.select_speed = sr_select_speed,
|
|
|
|
.get_last_session = sr_get_last_session,
|
|
|
|
.get_mcn = sr_get_mcn,
|
|
|
|
.reset = sr_reset,
|
|
|
|
.audio_ioctl = sr_audio_ioctl,
|
|
|
|
.capability = SR_CAPABILITIES,
|
|
|
|
.generic_packet = sr_packet,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sr_kref_release(struct kref *kref);
|
|
|
|
|
|
|
|
static inline struct scsi_cd *scsi_cd(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
return container_of(disk->private_data, struct scsi_cd, driver);
|
|
|
|
}
|
|
|
|
|
2013-01-23 15:09:31 +08:00
|
|
|
static int sr_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = dev_get_drvdata(dev);
|
|
|
|
|
2016-01-21 00:26:01 +08:00
|
|
|
if (!cd) /* E.g.: runtime suspend following sr_remove() */
|
|
|
|
return 0;
|
|
|
|
|
2013-01-23 15:09:31 +08:00
|
|
|
if (cd->media_present)
|
|
|
|
return -EBUSY;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* The get and put routines for the struct scsi_cd. Note this entity
|
|
|
|
* has a scsi_device pointer and owns a reference to this.
|
|
|
|
*/
|
|
|
|
static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = NULL;
|
|
|
|
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_lock(&sr_ref_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (disk->private_data == NULL)
|
|
|
|
goto out;
|
|
|
|
cd = scsi_cd(disk);
|
|
|
|
kref_get(&cd->kref);
|
2013-10-28 15:27:49 +08:00
|
|
|
if (scsi_device_get(cd->device)) {
|
|
|
|
kref_put(&cd->kref, sr_kref_release);
|
|
|
|
cd = NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_unlock(&sr_ref_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return cd;
|
|
|
|
}
|
|
|
|
|
2006-01-15 05:20:43 +08:00
|
|
|
static void scsi_cd_put(struct scsi_cd *cd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct scsi_device *sdev = cd->device;
|
|
|
|
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_lock(&sr_ref_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
kref_put(&cd->kref, sr_kref_release);
|
|
|
|
scsi_device_put(sdev);
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_unlock(&sr_ref_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-12-17 00:52:17 +08:00
|
|
|
static unsigned int sr_get_events(struct scsi_device *sdev)
|
|
|
|
{
|
|
|
|
u8 buf[8];
|
|
|
|
u8 cmd[] = { GET_EVENT_STATUS_NOTIFICATION,
|
|
|
|
1, /* polled */
|
|
|
|
0, 0, /* reserved */
|
|
|
|
1 << 4, /* notification class: media */
|
|
|
|
0, 0, /* reserved */
|
|
|
|
0, sizeof(buf), /* allocation length */
|
|
|
|
0, /* control */
|
|
|
|
};
|
|
|
|
struct event_header *eh = (void *)buf;
|
|
|
|
struct media_event_desc *med = (void *)(buf + 4);
|
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, sizeof(buf),
|
|
|
|
&sshdr, SR_TIMEOUT, MAX_RETRIES, NULL);
|
|
|
|
if (scsi_sense_valid(&sshdr) && sshdr.sense_key == UNIT_ATTENTION)
|
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
|
|
|
|
if (result || be16_to_cpu(eh->data_len) < sizeof(*med))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (eh->nea || eh->notification_class != 0x4)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (med->media_event_code == 1)
|
|
|
|
return DISK_EVENT_EJECT_REQUEST;
|
|
|
|
else if (med->media_event_code == 2)
|
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
2024-06-12 13:13:20 +08:00
|
|
|
else if (med->media_event_code == 3)
|
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
2010-12-17 00:52:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2010-12-17 00:52:17 +08:00
|
|
|
* This function checks to see if the media has been changed or eject
|
|
|
|
* button has been pressed. It is possible that we have already
|
|
|
|
* sensed a change, or the drive may have sensed one and not yet
|
|
|
|
* reported it. The past events are accumulated in sdev->changed and
|
|
|
|
* returned together with the current state.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2010-12-17 00:52:17 +08:00
|
|
|
static unsigned int sr_check_events(struct cdrom_device_info *cdi,
|
|
|
|
unsigned int clearing, int slot)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
2010-12-17 00:52:17 +08:00
|
|
|
bool last_present;
|
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
unsigned int events;
|
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-12-17 00:52:17 +08:00
|
|
|
/* no changer support */
|
|
|
|
if (CDSL_CURRENT != slot)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
events = sr_get_events(cd->device);
|
2011-06-30 21:03:48 +08:00
|
|
|
cd->get_event_changed |= events & DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If earlier GET_EVENT_STATUS_NOTIFICATION and TUR did not agree
|
|
|
|
* for several times in a row. We rely on TUR only for this likely
|
|
|
|
* broken device, to prevent generating incorrect media changed
|
|
|
|
* events for every open().
|
|
|
|
*/
|
|
|
|
if (cd->ignore_get_event) {
|
|
|
|
events &= ~DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
goto do_tur;
|
|
|
|
}
|
|
|
|
|
2010-12-17 00:52:17 +08:00
|
|
|
/*
|
|
|
|
* GET_EVENT_STATUS_NOTIFICATION is enough unless MEDIA_CHANGE
|
|
|
|
* is being cleared. Note that there are devices which hang
|
|
|
|
* if asked to execute TUR repeatedly.
|
|
|
|
*/
|
2011-06-30 21:03:48 +08:00
|
|
|
if (cd->device->changed) {
|
|
|
|
events |= DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
cd->device->changed = 0;
|
|
|
|
cd->tur_changed = true;
|
|
|
|
}
|
2010-12-17 00:52:17 +08:00
|
|
|
|
2011-06-30 21:03:48 +08:00
|
|
|
if (!(clearing & DISK_EVENT_MEDIA_CHANGE))
|
|
|
|
return events;
|
|
|
|
do_tur:
|
2010-12-17 00:52:17 +08:00
|
|
|
/* let's see whether the media is there with TUR */
|
|
|
|
last_present = cd->media_present;
|
|
|
|
ret = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-12-09 18:18:42 +08:00
|
|
|
/*
|
|
|
|
* Media is considered to be present if TUR succeeds or fails with
|
|
|
|
* sense data indicating something other than media-not-present
|
|
|
|
* (ASC 0x3a).
|
|
|
|
*/
|
2010-12-17 00:52:17 +08:00
|
|
|
cd->media_present = scsi_status_is_good(ret) ||
|
|
|
|
(scsi_sense_valid(&sshdr) && sshdr.asc != 0x3a);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-12-17 00:52:17 +08:00
|
|
|
if (last_present != cd->media_present)
|
2011-06-30 21:03:48 +08:00
|
|
|
cd->device->changed = 1;
|
|
|
|
|
2010-12-17 00:52:17 +08:00
|
|
|
if (cd->device->changed) {
|
|
|
|
events |= DISK_EVENT_MEDIA_CHANGE;
|
|
|
|
cd->device->changed = 0;
|
2011-06-30 21:03:48 +08:00
|
|
|
cd->tur_changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cd->ignore_get_event)
|
|
|
|
return events;
|
|
|
|
|
|
|
|
/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */
|
|
|
|
if (!cd->tur_changed) {
|
|
|
|
if (cd->get_event_changed) {
|
|
|
|
if (cd->tur_mismatch++ > 8) {
|
2014-06-25 22:39:54 +08:00
|
|
|
sr_printk(KERN_WARNING, cd,
|
|
|
|
"GET_EVENT and TUR disagree continuously, suppress GET_EVENT events\n");
|
2011-06-30 21:03:48 +08:00
|
|
|
cd->ignore_get_event = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cd->tur_mismatch = 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-06-30 21:03:48 +08:00
|
|
|
cd->tur_changed = false;
|
|
|
|
cd->get_event_changed = false;
|
2007-08-14 20:10:39 +08:00
|
|
|
|
2010-12-17 00:52:17 +08:00
|
|
|
return events;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-12-17 00:52:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-07 02:17:12 +08:00
|
|
|
* sr_done is the interrupt routine for the device driver.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-07 02:17:12 +08:00
|
|
|
* It will be notified on the end of a SCSI read / write, and will take one
|
2005-04-17 06:20:36 +08:00
|
|
|
* of several actions based on success or failure.
|
|
|
|
*/
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-07 02:17:12 +08:00
|
|
|
static int sr_done(struct scsi_cmnd *SCpnt)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int result = SCpnt->result;
|
2007-12-13 19:47:40 +08:00
|
|
|
int this_count = scsi_bufflen(SCpnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
int good_bytes = (result == 0 ? this_count : 0);
|
|
|
|
int block_sectors = 0;
|
|
|
|
long error_sector;
|
|
|
|
struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-06-25 22:39:54 +08:00
|
|
|
scmd_printk(KERN_INFO, SCpnt, "done: %x\n", result);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle MEDIUM ERRORs or VOLUME OVERFLOWs that indicate partial
|
|
|
|
* success. Since this is a relatively rare error condition, no
|
|
|
|
* care is taken to avoid unnecessary additional work such as
|
|
|
|
* memcpy's that could be avoided.
|
|
|
|
*/
|
|
|
|
if (driver_byte(result) != 0 && /* An error occurred */
|
|
|
|
(SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */
|
|
|
|
switch (SCpnt->sense_buffer[2]) {
|
|
|
|
case MEDIUM_ERROR:
|
|
|
|
case VOLUME_OVERFLOW:
|
|
|
|
case ILLEGAL_REQUEST:
|
|
|
|
if (!(SCpnt->sense_buffer[0] & 0x90))
|
|
|
|
break;
|
|
|
|
error_sector = (SCpnt->sense_buffer[3] << 24) |
|
|
|
|
(SCpnt->sense_buffer[4] << 16) |
|
|
|
|
(SCpnt->sense_buffer[5] << 8) |
|
|
|
|
SCpnt->sense_buffer[6];
|
|
|
|
if (SCpnt->request->bio != NULL)
|
|
|
|
block_sectors =
|
|
|
|
bio_sectors(SCpnt->request->bio);
|
|
|
|
if (block_sectors < 4)
|
|
|
|
block_sectors = 4;
|
|
|
|
if (cd->device->sector_size == 2048)
|
|
|
|
error_sector <<= 2;
|
|
|
|
error_sector &= ~(block_sectors - 1);
|
2009-05-07 21:24:39 +08:00
|
|
|
good_bytes = (error_sector -
|
|
|
|
blk_rq_pos(SCpnt->request)) << 9;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (good_bytes < 0 || good_bytes >= this_count)
|
|
|
|
good_bytes = 0;
|
|
|
|
/*
|
|
|
|
* The SCSI specification allows for the value
|
|
|
|
* returned by READ CAPACITY to be up to 75 2K
|
|
|
|
* sectors past the last readable block.
|
|
|
|
* Therefore, if we hit a medium error within the
|
|
|
|
* last 75 2K sectors, we decrease the saved size
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
if (error_sector < get_capacity(cd->disk) &&
|
|
|
|
cd->capacity - error_sector < 4 * 75)
|
|
|
|
set_capacity(cd->disk, error_sector);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECOVERED_ERROR:
|
|
|
|
good_bytes = this_count;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Revert "scsi: revert "[SCSI] Get rid of scsi_cmnd->done""
This reverts commit ac40532ef0b8649e6f7f83859ea0de1c4ed08a19, which gets
us back the original cleanup of 6f5391c283d7fdcf24bf40786ea79061919d1e1d.
It turns out that the bug that was triggered by that commit was
apparently not actually triggered by that commit at all, and just the
testing conditions had changed enough to make it appear to be due to it.
The real problem seems to have been found by Peter Osterlund:
"pktcdvd sets it [block device size] when opening the /dev/pktcdvd
device, but when the drive is later opened as /dev/scd0, there is
nothing that sets it back. (Btw, 40944 is possible if the disk is a
CDRW that was formatted with "cdrwtool -m 10236".)
The problem is that pktcdvd opens the cd device in non-blocking mode
when pktsetup is run, and doesn't close it again until pktsetup -d is
run. The effect is that if you meanwhile open the cd device,
blkdev.c:do_open() doesn't call bd_set_size() because
bdev->bd_openers is non-zero."
In particular, to repeat the bug (regardless of whether commit
6f5391c283d7fdcf24bf40786ea79061919d1e1d is applied or not):
" 1. Start with an empty drive.
2. pktsetup 0 /dev/scd0
3. Insert a CD containing an isofs filesystem.
4. mount /dev/pktcdvd/0 /mnt/tmp
5. umount /mnt/tmp
6. Press the eject button.
7. Insert a DVD containing a non-writable filesystem.
8. mount /dev/scd0 /mnt/tmp
9. find /mnt/tmp -type f -print0 | xargs -0 sha1sum >/dev/null
10. If the DVD contains data beyond the physical size of a CD, you
get I/O errors in the terminal, and dmesg reports lots of
"attempt to access beyond end of device" errors."
which in turn is because the nested open after the media change won't
cause the size to be set properly (because the original open still holds
the block device, and we only do the bd_set_size() when we don't have
other people holding the device open).
The proper fix for that is probably to just do something like
bdev->bd_inode->i_size = (loff_t)get_capacity(disk)<<9;
in fs/block_dev.c:do_open() even for the cases where we're not the
original opener (but *not* call bd_set_size(), since that will also
change the block size of the device).
Cc: Peter Osterlund <petero2@telia.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-07 02:17:12 +08:00
|
|
|
return good_bytes;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-11-09 21:42:39 +08:00
|
|
|
static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-14 20:55:09 +08:00
|
|
|
int block = 0, this_count, s_size;
|
2007-08-04 23:06:25 +08:00
|
|
|
struct scsi_cd *cd;
|
2014-05-01 22:51:04 +08:00
|
|
|
struct request *rq = SCpnt->request;
|
2018-11-09 21:42:39 +08:00
|
|
|
blk_status_t ret;
|
2007-08-04 23:06:25 +08:00
|
|
|
|
2014-09-06 09:20:23 +08:00
|
|
|
ret = scsi_init_io(SCpnt);
|
2018-11-09 21:42:39 +08:00
|
|
|
if (ret != BLK_STS_OK)
|
2007-08-04 23:06:25 +08:00
|
|
|
goto out;
|
|
|
|
cd = scsi_cd(rq->rq_disk);
|
|
|
|
|
|
|
|
/* from here on until we're complete, any goto out
|
|
|
|
* is used for a killable error condition */
|
2018-11-09 21:42:39 +08:00
|
|
|
ret = BLK_STS_IOERR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-25 22:39:54 +08:00
|
|
|
SCSI_LOG_HLQUEUE(1, scmd_printk(KERN_INFO, SCpnt,
|
|
|
|
"Doing sr request, block = %d\n", block));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!cd->device || !scsi_device_online(cd->device)) {
|
2014-06-25 22:39:54 +08:00
|
|
|
SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
|
|
|
|
"Finishing %u sectors\n", blk_rq_sectors(rq)));
|
|
|
|
SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
|
|
|
|
"Retry with 0x%p\n", SCpnt));
|
2007-08-04 23:06:25 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cd->device->changed) {
|
|
|
|
/*
|
|
|
|
* quietly refuse to do anything to a changed disc until the
|
|
|
|
* changed bit has been reset
|
|
|
|
*/
|
2007-08-04 23:06:25 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we do lazy blocksize switching (when reading XA sectors,
|
|
|
|
* see CDROMREADMODE2 ioctl)
|
|
|
|
*/
|
|
|
|
s_size = cd->device->sector_size;
|
|
|
|
if (s_size > 2048) {
|
|
|
|
if (!in_interrupt())
|
|
|
|
sr_set_blocklength(cd, 2048);
|
|
|
|
else
|
2014-06-25 22:39:54 +08:00
|
|
|
scmd_printk(KERN_INFO, SCpnt,
|
|
|
|
"can't switch blocksize: in interrupt\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s_size != 512 && s_size != 1024 && s_size != 2048) {
|
2005-10-25 06:04:06 +08:00
|
|
|
scmd_printk(KERN_ERR, SCpnt, "bad sector size %d\n", s_size);
|
2007-08-04 23:06:25 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-01-31 23:57:31 +08:00
|
|
|
switch (req_op(rq)) {
|
|
|
|
case REQ_OP_WRITE:
|
2014-07-18 22:59:19 +08:00
|
|
|
if (!cd->writeable)
|
2007-08-04 23:06:25 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
SCpnt->cmnd[0] = WRITE_10;
|
2014-06-25 22:39:54 +08:00
|
|
|
cd->cdi.media_written = 1;
|
2017-01-31 23:57:31 +08:00
|
|
|
break;
|
|
|
|
case REQ_OP_READ:
|
2005-04-17 06:20:36 +08:00
|
|
|
SCpnt->cmnd[0] = READ_10;
|
2017-01-31 23:57:31 +08:00
|
|
|
break;
|
|
|
|
default:
|
2007-08-04 23:06:25 +08:00
|
|
|
blk_dump_rq_flags(rq, "Unknown sr command");
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2007-12-13 19:47:40 +08:00
|
|
|
struct scatterlist *sg;
|
|
|
|
int i, size = 0, sg_count = scsi_sg_count(SCpnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-12-13 19:47:40 +08:00
|
|
|
scsi_for_each_sg(SCpnt, sg, sg_count, i)
|
|
|
|
size += sg->length;
|
|
|
|
|
|
|
|
if (size != scsi_bufflen(SCpnt)) {
|
2005-10-25 06:04:06 +08:00
|
|
|
scmd_printk(KERN_ERR, SCpnt,
|
|
|
|
"mismatch count %d, bytes %d\n",
|
2007-12-13 19:47:40 +08:00
|
|
|
size, scsi_bufflen(SCpnt));
|
|
|
|
if (scsi_bufflen(SCpnt) > size)
|
|
|
|
SCpnt->sdb.length = size;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* request doesn't start on hw block boundary, add scatter pads
|
|
|
|
*/
|
2009-05-07 21:24:39 +08:00
|
|
|
if (((unsigned int)blk_rq_pos(rq) % (s_size >> 9)) ||
|
2007-12-13 19:47:40 +08:00
|
|
|
(scsi_bufflen(SCpnt) % s_size)) {
|
2005-10-25 06:04:06 +08:00
|
|
|
scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n");
|
2007-08-04 23:06:25 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-12-13 19:47:40 +08:00
|
|
|
this_count = (scsi_bufflen(SCpnt) >> 9) / (s_size >> 9);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2014-06-25 22:39:54 +08:00
|
|
|
SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
|
|
|
|
"%s %d/%u 512 byte blocks.\n",
|
|
|
|
(rq_data_dir(rq) == WRITE) ?
|
2005-04-17 06:20:36 +08:00
|
|
|
"writing" : "reading",
|
2014-06-25 22:39:54 +08:00
|
|
|
this_count, blk_rq_sectors(rq)));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
SCpnt->cmnd[1] = 0;
|
2009-05-07 21:24:39 +08:00
|
|
|
block = (unsigned int)blk_rq_pos(rq) / (s_size >> 9);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (this_count > 0xffff) {
|
|
|
|
this_count = 0xffff;
|
2007-12-13 19:47:40 +08:00
|
|
|
SCpnt->sdb.length = this_count * s_size;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;
|
|
|
|
SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
|
|
|
|
SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
|
|
|
|
SCpnt->cmnd[5] = (unsigned char) block & 0xff;
|
|
|
|
SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
|
|
|
|
SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
|
|
|
|
SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We shouldn't disconnect in the middle of a sector, so with a dumb
|
|
|
|
* host adapter, it's safe to assume that we can at least transfer
|
|
|
|
* this many bytes between each connect / disconnect.
|
|
|
|
*/
|
|
|
|
SCpnt->transfersize = cd->device->sector_size;
|
|
|
|
SCpnt->underflow = this_count << 9;
|
|
|
|
SCpnt->allowed = MAX_RETRIES;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This indicates that the command is ready from our end to be
|
|
|
|
* queued.
|
|
|
|
*/
|
2018-11-09 21:42:39 +08:00
|
|
|
ret = BLK_STS_OK;
|
2007-08-04 23:06:25 +08:00
|
|
|
out:
|
2014-05-01 22:51:04 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-03-02 23:41:28 +08:00
|
|
|
static int sr_block_open(struct block_device *bdev, fmode_t mode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-08-08 00:25:34 +08:00
|
|
|
struct scsi_cd *cd;
|
2018-08-03 01:44:42 +08:00
|
|
|
struct scsi_device *sdev;
|
2008-03-02 23:41:28 +08:00
|
|
|
int ret = -ENXIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-03 01:44:42 +08:00
|
|
|
cd = scsi_cd_get(bdev->bd_disk);
|
|
|
|
if (!cd)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sdev = cd->device;
|
|
|
|
scsi_autopm_get_device(sdev);
|
2018-03-09 20:59:06 +08:00
|
|
|
check_disk_change(bdev);
|
|
|
|
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_lock(&sr_mutex);
|
2018-08-03 01:44:42 +08:00
|
|
|
ret = cdrom_open(&cd->cdi, bdev, mode);
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_unlock(&sr_mutex);
|
2018-08-03 01:44:42 +08:00
|
|
|
|
|
|
|
scsi_autopm_put_device(sdev);
|
|
|
|
if (ret)
|
|
|
|
scsi_cd_put(cd);
|
|
|
|
|
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-05-06 09:52:57 +08:00
|
|
|
static void sr_block_release(struct gendisk *disk, fmode_t mode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-03-02 23:41:28 +08:00
|
|
|
struct scsi_cd *cd = scsi_cd(disk);
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_lock(&sr_mutex);
|
2008-03-02 23:41:28 +08:00
|
|
|
cdrom_release(&cd->cdi, mode);
|
2005-04-17 06:20:36 +08:00
|
|
|
scsi_cd_put(cd);
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_unlock(&sr_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-03-02 23:41:28 +08:00
|
|
|
static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long arg)
|
|
|
|
{
|
2008-03-02 23:41:28 +08:00
|
|
|
struct scsi_cd *cd = scsi_cd(bdev->bd_disk);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct scsi_device *sdev = cd->device;
|
2006-03-23 19:00:15 +08:00
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_lock(&sr_mutex);
|
2010-07-08 16:18:46 +08:00
|
|
|
|
2014-10-11 22:25:31 +08:00
|
|
|
ret = scsi_ioctl_block_when_processing_errors(sdev, cmd,
|
|
|
|
(mode & FMODE_NDELAY) != 0);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2018-08-03 01:44:42 +08:00
|
|
|
scsi_autopm_get_device(sdev);
|
|
|
|
|
2006-03-23 19:00:15 +08:00
|
|
|
/*
|
|
|
|
* Send SCSI addressing ioctls directly to mid level, send other
|
|
|
|
* ioctls to cdrom/block level.
|
|
|
|
*/
|
|
|
|
switch (cmd) {
|
|
|
|
case SCSI_IOCTL_GET_IDLUN:
|
|
|
|
case SCSI_IOCTL_GET_BUS_NUMBER:
|
2010-07-08 16:18:46 +08:00
|
|
|
ret = scsi_ioctl(sdev, cmd, argp);
|
2018-08-03 01:44:42 +08:00
|
|
|
goto put;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-03-23 19:00:15 +08:00
|
|
|
|
2008-03-02 23:41:28 +08:00
|
|
|
ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg);
|
2007-01-02 16:41:04 +08:00
|
|
|
if (ret != -ENOSYS)
|
2018-08-03 01:44:42 +08:00
|
|
|
goto put;
|
2006-03-23 19:00:15 +08:00
|
|
|
|
2010-07-08 16:18:46 +08:00
|
|
|
ret = scsi_ioctl(sdev, cmd, argp);
|
|
|
|
|
2018-08-03 01:44:42 +08:00
|
|
|
put:
|
|
|
|
scsi_autopm_put_device(sdev);
|
|
|
|
|
2010-07-08 16:18:46 +08:00
|
|
|
out:
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_unlock(&sr_mutex);
|
2010-07-08 16:18:46 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-12-17 00:52:17 +08:00
|
|
|
static unsigned int sr_block_check_events(struct gendisk *disk,
|
|
|
|
unsigned int clearing)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-04-12 01:26:09 +08:00
|
|
|
unsigned int ret = 0;
|
|
|
|
struct scsi_cd *cd;
|
2013-01-23 15:09:31 +08:00
|
|
|
|
2018-04-12 01:26:09 +08:00
|
|
|
cd = scsi_cd_get(disk);
|
|
|
|
if (!cd)
|
2013-10-28 15:27:49 +08:00
|
|
|
return 0;
|
2013-01-23 15:09:31 +08:00
|
|
|
|
2018-04-12 01:26:09 +08:00
|
|
|
if (!atomic_read(&cd->device->disk_events_disable_depth))
|
|
|
|
ret = cdrom_check_events(&cd->cdi, clearing);
|
|
|
|
|
|
|
|
scsi_cd_put(cd);
|
|
|
|
return ret;
|
2010-12-17 00:52:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sr_block_revalidate_disk(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
struct scsi_sense_hdr sshdr;
|
2018-04-12 01:26:09 +08:00
|
|
|
struct scsi_cd *cd;
|
|
|
|
|
|
|
|
cd = scsi_cd_get(disk);
|
|
|
|
if (!cd)
|
|
|
|
return -ENXIO;
|
2010-12-17 00:52:17 +08:00
|
|
|
|
|
|
|
/* if the unit is not ready, nothing more to do */
|
|
|
|
if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
|
2013-01-23 15:09:31 +08:00
|
|
|
goto out;
|
2010-12-17 00:52:17 +08:00
|
|
|
|
|
|
|
sr_cd_check(&cd->cdi);
|
|
|
|
get_sectorsize(cd);
|
2013-01-23 15:09:31 +08:00
|
|
|
out:
|
2018-04-12 01:26:09 +08:00
|
|
|
scsi_cd_put(cd);
|
2010-12-17 00:52:17 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-22 08:01:13 +08:00
|
|
|
static const struct block_device_operations sr_bdops =
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.owner = THIS_MODULE,
|
2008-03-02 23:41:28 +08:00
|
|
|
.open = sr_block_open,
|
|
|
|
.release = sr_block_release,
|
2010-07-08 16:18:46 +08:00
|
|
|
.ioctl = sr_block_ioctl,
|
2010-12-17 00:52:17 +08:00
|
|
|
.check_events = sr_block_check_events,
|
|
|
|
.revalidate_disk = sr_block_revalidate_disk,
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* No compat_ioctl for now because sr_block_ioctl never
|
2011-03-31 09:57:33 +08:00
|
|
|
* seems to pass arbitrary ioctls down to host drivers.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sr_open(struct cdrom_device_info *cdi, int purpose)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
struct scsi_device *sdev = cd->device;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the device is in error recovery, wait until it is done.
|
|
|
|
* If the device is offline, then disallow any access to it.
|
|
|
|
*/
|
|
|
|
retval = -ENXIO;
|
|
|
|
if (!scsi_block_when_processing_errors(sdev))
|
|
|
|
goto error_out;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sr_release(struct cdrom_device_info *cdi)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
|
|
|
|
if (cd->device->sector_size > 2048)
|
|
|
|
sr_set_blocklength(cd, 2048);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sr_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
struct scsi_device *sdev = to_scsi_device(dev);
|
|
|
|
struct gendisk *disk;
|
|
|
|
struct scsi_cd *cd;
|
|
|
|
int minor, error;
|
|
|
|
|
2014-09-10 19:54:09 +08:00
|
|
|
scsi_autopm_get_device(sdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
error = -ENODEV;
|
|
|
|
if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
error = -ENOMEM;
|
2006-01-16 23:31:18 +08:00
|
|
|
cd = kzalloc(sizeof(*cd), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!cd)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
kref_init(&cd->kref);
|
|
|
|
|
|
|
|
disk = alloc_disk(1);
|
|
|
|
if (!disk)
|
|
|
|
goto fail_free;
|
|
|
|
|
|
|
|
spin_lock(&sr_index_lock);
|
|
|
|
minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
|
|
|
|
if (minor == SR_DISKS) {
|
|
|
|
spin_unlock(&sr_index_lock);
|
|
|
|
error = -EBUSY;
|
|
|
|
goto fail_put;
|
|
|
|
}
|
|
|
|
__set_bit(minor, sr_index_bits);
|
|
|
|
spin_unlock(&sr_index_lock);
|
|
|
|
|
|
|
|
disk->major = SCSI_CDROM_MAJOR;
|
|
|
|
disk->first_minor = minor;
|
|
|
|
sprintf(disk->disk_name, "sr%d", minor);
|
|
|
|
disk->fops = &sr_bdops;
|
2011-04-22 02:54:46 +08:00
|
|
|
disk->flags = GENHD_FL_CD | GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE;
|
2010-12-17 00:52:17 +08:00
|
|
|
disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST;
|
2019-03-27 21:51:02 +08:00
|
|
|
disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-14 20:55:09 +08:00
|
|
|
blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
cd->device = sdev;
|
|
|
|
cd->disk = disk;
|
|
|
|
cd->driver = &sr_template;
|
|
|
|
cd->disk = disk;
|
|
|
|
cd->capacity = 0x1fffff;
|
|
|
|
cd->device->changed = 1; /* force recheck CD type */
|
2010-12-17 00:52:17 +08:00
|
|
|
cd->media_present = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
cd->use = 1;
|
|
|
|
cd->readcd_known = 0;
|
|
|
|
cd->readcd_cdda = 0;
|
|
|
|
|
|
|
|
cd->cdi.ops = &sr_dops;
|
|
|
|
cd->cdi.handle = cd;
|
|
|
|
cd->cdi.mask = 0;
|
|
|
|
cd->cdi.capacity = 1;
|
|
|
|
sprintf(cd->cdi.name, "sr%d", minor);
|
|
|
|
|
|
|
|
sdev->sector_size = 2048; /* A guess, just in case */
|
|
|
|
|
|
|
|
/* FIXME: need to handle a get_capabilities failure properly ?? */
|
|
|
|
get_capabilities(cd);
|
|
|
|
sr_vendor_init(cd);
|
|
|
|
|
|
|
|
set_capacity(disk, cd->capacity);
|
|
|
|
disk->private_data = &cd->driver;
|
|
|
|
disk->queue = sdev->request_queue;
|
|
|
|
cd->cdi.disk = disk;
|
|
|
|
|
|
|
|
if (register_cdrom(&cd->cdi))
|
2024-06-11 20:26:44 +08:00
|
|
|
goto fail_minor;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-28 15:27:49 +08:00
|
|
|
/*
|
|
|
|
* Initialize block layer runtime PM stuffs before the
|
|
|
|
* periodic event checking request gets started in add_disk.
|
|
|
|
*/
|
|
|
|
blk_pm_runtime_init(sdev->request_queue, dev);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_set_drvdata(dev, cd);
|
|
|
|
disk->flags |= GENHD_FL_REMOVABLE;
|
2018-09-28 14:17:19 +08:00
|
|
|
device_add_disk(&sdev->sdev_gendev, disk, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-03 00:45:08 +08:00
|
|
|
sdev_printk(KERN_DEBUG, sdev,
|
|
|
|
"Attached scsi CD-ROM %s\n", cd->cdi.name);
|
2013-01-23 15:09:31 +08:00
|
|
|
scsi_autopm_put_device(cd->device);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
2024-06-11 20:26:44 +08:00
|
|
|
fail_minor:
|
|
|
|
spin_lock(&sr_index_lock);
|
|
|
|
clear_bit(minor, sr_index_bits);
|
|
|
|
spin_unlock(&sr_index_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
fail_put:
|
|
|
|
put_disk(disk);
|
|
|
|
fail_free:
|
|
|
|
kfree(cd);
|
|
|
|
fail:
|
2014-09-10 19:54:09 +08:00
|
|
|
scsi_autopm_put_device(sdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void get_sectorsize(struct scsi_cd *cd)
|
|
|
|
{
|
|
|
|
unsigned char cmd[10];
|
2008-07-04 15:31:50 +08:00
|
|
|
unsigned char buffer[8];
|
2005-04-17 06:20:36 +08:00
|
|
|
int the_result, retries = 3;
|
|
|
|
int sector_size;
|
2007-07-24 15:28:11 +08:00
|
|
|
struct request_queue *queue;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
do {
|
|
|
|
cmd[0] = READ_CAPACITY;
|
|
|
|
memset((void *) &cmd[1], 0, 9);
|
2008-07-04 15:31:50 +08:00
|
|
|
memset(buffer, 0, sizeof(buffer));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Do the command and wait.. */
|
2005-06-13 11:21:29 +08:00
|
|
|
the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
|
2008-07-04 15:31:50 +08:00
|
|
|
buffer, sizeof(buffer), NULL,
|
2008-12-04 13:24:39 +08:00
|
|
|
SR_TIMEOUT, MAX_RETRIES, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
retries--;
|
|
|
|
|
|
|
|
} while (the_result && retries);
|
|
|
|
|
|
|
|
|
|
|
|
if (the_result) {
|
|
|
|
cd->capacity = 0x1fffff;
|
|
|
|
sector_size = 2048; /* A guess, just in case */
|
|
|
|
} else {
|
2009-09-04 10:38:02 +08:00
|
|
|
long last_written;
|
|
|
|
|
|
|
|
cd->capacity = 1 + ((buffer[0] << 24) | (buffer[1] << 16) |
|
|
|
|
(buffer[2] << 8) | buffer[3]);
|
|
|
|
/*
|
|
|
|
* READ_CAPACITY doesn't return the correct size on
|
|
|
|
* certain UDF media. If last_written is larger, use
|
|
|
|
* it instead.
|
|
|
|
*
|
|
|
|
* http://bugzilla.kernel.org/show_bug.cgi?id=9668
|
|
|
|
*/
|
|
|
|
if (!cdrom_get_last_written(&cd->cdi, &last_written))
|
|
|
|
cd->capacity = max_t(long, cd->capacity, last_written);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
sector_size = (buffer[4] << 24) |
|
|
|
|
(buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
|
|
|
|
switch (sector_size) {
|
|
|
|
/*
|
|
|
|
* HP 4020i CD-Recorder reports 2340 byte sectors
|
|
|
|
* Philips CD-Writers report 2352 byte sectors
|
|
|
|
*
|
|
|
|
* Use 2k sectors for them..
|
|
|
|
*/
|
|
|
|
case 0:
|
|
|
|
case 2340:
|
|
|
|
case 2352:
|
|
|
|
sector_size = 2048;
|
|
|
|
/* fall through */
|
|
|
|
case 2048:
|
|
|
|
cd->capacity *= 4;
|
|
|
|
/* fall through */
|
|
|
|
case 512:
|
|
|
|
break;
|
|
|
|
default:
|
2014-06-25 22:39:54 +08:00
|
|
|
sr_printk(KERN_INFO, cd,
|
|
|
|
"unsupported sector size %d.", sector_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
cd->capacity = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->device->sector_size = sector_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add this so that we have the ability to correctly gauge
|
|
|
|
* what the device is capable of.
|
|
|
|
*/
|
|
|
|
set_capacity(cd->disk, cd->capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
queue = cd->device->request_queue;
|
2009-05-23 05:17:49 +08:00
|
|
|
blk_queue_logical_block_size(queue, sector_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-04 15:31:50 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void get_capabilities(struct scsi_cd *cd)
|
|
|
|
{
|
|
|
|
unsigned char *buffer;
|
|
|
|
struct scsi_mode_data data;
|
2005-06-13 11:21:29 +08:00
|
|
|
struct scsi_sense_hdr sshdr;
|
2017-03-17 20:47:14 +08:00
|
|
|
unsigned int ms_len = 128;
|
2008-02-07 03:01:58 +08:00
|
|
|
int rc, n;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-28 23:22:25 +08:00
|
|
|
static const char *loadmech[] =
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
"caddy",
|
|
|
|
"tray",
|
|
|
|
"pop-up",
|
|
|
|
"",
|
|
|
|
"changer",
|
|
|
|
"cartridge changer",
|
|
|
|
"",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* allocate transfer buffer */
|
2024-06-12 13:13:20 +08:00
|
|
|
buffer = kmalloc(512, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!buffer) {
|
2014-06-25 22:39:54 +08:00
|
|
|
sr_printk(KERN_ERR, cd, "out of memory.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-07 03:01:58 +08:00
|
|
|
/* eat unit attentions */
|
2010-12-09 03:57:40 +08:00
|
|
|
scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* ask for mode page 0x2a */
|
2017-03-17 20:47:14 +08:00
|
|
|
rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, ms_len,
|
2005-08-29 00:27:01 +08:00
|
|
|
SR_TIMEOUT, 3, &data, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-03-17 20:47:14 +08:00
|
|
|
if (!scsi_status_is_good(rc) || data.length > ms_len ||
|
|
|
|
data.header_length + data.block_descriptor_length > data.length) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* failed, drive doesn't have capabilities mode page */
|
|
|
|
cd->cdi.speed = 1;
|
|
|
|
cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
|
2006-01-12 12:58:40 +08:00
|
|
|
CDC_DVD | CDC_DVD_RAM |
|
|
|
|
CDC_SELECT_DISC | CDC_SELECT_SPEED |
|
|
|
|
CDC_MRW | CDC_MRW_W | CDC_RAM);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(buffer);
|
2014-06-25 22:39:54 +08:00
|
|
|
sr_printk(KERN_INFO, cd, "scsi-1 drive");
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = data.header_length + data.block_descriptor_length;
|
|
|
|
cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
|
|
|
|
cd->readcd_known = 1;
|
|
|
|
cd->readcd_cdda = buffer[n + 5] & 0x01;
|
|
|
|
/* print some capability bits */
|
2014-06-25 22:39:54 +08:00
|
|
|
sr_printk(KERN_INFO, cd,
|
|
|
|
"scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n",
|
|
|
|
((buffer[n + 14] << 8) + buffer[n + 15]) / 176,
|
|
|
|
cd->cdi.speed,
|
|
|
|
buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */
|
|
|
|
buffer[n + 3] & 0x20 ? "dvd-ram " : "",
|
|
|
|
buffer[n + 2] & 0x02 ? "cd/rw " : "", /* can read rewriteable */
|
|
|
|
buffer[n + 4] & 0x20 ? "xa/form2 " : "", /* can read xa/from2 */
|
|
|
|
buffer[n + 5] & 0x01 ? "cdda " : "", /* can read audio data */
|
|
|
|
loadmech[buffer[n + 6] >> 5]);
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((buffer[n + 6] >> 5) == 0)
|
|
|
|
/* caddy drives can't close tray... */
|
|
|
|
cd->cdi.mask |= CDC_CLOSE_TRAY;
|
|
|
|
if ((buffer[n + 2] & 0x8) == 0)
|
|
|
|
/* not a DVD drive */
|
|
|
|
cd->cdi.mask |= CDC_DVD;
|
2014-06-25 22:39:54 +08:00
|
|
|
if ((buffer[n + 3] & 0x20) == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
/* can't write DVD-RAM media */
|
|
|
|
cd->cdi.mask |= CDC_DVD_RAM;
|
|
|
|
if ((buffer[n + 3] & 0x10) == 0)
|
|
|
|
/* can't write DVD-R media */
|
|
|
|
cd->cdi.mask |= CDC_DVD_R;
|
|
|
|
if ((buffer[n + 3] & 0x2) == 0)
|
|
|
|
/* can't write CD-RW media */
|
|
|
|
cd->cdi.mask |= CDC_CD_RW;
|
|
|
|
if ((buffer[n + 3] & 0x1) == 0)
|
|
|
|
/* can't write CD-R media */
|
|
|
|
cd->cdi.mask |= CDC_CD_R;
|
|
|
|
if ((buffer[n + 6] & 0x8) == 0)
|
|
|
|
/* can't eject */
|
|
|
|
cd->cdi.mask |= CDC_OPEN_TRAY;
|
|
|
|
|
|
|
|
if ((buffer[n + 6] >> 5) == mechtype_individual_changer ||
|
|
|
|
(buffer[n + 6] >> 5) == mechtype_cartridge_changer)
|
|
|
|
cd->cdi.capacity =
|
|
|
|
cdrom_number_of_slots(&cd->cdi);
|
|
|
|
if (cd->cdi.capacity <= 1)
|
|
|
|
/* not a changer */
|
|
|
|
cd->cdi.mask |= CDC_SELECT_DISC;
|
|
|
|
/*else I don't think it can close its tray
|
|
|
|
cd->cdi.mask |= CDC_CLOSE_TRAY; */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if DVD-RAM, MRW-W or CD-RW, we are randomly writable
|
|
|
|
*/
|
|
|
|
if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
|
|
|
|
(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
|
2014-07-18 22:59:19 +08:00
|
|
|
cd->writeable = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sr_packet() is the entry point for the generic commands generated
|
2014-06-25 22:39:54 +08:00
|
|
|
* by the Uniform CD-ROM layer.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static int sr_packet(struct cdrom_device_info *cdi,
|
|
|
|
struct packet_command *cgc)
|
|
|
|
{
|
2010-10-02 05:20:08 +08:00
|
|
|
struct scsi_cd *cd = cdi->handle;
|
|
|
|
struct scsi_device *sdev = cd->device;
|
|
|
|
|
|
|
|
if (cgc->cmd[0] == GPCMD_READ_DISC_INFO && sdev->no_read_disc_info)
|
|
|
|
return -EDRIVE_CANT_DO_THIS;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cgc->timeout <= 0)
|
|
|
|
cgc->timeout = IOCTL_TIMEOUT;
|
|
|
|
|
2010-10-02 05:20:08 +08:00
|
|
|
sr_do_ioctl(cd, cgc);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return cgc->stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sr_kref_release - Called to free the scsi_cd structure
|
|
|
|
* @kref: pointer to embedded kref
|
|
|
|
*
|
2006-01-11 20:16:10 +08:00
|
|
|
* sr_ref_mutex must be held entering this routine. Because it is
|
2005-04-17 06:20:36 +08:00
|
|
|
* called on last put, you should always use the scsi_cd_get()
|
|
|
|
* scsi_cd_put() helpers which manipulate the semaphore directly
|
|
|
|
* and never do a direct kref_put().
|
|
|
|
**/
|
|
|
|
static void sr_kref_release(struct kref *kref)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = container_of(kref, struct scsi_cd, kref);
|
|
|
|
struct gendisk *disk = cd->disk;
|
|
|
|
|
|
|
|
spin_lock(&sr_index_lock);
|
2008-09-03 15:01:48 +08:00
|
|
|
clear_bit(MINOR(disk_devt(disk)), sr_index_bits);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock(&sr_index_lock);
|
|
|
|
|
|
|
|
unregister_cdrom(&cd->cdi);
|
|
|
|
|
|
|
|
disk->private_data = NULL;
|
|
|
|
|
|
|
|
put_disk(disk);
|
|
|
|
|
|
|
|
kfree(cd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sr_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
struct scsi_cd *cd = dev_get_drvdata(dev);
|
|
|
|
|
2013-01-23 15:09:31 +08:00
|
|
|
scsi_autopm_get_device(cd->device);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
del_gendisk(cd->disk);
|
2016-01-21 00:26:01 +08:00
|
|
|
dev_set_drvdata(dev, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_lock(&sr_ref_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
kref_put(&cd->kref, sr_kref_release);
|
2006-01-11 20:16:10 +08:00
|
|
|
mutex_unlock(&sr_ref_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init init_sr(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = register_blkdev(SCSI_CDROM_MAJOR, "sr");
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2007-06-25 23:39:33 +08:00
|
|
|
rc = scsi_register_driver(&sr_template.gendrv);
|
|
|
|
if (rc)
|
|
|
|
unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
|
|
|
|
|
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_sr(void)
|
|
|
|
{
|
|
|
|
scsi_unregister_driver(&sr_template.gendrv);
|
|
|
|
unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_sr);
|
|
|
|
module_exit(exit_sr);
|
|
|
|
MODULE_LICENSE("GPL");
|