drivers/mtd/mtdpart.c
Source file repositories/reference/linux-study-clean/drivers/mtd/mtdpart.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/mtdpart.c- Extension
.c- Size
- 20204 bytes
- Lines
- 750
- Domain
- Driver Families
- Bucket
- drivers/mtd
- 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.
- 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/types.hlinux/kernel.hlinux/slab.hlinux/list.hlinux/kmod.hlinux/mtd/mtd.hlinux/mtd/partitions.hlinux/err.hlinux/of.hlinux/of_platform.hlinux/mtd/concat.hmtdcore.h
Detected Declarations
function free_partitionfunction release_mtd_partitionfunction offset_showfunction mtd_add_partition_attrsfunction mtd_add_partitionfunction __mtd_del_partitionfunction list_for_each_entry_safefunction __del_mtd_partitionsfunction list_for_each_entry_safefunction del_mtd_partitionsfunction mtd_del_partitionfunction add_mtd_partitionsfunction list_for_each_entryfunction mtd_part_parser_putfunction kfreefunction __register_mtd_parserfunction deregister_mtd_parserfunction mtd_part_do_parsefunction list_for_each_entryfunction mtd_part_of_parsefunction of_property_for_each_stringfunction parse_mtd_partitionsfunction mtd_part_parser_cleanupfunction mtd_get_device_sizeexport mtd_add_partitionexport mtd_del_partitionexport __register_mtd_parserexport deregister_mtd_parserexport mtd_get_device_size
Annotated Snippet
if (remainder) {
child->part.offset += wr_alignment - remainder;
printk(KERN_NOTICE "Moving partition %d: "
"0x%012llx -> 0x%012llx\n", partno,
(unsigned long long)cur_offset,
child->part.offset);
}
}
if (child->part.offset == MTDPART_OFS_RETAIN) {
child->part.offset = cur_offset;
if (parent_size - child->part.offset >= child->part.size) {
child->part.size = parent_size - child->part.offset -
child->part.size;
} else {
printk(KERN_ERR "mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
part->name, parent_size - child->part.offset,
child->part.size);
/* register to preserve ordering */
goto out_register;
}
}
if (child->part.size == MTDPART_SIZ_FULL)
child->part.size = parent_size - child->part.offset;
printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n",
child->part.offset, child->part.offset + child->part.size,
child->name);
/* let's do some sanity checks */
if (child->part.offset >= parent_size) {
/* let's register it anyway to preserve ordering */
child->part.offset = 0;
child->part.size = 0;
/* Initialize ->erasesize to make add_mtd_device() happy. */
child->erasesize = parent->erasesize;
printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
part->name);
goto out_register;
}
if (child->part.offset + child->part.size > parent->size) {
child->part.size = parent_size - child->part.offset;
printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n",
part->name, parent->name, child->part.size);
}
if (parent->numeraseregions > 1) {
/* Deal with variable erase size stuff */
int i, max = parent->numeraseregions;
u64 end = child->part.offset + child->part.size;
struct mtd_erase_region_info *regions = parent->eraseregions;
/* Find the first erase regions which is part of this
* partition. */
for (i = 0; i < max && regions[i].offset <= child->part.offset;
i++)
;
/* The loop searched for the region _behind_ the first one */
if (i > 0)
i--;
/* Pick biggest erasesize */
for (; i < max && regions[i].offset < end; i++) {
if (child->erasesize < regions[i].erasesize)
child->erasesize = regions[i].erasesize;
}
BUG_ON(child->erasesize == 0);
} else {
/* Single erase size */
child->erasesize = master->erasesize;
}
/*
* Child erasesize might differ from the parent one if the parent
* exposes several regions with different erasesize. Adjust
* wr_alignment accordingly.
*/
if (!(child->flags & MTD_NO_ERASE))
wr_alignment = child->erasesize;
tmp = mtd_get_master_ofs(child, 0);
remainder = do_div(tmp, wr_alignment);
if ((child->flags & MTD_WRITEABLE) && remainder) {
/* Doesn't start on a boundary of major erase size */
/* FIXME: Let it be writable if it is on a boundary of
* _minor_ erase size though */
child->flags &= ~MTD_WRITEABLE;
printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
part->name);
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/slab.h`, `linux/list.h`, `linux/kmod.h`, `linux/mtd/mtd.h`, `linux/mtd/partitions.h`.
- Detected declarations: `function free_partition`, `function release_mtd_partition`, `function offset_show`, `function mtd_add_partition_attrs`, `function mtd_add_partition`, `function __mtd_del_partition`, `function list_for_each_entry_safe`, `function __del_mtd_partitions`, `function list_for_each_entry_safe`, `function del_mtd_partitions`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: integration implementation candidate.
- 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.