13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
18 #include <linux/compiler.h>
20 #include <linux/sched.h>
30 static void jffs2_erase_callback(
struct erase_info *);
42 ret = jffs2_flash_erase(c, jeb);
44 jffs2_erase_succeeded(c, jeb);
51 jffs2_dbg(1,
"%s(): erase block %#08x (range %#08x-%#08x)\n",
56 pr_warn(
"kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n");
68 memset(instr, 0,
sizeof(*instr));
73 instr->
callback = jffs2_erase_callback;
74 instr->
priv = (
unsigned long)(&instr[1]);
89 jffs2_dbg(1,
"Erase at 0x%08x failed: %d. Refiling on erase_pending_list\n",
103 pr_warn(
"Erase at 0x%08x failed immediately: -EROFS. Is the sector locked?\n",
106 pr_warn(
"Erase at 0x%08x failed immediately: errno %d\n",
109 jffs2_erase_failed(c, jeb, bad_offset);
129 jffs2_mark_erased_block(c, jeb);
133 jffs2_dbg(1,
"Count reached. jffs2_erase_pending_blocks leaving\n");
139 jffs2_dbg(1,
"Starting erase of pending block 0x%08x\n",
153 jffs2_erase_block(c, jeb);
168 jffs2_dbg(1,
"jffs2_erase_pending_blocks completed\n");
218 static void jffs2_erase_callback(
struct erase_info *instr)
223 pr_warn(
"Erase at 0x%08llx finished, but state != MTD_ERASE_DONE. State is 0x%x instead.\n",
224 (
unsigned long long)instr->
addr, instr->
state);
227 jffs2_erase_succeeded(priv->
c, priv->
jeb);
235 static inline void jffs2_remove_node_refs_from_ino_list(
struct jffs2_sb_info *c,
245 if (!(*prev)->next_in_ino) {
268 prev = &((*prev)->next_in_ino);
274 " not found in remove_node_refs()!!\n");
278 jffs2_dbg(1,
"Removed nodes in range 0x%08x-0x%08x from ino #%u\n",
302 #ifdef CONFIG_JFFS2_FS_XATTR
319 jffs2_dbg(1,
"Freeing all node refs for eraseblock offset 0x%08x\n",
332 jffs2_remove_node_refs_from_ino_list(c, ref, jeb);
346 unsigned long *wordebuf;
352 jffs2_dbg(1,
"MTD point failed %d\n", ret);
357 jffs2_dbg(1,
"MTD point returned len too short: 0x%zx\n",
362 wordebuf = ebuf-
sizeof(*wordebuf);
363 retlen /=
sizeof(*wordebuf);
365 if (*++wordebuf != ~0)
370 pr_warn(
"Newly-erased block contained word 0x%lx at offset 0x%08tx\n",
381 pr_warn(
"Failed to allocate page buffer for verifying erase at 0x%08x. Refiling\n",
394 ret =
mtd_read(c->
mtd, ofs, readlen, &retlen, ebuf);
396 pr_warn(
"Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n",
401 if (retlen != readlen) {
402 pr_warn(
"Short read from newly-erased block at 0x%08x. Wanted %d, got %zd\n",
403 ofs, readlen, retlen);
407 for (i=0; i<readlen; i +=
sizeof(
unsigned long)) {
409 unsigned long *datum = ebuf +
i;
412 pr_warn(
"Newly-erased block contained word 0x%lx at offset 0x%08x\n",
413 *datum, *bad_offset);
433 switch (jffs2_block_check_erase(c, jeb, &bad_offset)) {
434 case -
EAGAIN:
goto refile;
435 case -
EIO:
goto filebad;
439 jffs2_dbg(1,
"Writing erased marker to block at 0x%08x\n", jeb->
offset);
462 vecs[0].iov_base = (
unsigned char *) ▮
463 vecs[0].iov_len =
sizeof(marker);
466 if (ret || retlen !=
sizeof(marker)) {
468 pr_warn(
"Write clean marker to block at 0x%08x failed: %d\n",
471 pr_warn(
"Short write to newly-erased block at 0x%08x: Wanted %zd, got %zd\n",
472 jeb->
offset,
sizeof(marker), retlen);
503 jffs2_erase_failed(c, jeb, bad_offset);