drivers/mtd/ubi/eba.c
Source file repositories/reference/linux-study-clean/drivers/mtd/ubi/eba.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/ubi/eba.c- Extension
.c- Size
- 47257 bytes
- Lines
- 1710
- 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.
- 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/slab.hlinux/crc32.hlinux/err.hubi.h
Detected Declarations
struct ubi_eba_entrystruct ubi_eba_tablefunction ubi_next_sqnumfunction ubi_get_compatfunction ubi_eba_get_ldescfunction ubi_eba_destroy_tablefunction ubi_eba_copy_tablefunction ubi_eba_replace_tablefunction eraseblockfunction leb_read_lockfunction leb_read_unlockfunction leb_write_lockfunction leb_write_trylockfunction leb_write_unlockfunction ubi_eba_is_mappedfunction ubi_eba_unmap_lebfunction check_mappingfunction check_mappingfunction ubi_eba_read_lebfunction ubi_eba_read_lebfunction errorfunction recover_pebfunction try_write_vid_and_datafunction ubi_eba_write_lebfunction ubi_eba_write_leb_stfunction ubi_eba_atomic_leb_changefunction PEBfunction ubi_eba_copy_lebfunction print_rsvd_warningfunction ubi_assertfunction ubi_eba_initfunction ubi_rb_for_each_entry
Annotated Snippet
struct ubi_eba_entry {
int pnum;
};
/**
* struct ubi_eba_table - LEB -> PEB association information
* @entries: the LEB to PEB mapping (one entry per LEB).
*
* This structure is private to the EBA logic and should be kept here.
* It is encoding the LEB to PEB association table, and is subject to
* changes.
*/
struct ubi_eba_table {
struct ubi_eba_entry *entries;
};
/**
* ubi_next_sqnum - get next sequence number.
* @ubi: UBI device description object
*
* This function returns next sequence number to use, which is just the current
* global sequence counter value. It also increases the global sequence
* counter.
*/
unsigned long long ubi_next_sqnum(struct ubi_device *ubi)
{
unsigned long long sqnum;
spin_lock(&ubi->ltree_lock);
sqnum = ubi->global_sqnum++;
spin_unlock(&ubi->ltree_lock);
return sqnum;
}
/**
* ubi_get_compat - get compatibility flags of a volume.
* @ubi: UBI device description object
* @vol_id: volume ID
*
* This function returns compatibility flags for an internal volume. User
* volumes have no compatibility flags, so %0 is returned.
*/
static int ubi_get_compat(const struct ubi_device *ubi, int vol_id)
{
if (vol_id == UBI_LAYOUT_VOLUME_ID)
return UBI_LAYOUT_VOLUME_COMPAT;
return 0;
}
/**
* ubi_eba_get_ldesc - get information about a LEB
* @vol: volume description object
* @lnum: logical eraseblock number
* @ldesc: the LEB descriptor to fill
*
* Used to query information about a specific LEB.
* It is currently only returning the physical position of the LEB, but will be
* extended to provide more information.
*/
void ubi_eba_get_ldesc(struct ubi_volume *vol, int lnum,
struct ubi_eba_leb_desc *ldesc)
{
ldesc->lnum = lnum;
ldesc->pnum = vol->eba_tbl->entries[lnum].pnum;
}
/**
* ubi_eba_create_table - allocate a new EBA table and initialize it with all
* LEBs unmapped
* @vol: volume containing the EBA table to copy
* @nentries: number of entries in the table
*
* Allocate a new EBA table and initialize it with all LEBs unmapped.
* Returns a valid pointer if it succeed, an ERR_PTR() otherwise.
*/
struct ubi_eba_table *ubi_eba_create_table(struct ubi_volume *vol,
int nentries)
{
struct ubi_eba_table *tbl;
int err = -ENOMEM;
int i;
tbl = kzalloc_obj(*tbl);
if (!tbl)
return ERR_PTR(-ENOMEM);
tbl->entries = kmalloc_objs(*tbl->entries, nentries);
if (!tbl->entries)
goto err;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/crc32.h`, `linux/err.h`, `ubi.h`.
- Detected declarations: `struct ubi_eba_entry`, `struct ubi_eba_table`, `function ubi_next_sqnum`, `function ubi_get_compat`, `function ubi_eba_get_ldesc`, `function ubi_eba_destroy_table`, `function ubi_eba_copy_table`, `function ubi_eba_replace_table`, `function eraseblock`, `function leb_read_lock`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: source 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.