Commit 6f14c533 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] (12/25) sr.c passes pointers instead of minors now

	 killed passing minors around; we always pass a pointer to structure;
scsi_CDs made static.  That killed uses of cdi->dev in sr.c and friends.
parent c7633c22
......@@ -87,12 +87,12 @@ static struct Scsi_Device_Template sr_template =
init_command:sr_init_command
};
Scsi_CD *scsi_CDs;
static Scsi_CD *scsi_CDs;
static int *sr_sizes;
static int sr_open(struct cdrom_device_info *, int);
void get_sectorsize(int);
void get_capabilities(int);
static void get_sectorsize(Scsi_CD *);
static void get_capabilities(Scsi_CD *);
static int sr_media_change(struct cdrom_device_info *, int);
static int sr_packet(struct cdrom_device_info *, struct cdrom_generic_command *);
......@@ -102,7 +102,7 @@ static void sr_release(struct cdrom_device_info *cdi)
Scsi_CD *cd = cdi->handle;
if (cd->device->sector_size > 2048)
sr_set_blocklength(minor(cdi->dev), 2048);
sr_set_blocklength(cd, 2048);
cd->device->access_count--;
if (cd->device->host->hostt->module)
__MOD_DEC_USE_COUNT(cd->device->host->hostt->module);
......@@ -298,7 +298,7 @@ static int sr_init_command(Scsi_Cmnd * SCpnt)
s_size = cd->device->sector_size;
if (s_size > 2048) {
if (!in_interrupt())
sr_set_blocklength(DEVICE_NR(CURRENT->rq_dev), 2048);
sr_set_blocklength(cd, 2048);
else
printk("sr: can't switch blocksize: in interrupt\n");
}
......@@ -402,9 +402,8 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose)
{
Scsi_CD *cd = cdi->handle;
if (minor(cdi->dev) >= sr_template.dev_max || !cd->device) {
if (!cd->device)
return -ENXIO; /* No such device */
}
/*
* If the device is in error recovery, wait until it is done.
* If the device is offline, then disallow any access to it.
......@@ -424,7 +423,7 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose)
*/
if (cd->needs_sector_size)
get_sectorsize(minor(cdi->dev));
get_sectorsize(cd);
return 0;
}
......@@ -470,17 +469,16 @@ static int sr_attach(Scsi_Device * SDp)
}
void get_sectorsize(int i)
static void get_sectorsize(Scsi_CD *cd)
{
unsigned char cmd[10];
unsigned char *buffer;
int the_result, retries = 3;
int sector_size;
Scsi_Request *SRpnt = NULL;
Scsi_CD *cd;
request_queue_t *queue;
cd = &scsi_CDs[i];
int unit = cd - scsi_CDs; /* gack... we still need it for corresponding
sr_sizes[] element access */
buffer = kmalloc(512, GFP_DMA);
if (!buffer)
......@@ -560,7 +558,7 @@ void get_sectorsize(int i)
* what the device is capable of.
*/
cd->needs_sector_size = 0;
sr_sizes[i] = cd->capacity >> (BLOCK_SIZE_BITS - 9);
sr_sizes[unit] = cd->capacity >> (BLOCK_SIZE_BITS - 9);
}
queue = &cd->device->request_queue;
......@@ -578,9 +576,8 @@ void get_sectorsize(int i)
goto out;
}
void get_capabilities(int i)
void get_capabilities(Scsi_CD *cd)
{
Scsi_CD *cd;
unsigned char cmd[6];
unsigned char *buffer;
int rc, n;
......@@ -597,7 +594,6 @@ void get_capabilities(int i)
""
};
cd = &scsi_CDs[i];
buffer = kmalloc(512, GFP_DMA);
if (!buffer)
{
......@@ -610,7 +606,7 @@ void get_capabilities(int i)
cmd[2] = 0x2a;
cmd[4] = 128;
cmd[3] = cmd[5] = 0;
rc = sr_do_ioctl(i, cmd, buffer, 128, 1, SCSI_DATA_READ, NULL);
rc = sr_do_ioctl(cd, cmd, buffer, 128, 1, SCSI_DATA_READ, NULL);
if (rc) {
/* failed, drive doesn't have capabilities mode page */
......@@ -687,7 +683,7 @@ static int sr_packet(struct cdrom_device_info *cdi, struct cdrom_generic_command
if (device->scsi_level <= SCSI_2)
cgc->cmd[1] |= device->lun << 5;
cgc->stat = sr_do_ioctl(minor(cdi->dev), cgc->cmd, cgc->buffer, cgc->buflen, cgc->quiet, cgc->data_direction, cgc->sense);
cgc->stat = sr_do_ioctl(cdi->handle, cgc->cmd, cgc->buffer, cgc->buflen, cgc->quiet, cgc->data_direction, cgc->sense);
return cgc->stat;
}
......@@ -769,7 +765,7 @@ void sr_finish()
cd->device->changed = 1; /* force recheck CD type */
#if 0
/* seems better to leave this for later */
get_sectorsize(i);
get_sectorsize(cd);
printk("Scd sectorsize = %d bytes.\n", cd->sector_size);
#endif
cd->use = 1;
......@@ -789,7 +785,7 @@ void sr_finish()
* FIXME: someone needs to handle a get_capabilities
* failure properly ??
*/
get_capabilities(i);
get_capabilities(cd);
sr_vendor_init(cd);
sprintf(cd->cdi.cdrom_driverfs_dev.bus_id, "%s:cd",
......
......@@ -32,9 +32,7 @@ typedef struct {
struct cdrom_device_info cdi;
} Scsi_CD;
extern Scsi_CD *scsi_CDs;
int sr_do_ioctl(int, unsigned char *, void *, unsigned, int, int, struct request_sense *);
int sr_do_ioctl(Scsi_CD *, unsigned char *, void *, unsigned, int, int, struct request_sense *);
int sr_lock_door(struct cdrom_device_info *, int);
int sr_tray_move(struct cdrom_device_info *, int);
......@@ -47,12 +45,11 @@ int sr_select_speed(struct cdrom_device_info *cdi, int speed);
int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *);
int sr_dev_ioctl(struct cdrom_device_info *, unsigned int, unsigned long);
int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest);
int sr_is_xa(int minor);
int sr_is_xa(Scsi_CD *);
/* sr_vendor.c */
void sr_vendor_init(Scsi_CD *);
int sr_cd_check(struct cdrom_device_info *);
int sr_set_blocklength(int minor, int blocklength);
int sr_set_blocklength(Scsi_CD *, int blocklength);
#endif
......@@ -24,8 +24,6 @@
* It is off by default and can be turned on with this module parameter */
static int xa_test = 0;
extern void get_sectorsize(int);
#define IOCTL_RETRIES 3
/* The CDROM is fairly slow, so we need a little extra time */
/* In fact, it is very slow if it has to spin up first */
......@@ -69,16 +67,15 @@ static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti
sr_cmd[6] = trk1_te.cdte_addr.msf.minute;
sr_cmd[7] = trk1_te.cdte_addr.msf.second;
sr_cmd[8] = trk1_te.cdte_addr.msf.frame;
return sr_do_ioctl(minor(cdi->dev), sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
return sr_do_ioctl(cdi->handle, sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
}
/* We do our own retries because we want to know what the specific
error code is. Normally the UNIT_ATTENTION code will automatically
clear after one error */
int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflength, int quiet, int readwrite, struct request_sense *sense)
int sr_do_ioctl(Scsi_CD *cd, unsigned char *sr_cmd, void *buffer, unsigned buflength, int quiet, int readwrite, struct request_sense *sense)
{
Scsi_CD *cd = &scsi_CDs[target];
Scsi_Request *SRpnt;
Scsi_Device *SDev;
struct request *req;
......@@ -192,17 +189,15 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
/* ---------------------------------------------------------------------- */
/* interface to cdrom.c */
static int test_unit_ready(int minor)
static int test_unit_ready(Scsi_CD *cd)
{
Scsi_CD *cd;
u_char sr_cmd[10];
cd = &scsi_CDs[minor];
sr_cmd[0] = GPCMD_TEST_UNIT_READY;
sr_cmd[1] = (cd->device->scsi_level <= SCSI_2) ?
((cd->device->lun) << 5) : 0;
sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
return sr_do_ioctl(minor, sr_cmd, NULL, 0, 1, SCSI_DATA_NONE, NULL);
return sr_do_ioctl(cd, sr_cmd, NULL, 0, 1, SCSI_DATA_NONE, NULL);
}
int sr_tray_move(struct cdrom_device_info *cdi, int pos)
......@@ -216,7 +211,7 @@ int sr_tray_move(struct cdrom_device_info *cdi, int pos)
sr_cmd[2] = sr_cmd[3] = sr_cmd[5] = 0;
sr_cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
return sr_do_ioctl(minor(cdi->dev), sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
return sr_do_ioctl(cd, sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
}
int sr_lock_door(struct cdrom_device_info *cdi, int lock)
......@@ -233,7 +228,7 @@ int sr_drive_status(struct cdrom_device_info *cdi, int slot)
/* we have no changer support */
return -EINVAL;
}
if (0 == test_unit_ready(minor(cdi->dev)))
if (0 == test_unit_ready(cdi->handle))
return CDS_DISC_OK;
return CDS_TRAY_OPEN;
......@@ -298,7 +293,7 @@ int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
sr_cmd[8] = 24;
sr_cmd[9] = 0;
result = sr_do_ioctl(minor(cdi->dev), sr_cmd, buffer, 24, 0, SCSI_DATA_READ, NULL);
result = sr_do_ioctl(cd, sr_cmd, buffer, 24, 0, SCSI_DATA_READ, NULL);
memcpy(mcn->medium_catalog_number, buffer + 9, 13);
mcn->medium_catalog_number[13] = 0;
......@@ -329,7 +324,7 @@ int sr_select_speed(struct cdrom_device_info *cdi, int speed)
sr_cmd[2] = (speed >> 8) & 0xff; /* MSB for speed (in kbytes/sec) */
sr_cmd[3] = speed & 0xff; /* LSB */
if (sr_do_ioctl(minor(cdi->dev), sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL))
if (sr_do_ioctl(cd, sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL))
return -EIO;
return 0;
}
......@@ -344,7 +339,7 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
{
Scsi_CD *cd = cdi->handle;
u_char sr_cmd[10];
int result, target = minor(cdi->dev);
int result;
unsigned char buffer[32];
memset(sr_cmd, 0, sizeof(sr_cmd));
......@@ -360,7 +355,7 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
sr_cmd[8] = 12; /* LSB of length */
result = sr_do_ioctl(target, sr_cmd, buffer, 12, 1, SCSI_DATA_READ, NULL);
result = sr_do_ioctl(cd, sr_cmd, buffer, 12, 1, SCSI_DATA_READ, NULL);
tochdr->cdth_trk0 = buffer[2];
tochdr->cdth_trk1 = buffer[3];
......@@ -380,7 +375,7 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
sr_cmd[6] = tocentry->cdte_track;
sr_cmd[8] = 12; /* LSB of length */
result = sr_do_ioctl(target, sr_cmd, buffer, 12, 0, SCSI_DATA_READ, NULL);
result = sr_do_ioctl(cd, sr_cmd, buffer, 12, 0, SCSI_DATA_READ, NULL);
tocentry->cdte_ctrl = buffer[5] & 0xf;
tocentry->cdte_adr = buffer[5] >> 4;
......@@ -407,7 +402,7 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
sr_cmd[7] = ti->cdti_trk1;
sr_cmd[8] = ti->cdti_ind1;
result = sr_do_ioctl(target, sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
result = sr_do_ioctl(cd, sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
if (result == -EDRIVE_CANT_DO_THIS)
result = sr_fake_playtrkind(cdi, ti);
......@@ -440,10 +435,9 @@ int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
* blksize: 2048 | 2336 | 2340 | 2352
*/
int sr_read_cd(int minor, unsigned char *dest, int lba, int format, int blksize)
static int sr_read_cd(Scsi_CD *cd, unsigned char *dest, int lba, int format, int blksize)
{
unsigned char cmd[MAX_COMMAND_SIZE];
Scsi_CD *cd = &scsi_CDs[minor];
#ifdef DEBUG
printk("%s: sr_read_cd lba=%d format=%d blksize=%d\n",
......@@ -474,22 +468,21 @@ int sr_read_cd(int minor, unsigned char *dest, int lba, int format, int blksize)
cmd[9] = 0x10;
break;
}
return sr_do_ioctl(minor, cmd, dest, blksize, 0, SCSI_DATA_READ, NULL);
return sr_do_ioctl(cd, cmd, dest, blksize, 0, SCSI_DATA_READ, NULL);
}
/*
* read sectors with blocksizes other than 2048
*/
int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
static int sr_read_sector(Scsi_CD *cd, int lba, int blksize, unsigned char *dest)
{
unsigned char cmd[MAX_COMMAND_SIZE]; /* the scsi-command */
Scsi_CD *cd = &scsi_CDs[minor];
int rc;
/* we try the READ CD command first... */
if (cd->readcd_known) {
rc = sr_read_cd(minor, dest, lba, 0, blksize);
rc = sr_read_cd(cd, dest, lba, 0, blksize);
if (-EDRIVE_CANT_DO_THIS != rc)
return rc;
cd->readcd_known = 0;
......@@ -498,7 +491,7 @@ int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
}
/* ... if this fails, we switch the blocksize using MODE SELECT */
if (blksize != cd->device->sector_size) {
if (0 != (rc = sr_set_blocklength(minor, blksize)))
if (0 != (rc = sr_set_blocklength(cd, blksize)))
return rc;
}
#ifdef DEBUG
......@@ -514,7 +507,7 @@ int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
cmd[4] = (unsigned char) (lba >> 8) & 0xff;
cmd[5] = (unsigned char) lba & 0xff;
cmd[8] = 1;
rc = sr_do_ioctl(minor, cmd, dest, blksize, 0, SCSI_DATA_READ, NULL);
rc = sr_do_ioctl(cd, cmd, dest, blksize, 0, SCSI_DATA_READ, NULL);
return rc;
}
......@@ -524,10 +517,9 @@ int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
* ret: 1 == mode2 (XA), 0 == mode1, <0 == error
*/
int sr_is_xa(int minor)
int sr_is_xa(Scsi_CD *cd)
{
unsigned char *raw_sector;
Scsi_CD *cd = &scsi_CDs[minor];
int is_xa;
if (!xa_test)
......@@ -536,7 +528,7 @@ int sr_is_xa(int minor)
raw_sector = (unsigned char *) kmalloc(2048, GFP_DMA | GFP_KERNEL);
if (!raw_sector)
return -ENOMEM;
if (0 == sr_read_sector(minor, cd->ms_offset + 16,
if (0 == sr_read_sector(cd, cd->ms_offset + 16,
CD_FRAMESIZE_RAW1, raw_sector)) {
is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
} else {
......
......@@ -101,12 +101,11 @@ void sr_vendor_init(Scsi_CD *cd)
/* small handy function for switching block length using MODE SELECT,
* used by sr_read_sector() */
int sr_set_blocklength(int minor, int blocklength)
int sr_set_blocklength(Scsi_CD *cd, int blocklength)
{
unsigned char *buffer; /* the buffer for the ioctl */
unsigned char cmd[MAX_COMMAND_SIZE]; /* the scsi-command */
struct ccs_modesel_head *modesel;
Scsi_CD *cd = &scsi_CDs[minor];
int rc, density = 0;
#ifdef CONFIG_BLK_DEV_SR_VENDOR
......@@ -133,7 +132,7 @@ int sr_set_blocklength(int minor, int blocklength)
modesel->density = density;
modesel->block_length_med = (blocklength >> 8) & 0xff;
modesel->block_length_lo = blocklength & 0xff;
if (0 == (rc = sr_do_ioctl(minor, cmd, buffer, sizeof(*modesel), 0, SCSI_DATA_WRITE, NULL))) {
if (0 == (rc = sr_do_ioctl(cd, cmd, buffer, sizeof(*modesel), 0, SCSI_DATA_WRITE, NULL))) {
cd->device->sector_size = blocklength;
}
#ifdef DEBUG
......@@ -156,9 +155,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
unsigned long sector;
unsigned char *buffer; /* the buffer for the ioctl */
unsigned char cmd[MAX_COMMAND_SIZE]; /* the scsi-command */
int rc, no_multi, minor;
int rc, no_multi;
minor = minor(cdi->dev);
if (cd->cdi.mask & CDC_MULTI_SESSION)
return 0;
......@@ -179,7 +177,7 @@ int sr_cd_check(struct cdrom_device_info *cdi)
(cd->device->lun << 5) : 0;
cmd[8] = 12;
cmd[9] = 0x40;
rc = sr_do_ioctl(minor, cmd, buffer, 12, 1, SCSI_DATA_READ, NULL);
rc = sr_do_ioctl(cd, cmd, buffer, 12, 1, SCSI_DATA_READ, NULL);
if (rc != 0)
break;
if ((buffer[0] << 8) + buffer[1] < 0x0a) {
......@@ -205,12 +203,13 @@ int sr_cd_check(struct cdrom_device_info *cdi)
(cd->device->lun << 5) : 0;
cmd[1] |= 0x03;
cmd[2] = 0xb0;
rc = sr_do_ioctl(minor, cmd, buffer, 0x16, 1, SCSI_DATA_READ, NULL);
rc = sr_do_ioctl(cd, cmd, buffer, 0x16, 1, SCSI_DATA_READ, NULL);
if (rc != 0)
break;
if (buffer[14] != 0 && buffer[14] != 0xb0) {
printk(KERN_INFO "%s: Hmm, seems the cdrom "
"doesn't support multisession CD's\n", cd->cdi.name);
"doesn't support multisession CD's\n",
cd->cdi.name);
no_multi = 1;
break;
}
......@@ -231,10 +230,11 @@ int sr_cd_check(struct cdrom_device_info *cdi)
cmd[1] = (cd->device->scsi_level <= SCSI_2) ?
(cd->device->lun << 5) : 0;
cmd[1] |= 0x03;
rc = sr_do_ioctl(minor, cmd, buffer, 4, 1, SCSI_DATA_READ, NULL);
rc = sr_do_ioctl(cd, cmd, buffer, 4, 1, SCSI_DATA_READ, NULL);
if (rc == -EINVAL) {
printk(KERN_INFO "%s: Hmm, seems the drive "
"doesn't support multisession CD's\n", cd->cdi.name);
"doesn't support multisession CD's\n",
cd->cdi.name);
no_multi = 1;
break;
}
......@@ -246,7 +246,7 @@ int sr_cd_check(struct cdrom_device_info *cdi)
sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
if (sector)
sector -= CD_MSF_OFFSET;
sr_set_blocklength(minor, 2048);
sr_set_blocklength(cd, 2048);
break;
}
......@@ -257,7 +257,7 @@ int sr_cd_check(struct cdrom_device_info *cdi)
(cd->device->lun << 5) : 0;
cmd[8] = 0x04;
cmd[9] = 0x40;
rc = sr_do_ioctl(minor, cmd, buffer, 0x04, 1, SCSI_DATA_READ, NULL);
rc = sr_do_ioctl(cd, cmd, buffer, 0x04, 1, SCSI_DATA_READ, NULL);
if (rc != 0) {
break;
}
......@@ -272,7 +272,7 @@ int sr_cd_check(struct cdrom_device_info *cdi)
cmd[6] = rc & 0x7f; /* number of last session */
cmd[8] = 0x0c;
cmd[9] = 0x40;
rc = sr_do_ioctl(minor, cmd, buffer, 12, 1, SCSI_DATA_READ, NULL);
rc = sr_do_ioctl(cd, cmd, buffer, 12, 1, SCSI_DATA_READ, NULL);
if (rc != 0) {
break;
}
......@@ -292,11 +292,11 @@ int sr_cd_check(struct cdrom_device_info *cdi)
}
cd->ms_offset = sector;
cd->xa_flag = 0;
if (CDS_AUDIO != sr_disk_status(cdi) && 1 == sr_is_xa(minor))
if (CDS_AUDIO != sr_disk_status(cdi) && 1 == sr_is_xa(cd))
cd->xa_flag = 1;
if (2048 != cd->device->sector_size) {
sr_set_blocklength(minor, 2048);
sr_set_blocklength(cd, 2048);
}
if (no_multi)
cdi->mask |= CDC_MULTI_SESSION;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment