drivers/mtd/ftl.c
Source file repositories/reference/linux-study-clean/drivers/mtd/ftl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/ftl.c- Extension
.c- Size
- 31047 bytes
- Lines
- 1061
- 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/mtd/blktrans.hlinux/module.hlinux/mtd/mtd.hlinux/kernel.hlinux/ptrace.hlinux/slab.hlinux/string.hlinux/timer.hlinux/major.hlinux/fs.hlinux/init.hlinux/hdreg.hlinux/vmalloc.hlinux/blkpg.hlinux/uaccess.hlinux/mtd/ftl.h
Detected Declarations
struct eun_info_tstruct xfer_info_tfunction Scan_headerfunction build_mapsfunction Erase_xferfunction Prepare_xferfunction Copy_erase_unitfunction reclaim_blockfunction Find_freefunction find_freefunction ftl_readfunction set_bam_entryfunction ftl_writefunction ftl_getgeofunction ftl_readsectfunction ftl_writesectfunction ftl_discardsectfunction ftl_freepartfunction ftl_add_mtdfunction ftl_remove_dev
Annotated Snippet
struct eun_info_t {
uint32_t Offset;
uint32_t EraseCount;
uint32_t Free;
uint32_t Deleted;
} *EUNInfo;
struct xfer_info_t {
uint32_t Offset;
uint32_t EraseCount;
uint16_t state;
} *XferInfo;
uint16_t bam_index;
uint32_t *bam_cache;
uint16_t DataUnits;
uint32_t BlocksPerUnit;
erase_unit_header_t header;
} partition_t;
/* Partition state flags */
#define FTL_FORMATTED 0x01
/* Transfer unit states */
#define XFER_UNKNOWN 0x00
#define XFER_ERASING 0x01
#define XFER_ERASED 0x02
#define XFER_PREPARED 0x03
#define XFER_FAILED 0x04
/*======================================================================
Scan_header() checks to see if a memory region contains an FTL
partition. build_maps() reads all the erase unit headers, builds
the erase unit map, and then builds the virtual page map.
======================================================================*/
static int scan_header(partition_t *part)
{
erase_unit_header_t header;
loff_t offset, max_offset;
size_t ret;
int err;
part->header.FormattedSize = 0;
max_offset = (0x100000<part->mbd.mtd->size)?0x100000:part->mbd.mtd->size;
/* Search first megabyte for a valid FTL header */
for (offset = 0;
(offset + sizeof(header)) < max_offset;
offset += part->mbd.mtd->erasesize ? : 0x2000) {
err = mtd_read(part->mbd.mtd, offset, sizeof(header), &ret,
(unsigned char *)&header);
if (err)
return err;
if (strcmp(header.DataOrgTuple+3, "FTL100") == 0) break;
}
if (offset == max_offset) {
printk(KERN_NOTICE "ftl_cs: FTL header not found.\n");
return -ENOENT;
}
if (header.BlockSize != 9 ||
(header.EraseUnitSize < 10) || (header.EraseUnitSize > 31) ||
(header.NumTransferUnits >= le16_to_cpu(header.NumEraseUnits))) {
printk(KERN_NOTICE "ftl_cs: FTL header corrupt!\n");
return -1;
}
if ((1 << header.EraseUnitSize) != part->mbd.mtd->erasesize) {
printk(KERN_NOTICE "ftl: FTL EraseUnitSize %x != MTD erasesize %x\n",
1 << header.EraseUnitSize,part->mbd.mtd->erasesize);
return -1;
}
part->header = header;
return 0;
}
static int build_maps(partition_t *part)
{
erase_unit_header_t header;
uint16_t xvalid, xtrans, i;
unsigned blocks, j;
int hdr_ok, ret = -1;
ssize_t retval;
loff_t offset;
/* Set up erase unit maps */
part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) -
part->header.NumTransferUnits;
part->EUNInfo = kmalloc_objs(struct eun_info_t, part->DataUnits);
Annotation
- Immediate include surface: `linux/mtd/blktrans.h`, `linux/module.h`, `linux/mtd/mtd.h`, `linux/kernel.h`, `linux/ptrace.h`, `linux/slab.h`, `linux/string.h`, `linux/timer.h`.
- Detected declarations: `struct eun_info_t`, `struct xfer_info_t`, `function Scan_header`, `function build_maps`, `function Erase_xfer`, `function Prepare_xfer`, `function Copy_erase_unit`, `function reclaim_block`, `function Find_free`, `function find_free`.
- 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.