drivers/mtd/nftlcore.c
Source file repositories/reference/linux-study-clean/drivers/mtd/nftlcore.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/nftlcore.c- Extension
.c- Size
- 22679 bytes
- Lines
- 804
- Domain
- Driver Families
- Bucket
- drivers/mtd
- 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/module.hasm/errno.hasm/io.hlinux/uaccess.hlinux/delay.hlinux/slab.hlinux/init.hlinux/hdreg.hlinux/blkdev.hlinux/kmod.hlinux/mtd/mtd.hlinux/mtd/rawnand.hlinux/mtd/nftl.hlinux/mtd/blktrans.h
Detected Declarations
function problemsfunction nftl_remove_devfunction nftl_read_oobfunction nftl_write_oobfunction nftl_writefunction NFTL_findfreeblockfunction NFTL_move_blockfunction NFTL_foldchainfunction NFTL_makefreeblockfunction NFTL_findwriteunitfunction nftl_writeblockfunction nftl_readblockfunction nftl_getgeo
Annotated Snippet
if (NFTL_mount(nftl) < 0) {
printk(KERN_WARNING "NFTL: could not mount device\n");
kfree(nftl);
return;
}
/* OK, it's a new one. Set up all the data structures. */
/* Calculate geometry */
nftl->cylinders = 1024;
nftl->heads = 16;
temp = nftl->cylinders * nftl->heads;
nftl->sectors = nftl->mbd.size / temp;
if (nftl->mbd.size % temp) {
nftl->sectors++;
temp = nftl->cylinders * nftl->sectors;
nftl->heads = nftl->mbd.size / temp;
if (nftl->mbd.size % temp) {
nftl->heads++;
temp = nftl->heads * nftl->sectors;
nftl->cylinders = nftl->mbd.size / temp;
}
}
if (nftl->mbd.size != nftl->heads * nftl->cylinders * nftl->sectors) {
/*
Oh no we don't have
mbd.size == heads * cylinders * sectors
*/
printk(KERN_WARNING "NFTL: cannot calculate a geometry to "
"match size of 0x%lx.\n", nftl->mbd.size);
printk(KERN_WARNING "NFTL: using C:%d H:%d S:%d "
"(== 0x%lx sects)\n",
nftl->cylinders, nftl->heads , nftl->sectors,
(long)nftl->cylinders * (long)nftl->heads *
(long)nftl->sectors );
}
if (add_mtd_blktrans_dev(&nftl->mbd)) {
kfree(nftl->ReplUnitTable);
kfree(nftl->EUNtable);
kfree(nftl);
return;
}
#ifdef PSYCHO_DEBUG
printk(KERN_INFO "NFTL: Found new nftl%c\n", nftl->mbd.devnum + 'a');
#endif
}
static void nftl_remove_dev(struct mtd_blktrans_dev *dev)
{
struct NFTLrecord *nftl = (void *)dev;
pr_debug("NFTL: remove_dev (i=%d)\n", dev->devnum);
del_mtd_blktrans_dev(dev);
kfree(nftl->ReplUnitTable);
kfree(nftl->EUNtable);
}
/*
* Read oob data from flash
*/
int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
size_t *retlen, uint8_t *buf)
{
loff_t mask = mtd->writesize - 1;
struct mtd_oob_ops ops = { };
int res;
ops.mode = MTD_OPS_PLACE_OOB;
ops.ooboffs = offs & mask;
ops.ooblen = len;
ops.oobbuf = buf;
ops.datbuf = NULL;
res = mtd_read_oob(mtd, offs & ~mask, &ops);
*retlen = ops.oobretlen;
return res;
}
/*
* Write oob data to flash
*/
int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
size_t *retlen, uint8_t *buf)
{
loff_t mask = mtd->writesize - 1;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `asm/errno.h`, `asm/io.h`, `linux/uaccess.h`, `linux/delay.h`, `linux/slab.h`, `linux/init.h`.
- Detected declarations: `function problems`, `function nftl_remove_dev`, `function nftl_read_oob`, `function nftl_write_oob`, `function nftl_write`, `function NFTL_findfreeblock`, `function NFTL_move_block`, `function NFTL_foldchain`, `function NFTL_makefreeblock`, `function NFTL_findwriteunit`.
- Atlas domain: Driver Families / drivers/mtd.
- 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.