Commit e342ff2e authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] (10/25) sr.c device name handling

	sr.c: we set SCp->cdi.name from the very beginning, which allows
to kill passing minors in many cases (we can use "%s...", SCp->cd.name instead
of "sr%d...", minor and that turns out to be the majority of places where
we use minors at all).
parent 897c924e
......@@ -332,8 +332,8 @@ static int sr_init_command(Scsi_Cmnd * SCpnt)
this_count = (SCpnt->request_bufflen >> 9) / (s_size >> 9);
SCSI_LOG_HLQUEUE(2, printk("sr%d : %s %d/%ld 512 byte blocks.\n",
devm,
SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n",
SCp->cdi.name,
(rq_data_dir(SCpnt->request) == WRITE) ? "writing" : "reading",
this_count, SCpnt->request->nr_sectors));
......@@ -464,8 +464,8 @@ static int sr_attach(Scsi_Device * SDp)
if (sr_template.nr_dev > sr_template.dev_max)
panic("scsi_devices corrupt (sr)");
printk("Attached scsi CD-ROM sr%d at scsi%d, channel %d, id %d, lun %d\n",
i, SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
printk("Attached scsi CD-ROM %s at scsi%d, channel %d, id %d, lun %d\n",
scsi_CDs[i].cdi.name, SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
return 0;
}
......@@ -547,8 +547,8 @@ void get_sectorsize(int i)
case 512:
break;
default:
printk("sr%d: unsupported sector size %d.\n",
i, sector_size);
printk("%s: unsupported sector size %d.\n",
SCp->cdi.name, sector_size);
SCp->capacity = 0;
SCp->needs_sector_size = 1;
}
......@@ -619,7 +619,7 @@ void get_capabilities(int i)
CDC_DVD | CDC_DVD_RAM |
CDC_SELECT_DISC | CDC_SELECT_SPEED);
kfree(buffer);
printk("sr%i: scsi-1 drive\n", i);
printk("%s: scsi-1 drive\n", SCp->cdi.name);
return;
}
n = buffer[3] + 4;
......@@ -627,7 +627,7 @@ void get_capabilities(int i)
SCp->readcd_known = 1;
SCp->readcd_cdda = buffer[n + 5] & 0x01;
/* print some capability bits */
printk("sr%i: scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n", i,
printk("%s: scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n", SCp->cdi.name,
((buffer[n + 14] << 8) + buffer[n + 15]) / 176,
SCp->cdi.speed,
buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */
......@@ -696,6 +696,7 @@ static int sr_registered;
static int sr_init()
{
int i;
if (sr_template.dev_noticed == 0)
return 0;
......@@ -714,6 +715,8 @@ static int sr_init()
if (!scsi_CDs)
goto cleanup_dev;
memset(scsi_CDs, 0, sr_template.dev_max * sizeof(Scsi_CD));
for (i = 0; i < sr_template.dev_max; i++)
sprintf(scsi_CDs[i].cdi.name, "sr%d", i);
sr_sizes = kmalloc(sr_template.dev_max * sizeof(int), GFP_ATOMIC);
if (!sr_sizes)
......@@ -750,7 +753,6 @@ static DEVICE_ATTR(type,S_IRUGO,sr_device_type_read,NULL);
void sr_finish()
{
int i;
char name[6];
blk_dev[MAJOR_NR].queue = sr_find_queue;
blk_size[MAJOR_NR] = sr_sizes;
......@@ -790,8 +792,6 @@ void sr_finish()
get_capabilities(i);
sr_vendor_init(SCp);
sprintf(name, "sr%d", i);
strcpy(SCp->cdi.name, name);
sprintf(SCp->cdi.cdrom_driverfs_dev.bus_id, "%s:cd",
SCp->device->sdev_driverfs_dev.bus_id);
sprintf(SCp->cdi.cdrom_driverfs_dev.name, "%scdrom",
......
......@@ -78,13 +78,14 @@ static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti
int sr_do_ioctl(int target, 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;
int result, err = 0, retries = 0;
char *bounce_buffer;
SDev = scsi_CDs[target].device;
SDev = cd->device;
SRpnt = scsi_allocate_request(SDev);
if (!SRpnt) {
printk("Unable to allocate SCSI request in sr_do_ioctl");
......@@ -127,7 +128,7 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
case UNIT_ATTENTION:
SDev->changed = 1;
if (!quiet)
printk(KERN_INFO "sr%d: disc change detected.\n", target);
printk(KERN_INFO "%s: disc change detected.\n", cd->cdi.name);
if (retries++ < 10)
goto retry;
err = -ENOMEDIUM;
......@@ -137,7 +138,7 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
SRpnt->sr_sense_buffer[13] == 0x01) {
/* sense: Logical unit is in process of becoming ready */
if (!quiet)
printk(KERN_INFO "sr%d: CDROM not ready yet.\n", target);
printk(KERN_INFO "%s: CDROM not ready yet.\n", cd->cdi.name);
if (retries++ < 10) {
/* sleep 2 sec and try again */
scsi_sleep(2 * HZ);
......@@ -149,7 +150,7 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
}
}
if (!quiet)
printk(KERN_INFO "sr%d: CDROM not ready. Make sure there is a disc in the drive.\n", target);
printk(KERN_INFO "%s: CDROM not ready. Make sure there is a disc in the drive.\n", cd->cdi.name);
#ifdef DEBUG
print_req_sense("sr", SRpnt);
#endif
......@@ -157,8 +158,8 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
break;
case ILLEGAL_REQUEST:
if (!quiet)
printk(KERN_ERR "sr%d: CDROM (ioctl) reports ILLEGAL "
"REQUEST.\n", target);
printk(KERN_ERR "%s: CDROM (ioctl) reports ILLEGAL "
"REQUEST.\n", cd->cdi.name);
if (SRpnt->sr_sense_buffer[12] == 0x20 &&
SRpnt->sr_sense_buffer[13] == 0x00) {
/* sense: Invalid command operation code */
......@@ -172,7 +173,7 @@ int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflen
#endif
break;
default:
printk(KERN_ERR "sr%d: CDROM (ioctl) error, command: ", target);
printk(KERN_ERR "%s: CDROM (ioctl) error, command: ", cd->cdi.name);
print_command(sr_cmd);
print_req_sense("sr", SRpnt);
err = -EIO;
......@@ -445,8 +446,8 @@ int sr_read_cd(int minor, unsigned char *dest, int lba, int format, int blksize)
Scsi_CD *SCp = &scsi_CDs[minor];
#ifdef DEBUG
printk("sr%d: sr_read_cd lba=%d format=%d blksize=%d\n",
minor, lba, format, blksize);
printk("%s: sr_read_cd lba=%d format=%d blksize=%d\n",
SCp->cdi.name, lba, format, blksize);
#endif
memset(cmd, 0, MAX_COMMAND_SIZE);
......@@ -501,7 +502,7 @@ int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
return rc;
}
#ifdef DEBUG
printk("sr%d: sr_read_sector lba=%d blksize=%d\n", minor, lba, blksize);
printk("%s: sr_read_sector lba=%d blksize=%d\n", SCp->cdi.name, lba, blksize);
#endif
memset(cmd, 0, MAX_COMMAND_SIZE);
......@@ -544,7 +545,7 @@ int sr_is_xa(int minor)
}
kfree(raw_sector);
#ifdef DEBUG
printk("sr%d: sr_is_xa: %d\n", minor, is_xa);
printk("%s: sr_is_xa: %d\n", SCp->cdi.name, is_xa);
#endif
return is_xa;
}
......
......@@ -119,7 +119,7 @@ int sr_set_blocklength(int minor, int blocklength)
return -ENOMEM;
#ifdef DEBUG
printk("sr%d: MODE SELECT 0x%x/%d\n", minor, density, blocklength);
printk("%s: MODE SELECT 0x%x/%d\n", SCp->cdi.name, density, blocklength);
#endif
memset(cmd, 0, MAX_COMMAND_SIZE);
cmd[0] = MODE_SELECT;
......@@ -138,8 +138,8 @@ int sr_set_blocklength(int minor, int blocklength)
}
#ifdef DEBUG
else
printk("sr%d: switching blocklength to %d bytes failed\n",
minor, blocklength);
printk("%s: switching blocklength to %d bytes failed\n",
SCp->cdi.name, blocklength);
#endif
kfree(buffer);
return rc;
......@@ -183,8 +183,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
if (rc != 0)
break;
if ((buffer[0] << 8) + buffer[1] < 0x0a) {
printk(KERN_INFO "sr%d: Hmm, seems the drive "
"doesn't support multisession CD's\n", minor);
printk(KERN_INFO "%s: Hmm, seems the drive "
"doesn't support multisession CD's\n", SCp->cdi.name);
no_multi = 1;
break;
}
......@@ -209,8 +209,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
if (rc != 0)
break;
if (buffer[14] != 0 && buffer[14] != 0xb0) {
printk(KERN_INFO "sr%d: Hmm, seems the cdrom "
"doesn't support multisession CD's\n", minor);
printk(KERN_INFO "%s: Hmm, seems the cdrom "
"doesn't support multisession CD's\n", SCp->cdi.name);
no_multi = 1;
break;
}
......@@ -233,8 +233,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
cmd[1] |= 0x03;
rc = sr_do_ioctl(minor, cmd, buffer, 4, 1, SCSI_DATA_READ, NULL);
if (rc == -EINVAL) {
printk(KERN_INFO "sr%d: Hmm, seems the drive "
"doesn't support multisession CD's\n", minor);
printk(KERN_INFO "%s: Hmm, seems the drive "
"doesn't support multisession CD's\n", SCp->cdi.name);
no_multi = 1;
break;
}
......@@ -263,7 +263,7 @@ int sr_cd_check(struct cdrom_device_info *cdi)
}
if ((rc = buffer[2]) == 0) {
printk(KERN_WARNING
"sr%d: No finished session\n", minor);
"%s: No finished session\n", SCp->cdi.name);
break;
}
cmd[0] = READ_TOC; /* Read TOC */
......@@ -284,8 +284,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
default:
/* should not happen */
printk(KERN_WARNING
"sr%d: unknown vendor code (%i), not initialized ?\n",
minor, SCp->vendor);
"%s: unknown vendor code (%i), not initialized ?\n",
SCp->cdi.name, SCp->vendor);
sector = 0;
no_multi = 1;
break;
......@@ -303,8 +303,8 @@ int sr_cd_check(struct cdrom_device_info *cdi)
#ifdef DEBUG
if (sector)
printk(KERN_DEBUG "sr%d: multisession offset=%lu\n",
minor, sector);
printk(KERN_DEBUG "%s: multisession offset=%lu\n",
SCp->cdi.name, sector);
#endif
kfree(buffer);
return rc;
......
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