drivers/scsi/scsi_proc.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_proc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_proc.c- Extension
.c- Size
- 13617 bytes
- Lines
- 577
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/init.hlinux/string.hlinux/mm.hlinux/proc_fs.hlinux/errno.hlinux/blkdev.hlinux/seq_file.hlinux/mutex.hlinux/gfp.hlinux/uaccess.hscsi/scsi.hscsi/scsi_device.hscsi/scsi_host.hscsi/scsi_transport.hscsi_priv.hscsi_logging.h
Detected Declarations
struct scsi_proc_entryfunction proc_scsi_host_writefunction proc_scsi_showfunction proc_scsi_host_openfunction __scsi_lookup_proc_entryfunction scsi_lookup_proc_entryfunction scsi_template_proc_dirfunction scsi_proc_hostdir_addfunction scsi_proc_hostdir_rmfunction scsi_proc_host_addfunction scsi_proc_host_rmfunction proc_print_scsidevicefunction scsi_host_lookupfunction scsi_remove_single_devicefunction proc_scsi_writefunction scsi_seq_stopfunction scsi_seq_showfunction proc_scsi_openfunction scsi_init_procfsfunction scsi_exit_procfsexport scsi_template_proc_dir
Annotated Snippet
struct scsi_proc_entry {
struct list_head entry;
const struct scsi_host_template *sht;
struct proc_dir_entry *proc_dir;
unsigned int present;
};
static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
struct Scsi_Host *shost = pde_data(file_inode(file));
ssize_t ret = -ENOMEM;
char *page;
if (count > PROC_BLOCK_SIZE)
return -EOVERFLOW;
if (!shost->hostt->write_info)
return -EINVAL;
page = (char *)__get_free_page(GFP_KERNEL);
if (page) {
ret = -EFAULT;
if (copy_from_user(page, buf, count))
goto out;
ret = shost->hostt->write_info(shost, page, count);
}
out:
free_page((unsigned long)page);
return ret;
}
static int proc_scsi_show(struct seq_file *m, void *v)
{
struct Scsi_Host *shost = m->private;
return shost->hostt->show_info(m, shost);
}
static int proc_scsi_host_open(struct inode *inode, struct file *file)
{
return single_open_size(file, proc_scsi_show, pde_data(inode),
4 * PAGE_SIZE);
}
static struct scsi_proc_entry *
__scsi_lookup_proc_entry(const struct scsi_host_template *sht)
{
struct scsi_proc_entry *e;
lockdep_assert_held(&global_host_template_mutex);
list_for_each_entry(e, &scsi_proc_list, entry)
if (e->sht == sht)
return e;
return NULL;
}
static struct scsi_proc_entry *
scsi_lookup_proc_entry(const struct scsi_host_template *sht)
{
struct scsi_proc_entry *e;
mutex_lock(&global_host_template_mutex);
e = __scsi_lookup_proc_entry(sht);
mutex_unlock(&global_host_template_mutex);
return e;
}
/**
* scsi_template_proc_dir() - returns the procfs dir for a SCSI host template
* @sht: SCSI host template pointer.
*/
struct proc_dir_entry *
scsi_template_proc_dir(const struct scsi_host_template *sht)
{
struct scsi_proc_entry *e = scsi_lookup_proc_entry(sht);
return e ? e->proc_dir : NULL;
}
EXPORT_SYMBOL_GPL(scsi_template_proc_dir);
static const struct proc_ops proc_scsi_ops = {
.proc_open = proc_scsi_host_open,
.proc_release = single_release,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_write = proc_scsi_host_write
};
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/string.h`, `linux/mm.h`, `linux/proc_fs.h`, `linux/errno.h`, `linux/blkdev.h`, `linux/seq_file.h`.
- Detected declarations: `struct scsi_proc_entry`, `function proc_scsi_host_write`, `function proc_scsi_show`, `function proc_scsi_host_open`, `function __scsi_lookup_proc_entry`, `function scsi_lookup_proc_entry`, `function scsi_template_proc_dir`, `function scsi_proc_hostdir_add`, `function scsi_proc_hostdir_rm`, `function scsi_proc_host_add`.
- 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.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.