drivers/mtd/ubi/io.c
Source file repositories/reference/linux-study-clean/drivers/mtd/ubi/io.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/ubi/io.c- Extension
.c- Size
- 44010 bytes
- Lines
- 1485
- 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/crc32.hlinux/err.hlinux/slab.hubi.h
Detected Declarations
function ubi_io_readfunction ubi_io_writefunction do_sync_erasefunction torture_pebfunction nor_erase_preparefunction ubi_io_sync_erasefunction ubi_io_is_badfunction ubi_io_mark_badfunction validate_ec_hdrfunction ubi_io_read_ec_hdrfunction ubi_io_write_ec_hdrfunction validate_vid_hdrfunction ubi_io_read_vid_hdrfunction ubi_io_write_vid_hdrfunction self_check_not_badfunction self_check_ec_hdrfunction self_check_peb_ec_hdrfunction self_check_vid_hdrfunction self_check_peb_vid_hdrfunction self_check_writefunction ubi_self_check_all_ff
Annotated Snippet
if (mtd_is_bitflip(err)) {
/*
* -EUCLEAN is reported if there was a bit-flip which
* was corrected, so this is harmless.
*
* We do not report about it here unless debugging is
* enabled. A corresponding message will be printed
* later, when it is has been scrubbed.
*/
ubi_msg(ubi, "fixable bit-flip detected at PEB %d",
pnum);
ubi_assert(len == read);
return UBI_IO_BITFLIPS;
}
if (retries++ < UBI_IO_RETRIES) {
ubi_warn(ubi, "error %d%s while reading %d bytes from PEB %d:%d, read only %zd bytes, retry",
err, errstr, len, pnum, offset, read);
yield();
goto retry;
}
ubi_err(ubi, "error %d%s while reading %d bytes from PEB %d:%d, read %zd bytes",
err, errstr, len, pnum, offset, read);
dump_stack();
/*
* The driver should never return -EBADMSG if it failed to read
* all the requested data. But some buggy drivers might do
* this, so we change it to -EIO.
*/
if (read != len && mtd_is_eccerr(err)) {
ubi_assert(0);
err = -EIO;
}
} else {
ubi_assert(len == read);
if (ubi_dbg_is_bitflip(ubi)) {
dbg_gen("bit-flip (emulated)");
return UBI_IO_BITFLIPS;
}
if (ubi_dbg_is_read_failure(ubi, MASK_READ_FAILURE)) {
ubi_warn(ubi, "cannot read %d bytes from PEB %d:%d (emulated)",
len, pnum, offset);
return -EIO;
}
if (ubi_dbg_is_eccerr(ubi)) {
ubi_warn(ubi, "ECC error (emulated) while reading %d bytes from PEB %d:%d, read %zd bytes",
len, pnum, offset, read);
return -EBADMSG;
}
}
return err;
}
/**
* ubi_io_write - write data to a physical eraseblock.
* @ubi: UBI device description object
* @buf: buffer with the data to write
* @pnum: physical eraseblock number to write to
* @offset: offset within the physical eraseblock where to write
* @len: how many bytes to write
*
* This function writes @len bytes of data from buffer @buf to offset @offset
* of physical eraseblock @pnum. If all the data were successfully written,
* zero is returned. If an error occurred, this function returns a negative
* error code. If %-EIO is returned, the physical eraseblock most probably went
* bad.
*
* Note, in case of an error, it is possible that something was still written
* to the flash media, but may be some garbage.
*/
int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
int len)
{
int err;
size_t written;
loff_t addr;
dbg_io("write %d bytes to PEB %d:%d", len, pnum, offset);
ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
ubi_assert(offset >= 0 && offset + len <= ubi->peb_size);
ubi_assert(offset % ubi->hdrs_min_io_size == 0);
ubi_assert(len > 0 && len % ubi->hdrs_min_io_size == 0);
Annotation
- Immediate include surface: `linux/crc32.h`, `linux/err.h`, `linux/slab.h`, `ubi.h`.
- Detected declarations: `function ubi_io_read`, `function ubi_io_write`, `function do_sync_erase`, `function torture_peb`, `function nor_erase_prepare`, `function ubi_io_sync_erase`, `function ubi_io_is_bad`, `function ubi_io_mark_bad`, `function validate_ec_hdr`, `function ubi_io_read_ec_hdr`.
- 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.