drivers/mtd/ubi/debug.c
Source file repositories/reference/linux-study-clean/drivers/mtd/ubi/debug.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/ubi/debug.c- Extension
.c- Size
- 19458 bytes
- Lines
- 698
- Domain
- Driver Families
- Bucket
- drivers/mtd
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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
ubi.hlinux/debugfs.hlinux/uaccess.hlinux/module.hlinux/seq_file.hlinux/fault-inject.h
Detected Declarations
function ubi_dump_flashfunction ubi_dump_ec_hdrfunction ubi_dump_vid_hdrfunction ubi_dump_vol_infofunction ubi_dump_vtbl_recordfunction ubi_dump_avfunction ubi_dump_aebfunction ubi_dump_mkvol_reqfunction dfs_create_fault_entryfunction ubi_debugfs_initfunction ubi_debugfs_exitfunction dfs_file_readfunction dfs_file_writefunction eraseblk_count_seq_stopfunction eraseblk_count_openfunction eraseblk_count_releasefunction ubi_debugfs_init_devfunction ubi_debugfs_exit_devfunction ubi_dbg_power_cut
Annotated Snippet
static const struct file_operations dfs_fops = {
.read = dfs_file_read,
.write = dfs_file_write,
.open = simple_open,
.owner = THIS_MODULE,
};
/* As long as the position is less then that total number of erase blocks,
* we still have more to print.
*/
static void *eraseblk_count_seq_start(struct seq_file *s, loff_t *pos)
{
struct ubi_device *ubi = s->private;
if (*pos < ubi->peb_count)
return pos;
return NULL;
}
/* Since we are using the position as the iterator, we just need to check if we
* are done and increment the position.
*/
static void *eraseblk_count_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
struct ubi_device *ubi = s->private;
(*pos)++;
if (*pos < ubi->peb_count)
return pos;
return NULL;
}
static void eraseblk_count_seq_stop(struct seq_file *s, void *v)
{
}
static int eraseblk_count_seq_show(struct seq_file *s, void *iter)
{
struct ubi_device *ubi = s->private;
struct ubi_wl_entry *wl;
int *block_number = iter;
int erase_count = -1;
int err;
/* If this is the start, print a header */
if (*block_number == 0)
seq_puts(s, "physical_block_number\terase_count\n");
err = ubi_io_is_bad(ubi, *block_number);
if (err)
return err;
spin_lock(&ubi->wl_lock);
wl = ubi->lookuptbl[*block_number];
if (wl)
erase_count = wl->ec;
spin_unlock(&ubi->wl_lock);
if (erase_count < 0)
return 0;
seq_printf(s, "%-22d\t%-11d\n", *block_number, erase_count);
return 0;
}
static const struct seq_operations eraseblk_count_seq_ops = {
.start = eraseblk_count_seq_start,
.next = eraseblk_count_seq_next,
.stop = eraseblk_count_seq_stop,
.show = eraseblk_count_seq_show
};
static int eraseblk_count_open(struct inode *inode, struct file *f)
{
struct seq_file *s;
int err;
err = seq_open(f, &eraseblk_count_seq_ops);
if (err)
return err;
s = f->private_data;
s->private = ubi_get_device((unsigned long)inode->i_private);
Annotation
- Immediate include surface: `ubi.h`, `linux/debugfs.h`, `linux/uaccess.h`, `linux/module.h`, `linux/seq_file.h`, `linux/fault-inject.h`.
- Detected declarations: `function ubi_dump_flash`, `function ubi_dump_ec_hdr`, `function ubi_dump_vid_hdr`, `function ubi_dump_vol_info`, `function ubi_dump_vtbl_record`, `function ubi_dump_av`, `function ubi_dump_aeb`, `function ubi_dump_mkvol_req`, `function dfs_create_fault_entry`, `function ubi_debugfs_init`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.