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