drivers/scsi/scsi_ioctl.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_ioctl.c- Extension
.c- Size
- 25053 bytes
- Lines
- 989
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/module.hlinux/blkdev.hlinux/interrupt.hlinux/errno.hlinux/kernel.hlinux/sched.hlinux/mm.hlinux/string.hlinux/uaccess.hlinux/cdrom.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_device.hscsi/scsi_eh.hscsi/scsi_host.hscsi/scsi_ioctl.hscsi/sg.hscsi/scsi_dbg.hscsi_logging.h
Detected Declarations
struct compat_cdrom_generic_commandfunction ioctl_probefunction ioctl_internal_commandfunction scsi_set_medium_removalfunction scsi_ioctl_get_pcifunction sg_get_versionfunction sg_set_timeoutfunction sg_get_reserved_sizefunction sg_set_reserved_sizefunction aboutfunction scsi_get_idlunfunction scsi_send_start_stopfunction scsi_cmd_allowedfunction scsi_fill_sghdr_rqfunction scsi_complete_sghdr_rqfunction sg_iofunction OMAX_SB_LENfunction put_sg_io_hdrfunction get_sg_io_hdrfunction scsi_get_cdrom_generic_argfunction scsi_put_cdrom_generic_argfunction scsi_cdrom_send_packetfunction scsi_ioctl_sg_iofunction scsi_ioctlfunction scsi_ioctl_block_when_processing_errorsexport scsi_set_medium_removalexport scsi_cmd_allowedexport put_sg_io_hdrexport get_sg_io_hdrexport scsi_ioctlexport scsi_ioctl_block_when_processing_errors
Annotated Snippet
struct compat_cdrom_generic_command {
unsigned char cmd[CDROM_PACKET_SIZE];
compat_caddr_t buffer;
compat_uint_t buflen;
compat_int_t stat;
compat_caddr_t sense;
unsigned char data_direction;
unsigned char pad[3];
compat_int_t quiet;
compat_int_t timeout;
compat_caddr_t unused;
};
#endif
static int scsi_get_cdrom_generic_arg(struct cdrom_generic_command *cgc,
const void __user *arg)
{
#ifdef CONFIG_COMPAT
if (in_compat_syscall()) {
struct compat_cdrom_generic_command cgc32;
if (copy_from_user(&cgc32, arg, sizeof(cgc32)))
return -EFAULT;
*cgc = (struct cdrom_generic_command) {
.buffer = compat_ptr(cgc32.buffer),
.buflen = cgc32.buflen,
.stat = cgc32.stat,
.sense = compat_ptr(cgc32.sense),
.data_direction = cgc32.data_direction,
.quiet = cgc32.quiet,
.timeout = cgc32.timeout,
.unused = compat_ptr(cgc32.unused),
};
memcpy(&cgc->cmd, &cgc32.cmd, CDROM_PACKET_SIZE);
return 0;
}
#endif
if (copy_from_user(cgc, arg, sizeof(*cgc)))
return -EFAULT;
return 0;
}
static int scsi_put_cdrom_generic_arg(const struct cdrom_generic_command *cgc,
void __user *arg)
{
#ifdef CONFIG_COMPAT
if (in_compat_syscall()) {
struct compat_cdrom_generic_command cgc32 = {
.buffer = (uintptr_t)(cgc->buffer),
.buflen = cgc->buflen,
.stat = cgc->stat,
.sense = (uintptr_t)(cgc->sense),
.data_direction = cgc->data_direction,
.quiet = cgc->quiet,
.timeout = cgc->timeout,
.unused = (uintptr_t)(cgc->unused),
};
memcpy(&cgc32.cmd, &cgc->cmd, CDROM_PACKET_SIZE);
if (copy_to_user(arg, &cgc32, sizeof(cgc32)))
return -EFAULT;
return 0;
}
#endif
if (copy_to_user(arg, cgc, sizeof(*cgc)))
return -EFAULT;
return 0;
}
static int scsi_cdrom_send_packet(struct scsi_device *sdev, bool open_for_write,
void __user *arg)
{
struct cdrom_generic_command cgc;
struct sg_io_hdr hdr;
int err;
err = scsi_get_cdrom_generic_arg(&cgc, arg);
if (err)
return err;
cgc.timeout = clock_t_to_jiffies(cgc.timeout);
memset(&hdr, 0, sizeof(hdr));
hdr.interface_id = 'S';
hdr.cmd_len = sizeof(cgc.cmd);
hdr.dxfer_len = cgc.buflen;
switch (cgc.data_direction) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/blkdev.h`, `linux/interrupt.h`, `linux/errno.h`, `linux/kernel.h`, `linux/sched.h`, `linux/mm.h`, `linux/string.h`.
- Detected declarations: `struct compat_cdrom_generic_command`, `function ioctl_probe`, `function ioctl_internal_command`, `function scsi_set_medium_removal`, `function scsi_ioctl_get_pci`, `function sg_get_version`, `function sg_set_timeout`, `function sg_get_reserved_size`, `function sg_set_reserved_size`, `function about`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.