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.

Dependency Surface

Detected Declarations

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

Implementation Notes