fs/jffs2/debug.c

Source file repositories/reference/linux-study-clean/fs/jffs2/debug.c

File Facts

System
Linux kernel
Corpus path
fs/jffs2/debug.c
Extension
.c
Size
26252 bytes
Lines
867
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ref_flags(fn->raw) == REF_PRISTINE) {
			if (fn->frags > 1) {
				JFFS2_ERROR("REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2.\n",
					ref_offset(fn->raw), fn->frags);
				bitched = 1;
			}

			/* A hole node which isn't multi-page should be garbage-collected
			   and merged anyway, so we just check for the frag size here,
			   rather than mucking around with actually reading the node
			   and checking the compression type, which is the real way
			   to tell a hole node. */
			if (frag->ofs & (PAGE_SIZE-1) && frag_prev(frag)
					&& frag_prev(frag)->size < PAGE_SIZE && frag_prev(frag)->node) {
				JFFS2_ERROR("REF_PRISTINE node at 0x%08x had a previous non-hole frag in the same page. Tell dwmw2.\n",
					ref_offset(fn->raw));
				bitched = 1;
			}

			if ((frag->ofs+frag->size) & (PAGE_SIZE-1) && frag_next(frag)
					&& frag_next(frag)->size < PAGE_SIZE && frag_next(frag)->node) {
				JFFS2_ERROR("REF_PRISTINE node at 0x%08x (%08x-%08x) had a following non-hole frag in the same page. Tell dwmw2.\n",
				       ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size);
				bitched = 1;
			}
		}
	}

	if (bitched) {
		JFFS2_ERROR("fragtree is corrupted.\n");
		__jffs2_dbg_dump_fragtree_nolock(f);
		BUG();
	}
}

/*
 * Check if the flash contains all 0xFF before we start writing.
 */
void
__jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
				    uint32_t ofs, int len)
{
	size_t retlen;
	int ret, i;
	unsigned char *buf;

	buf = kmalloc(len, GFP_KERNEL);
	if (!buf)
		return;

	ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
	if (ret || (retlen != len)) {
		JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n",
				len, ret, retlen);
		kfree(buf);
		return;
	}

	ret = 0;
	for (i = 0; i < len; i++)
		if (buf[i] != 0xff)
			ret = 1;

	if (ret) {
		JFFS2_ERROR("argh, about to write node to %#08x on flash, but there are data already there. The first corrupted byte is at %#08x offset.\n",
			ofs, ofs + i);
		__jffs2_dbg_dump_buffer(buf, len, ofs);
		kfree(buf);
		BUG();
	}

	kfree(buf);
}

static void __jffs2_dbg_superblock_counts(struct jffs2_sb_info *c)
{
	struct jffs2_eraseblock *jeb;
	uint32_t free = 0, dirty = 0, used = 0, wasted = 0,
		erasing = 0, bad = 0, unchecked = 0;
	int nr_counted = 0;
	int dump = 0;

	if (c->gcblock) {
		nr_counted++;
		free += c->gcblock->free_size;
		dirty += c->gcblock->dirty_size;
		used += c->gcblock->used_size;
		wasted += c->gcblock->wasted_size;
		unchecked += c->gcblock->unchecked_size;
	}

Annotation

Implementation Notes