drivers/scsi/sr_ioctl.c
Source file repositories/reference/linux-study-clean/drivers/scsi/sr_ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/sr_ioctl.c- Extension
.c- Size
- 15242 bytes
- Lines
- 601
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/mm.hlinux/fs.hlinux/errno.hlinux/string.hlinux/blkdev.hlinux/module.hlinux/blkpg.hlinux/cdrom.hlinux/delay.hlinux/slab.hasm/io.hlinux/uaccess.hscsi/scsi.hscsi/scsi_dbg.hscsi/scsi_device.hscsi/scsi_eh.hscsi/scsi_host.hscsi/scsi_ioctl.hscsi/scsi_cmnd.hsr.h
Detected Declarations
function sr_read_tochdrfunction sr_read_tocentryfunction sr_fake_playtrkindfunction sr_play_trkindfunction sr_do_ioctlfunction sr_tray_movefunction sr_lock_doorfunction sr_drive_statusfunction sr_disk_statusfunction sr_get_last_sessionfunction sr_get_mcnfunction sr_resetfunction sr_select_speedfunction sr_audio_ioctlfunction sr_read_cdfunction sr_read_sectorfunction sr_is_xa
Annotated Snippet
switch (sshdr->sense_key) {
case UNIT_ATTENTION:
SDev->changed = 1;
if (!cgc->quiet)
sr_printk(KERN_INFO, cd,
"disc change detected.\n");
if (retries++ < 10)
goto retry;
err = -ENOMEDIUM;
break;
case NOT_READY: /* This happens if there is no disc in drive */
if (sshdr->asc == 0x04 &&
sshdr->ascq == 0x01) {
/* sense: Logical unit is in process of becoming ready */
if (!cgc->quiet)
sr_printk(KERN_INFO, cd,
"CDROM not ready yet.\n");
if (retries++ < 10) {
/* sleep 2 sec and try again */
ssleep(2);
goto retry;
} else {
/* 20 secs are enough? */
err = -ENOMEDIUM;
break;
}
}
if (!cgc->quiet)
sr_printk(KERN_INFO, cd,
"CDROM not ready. Make sure there "
"is a disc in the drive.\n");
err = -ENOMEDIUM;
break;
case ILLEGAL_REQUEST:
err = -EIO;
if (sshdr->asc == 0x20 &&
sshdr->ascq == 0x00)
/* sense: Invalid command operation code */
err = -EDRIVE_CANT_DO_THIS;
break;
default:
err = -EIO;
}
}
/* Wake up a process waiting for device */
out:
cgc->stat = err;
return err;
}
/* ---------------------------------------------------------------------- */
/* interface to cdrom.c */
int sr_tray_move(struct cdrom_device_info *cdi, int pos)
{
Scsi_CD *cd = cdi->handle;
struct packet_command cgc;
memset(&cgc, 0, sizeof(struct packet_command));
cgc.cmd[0] = GPCMD_START_STOP_UNIT;
cgc.cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
cgc.data_direction = DMA_NONE;
cgc.timeout = IOCTL_TIMEOUT;
return sr_do_ioctl(cd, &cgc);
}
int sr_lock_door(struct cdrom_device_info *cdi, int lock)
{
Scsi_CD *cd = cdi->handle;
return scsi_set_medium_removal(cd->device, lock ?
SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
}
int sr_drive_status(struct cdrom_device_info *cdi, int slot)
{
struct scsi_cd *cd = cdi->handle;
struct scsi_sense_hdr sshdr;
struct media_event_desc med;
if (CDSL_CURRENT != slot) {
/* we have no changer support */
return -EINVAL;
}
if (!scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
return CDS_DISC_OK;
/* SK/ASC/ASCQ of 2/4/1 means "unit is becoming ready" */
if (scsi_sense_valid(&sshdr) && sshdr.sense_key == NOT_READY
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/mm.h`, `linux/fs.h`, `linux/errno.h`, `linux/string.h`, `linux/blkdev.h`, `linux/module.h`, `linux/blkpg.h`.
- Detected declarations: `function sr_read_tochdr`, `function sr_read_tocentry`, `function sr_fake_playtrkind`, `function sr_play_trkind`, `function sr_do_ioctl`, `function sr_tray_move`, `function sr_lock_door`, `function sr_drive_status`, `function sr_disk_status`, `function sr_get_last_session`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.