drivers/mtd/mtdchar.c
Source file repositories/reference/linux-study-clean/drivers/mtd/mtdchar.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/mtdchar.c- Extension
.c- Size
- 31235 bytes
- Lines
- 1427
- Domain
- Driver Families
- Bucket
- drivers/mtd
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/device.hlinux/fs.hlinux/mm.hlinux/err.hlinux/init.hlinux/kernel.hlinux/module.hlinux/slab.hlinux/sched.hlinux/mutex.hlinux/backing-dev.hlinux/compat.hlinux/mount.hlinux/blkpg.hlinux/magic.hlinux/major.hlinux/mtd/mtd.hlinux/mtd/partitions.hlinux/mtd/map.hlinux/uaccess.hmtdcore.h
Detected Declarations
struct mtd_file_infostruct mtd_oob_buf32function mtdchar_lseekfunction mtdchar_openfunction mtdchar_closefunction mtdchar_readfunction mtdchar_writefunction otp_select_filemodefunction mtdchar_writeoobfunction mtdchar_readoobfunction Copiesfunction get_oobinfofunction mtdchar_blkpg_ioctlfunction adjust_oob_lengthfunction mtdchar_write_ioctlfunction mtdchar_read_ioctlfunction loopfunction mtdchar_ioctlfunction mtdchar_unlocked_ioctlfunction mtdchar_compat_ioctlfunction mtdchar_get_unmapped_areafunction mtdchar_mmap_capabilitiesfunction mtdchar_mmap_preparefunction init_mtdcharfunction cleanup_mtdchar
Annotated Snippet
static const struct file_operations mtd_fops = {
.owner = THIS_MODULE,
.llseek = mtdchar_lseek,
.read = mtdchar_read,
.write = mtdchar_write,
.unlocked_ioctl = mtdchar_unlocked_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = mtdchar_compat_ioctl,
#endif
.open = mtdchar_open,
.release = mtdchar_close,
.mmap_prepare = mtdchar_mmap_prepare,
#ifndef CONFIG_MMU
.get_unmapped_area = mtdchar_get_unmapped_area,
.mmap_capabilities = mtdchar_mmap_capabilities,
#endif
};
int __init init_mtdchar(void)
{
int ret;
ret = __register_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS,
"mtd", &mtd_fops);
if (ret < 0) {
pr_err("Can't allocate major number %d for MTD\n",
MTD_CHAR_MAJOR);
return ret;
}
return ret;
}
void __exit cleanup_mtdchar(void)
{
__unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd");
}
MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR);
Annotation
- Immediate include surface: `linux/device.h`, `linux/fs.h`, `linux/mm.h`, `linux/err.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/slab.h`.
- Detected declarations: `struct mtd_file_info`, `struct mtd_oob_buf32`, `function mtdchar_lseek`, `function mtdchar_open`, `function mtdchar_close`, `function mtdchar_read`, `function mtdchar_write`, `function otp_select_filemode`, `function mtdchar_writeoob`, `function mtdchar_readoob`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: pattern 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.